[R] How to use predict() so that one retains the rows that they're associated with?
David L Carlson
dcarlson at tamu.edu
Thu Oct 20 15:20:29 CEST 2016
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
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Richard M. Heiberger
Sent: Thursday, October 20, 2016 8:05 AM
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
glm(formula, data, na.action=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'.
On Thu, Oct 20, 2016 at 7:40 AM, mviljamaa <mviljamaa at 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help