By subsetting the rows in the firstkids data frame, you've already subsetted your data.
Try specifying firstkids as your data instead of a subset in the lm call. Also, eliminate the kidmomhsage prefix from all of your variables since you're running the linear model on a different data frame(firstkids) Something along this line: lm(kid_score ~ mom_age ...., data = firstkids) *Jorge Cimentada* *Ph.D. Candidate* Dpt. Ciències Polítiques i Socials Ramon Trias Fargas, 25-27 | 08005 Barcelona Office 24.331 [Tel.] 697 382 009 jorge.ciment...@upf.edu http://www.upf.edu/dcpis/ On Tue, Sep 20, 2016 at 10:00 AM, mviljamaa <mvilja...@kapsi.fi> wrote: > 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/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code. >
______________________________________________ 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.