Re: [R] bootstrap help

2010-01-06 Thread Dennis Murphy
Hi: Does this work? df <- data.frame(x = rnorm(49, mean = 1), y = rnorm(49, mean = 2)) # Generate matrix of bootstrap indices idx <- matrix(sample(1:nrow(df), 50 * nrow(df), replace = TRUE), nrow = nrow(df)) dim(idx) # [1] 49 50 # Generate the corresponding x, y, bootstrap samples by

Re: [R] bootstrap help

2010-01-06 Thread luciferyan
I have a similar question. I want to generate list of 50 bootstrap samples, it can be done by: lapply(1:50,function(i){data[sample(nrow(data),size=nrow(data),replace=TRUE),]}) >From these bootstrap samples, I want to work out the Bootstrap estimates, which is E[y]/E[x]. How can I do it? '>> da

Re: [R] bootstrap help

2009-12-07 Thread Marek Janad
If I read your question now, I think, that I didn't understand you correctly, but... My code generates 50 bootstrap samples (50 tables) and for each calculates mean of column x and mean of column y, so the final result is matrix with means. If you don't want to calculate means, code below generat

Re: [R] bootstrap help

2009-12-06 Thread casperyc
Hi there, This seems to 'simple' for that. ( I mean the codes are too good) Can I ask for a bit explaination? or some simplier (maybe few more line codes) to archieve that goal? And the codes you gave here, first line give a table with x and y , random normal values, but the second line, what d

[R] bootstrap help

2009-12-06 Thread Casper
Hi, I have a dataframe with x and y in pairs, ( 49 pairs i.e. 49 rows ) x y 76 80 138 143 67 67 29 50 381 464 23 48 37 63 120 115 how do i generate 50 Bootstrap samples and corresponding estimates? i have tried sample( data, size=50,replace=T) does not seem to be right Thanks.

Re: [R] bootstrap help

2009-12-06 Thread Marek Janad
data<-data.frame(x=rnorm(49), y=rnorm(49)) t(sapply(1:50,function(i){colMeans(data[sample(nrow(data),size=nrow(data),replace=TRUE),])})) r-help@r-project.org 2009/12/7 casperyc : > > Hi there, > > i think that's not what i was aiming for... > > i was aked to > > Generate 50 Bootstrap samples and

Re: [R] bootstrap help

2009-12-06 Thread casperyc
Hi there, i think that's not what i was aiming for... i was aked to Generate 50 Bootstrap samples and corresponding estimates if i do data[sample(nrow(data),size=50,replace=TRUE),] it will give me a table of 50 rows ( 50 sets of x and y) then how do i estimate the mean? ( mean was esitmated b

Re: [R] bootstrap help

2009-12-06 Thread Ben Bolker
casperyc hotmail.co.uk> writes: > I have 49 pairs in my data.frame 'data' > > x y > 7680 > ... ... > > how do I get a bootstrap sample of size n=50? > data[sample(nrow(data),size=50,replace=TRUE),] __ R-help@r-project.org mailing list http

[R] bootstrap help

2009-12-06 Thread casperyc
Hi, I have 49 pairs in my data.frame 'data' x y 76 80 138 143 67 67 29 50 381 464 23 48 37 63 120 115 ... ... how do I get a bootstrap sample of size n=50? i have tried sample(data,size=50,replace=TRUE) and sample(data,replace=TRUE) both didnt see