Right.
To see it in action just compare the results of the two calls to boot.
library(boot)
set.seed(1007)
x <- rnorm(100)
y <- x + rnorm(100)
dat <- data.frame(x, y)
#Wrong
stat1 <- function(DF, f){
model <- lm(DF$y ~ DF$x, data = DF[f,]) #Doesn't bootstrap DF
coef(model)
}
#Correct
stat2 <- function(DF, f){
model <- lm(y ~ x, data = DF[f,])
coef(model)
}
boot(dat, stat1, R = 100)
boot(dat, stat2, R = 100)
Rui Barradas
Citando peter dalgaard <pda...@gmail.com>:
On 01 Oct 2016, at 16:11 , Daniel Nordlund <djnordl...@gmail.com> wrote:
You haven't told us anything about the structure of your data, or
the definition of the DataSummary function.
Yes. Just let me add that a common error with boot() is not to pay
attention to the required form of the statistic= function argument.
It should depend on the data and a set of indices and (for
nonparametic bootstrap) it is the indices that are random.
Typical mistakes are to completely ignore the index argument, or to
write clumsy code that ignores the data specification, as in
coef(lm(df$y~df$x, data=d[f])).
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd....@cbs.dk Priv: pda...@gmail.com
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.