[R] boot package question: sampling on factor, not row

Scott Norton snorton at surromed.com
Tue Nov 11 00:08:04 CET 2003


Hi all:

      I've been looking at the boot package to "bootstrap" sample my data in a particular way.  I haven't figured out how to set this up using the boot() command and thus have resorted to trying to write my own script (although I'd prefer if I could get boot() to work for this problem!)

The dataset is set up in the following way:

ix(factor)  value
1		5.73
1		6.99
1		0.32
1		4.64
1		8.39
2		8.47
2		1.04
2		0.73
2		0.29
3		6.82
3		8.81
3		1.33
3		9.17
3		9.84
4		8.57
4		5.04
4		7.18
4		4.54
4		4.37
5		7.36
5		4.97
5		2.66

What I would like to do is repeatedly sample the ix (a factor), not the individual rows.  For example, say I wanted to repeatedly sample (at a sample size of 3) the ix value - 
e.g. 1,3,5 then average the "value"s within those factors and then lets say take the median across this each.   
So for a random sample of (1,3,5) that would be: median(c(mean(c(5.73,6.99,0.32,4.64,8.39)), mean(6.82,8.81,1.33,9.17,9.84), mean(7.36,4.97,2.66)))
Then repeat this over combinations of 3 ix factors e.g. (1,2,3), (1,1,4), etc...

Is it possible to subsample a factor using boot() and then use that sample of factors to access rows, rather than directly sample rows?

Thanks!!!
-Scott




More information about the R-help mailing list