One additional issue, since you are using logistic regression, you are predicting a dichotomy (i.e. 0 and 1 or factor with 2 categories). The value returned by predict() is a log odds ratio of belonging in the second category. Alternatively if you use the type="response" argument with predict(), you get the estimated probability of being in the second category. You can use ifelse() to convert the fitted values back to your original categories, but you must decide where to break the values (.5 is an obvious choice for the probabilities or 0 for the log odds, but these are not always the best).
There are a number of tutorials on the web that discuss logistic regression. You should look at one of them. ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Richard M. Heiberger Sent: Thursday, October 20, 2016 8:05 AM To: mviljamaa Cc: r-help Subject: Re: [R] How to use predict() so that one retains the rows that they're associated with? I believe you have missing values and therefore you need to use the argument glm(formula, data, na.action=na.exclude, ...) ?na.exclude The relevant line is when 'na.exclude' is used the residuals and predictions are padded to the correct length by inserting 'NA's for cases omitted by 'na.exclude'. Rich On Thu, Oct 20, 2016 at 7:40 AM, mviljamaa <mvilja...@kapsi.fi> wrote: > I'm using predict() for my glm() logistic model, but I'm having trouble > relating the predicted results to the rows that produced them. > > I want to be able to plot predictions along some categorical variables. > > So what can I do in order to get predicted values but also know what > variable values produced them? > > ______________________________________________ > 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. ______________________________________________ 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. ______________________________________________ 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.