[R] bootstraping lm
Ernesto Jardim
ernesto at ipimar.pt
Thu Jan 16 16:00:03 CET 2003
Hi
I found the problem (I hope:).
In "boot" a data.frame with the expected results from "statistic" is
created, "t.star", wich has dim[[1]]=sum(R), the number of replicates,
and dim[[2]]=lt0, the length of the output of statistic using the
original data.
t0 <- statistic(data, original, ...)
lt0 <- length(t0)
t.star <- matrix(NA, sum(R), lt0)
However when fitting the "lm" with different sets of data, it might
happen that the result of "statistic" is not of the same length has with
the original data. That's when
for (r in 1:sum(R)) t.star[r, ] <- statistic(data, i[r,], ...)
fails, because its not able to replace the complete row of t.star.
So "statistic" shall guarantee that all the outputs are of the same
length.
Something you might want to had to "boot" documentation.
Regards
EJ
On Thu, 2003-01-16 at 12:44, Ernesto Jardim wrote:
> Hi
>
> I'm doing a bootstrap of a linear model using:
>
> boot.fishpower <- function(data, i){
>
> data <- data[i,]
> fplm <- lm(log(U)~Q+S+P+B+D, data=data)
> fp <- coef(fplm)
> exp(fp)
> }
>
>
> > boot(logglm.data,boot.fishpower,100)
> Error in "[<-"(*tmp*, r, , value = statistic(data, i[r, ], ...)) :
> number of items to replace is not a multiple of replacement
> length
>
>
> I've used debug to look at the process and it seems ok. The "i" are
> allways of the same length as the dataframe rows. And it loops for a
> while, but at some point it stops and gives this error ...
>
> Can someone help me with this ?
>
> Thanks
>
> EJ
--
Ernesto Jardim <ernesto at ipimar.pt>
Marine Biologist
Research Institute for Agriculture and Fisheries
Lisboa, Portugal
Tel: +351 213 027 000
Fax: +351 213 015 948
More information about the R-help
mailing list