[R] resampling problem counting number of means above a specific value

2009-11-15 Thread Graham Smith
I am trying to modify some code from Good 2005.

I am trying  to resample the mean of 8 values and then count how many
times the resampled mean is greater than 10. But my count of means
above 10 is coming out as zero, which I know isn't correct.

I would appreciate it if someone could look at the code below and tell
me what I am doing wrong.

Many thanks,

Graham

 LL- c(12.5,17,12,11.5,9.5,15.5,16,14)
 N-1000
 n-length(LL)
 threshold-10
 cnt-0
 for(i in 1:N){
+ LLb - sample (LL, n, replace=TRUE)
+ if (mean(LLb)=threshold) cnt-cnt+1
+ }
 cnt
[1] 0

__
R-help@r-project.org mailing list
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] resampling problem counting number of means above a specific value

2009-11-15 Thread David Winsemius


On Nov 15, 2009, at 12:12 PM, Graham Smith wrote:


I am trying to modify some code from Good 2005.

I am trying  to resample the mean of 8 values and then count how many
times the resampled mean is greater than 10. But my count of means
above 10 is coming out as zero, which I know isn't correct.


If that is your goal, then why are you using = and not  in your  
test?


 for(i in 1:N){
+  LLb - sample (LL, n, replace=TRUE)
+  if (mean(LLb)  threshold) cnt-cnt+1
+  }
 cnt
[1] 1000





I would appreciate it if someone could look at the code below and tell
me what I am doing wrong.

Many thanks,

Graham


LL- c(12.5,17,12,11.5,9.5,15.5,16,14)
N-1000
n-length(LL)
threshold-10
cnt-0
for(i in 1:N){

+ LLb - sample (LL, n, replace=TRUE)
+ if (mean(LLb)=threshold) cnt-cnt+1
+ }

cnt

[1] 0

__
R-help@r-project.org mailing list
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, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
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] resampling problem counting number of means above a specific value

2009-11-15 Thread Dimitris Rizopoulos

try the following:

LL - c(12.5,17,12,11.5,9.5,15.5,16,14)
n - length(LL)
N - 1000
threshold - 10

smpls - sample(LL, N*n, replace = TRUE)
dim(smpls) - c(n, N)
cnt - sum(colMeans(smpls)  threshold)
cnt


I hope it helps.

Best,
Dimitris


Graham Smith wrote:

I am trying to modify some code from Good 2005.

I am trying  to resample the mean of 8 values and then count how many
times the resampled mean is greater than 10. But my count of means
above 10 is coming out as zero, which I know isn't correct.

I would appreciate it if someone could look at the code below and tell
me what I am doing wrong.

Many thanks,

Graham


LL- c(12.5,17,12,11.5,9.5,15.5,16,14)
N-1000
n-length(LL)
threshold-10
cnt-0
for(i in 1:N){

+ LLb - sample (LL, n, replace=TRUE)
+ if (mean(LLb)=threshold) cnt-cnt+1
+ }

cnt

[1] 0

__
R-help@r-project.org mailing list
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.



--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

__
R-help@r-project.org mailing list
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] resampling problem counting number of means above a specific value

2009-11-15 Thread Graham Smith
David,

Thanks, its me getting mixed up I actually meant less than or equal to
10.  That apart, I guess the code is OK, I just expected, especially
as I increased N that I might have got some means less than 10, but
having gone back to it , I see I need a million iterations before
getting two means less than 10.

It seems I misjudged the probabilities.

Thanks again.

Graham



2009/11/15 David Winsemius dwinsem...@comcast.net:

 On Nov 15, 2009, at 12:12 PM, Graham Smith wrote:

 I am trying to modify some code from Good 2005.

 I am trying  to resample the mean of 8 values and then count how many
 times the resampled mean is greater than 10. But my count of means
 above 10 is coming out as zero, which I know isn't correct.

 If that is your goal, then why are you using = and not  in your test?

 for(i in 1:N){
 +  LLb - sample (LL, n, replace=TRUE)
 +  if (mean(LLb)  threshold) cnt-cnt+1
 +  }
 cnt
 [1] 1000


 I would appreciate it if someone could look at the code below and tell
 me what I am doing wrong.

 Many thanks,

 Graham

 LL- c(12.5,17,12,11.5,9.5,15.5,16,14)
 N-1000
 n-length(LL)
 threshold-10
 cnt-0
 for(i in 1:N){

 + LLb - sample (LL, n, replace=TRUE)
 + if (mean(LLb)=threshold) cnt-cnt+1
 + }

 cnt

 [1] 0

 __
 R-help@r-project.org mailing list
 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, MD
 Heritage Laboratories
 West Hartford, CT



__
R-help@r-project.org mailing list
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] resampling problem counting number of means above a specific value

2009-11-15 Thread Graham Smith
Dimitris,

Thanks, I shall give this a try as an alternative.

Graham

2009/11/15 Dimitris Rizopoulos d.rizopou...@erasmusmc.nl:
 try the following:

 LL - c(12.5,17,12,11.5,9.5,15.5,16,14)
 n - length(LL)
 N - 1000
 threshold - 10

 smpls - sample(LL, N*n, replace = TRUE)
 dim(smpls) - c(n, N)
 cnt - sum(colMeans(smpls)  threshold)
 cnt


 I hope it helps.

 Best,
 Dimitris


 Graham Smith wrote:

 I am trying to modify some code from Good 2005.

 I am trying  to resample the mean of 8 values and then count how many
 times the resampled mean is greater than 10. But my count of means
 above 10 is coming out as zero, which I know isn't correct.

 I would appreciate it if someone could look at the code below and tell
 me what I am doing wrong.

 Many thanks,

 Graham

 LL- c(12.5,17,12,11.5,9.5,15.5,16,14)
 N-1000
 n-length(LL)
 threshold-10
 cnt-0
 for(i in 1:N){

 + LLb - sample (LL, n, replace=TRUE)
 + if (mean(LLb)=threshold) cnt-cnt+1
 + }

 cnt

 [1] 0

 __
 R-help@r-project.org mailing list
 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.


 --
 Dimitris Rizopoulos
 Assistant Professor
 Department of Biostatistics
 Erasmus University Medical Center

 Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
 Tel: +31/(0)10/7043478
 Fax: +31/(0)10/7043014


__
R-help@r-project.org mailing list
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.