model.frame mangles time series (PR#121)

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
18 Feb 1999 18:27:11 +0100


Thomas Lumley <thomas@biostat.washington.edu> writes:

> On 18 Feb 1999, Peter Dalgaard BSA wrote:
> 
> > 
> > (6) since [subset,] seems to work, perhaps do_subset is what should be
> > called from inside do_modelframe?
> 
> No, subset doesn't work -- it loses contrasts
> 
> R>  contrasts(df$x)
>   [,1] [,2]
> 1    1    0
> 2    0    1
> 3   -1   -1
> R> contrasts(df[1:5,]$x)
>   2 3
> 1 0 0
> 2 1 0
> 3 0 1

That can be fixed by a one-line change to [.factor :

> contrasts(df[1:3,]$x)
          .L   .Q         .C
1 -0.6708204  0.5 -0.2236068
2 -0.2236068 -0.5  0.6708204
3  0.2236068 -0.5 -0.6708204
4  0.6708204  0.5  0.2236068

I suspect that is the correct solution.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._