[R] bootstrap help

Marek Janad marek.janad at gmail.com
Mon Dec 7 22:56:34 CET 2009


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 generates list of 50
bootstrap samples.

lapply(1:50,function(i){data[sample(nrow(data),size=nrow(data),replace=TRUE),]})

Please check help if some functions aren't understandable.

2009/12/7 casperyc <casperyc at hotmail.co.uk>:
>
> 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 does that do?
>
> I totally can't follow that line.
> the result is a 50 by 2 table.
> what is that? is a sample?
>
> Thanks.
>
> casper
>
>
>
>
> Marek Janad wrote:
>>
>> 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 at r-project.org
>>
>> 2009/12/7 casperyc <casperyc at hotmail.co.uk>:
>>>
>>> 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 by the
>>> bar{x}/bar{y} )
>>>
>>> i mis undertood that too.
>>> but now, i think what i actually need is
>>>
>>> 50 sets of this kind (49 rows) of tables from bootstrapping
>>> so that i can have 50 different 'bar{x}/bar{y}' s
>>> then to estimate the mean...
>>>
>>> Thanks.
>>>
>>> casper
>>>
>>>
>>>
>>> Ben Bolker wrote:
>>>>
>>>> casperyc <casperyc <at> hotmail.co.uk> writes:
>>>>
>>>>> I have 49 pairs in my data.frame 'data'
>>>>>
>>>>> x    y
>>>>> 76   80
>>>>> ...  ...
>>>>>
>>>>> how do I get a bootstrap sample of size n=50?
>>>>>
>>>>
>>>> data[sample(nrow(data),size=50,replace=TRUE),]
>>>>
>>>> ______________________________________________
>>>> 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.
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://n4.nabble.com/bootstrap-help-tp949807p954053.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.
>>>
>>
>>
>>
>> --
>> Marek
>>
>> ______________________________________________
>> 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.
>>
>>
>
> --
> View this message in context: http://n4.nabble.com/bootstrap-help-tp949807p954088.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.
>



-- 
Marek




More information about the R-help mailing list