[R] Counting

Bill.Venables at csiro.au Bill.Venables at csiro.au
Tue Nov 16 23:54:21 CET 2010


Your outlier has row.names "1".  If this is selected in the bootstrap sample once, it will also have row.names "1".  If it is selected more than once the row.names of the successive entries will begin with "1."

Here is a possibility you may wish to consider.

> txt <- textConnection("
+              y           x
+ 1           10          25
+ 2   0.02769361 -0.02172165
+ 3   1.00927527 -1.80072610
+ 4   0.56504053 -1.12236685
+ 5   0.58332337 -1.24263981
+ 6  -1.70257274  0.46238255
+ 7  -0.88501561  0.89484429
+ 8   1.14466282  0.34193875
+ 9   0.58827457  0.15923694
+ 10 -0.79532232 -1.44193770
+ ")
> dat <- read.table(txt)
> close(txt)
> 
> bsample <- function(data) data[sample(nrow(data), rep = TRUE), ]
> 
> boots <- replicate(10000, bsample(dat), simplify = FALSE)
> check <- function(x) row.names(x) == "1" | 
+                      substring(row.names(x),0,2) == "1."
> table(sapply(boots, function(x) sum(check(x))))

   0    1    2    3    4    5    6 
3495 3868 1914  574  129   19    1 
> 


 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of ufuk beyaztas
Sent: Wednesday, 17 November 2010 8:44 AM
To: r-help at r-project.org
Subject: Re: [R] Counting


thank you very much for your idea,
if i write code as;
my data name is data.

samples<-function(data,num){
resamples<-lapply(1:num,function(i) sample(data,n,replace=TRUE))
list(resamples=resamples)}

>n=10
data<-rnorm(n=10,mean=5,sd=2)
data[1]=100
obj<-samples(data,1000)

i generate 1000 sample, i did not use 'boot'.  100 is a outlier in the data
set and same stuation, some of samples not contain , some of samples contain
once and some of them contain many times. Now can you tell me how i count
how many samples are there not contain any outlier in the 1000 samples?


-- 
View this message in context: http://r.789695.n4.nabble.com/Counting-tp3045756p3045842.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at 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.



More information about the R-help mailing list