0

I have spent over a week looking at different forums in order to figure this out and unfortunately remain stuck. I'm new to boostrapping and have found it difficult to get it to work using R for my data set.

I have a matrix of data, that I would like to simply draw 1000 samples from and the matrix by parametric bootstrapping. And then calculate the mean from these sampled values. I have tried the below code and get no results.

Any help would be appreciated.

        A1        A2        A3        A4        D1        D2        E1
[1,]  0.900111 -0.314068  0.203188 -0.548964 -0.107771 -0.072454  0.084097
[2,] -0.314068  0.195798 -0.138751  0.198521  0.066360  0.048523 -0.126348
[3,]  0.203188 -0.138751  0.400325 -0.128715 -0.180103 -0.037768  0.128198
[4,] -0.548964  0.198521 -0.128715  1.190415  0.067779  0.047209 -0.053145
[5,] -0.107771  0.066360 -0.180103  0.067779  0.149419  0.039649 -0.102587
[6,] -0.072454  0.048523 -0.037768  0.047209  0.039649  0.396405  0.016789
[7,]  0.084097 -0.126348  0.128198 -0.053145 -0.102587  0.016789  0.790767

#creating the data matrix 

data <- read.csv("Matrix.csv", header=F) 
data1 <- as.matrix(data)

#Bootstrap 1000 samples

psi<- function (data,i) mean (data[i])
byboot = boot(data, psi, R=1000)
myboot
StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Guest
  • 17
  • 7
  • It is not clear what you want to achieve. Do you want to bootstrap the column means? – Roland Feb 20 '15 at 12:33
  • Thanks for your response. The matrix is a variance-covariance matrix for my parameters A1 to E1. I would like to calculate the mean for each column. – Guest Feb 24 '15 at 15:10
  • Just to clarify? Do you mean psi<- function (data,i) colMean (data[i]) byboot = boot(data, psi, R=1000) myboot – Guest Feb 25 '15 at 11:24

1 Answers1

0

If you're trying to sample from a correlated normal distribution you can use MASS::mvrnorm

library(MASS)
x <- mvrnorm(1000, rep(0,7), data)
colMeans(x)
cov(x) # check the covariance matrix is approximately recovered
pseudospin
  • 2,737
  • 1
  • 4
  • 19