i generate 4 bootstrap samples time series data set , have each new bootstrapped sample become new list element. sample size needs same length original data set. can please give me hand? come far.
data <- ts(matrix(rnorm(36), 12, 3), start=c(2012, 1), frequency=12) data replicate(4, apply(data, 1, sample, replace=true))
you there. description wasn't totally clear @ first, comment cleared up. need apply
across columns, , use list
make each replicate list element:
boot <- replicate( 4 , list( apply(data , 2 , function(x) sample( x , replace=true ) ) ) ) class(boot) #[1] "list" length( boot ) #[1] 4 head(boot[[1]]) # series 1 series 2 series 3 #[1,] 0.4652513 -0.02065698 0.3328945 #[2,] 0.6649865 0.08845410 0.2032134 #[3,] 0.5975473 -1.64571306 1.6516726 #[4,] 0.5975473 -0.23359075 -0.3255437 #[5,] 0.4008458 0.42180633 1.8402009 #[6,] -0.5436319 1.17034910 0.3456304
edit
since need whole rows @ time easier!
boot <- replicate( 4 , list( data[ sample( nrow(data) , replace = true ) , ] ) )
Comments
Post a Comment