Re: [R] [FORGED] how to draw the confidence interval

2017-03-05 Thread laomeng_3
this is not homework,just a case which I made by myself.


��ʦ



On 2017-03-06 06:47 , Rolf Turner Wrote:

On 04/03/17 19:39, laomeng_3 wrote:
> hi all I have a question about drawing the confidence interval .
>
> For instance,if I want to sample 100 times,and each time,the sample
> size is 10,and the mean and sd is 15 and 1 respectively .I want to draw
> the 100 confidence intervals(as the attachment) .Which function should
> be used to draw the confidence interval ?

This list does not answer questions about homework.

(BTW, no attachment came through; only a *very* limited range of file
types is permitted for attachments).

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] help

2017-03-05 Thread David Winsemius

> On Mar 4, 2017, at 10:00 AM, Nikhil Raj  wrote:
> 
> hello Team R,
> i have been using R for statistical analysis of phylogeny and i have
> installed the required packages phangorn and phytools but whenever i give
> the command "pml.fit" the program stops and it appears thatb r for windows
> GUI has stopped etc..

What does it mean to `give the command "pml.fit"`?

(R is a functional language so it doesn't really have "commands". It is a 
language where function names are entered followed by a left-parenthesis, 
followed by arguments and closed by a right parenthesis. This then returns a 
value to the read-eval-print loop and if that expression has an assignment 
operator to its left then the value would be stored in a data object.)


> previously i thought it was a fault in my computer but it appears to happen
> the same when i give the command in any other computer.
> can i get a solution for this i have tried it on windows 10 and older
> versions can it be fixed?
> and also can you please send me the the commands for performing SH test of
> phylogeny using phangorn if possible.

Most packages have help pages where sample code appears at the bottom of the 
page for a particular function. This particular function appears designed as 
"internal" meaning that you should have followed the See Also links at the 
bottom of its page.


> please do reply

And do, sir or madam, read the posting guide reference below.

> 
> thank you
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Text cutoff in legends

2017-03-05 Thread Jim Lemon
Hi Burhan,
I think you may have set records in both obscurity and brevity (watch
out, Jeff). Undeterred, I will guess that you have positioned the
legend so that it runs off the plot. Try adding the "xpd=TRUE"
argument to the call to legend.

Jim


On Sun, Mar 5, 2017 at 10:56 AM, Burhan Mohamedali
 wrote:
> R adds cut tea e
>
> Excuse my brevity;to  this message is sent from my iPhonequ
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] (no subject)

2017-03-05 Thread Bert Gunter
Well, this is your 3rd post to appear here with no replies. At what
point will you stop posting and realize that no one here is able or
willing to answer your almost incomprehensible post?

However, you might try to contact the package maintainer to see if
this is a bug ( -- you **have the latest version of the package**, do
you not?).

As for providing free consulting help  lots of luck with that!
Read the posting guide to learn what sort of help you can expect here.

cheers,
Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sat, Mar 4, 2017 at 9:59 AM, Nikhil Raj  wrote:
> hello Team R,
> i have been using R for statistical analysis of phylogeny and i have
> installed the required packages phangorn and phytools but whenever i give
> the command "pml.fit" the program stops and it appears thatb r for windows
> GUI has stopped etc..
> previously i thought it was a fault in my computer but it appears to happen
> the same when i give the command in any other computer.
> can i get a solution for this i have tried it on windows 10 and older
> versions can it be fixed?
> and also can you please send me the the commands for performing SH test of
> phylogeny using phangorn if possible.
> please do reply
>
> thank you
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] array - how to create "logical expression" for subset dynamically

2017-03-05 Thread Bert Gunter
A great example of why you need to read and follow the posting guide
-- this is a plain text list: NO HTML.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Mar 3, 2017 at 9:59 AM, exponential  wrote:
> Hi!   I've tried on SO, but without success. Maybe you will be able to 
> help.   I have the following array (I use 3-dimensional in this example for 
> simplicity, but it can be 3+ dims - 10,11 or more):   a <- c('a1', 
> 'a2', 'a3')  b <- c('bb', 'bbb')  c <- 
> c('C', 'CC', 'CCC')   dimNa <- list('a' = 
> a, 'b' = b, 'c' = c)   outputArray <- array(NA,
>   unname(sapply(dimNa, function(x) length(x), simplify = T)), 
>  unname(dimNa))   I can subset it using name from one dimension manually, 
> like:   > outputArray[,'bb',]  C CC CCC  a1 NA NA  NA  a2 NA 
> NA  NA  a3 NA NA  NA   or   > outputArray[,,'CCC'] bb bbb  a1 
> NA  NA  a2 NA  NA  a3 NA  NA   I would like to write a function which subsets 
> particular named element from one dimension (I mean I don't expect one 
> dimension as a result by slicing using one named element, if tha!
 t makes sense). Something like myfunc <- function(inputArray, 
namedElement)   thus I can call it (using above example):   myfunc(outputArray, 
'bb')   ormyfunc(outputArray, 'CCC')   to get identical as 
above results.   I know how to deal with finding to which dimension 
"namedElement" belongs (in my case all names are unique).   The 
question is how to subset it from the array? One idea is to construct what is 
inside [ ] (in example: ,'bb', or ,,'CCC'). I've tried 
something like this:inputDims <- ",,'CCC'"   
outputArray[parse(text=inputDi   But this doesn't work. Maybe different 
approach should be used...   Any ideas are welcome:)!   Cheers!
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Error in curve 'expr' did not evaluate to an object of length 'n'

2017-03-05 Thread William Dunlap via R-help
You define a function called running.acf.max and then call
plot(running.acf.max)
R's plot, when given a function f, makes a plot of f(x) vs. x
by calling curve().

Did you mean to plot the result of running.acf.max with its
default arguments?  That would be done with
plot(running.acf.max())

There are several other problems with this code.  E.g., you have
  running.acf.max <-
  function (data = returns, window = 100, nlags = 5, plot = T, main = "")
  {
  clevel <- qnorm(0.5 + 0.95/2)/sqrt(window)
  series <- rollapply(data = returns, window, align = "right",
  by = 1, function(w) {
  ...

You should have data=data in the call to rollapply so it depends
on the 'data' argument to running.acf.max.

Use traceback() after an error to see where the error came from.



Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Mar 3, 2017 at 4:43 AM, Allan Tanaka  wrote:
> Please help. I try to re-produce R-script by plotting a set of functionWhen i 
> running code: plot(Vectorize(running.acf.max))it gets the error message like 
> this: Error in curve(expr = x, from = from, to = to, xlim = xlim, ylab = 
> ylab,  :   'expr' did not evaluate to an object of length 'n'
> Even though i have vectorized the function argument.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] List raster files

2017-03-05 Thread Robert Baer

On 3/4/2017 7:54 AM, Tomás Pérez C. wrote:

I am working with raster images of modis of the satellites aqua and terra
and I need to combine the images by its day and year (originally in Julian
day). However, for the earth I have 6031 images and for aqua 5277. I want
to know how to create an object that selects the images for both folders
with their same date and then create a loop after.
Thank you
You will need to provide more information on how where date information 
is stored and how the files are organized to get any useful response.  
If you are using file time stamps, I'm guessing some system info might 
be useful.  Please read the posting guide and see what you can do to 
help the list help you.







[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [FORGED] Error in curve 'expr' did not evaluate to an object of length 'n'

2017-03-05 Thread Rolf Turner

On 04/03/17 01:43, Allan Tanaka wrote:

Please help. I try to re-produce R-script by plotting a set of functionWhen i 
running code: plot(Vectorize(running.acf.max))it gets the error message like 
this: Error in curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab,  
:   'expr' did not evaluate to an object of length 'n'
Even though i have vectorized the function argument.


Your example is not reproducible.  We do not have the file 
EURJPY.m14401.csv.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [FORGED] AED package

2017-03-05 Thread Rolf Turner

On 05/03/17 20:20, Ibrahim Salman wrote:

Dear all,

I am trying to run corvif command in R and apparently it needs AED package.
Does anyone know where can I find this package ?


Have you ever heard of "Google"?

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] array - how to create "logical expression" for subset dynamically

2017-03-05 Thread Rolf Turner

On 04/03/17 06:59, exponential wrote:

Hi! I've tried on SO, but without success. Maybe you will be
able

to help. I have the following array (I use 3-dimensional in this example
for simplicity, but it can be 3+ dims - 10,11 or more): a <-
c('a1', 'a2', 'a3') b <- c('bb',
'bbb') c <- c('C', 'CC', 'CCC') dimNa
<- list('a' = a, 'b' = b, 'c' = c)
outputArray <- array(NA, unname(sapply(dimNa, function(x) length(x),
simplify = T)), unname(dimNa)) I can subset it using name from one
dimension manually, like: > outputArray[,'bb',] C CC CCC a1
NA NA NA a2 NA NA NA a3 NA NA NA or > outputArray[,,'CCC'] bb
bbb a1 NA NA a2 NA NA a3 NA NA I would like to write a function which
subsets particular named element from one dimension (I mean I don't
expect one dimension as a result by slicing using one named element, if
that makes sense). Something like myfunc <- function(inputArray,
namedElement) thus I can call it (using above example):
myfunc(outputArray, 'bb') or myfunc(outputArray, 'CCC')
to get identical as above results. I know how to deal with finding to
which dimension "namedElement" belongs (in my case all names are
unique). The question is how to subset it from the array? One idea is to
construct what is inside [ ] (in example: ,'bb', or
,,'CCC'). I've tried something like this: inputDims <-
",,'CCC'" outputArray[parse(text=inputDi But this
doesn't work. Maybe different approach should be used... Any ideas
are welcome:)! Cheers!


DO NOT post in HTML.  Your mail was an incomprehensible mess.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [FORGED] how to draw the confidence interval

2017-03-05 Thread Rolf Turner

On 04/03/17 19:39, laomeng_3 wrote:

hi all I have a question about drawing the confidence interval .

For instance,if I want to sample 100 times,and each time,the sample
size is 10,and the mean and sd is 15 and 1 respectively .I want to draw
the 100 confidence intervals(as the attachment) .Which function should
be used to draw the confidence interval ?


This list does not answer questions about homework.

(BTW, no attachment came through; only a *very* limited range of file 
types is permitted for attachments).


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] AED package

2017-03-05 Thread Ibrahim Salman
Dear all,

I am trying to run corvif command in R and apparently it needs AED package.
Does anyone know where can I find this package ?

Thanks a lot,
Ibrahim



--




Ibrahim N. Salman ​
Master Student
Prof. Yael Lubin's Lab
Mitrani Department of Desert Ecology
Ben-Gurion University of the Negev
Midreshet Ben-Gurion 84900, Israel

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] (no subject)

2017-03-05 Thread Nikhil Raj
hello Team R,
i have been using R for statistical analysis of phylogeny and i have
installed the required packages phangorn and phytools but whenever i give
the command "pml.fit" the program stops and it appears thatb r for windows
GUI has stopped etc..
previously i thought it was a fault in my computer but it appears to happen
the same when i give the command in any other computer.
can i get a solution for this i have tried it on windows 10 and older
versions can it be fixed?
and also can you please send me the the commands for performing SH test of
phylogeny using phangorn if possible.
please do reply

thank you

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] List raster files

2017-03-05 Thread Tomás Pérez C .
I am working with raster images of modis of the satellites aqua and terra
and I need to combine the images by its day and year (originally in Julian
day). However, for the earth I have 6031 images and for aqua 5277. I want
to know how to create an object that selects the images for both folders
with their same date and then create a loop after.
Thank you

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Text cutoff in legends

2017-03-05 Thread Burhan Mohamedali
R adds cut tea e

Excuse my brevity;to  this message is sent from my iPhonequ

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] regarding a problem in R

2017-03-05 Thread Nikhil Raj
hello Team R,
i have been using R for statistical analysis of phylogeny and i have
installed the required packages phangorn and phytools but whenever i give
the command "pml.fit" the program stops and it appears thatb r for windows
GUI has stopped etc..
previously i thought it was a fault in my computer but it appears to happen
the same when i give the command in any other computer.
can i get a solution for this i have tried it on windows 10 and older
versions can it be fixed?
and also can you please send me the the commands for performing SH test of
phylogeny using phangorn if possible.
please do reply

thank you

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Heatmap help

2017-03-05 Thread Patricia J. Hawkins
Hi, you have a couple of things going on here.  You can reorder your
matrix by creating an index like this:

> A_index=c(grep(".A", colnames(A)), grep(".B", colnames(A)))

and do this:

> heatmap.2(A[,A_index], dendrogram="col", Rowv = colnames(A)[A_index], 
> tracecol =
  NA,col=bluered(64), sub = "",
  distfun = function(y) dist(y, method = "euclidean"), hclustfun =
  function(y) hclust(y, method = "median"),
  scale = "row",cexCol = 1, cexRow = 0.9, ylab = "Enzymes", xlab =
 "Samples", margins = c(9,9), keysize = 1,
  main='Test')

But you're constructing your dendrogram on the columns, so your columns
get reordered by mean weight.  (Also, you've misunderstood Rowv and Colv.)

However, if you force your columns to not reorder by setting
"Colv=FALSE", AND tell it to construct the dendrogram on the columns,
you get a warning, because that's contradictory:

> heatmap.2(A[,A_index], dendrogram="col", Colv = FALSE, tracecol = 
> NA,col=bluered(64), sub = "",
  distfun = function(y) dist(y, method = "euclidean"),  
  hclustfun = function(y) hclust(y, method = "median"),
  scale = "row",cexCol = 1, cexRow = 0.9, ylab = "Enzymes", xlab =
  "Samples", margins = c(9,9), keysize = 1, main='Test')
Warning message:
In heatmap.2(A[, A_index], dendrogram = "col", Colv = FALSE, tracecol = NA,  :
  Discrepancy: Colv is FALSE, while dendrogram is `column'. Omitting column 
dendogram.

Maybe you really meant to build your dendrogram on the rows, like this:

heatmap.2(A[,A_index], dendrogram="row", Colv = FALSE, tracecol = 
NA,col=bluered(64), sub = "",
  distfun = function(y) dist(y, method = "euclidean"),  
  hclustfun = function(y) hclust(y, method = "median"),
  scale = "row",cexCol = 1, cexRow = 0.9, ylab = "Enzymes", xlab =
  "Samples", margins = c(9,9), keysize = 1, main='Test')

If that's not it, I suggest playing around with the examples in
?heatmap.2 since the documentation is kind of opaque, but the examples
are pretty good.

> "ALN" == André Luis Neves  writes:

ALN> Dear all,

ALN> I was wondering if you could help me to construct a heat map, in which the
ALN> columns are sorted by sample type (A first and then B).
ALN> My reproducible example below runs, but the columns of the heatmap are not
ALN> organized in the way I would like because it has first sampleA, SampleB,
ALN> sampleA, and then sampleB.


ALN> A = matrix(rnorm(20), 5,8)
ALN> A
ALN> colnames(A) <- c ("Sample1.A", "Sample2.B", "Sample3.A", "Sample4.B",
ALN> "Sample5.A", "Sample6.B", "Sample7.A", "Sample8.B")
ALN> A
ALN> rownames(A) <- c ("protein1","protein2", "protein3", "protein4","protein5")
ALN> A

ALN> heatmap.2(A, dendrogram="col", Rowv = colnames(A), tracecol =
ALN> NA,col=bluered(64), sub = "",
ALN>   distfun = function(y) dist(y, method = "euclidean"), hclustfun =
ALN> function(y) hclust(y, method = "median"),
ALN>   scale = "row",cexCol = 1, cexRow = 0.9, ylab = "Enzymes", xlab =
ALN> "Samples", margins = c(9,9), keysize = 1,
ALN>   main='Test')



ALN> ​Thanks.

ALN> -- 
ALN> Andre

ALN>[[alternative HTML version deleted]]

ALN> __
ALN> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
ALN> https://stat.ethz.ch/mailman/listinfo/r-help
ALN> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
ALN> and provide commented, minimal, self-contained, reproducible code.



-- 
Patricia J. Hawkins

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] help

2017-03-05 Thread Nikhil Raj
hello Team R,
i have been using R for statistical analysis of phylogeny and i have
installed the required packages phangorn and phytools but whenever i give
the command "pml.fit" the program stops and it appears thatb r for windows
GUI has stopped etc..
previously i thought it was a fault in my computer but it appears to happen
the same when i give the command in any other computer.
can i get a solution for this i have tried it on windows 10 and older
versions can it be fixed?
and also can you please send me the the commands for performing SH test of
phylogeny using phangorn if possible.
please do reply

thank you

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R code helps needed!

2017-03-05 Thread SH
Hi Jim,

I added more codes besides your original ones.  I bet there should be
simpler way(s) to do this but this is the best I can think of.  Any
feedback from you and others will be highly appreciated.

Thanks a lot!

Steve

result<-read.table(text=
 "intercept decision expected.decision
 1 reject reject
 2 reject reject
 3 reject reject
 0 pass pass
 3 reject skip
 0 pass skip
 3 reject skip
 5 reject skip
 0 pass skip
 0 pass pass
 3 reject skip
 1 reject skip
 0 pass skip
 0 pass skip
 2 reject skip
 1 reject reject
 0 pass pass
 3 reject skip
 0 pass skip
 2 reject skip
 0 pass skip
 1 reject skip
 2 reject reject
 2 reject reject
",
 header=TRUE,stringsAsFactors=FALSE)
int <- result$intercept
int
# [1] 1 2 3 0 3 0 3 5 0 0 3 1 0 0 2 1 0 3 0 2 0 1 2 2
pass.theo <- which(int==0)
pass.theo
#[1]  4  6  9 10 13 14 17 19 21
lv1 <- int==0
lv1
# [1] FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE  TRUE  TRUE FALSE
FALSE
#[13]  TRUE  TRUE FALSE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE
FALSE
pass.1st <- min(which(lv1==TRUE))
pass.1st
#[1] 4

m <- c(0:100)
 interval <- 6*m + pass.1st
 interval
# [1]   4  10  16  22  28  34  40  46  52  58  64  70  76  82  88  94 100
106
 #[19] 112 118 124 130 136 142 148 154 160 166 172 178 184 190 196 202 208
214
 #[37] 220 226 232 238 244 250 256 262 268 274 280 286 292 298 304 310 316
322
 #[55] 328 334 340 346 352 358 364 370 376 382 388 394 400 406 412 418 424
430
 #[73] 436 442 448 454 460 466 472 478 484 490 496 502 508 514 520 526 532
538
 #[91] 544 550 556 562 568 574 580 586 592 598 604
interval2 <- c(interval[interval<=length(int)], length(int))
interval2
#[1]  4 10 16 22 24
 pass.theo
#[1]  4  6  9 10 13 14 17 19 21

res <- as.list(NULL)
> for(i in 1:(length(interval2)-1)){
 res[[i]] <- min(pass.theo[pass.theo >= interval2[i] & pass.theo <
interval2[i+1]])
 res
 }
#Warning message:
#In min(pass.theo[pass.theo >= interval2[i] & pass.theo < interval2[i +  :
 # no non-missing arguments to min; returning Inf
res
#[[1]]
#[1] 4
#[[2]]
#[1] 10
#[[3]]
#[1] 17
#[[4]]
#[1] Inf

res <- unlist(res)
passes <- res[is.finite(res)]
passes
#[1]  4 10 17

skips<-as.vector(sapply(passes,function(x) return(x+1:5)))
skips2 <- skips[skips<=length(int)]
new.decision <- result$decision
new.decision[skips2] <- 'skip'
new.decision
# [1] "reject" "reject" "reject" "pass"   "skip"   "skip"   "skip"
"skip"
 #[9] "skip"   "pass"   "skip"   "skip"   "skip"   "skip"   "skip"
"reject"
#[17] "pass"   "skip"   "skip"   "skip"   "skip"   "skip"   "reject"
"reject"
cbind(result, new.decision)
#   intercept decision expected.decision  new.decision
#1  1   rejectreject reject
#2  2   rejectreject reject
#3  3   rejectreject reject
#4  0 pass  pass   pass
#5  3   reject  skip   skip
#6  0 pass  skip   skip
#7  3   reject  skip   skip
#8  5   reject  skip   skip
#9  0 pass  skip   skip
#10 0 pass  pass   pass
#11 3   reject  skip   skip
#12 1   reject  skip   skip
#13 0 pass  skip   skip
#14 0 pass  skip   skip
#15 2   reject  skip   skip
#16 1   rejectreject reject
#17 0 pass  pass   pass
#18 3   reject  skip   skip
#19 0 pass  skip   skip
#20 2   reject  skip   skip
#21 0 pass  skip   skip
#22 1   reject  skip   skip
#23 2   rejectreject reject
#24 2   rejectreject reject


On Fri, Mar 3, 2017 at 8:00 AM, SH  wrote:

> Hi Jim,
>
> Thank you very much for replying back.
>
> I think the data I presented have not many 'pass' than I thought.  The
> purpose of the code is to skip sampling for 5 consecutive rows when a
> previous row is found as 'pass'.  Thus, because the fourth row is
> 'pass', sampling will be skipped next five rows (i.e., from 5th to 9th
> rows).  Therefore any 'pass' within next 5 rows after first 'pass' should
> not affect 'skip'.  Could you try this?  Based on your code, I
> guess 'return' function may be one I should search.  I haven't used it
> before so I am not familiar with the function.  I made a new data set with
> 'expected.decision' column.  In the data set, once a 'pass' is found, the
> next sampling starts 5 rows after.  For example, since the forth row is
> 'pass',  the next sampling starts at 10th row.  Although 6th row should be
> 'pass', I want to label them as 'skip' since no sampling is made.
>
> The objective of the study is to investigate how many of 'reject' rows get
> 'skip' with a given sampling scheme, the rate of 'pass' because of skip
> sampling which should be 'reject'.
>
> Could you also try this data and give me your feedback?  Thanks agai

[R] how to draw the confidence interval

2017-03-05 Thread laomeng_3
hi all
I have a question about drawing the confidence interval .

For instance,if I want to sample 100 times,and each time,the sample size is 
10,and  the mean and sd is 15 and 1 respectively .I want to draw the 100 
confidence intervals(as the attachment) .Which function should be used to draw 
the confidence interval ?

Many thanks!



发自网易邮箱大师
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] R code helps needed!

2017-03-05 Thread SH
Hi Jim,

Thank you very much for replying back.

I think the data I presented have not many 'pass' than I thought.  The
purpose of the code is to skip sampling for 5 consecutive rows when a
previous row is found as 'pass'.  Thus, because the fourth row is
'pass', sampling will be skipped next five rows (i.e., from 5th to 9th
rows).  Therefore any 'pass' within next 5 rows after first 'pass' should
not affect 'skip'.  Could you try this?  Based on your code, I
guess 'return' function may be one I should search.  I haven't used it
before so I am not familiar with the function.  I made a new data set with
'expected.decision' column.  In the data set, once a 'pass' is found, the
next sampling starts 5 rows after.  For example, since the forth row is
'pass',  the next sampling starts at 10th row.  Although 6th row should be
'pass', I want to label them as 'skip' since no sampling is made.

The objective of the study is to investigate how many of 'reject' rows get
'skip' with a given sampling scheme, the rate of 'pass' because of skip
sampling which should be 'reject'.

Could you also try this data and give me your feedback?  Thanks again for
you helps!!!

Steve

result<-read.table(text=
"intercept decision expected.decision
 1 reject reject
 2 reject reject
 3 reject reject
 0 pass pass
 3 reject skip
 0 pass skip
 3 reject skip
 5 reject skip
0 pass skip
 0 pass pass
3 reject skip
 1 reject skip
 0 pass skip
 0 pass skip
 2 reject skip
 1 reject reject
 0 pass pass
 3 reject skip
 0 pass skip
 2 reject skip
 0 pass skip
 1 reject skip
 2 reject reject
 2 reject reject
",
  header=TRUE,stringsAsFactors=FALSE)
 passes<-which(result$intercept == 0)
 skips<-as.vector(sapply(passes,function(x) return(x+1:5)))
 result$decision[skips]<-"skip"
result



On Thu, Mar 2, 2017 at 5:42 PM, Jim Lemon  wrote:

> Hi Steve,
> Try this:
>
> result<-read.table(text=
>"intercept decision
>  1   reject
>  2   reject
>  3   reject
>  0   pass
>  3   reject
>  2   reject
>  3   reject
>  5   reject
>  3   reject
>  1   reject
>  1   reject
>  2   reject
>  2   reject
>  0   pass
>  3   reject
>  3   reject
>  2   reject
>  2   reject
>  1   reject
>  1   reject
>  2   reject
>  2   reject",
>  header=TRUE,stringsAsFactors=FALSE)
> passes<-which(result$intercept == 0)
> skips<-as.vector(sapply(passes,function(x) return(x+1:5)))
> result$decision[skips]<-"skip"
>
> Note that result$decision must be a character variable for this to
> work.If it is a factor, convert it to character.
>
> Jim
>
>
> On Thu, Mar 2, 2017 at 11:54 PM, SH  wrote:
> > Hi
> >
> > Although I posted this in stackoverflow yesterday, I am asking here to
> get
> > helps as soon as quickly.
> >
> > I need help make code for mocking sampling environment. Here is my code
> > below:
> >
> > First, I generated mock units with 1000 groups of 100 units. Each row is
> > considered as independent sample space.
> >
> > unit <- 100 # Total units
> > bad.unit.rate <- .05 # Proportion of bad units
> > bad.unit.num <- ceiling(unit*bad.unit.rate) # Bad units
> > n.sim=1000
> > unit.group <- matrix(0, nrow=n.sim, ncol=unit)for(i in 1:n.sim){
> > unit.group[i, ] <- sample(rep(0:1, c(unit-bad.unit.num,
> bad.unit.num)))}
> > dim(unit.group)
> >
> > It gives 1000 by 100 groups
> >
> > ss <- 44 # Selected sample size
> >
> > 44 out of 100 units will be selected and decision (pass or reject) will
> be
> > made based on sampling.
> >
> > This below is decision code:
> >
> > intercept <- rep(0, nrow(unit.group))
> > decision <- rep(0, nrow(unit.group))
> > set.seed(2017)for(i in 1:nrow(unit.group)){
> > selected.unit <- sample(1:unit, ss)
> > intercept[i] <- sum(unit.group[i,][selected.unit])
> > decision[i] <- ifelse(intercept[i]==0, 'pass', 'reject')
> > result <- cbind(intercept, decision)
> > result}
> > dim(result)
> > head(result, 30)
> >
> >> head(result, 30)
> >   intercept decision
> >  [1,] "1"   "reject"
> >  [2,] "2"   "reject"
> >  [3,] "3"   "reject"
> >  [4,] "0"   "pass"
> >  [5,] "3"   "reject"
> >  [6,] "2"   "reject"
> >  [7,] "3"   "reject"
> >  [8,] "5"   "reject"
> >  [9,] "3"   "reject"
> > [10,] "1"   "reject"
> > [11,] "1"   "reject"
> > [12,] "2"   "reject"
> > [13,] "2"   "reject"
> > [14,] "0"   "pass"
> > [15,] "3"   "reject"
> > [16,] "3"   "reject"
> > [17,] "2"   "reject"
> > [18,] "2"   "reject"
> > [19,] "1"   "reject"
> > [20,] "1"   "reject"
> > [21,] "2"   "reject"
> > [22,] "2"   "reject"
> >
> > I was able to make a decision for each 1000 rows based on sampling as
> above.
> >
> > Now, I want to make code for "second" decision option as follows.
> Assuming
> > the row number is in order of time or sequence, if 'intercept' value is 0
> > or 'decision' is 'pass' in the row 4 above, I want to skip any decision
> > next following 5 (or else) and t

[R] array - how to create "logical expression" for subset dynamically

2017-03-05 Thread exponential
Hi!   I've tried on SO, but without success. Maybe you will be able to 
help.   I have the following array (I use 3-dimensional in this example for 
simplicity, but it can be 3+ dims - 10,11 or more):   a <- c('a1', 
'a2', 'a3')  b <- c('bb', 'bbb')  c <- 
c('C', 'CC', 'CCC')   dimNa <- list('a' = a, 
'b' = b, 'c' = c)   outputArray <- array(NA,     
 unname(sapply(dimNa, function(x) length(x), simplify = T)),      
unname(dimNa))   I can subset it using name from one dimension manually, like:  
 > outputArray[,'bb',]      C CC CCC  a1 NA NA  NA  a2 NA NA  NA  a3 
NA NA  NA   or   > outputArray[,,'CCC']     bb bbb  a1 NA  NA  a2 NA 
 NA  a3 NA  NA   I would like to write a function which subsets particular 
named element from one dimension (I mean I don't expect one dimension as a 
result by slicing using one named element, if that makes sense). Something like 
    myfunc <- function(inputArray, namedElement)   thus I can call it (using 
above example):   myfunc(outputArray, 'bb')   or    myfunc(outputArray, 
'CCC')   to get identical as above results.   I know how to deal with 
finding to which dimension "namedElement" belongs (in my case all names 
are unique).   The question is how to subset it from the array? One idea is to 
construct what is inside [ ] (in example: ,'bb', or ,,'CCC'). 
I've tried something like this:    inputDims <- 
",,'CCC'"   outputArray[parse(text=inputDi   But this 
doesn't work. Maybe different approach should be used...   Any ideas are 
welcome:)!   Cheers!

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] Error in curve 'expr' did not evaluate to an object of length 'n'

2017-03-05 Thread Allan Tanaka
Please help. I try to re-produce R-script by plotting a set of functionWhen i 
running code: plot(Vectorize(running.acf.max))it gets the error message like 
this: Error in curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab,  
:   'expr' did not evaluate to an object of length 'n'
Even though i have vectorized the function argument.
data = read.csv("EURJPY.m14401.csv", header=T)
returns  = diff(log(data$C))
running.acf.max<-function(data=returns, window=100, nlags=5, plot=T, main=''){
  clevel<-qnorm(0.5+0.95/2)/sqrt(window)
  series<-rollapply(data=returns, window, align='right',by=1,function(w)
  {
acfs<-pacf(coredata(w),lag.max=nlags,plot=F)$acf
cum<-cumsum(acfs)
low<-min(cum)
high<-max(cum)
if(abs(low)>abs(high))
  low
else 
  high
  })
  if(plot)
  {
plot(series,main=main,cex.axis=0.65,xlab='',ylab='acf(cum max)')
abline(h=0,col='blue')
abline(h=-clevel,col='red', lty=2)
abline(h=clevel,col='red', lty=2)
  }
  invisible(series)
}
plot(running.acf.max)
plot(Vectorize(running.acf.max))__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.