Petr Pikal replied: [...]
> The following works > > > > results <- boot(data=test, statistic=bs, R=1000, A~B+C+D+C*D) > > > > Actually it does not work either > Correct, but I _did_ get it to work shortly before my initial post (sorry for not showing it, but I didn't save the output - silly me). What seems to happen is that I successfully run the version that _does_ work, which I then follow up with successful calls to -plot(results,index=#)- and -boot.ci(results,type="bca",index=#)-, then I follow up with the unsuccessful version of the code, which won't run and produces the error, but when I go back to run the original code, this too produces the same error. This, to me at least, is very weird behaviour for R. > > > results <- boot(data=test, statistic=bs, R=1000, A~B+C+D+C*D) > Error in data[indices, ] : incorrect number of dimensions > > > > I am not sure but I suspect your bs function expects some indices vector > and it is somehow not in accordance with your data. > This code, using different simulated data _does_ run, however: > mytest<-data.frame(Y=rnorm(500, mean=60, sd=1), X1=sample(c("AAA", "BBB", > "CCC", "DDD", "None", NA), size=500, replace=TRUE), X2=sample(c(0.88, 0.99, > 1.43, 1.22, 1.1), size=500, replace=TRUE), X3=sample(c("Yes", "No"), > size=500, prob=c(0.6,0.4), replace=TRUE)) > bs <- function(formula, data, indices) {+ mytest <- data[indices,]+ > fit <- lm(formula, data=mytest)+ return(coef(fit)) + }> results <- > boot(data=mytest, statistic=bs, R=1000, formula=Y~X1+X2+X3)> results ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = mytest, statistic = bs, R = 1000, formula = Y ~ X1 + X2 + X3) Bootstrap Statistics : original bias std. error t1* 60.10691271 -0.0012790917 0.28940597 t2* -0.01959846 -0.0033038861 0.14376648 t3* 0.24000669 -0.0016111232 0.16163714 t4* 0.19158141 -0.0015946959 0.14849004 t5* 0.08128826 -0.0013207129 0.14309419 t6* -0.25319061 0.0002987212 0.22874411 t7* 0.03443774 0.0047553487 0.09620542 How do you explain that? Or, indeed, this, which takes two variables with simulated proportions: > mytest<-data.frame(Y=rnorm(500, mean=60, sd=1), X1=sample(c("AAA", "BBB", > "CCC", "DDD", "None", NA), size=500, replace=TRUE), X2=sample(c(0.88, 0.99, > 1.43, 1.22, 1.1), size=500, replace=TRUE), X3=sample(c("Yes", "No"), > size=500, prob=c(0.6,0.4), replace=TRUE), X4=sample(c(0,1), size=500, > prob=c(0.25,0.75), replace=TRUE))> bs <- function(formula, data, indices) {+ > mytest <- data[indices,]+ fit <- lm(formula, data=mytest)+ > return(coef(fit)) + }> results <- boot(data=mytest, statistic=bs, R=1000, > formula=Y~X1+X2+X3+X4)> results ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = mytest, statistic = bs, R = 1000, formula = Y ~ X1 + X2 + X3 + X4) Bootstrap Statistics : original bias std. error t1* 60.28192671 -0.015122589 0.3016916 t2* -0.12397654 -0.005209852 0.1558575 t3* -0.15597837 -0.007948155 0.1593787 t4* -0.13420834 -0.004417036 0.1499142 t5* -0.03049650 -0.003097340 0.1600422 t6* -0.07926231 0.012471978 0.2477136 t7* -0.10564206 -0.002528748 0.1028371 t8* 0.01627027 0.005540313 0.1141790 And yet it won't run with my simulated dataset, despite the fact that it's quite similar to this? Sorry, I'm not buying it. Answers please! Clive Nicholas (clivenicholas.posterous.com [Please DO NOT mail me personally here, but at <clivenicho...@hotmail.com>. Please respond to contributions I make in a list thread here. Thanks!] "My colleagues in the social sciences talk a great deal about methodology. I prefer to call it style." -- Freeman J. Dyson [[alternative HTML version deleted]] ______________________________________________ R-help@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.