Abraham Mathew
2012-Aug-13 19:39 UTC
[R] Using the effects package to plot logit probabilities
I'm trying to run a logit model and plot the probability curve for a number of the important predictors. I'm trying to do this with the Effects package. df=data.frame(income=c(5,5,3,3,6,5), won=c(0,0,1,1,1,0), age=c(18,18,23,50,19,39), home=c(0,0,1,0,0,1)) str(df) md1 = glm(factor(won) ~ income + age + home, data=df, family=binomial(link="logit")) summary(md1) plot(effect("income", md1), grid=TRUE) But I want to know how to plot a graph so that it shows the probability of won (response) based on income (or any of the other predictors). However, what I want to do is generate the same plot, with won don y axis and income on x axis, but the curves showing the probabilities for age and home. Not seeing how to do this in the effects documentation. Help! Thanks. -- *Abraham Mathew Statistical Analyst www.amathew.com 720-648-0108 @abmathewks* [[alternative HTML version deleted]]
Bert Gunter
2012-Aug-13 21:01 UTC
[R] Using the effects package to plot logit probabilities
Why not use ?predict.glm ## with type = "response" ? -- Bert On Mon, Aug 13, 2012 at 12:39 PM, Abraham Mathew <abmathewks at gmail.com> wrote:> I'm trying to run a logit model and plot the probability curve for a number > of the important predictors. I'm trying to do this > with the Effects package. > > > df=data.frame(income=c(5,5,3,3,6,5), > won=c(0,0,1,1,1,0), > age=c(18,18,23,50,19,39), > home=c(0,0,1,0,0,1)) > str(df) > > md1 = glm(factor(won) ~ income + age + home, > data=df, family=binomial(link="logit")) > > summary(md1) > > plot(effect("income", md1), grid=TRUE) > > > But I want to know how to plot a graph so that it shows the probability of > won (response) based on income (or any of the other predictors). > > However, what I want to do is generate the same plot, with won don y axis > and income on x axis, but the curves showing the probabilities for age and > home. > > > Not seeing how to do this in the effects documentation. Help! > > > Thanks. > > > > -- > *Abraham Mathew > Statistical Analyst > www.amathew.com > 720-648-0108 > @abmathewks* > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Abraham Mathew
2012-Aug-13 22:49 UTC
[R] Using the effects package to plot logit probabilities
With multiple predictors, I feel that predict ends up being less elegant. Plus, I've found a lot of the simple log-odds plots available in the effect package to be simple and easy to use as compared to base predict. On Mon, Aug 13, 2012 at 3:01 PM, Bert Gunter <gunter.berton@gene.com> wrote:> Why not use > > ?predict.glm ## with type = "response" ? > > -- Bert > > On Mon, Aug 13, 2012 at 12:39 PM, Abraham Mathew <abmathewks@gmail.com> > wrote: > > I'm trying to run a logit model and plot the probability curve for a > number > > of the important predictors. I'm trying to do this > > with the Effects package. > > > > > > df=data.frame(income=c(5,5,3,3,6,5), > > won=c(0,0,1,1,1,0), > > age=c(18,18,23,50,19,39), > > home=c(0,0,1,0,0,1)) > > str(df) > > > > md1 = glm(factor(won) ~ income + age + home, > > data=df, family=binomial(link="logit")) > > > > summary(md1) > > > > plot(effect("income", md1), grid=TRUE) > > > > > > But I want to know how to plot a graph so that it shows the probability > of > > won (response) based on income (or any of the other predictors). > > > > However, what I want to do is generate the same plot, with won don y axis > > and income on x axis, but the curves showing the probabilities for age > and > > home. > > > > > > Not seeing how to do this in the effects documentation. Help! > > > > > > Thanks. > > > > > > > > -- > > *Abraham Mathew > > Statistical Analyst > > www.amathew.com > > 720-648-0108 > > @abmathewks* > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@r-project.org mailing list > > 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. > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >-- *Abraham Mathew Statistical Analyst www.amathew.com 720-648-0108 @abmathewks* [[alternative HTML version deleted]]
Dear Abraham, It's not entirely clear to me what you want to plot. If you want the "effect display" for each predictor holding the others to typical values, plot(allEffects(md1)) will do that. But you appear to want to plot fitted probabilities for combinations of the predictors even though the model is additive. If that's really what you want, you should be able to get it by specifying plot(effect("income*age*home", md1). This will generate a warning because "income:age:home" isn't a high-order term in the model, but it should work. I hope this helps, John ------------------------------------------------------- John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster Univeristy Hamilton, Ontario, Canada> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] > On Behalf Of Abraham Mathew > Sent: August-13-12 12:40 PM > To: r-help at r-project.org > Subject: [R] Using the effects package to plot logit probabilities > > I'm trying to run a logit model and plot the probability curve for anumber of> the important predictors. I'm trying to do this with the Effects package. > > > df=data.frame(income=c(5,5,3,3,6,5), > won=c(0,0,1,1,1,0), > age=c(18,18,23,50,19,39), > home=c(0,0,1,0,0,1)) > str(df) > > md1 = glm(factor(won) ~ income + age + home, > data=df, family=binomial(link="logit")) > > summary(md1) > > plot(effect("income", md1), grid=TRUE) > > > But I want to know how to plot a graph so that it shows the probability of > won (response) based on income (or any of the other predictors). > > However, what I want to do is generate the same plot, with won don y axis > and income on x axis, but the curves showing the probabilities for age and > home. > > > Not seeing how to do this in the effects documentation. Help! > > > Thanks. > > > > -- > *Abraham Mathew > Statistical Analyst > www.amathew.com > 720-648-0108 > @abmathewks* > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.