[R] bootstraping lm

2003-01-16 Thread Ernesto Jardim
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 [EMAIL PROTECTED]
Marine Biologist
Research Institute for Agriculture and Fisheries
Lisboa, Portugal
Tel: +351 213 027 000
Fax: +351 213 015 948

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help



Re: [R] bootstraping lm

2003-01-16 Thread Ernesto Jardim
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 [EMAIL PROTECTED]
Marine Biologist
Research Institute for Agriculture and Fisheries
Lisboa, Portugal
Tel: +351 213 027 000
Fax: +351 213 015 948

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help



Re: [R] bootstraping lm

2003-01-16 Thread ripley
That's not a problem in boot, but a problem in your usage of it.

On 16 Jan 2003, Ernesto Jardim wrote:

 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.

It's already there:

statistic: A function which when applied to data returns a vector
  containing the statistic(s) of interest.

   t: A matrix with `R' rows each of which is a bootstrap replicate
  of `statistic'. 

Where does it say that the statistic(s) of interest can change by 
replicate?


-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help



Re: [R] bootstraping lm

2003-01-16 Thread Ernesto Jardim
Hi

You're correct. The problem is in statistic not in boot.

However it is not clear for me that the definition of t states it must
have allways the same number of dimensions. What it says is that it will
be a bootstrap replicate of statistic. 

In my linear model I use factors and the number of coefficients might
change, if the bootstrap data set omits one or more levels. 

My understandment is that the result of statistic is still a bootstrap
replicate no matter the number of dimensions.

Anyway, thanks for being helpfull.

Regards

EJ

On Thu, 2003-01-16 at 15:02, [EMAIL PROTECTED] wrote:
 That's not a problem in boot, but a problem in your usage of it.
 
 On 16 Jan 2003, Ernesto Jardim wrote:
 
  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.
 
 It's already there:
 
 statistic: A function which when applied to data returns a vector
   containing the statistic(s) of interest.
 
t: A matrix with `R' rows each of which is a bootstrap replicate
   of `statistic'. 
 
 Where does it say that the statistic(s) of interest can change by 
 replicate?
-- 
Ernesto Jardim [EMAIL PROTECTED]
Marine Biologist
Research Institute for Agriculture and Fisheries
Lisboa, Portugal
Tel: +351 213 027 000
Fax: +351 213 015 948

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help