[R] lm: mark sample used in estimation
peter dalgaard
pdalgd at gmail.com
Mon Jul 11 13:52:13 CEST 2011
On Jul 11, 2011, at 09:55 , Anirban Mukherjee wrote:
> But I am ideally looking for a way that allows one to use any formula
> in lm, and still be able to mark the estimation sample.
> Function/option I am missing? The best I could come up with:
>
>> lm.D9 <- lm(weight ~ group, model=TRUE)
>> ind <- as.numeric(row.names(lm.D9$model))
>> esamp <- rep(0,length(group)) #substitute nrow(data.frame used in estimation) for length(group)
>> esamp[ind] <- 1
>> esamp
> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1
>
> Is this "safe" (recommended?)?
Maybe, but you're crossing the creek to fetch water:
> attr(lm.D9$model,"na.action")
18
18
attr(,"class")
[1] "omit"
So you could just do
esamp <- rep(1, length(group))
esamp[attr(lm.D9$model,"na.action")] <- 0
--
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list