|
I have a logit model with about 10 predictors and I am trying to plot the
probability curve for the model. Y=1 = 1 / 1+e^-z where z=B0 + B1X1 + ... + BnXi If the model had only one predictor, I know to do something like below. mod1 = glm(factor(won) ~ as.numeric(bid), data=mydat, family=binomial(link="logit")) all.x <- expand.grid(won=unique(won), bid=unique(bid)) y.hat.new <- predict(mod1, newdata=all.x, type="response") plot(bid<-000:250,predict(mod1,newdata=data.frame(bid<-c(000:250)),type="response"), lwd=5, col="blue", type="l") I'm not sure how to proceed when I have 10 or so predictors in the logit model. Do I simply expand the expand.grid() function to include all the variables? So my question is how do I form a plot of a logit probability curve when I have 10 predictors? would be nice to do this in ggplot2. Thanks! -- *Abraham Mathew Statistical Analyst www.amathew.com 720-648-0108 @abmathewks* [[alternative HTML version deleted]] ______________________________________________ [hidden email] 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. |
|
You have an about 11-D response surface, not a curve!
-- Bert On Thu, Jul 5, 2012 at 2:39 PM, Abraham Mathew <[hidden email]> wrote: > I have a logit model with about 10 predictors and I am trying to plot the > probability curve for the model. > > Y=1 = 1 / 1+e^-z where z=B0 + B1X1 + ... + BnXi > > If the model had only one predictor, I know to do something like below. > > mod1 = glm(factor(won) ~ as.numeric(bid), data=mydat, > family=binomial(link="logit")) > > all.x <- expand.grid(won=unique(won), bid=unique(bid)) > y.hat.new <- predict(mod1, newdata=all.x, type="response") > > plot(bid<-000:250,predict(mod1,newdata=data.frame(bid<-c(000:250)),type="response"), > lwd=5, col="blue", type="l") > > > I'm not sure how to proceed when I have 10 or so predictors in the logit > model. Do I simply expand the > expand.grid() function to include all the variables? > > So my question is how do I form a plot of a logit probability curve when I > have 10 predictors? > > would be nice to do this in ggplot2. > > Thanks! > > > -- > *Abraham Mathew > Statistical Analyst > www.amathew.com > 720-648-0108 > @abmathewks* > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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 [[alternative HTML version deleted]] ______________________________________________ [hidden email] 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. |
|
Ok, so let's say I have a logit equation outlined as Y= 2.5 + 3X1 + 2.3X2 +
4X3 + 3.6X4 + 2.2X5 So a one unit increase in X2 is associated with a 2.3 increase in Y, regardless of what the other predictor values are. So I guess instead of trying to plot of curve with all the predictors accounted for, I should plot each curve by itself. I'm still not sure how to do that with so many predictors. Any help would be appreciated. On Thu, Jul 5, 2012 at 4:23 PM, Bert Gunter <[hidden email]> wrote: > You have an about 11-D response surface, not a curve! > > -- Bert > > On Thu, Jul 5, 2012 at 2:39 PM, Abraham Mathew <[hidden email]>wrote: > >> I have a logit model with about 10 predictors and I am trying to plot the >> probability curve for the model. >> >> Y=1 = 1 / 1+e^-z where z=B0 + B1X1 + ... + BnXi >> >> If the model had only one predictor, I know to do something like below. >> >> mod1 = glm(factor(won) ~ as.numeric(bid), data=mydat, >> family=binomial(link="logit")) >> >> all.x <- expand.grid(won=unique(won), bid=unique(bid)) >> y.hat.new <- predict(mod1, newdata=all.x, type="response") >> >> plot(bid<-000:250,predict(mod1,newdata=data.frame(bid<-c(000:250)),type="response"), >> lwd=5, col="blue", type="l") >> >> >> I'm not sure how to proceed when I have 10 or so predictors in the logit >> model. Do I simply expand the >> expand.grid() function to include all the variables? >> >> So my question is how do I form a plot of a logit probability curve when I >> have 10 predictors? >> >> would be nice to do this in ggplot2. >> >> Thanks! >> >> >> -- >> *Abraham Mathew >> Statistical Analyst >> www.amathew.com >> 720-648-0108 >> @abmathewks* >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> [hidden email] 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]] ______________________________________________ [hidden email] 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. |
|
In reply to this post by Abraham Mathew
Look at the Predict.Plot and TkPredict functions in the TeachingDemos
package. These will not plot all 11 dimensions at once, but will plot 2 of the dimensions conditioned on the others. You can then change the conditioning to see relationships. These use base rather than ggplot graphics. On Thu, Jul 5, 2012 at 3:39 PM, Abraham Mathew <[hidden email]> wrote: > I have a logit model with about 10 predictors and I am trying to plot the > probability curve for the model. > > Y=1 = 1 / 1+e^-z where z=B0 + B1X1 + ... + BnXi > > If the model had only one predictor, I know to do something like below. > > mod1 = glm(factor(won) ~ as.numeric(bid), data=mydat, > family=binomial(link="logit")) > > all.x <- expand.grid(won=unique(won), bid=unique(bid)) > y.hat.new <- predict(mod1, newdata=all.x, type="response") > plot(bid<-000:250,predict(mod1,newdata=data.frame(bid<-c(000:250)),type="response"), > lwd=5, col="blue", type="l") > > > I'm not sure how to proceed when I have 10 or so predictors in the logit > model. Do I simply expand the > expand.grid() function to include all the variables? > > So my question is how do I form a plot of a logit probability curve when I > have 10 predictors? > > would be nice to do this in ggplot2. > > Thanks! > > > -- > *Abraham Mathew > Statistical Analyst > www.amathew.com > 720-648-0108 > @abmathewks* > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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. -- Gregory (Greg) L. Snow Ph.D. [hidden email] ______________________________________________ [hidden email] 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. |
|
In reply to this post by Abraham Mathew
On Jul 6, 2012, at 4:30 PM, Abraham Mathew wrote: > Ok, so let's say I have a logit equation outlined as Y= 2.5 + 3X1 + > 2.3X2 + > 4X3 + 3.6X4 + 2.2X5 > > So a one unit increase in X2 is associated with a 2.3 increase in Y, Assuming, that is, you also understand what Y is. From you comments so far, I have some nagging worries regarding your understanding of that point. -- David. > regardless of what the other > predictor values are. So I guess instead of trying to plot of curve > with > all the predictors accounted > for, I should plot each curve by itself. > > I'm still not sure how to do that with so many predictors. > > Any help would be appreciated. > > > > > On Thu, Jul 5, 2012 at 4:23 PM, Bert Gunter <[hidden email]> > wrote: > >> You have an about 11-D response surface, not a curve! >> >> -- Bert >> >> On Thu, Jul 5, 2012 at 2:39 PM, Abraham Mathew >> <[hidden email]>wrote: >> >>> I have a logit model with about 10 predictors and I am trying to >>> plot the >>> probability curve for the model. >>> >>> Y=1 = 1 / 1+e^-z where z=B0 + B1X1 + ... + BnXi >>> >>> If the model had only one predictor, I know to do something like >>> below. >>> >>> mod1 = glm(factor(won) ~ as.numeric(bid), data=mydat, >>> family=binomial(link="logit")) >>> >>> all.x <- expand.grid(won=unique(won), bid=unique(bid)) >>> y.hat.new <- predict(mod1, newdata=all.x, type="response") >>> >>> plot(bid<-000:250,predict(mod1,newdata=data.frame(bid<- >>> c(000:250)),type="response"), >>> lwd=5, col="blue", type="l") >>> >>> >>> I'm not sure how to proceed when I have 10 or so predictors in the >>> logit >>> model. Do I simply expand the >>> expand.grid() function to include all the variables? >>> >>> So my question is how do I form a plot of a logit probability >>> curve when I >>> have 10 predictors? >>> >>> would be nice to do this in ggplot2. >>> >>> Thanks! >>> >>> >>> -- >>> *Abraham Mathew >>> Statistical Analyst >>> www.amathew.com >>> 720-648-0108 >>> @abmathewks* >>> David Winsemius, MD West Hartford, CT ______________________________________________ [hidden email] 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. |
|
In reply to this post by Abraham Mathew
Try the following:
library(TeachingDemos) ?TkPredict fit.glm1 <- glm( Species=='virginica' ~ Sepal.Width+Sepal.Length, data=iris, family=binomial) TkPredict(fit.glm1) (you may need to install the TeachingDemos package first if you don't already have it installed) You will now see a plot that shows the predicted probability compared to one of the predictor variables, there are controls that you can then change which variable is shown on the x axis and what the value of the other variables are. Play with the controls to see the effects of the different variables. You can now do the same thing with other logistic regression models. This also works to show nonlinear (polynomial, spline, etc.) fits of the variables and interactions. There is a button that you can click that will show the command to create the same plot in regular R graphics, and you can then use that command (and change add=TRUE to overlay multiple ones) to create a static plot showing the relationship. On Fri, Jul 6, 2012 at 2:30 PM, Abraham Mathew <[hidden email]> wrote: > Ok, so let's say I have a logit equation outlined as Y= 2.5 + 3X1 + 2.3X2 + > 4X3 + 3.6X4 + 2.2X5 > > So a one unit increase in X2 is associated with a 2.3 increase in Y, > regardless of what the other > predictor values are. So I guess instead of trying to plot of curve with > all the predictors accounted > for, I should plot each curve by itself. > > I'm still not sure how to do that with so many predictors. > > Any help would be appreciated. > > > > > On Thu, Jul 5, 2012 at 4:23 PM, Bert Gunter <[hidden email]> wrote: > >> You have an about 11-D response surface, not a curve! >> >> -- Bert >> >> On Thu, Jul 5, 2012 at 2:39 PM, Abraham Mathew <[hidden email]>wrote: >> >>> I have a logit model with about 10 predictors and I am trying to plot the >>> probability curve for the model. >>> >>> Y=1 = 1 / 1+e^-z where z=B0 + B1X1 + ... + BnXi >>> >>> If the model had only one predictor, I know to do something like below. >>> >>> mod1 = glm(factor(won) ~ as.numeric(bid), data=mydat, >>> family=binomial(link="logit")) >>> >>> all.x <- expand.grid(won=unique(won), bid=unique(bid)) >>> y.hat.new <- predict(mod1, newdata=all.x, type="response") >>> >>> plot(bid<-000:250,predict(mod1,newdata=data.frame(bid<-c(000:250)),type="response"), >>> lwd=5, col="blue", type="l") >>> >>> >>> I'm not sure how to proceed when I have 10 or so predictors in the logit >>> model. Do I simply expand the >>> expand.grid() function to include all the variables? >>> >>> So my question is how do I form a plot of a logit probability curve when I >>> have 10 predictors? >>> >>> would be nice to do this in ggplot2. >>> >>> Thanks! >>> >>> >>> -- >>> *Abraham Mathew >>> Statistical Analyst >>> www.amathew.com >>> 720-648-0108 >>> @abmathewks* >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> [hidden email] 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]] > > ______________________________________________ > [hidden email] 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. -- Gregory (Greg) L. Snow Ph.D. [hidden email] ______________________________________________ [hidden email] 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. |
|
Also: require(rms); ?plot.Predict
Frank
Frank Harrell
Department of Biostatistics, Vanderbilt University |
| Powered by Nabble | Edit this page |
