[R] Bootstrapping a covariance matrix

meddee meddee1000 at gmail.com
Sun Sep 4 00:34:46 CEST 2011


Dear all I am a bit new to R so please keep your swords sheathed!

I would simply like to bootstrap a covariance matrix from a multivariate
gaussian density. At face value that seemed like a very straightforward
problem to solve but I somehow could not get the boot package to work and
did not really understand the documentation so I tried to do the bootstrap
manually. Hence:

x<-rmvnorm(n = 5, mean, diag(1,length(mean))) 
Var<-function(a) var(a)
Var(x)
sample<-matrix(sample(x,replace=T),ncol=length(mean))#single BS sample
Var(sample)# sqr matrix of length(mean)

#generate 1000 bootstrap samples
 boot <- array(NA, c(1000, 3, 3))
#assign the var for bootstrap sample i as the ith element in the vector
boot, using a for loop
for (i in 1:1000) boot[i,,] <- Var(sample)
mean(boot)

For output I expect to see a 3x3 covariance matrix but i am getting a single
scalar value.

So can some person(s) do either (or all) of the following:
- point out how I can get the intended result from the above code 
- point out how the boot function can be used to to solve this problem
- point me to further documentation for the boot function

p.s: rmvnorm is from the mvtnorm package.

Thanks in advance!



--
View this message in context: http://r.789695.n4.nabble.com/Bootstrapping-a-covariance-matrix-tp3788553p3788553.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list