I'm trying to take lm on a subset of my dataset and to do this I believe I need to pass my subset of the data as the subset parameter of lm.

So I do my subsetting:

firstkids <- kidmomhsage[0:234,], i.e. the first 234 rows of the data frame.

Then construct the model:

fit4 <- lm(kidmomhsage$kid_score ~ kidmomhsage$mom_age + kidmomhsage$mom_hs + kidmomhsage$mom_age * kidmomhsage$mom_hs, subset=firstkids)

which results in:

Error in xj[i] : invalid subscript type 'list'

I read somewhere a recommendation to use "unlist":

fit4 <- lm(kidmomhsage$kid_score ~ kidmomhsage$mom_age + kidmomhsage$mom_hs + kidmomhsage$mom_age * kidmomhsage$mom_hs, subset=unlist(firstkids))

which seems to not produce the error and results in some sort of model, but is this model the correct one (i.e. for the data set firstkids, just as it originally appears)? How does unlist change the data?

______________________________________________
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.

Reply via email to