5
$\begingroup$

I have fit a simple binary logistic GAM model in R and have used the plot() function to plot the results of this model. The plotted graph shows a fitted line and a confidence interval, but the scale is clearly not 0-1. Does anyone know what is being plotted? Ideally, I would like to get a graph of the predicted probability of the outcome versus the continuous predictor. Does anyone know how to get that out?

Thanks.

$\endgroup$
2
  • 4
    $\begingroup$ Add some sample code to this question. Specify what packages you are using. There are multiple packages that allow GAM modelling in R. $\endgroup$
    – John
    Commented Jun 21, 2012 at 11:13
  • $\begingroup$ perhaps the log odds is being plotted. $\endgroup$
    – Macro
    Commented Jun 21, 2012 at 21:37

3 Answers 3

5
$\begingroup$

The individual plots are on the scale of the linear predictor, i.e. a scale that is -Inf to +Inf. The inverse of the link function is used to map from this scale to the 0, ..., 1 scale of the response. Further note that each smooth is subject to centring constraints and so is centred about 0.

$\endgroup$
8
$\begingroup$

What is being plotted is the log-odds. It's log(p/(1-p)). That's the space of the logistic regression. You can convert the values using the logistic distribution and the qlogis and plogis functions.

I don't know what GAM functions you're using but often times there are options to get the p-values out.

$\endgroup$
1
  • 1
    $\begingroup$ The predict function often has a variable type and for a logistic regression you could use type="response". $\endgroup$
    – Wayne
    Commented Jun 21, 2012 at 12:42
4
$\begingroup$

The other answers already provide a good enough explanation, but I wanted to provide a worked example to show the differences in case somebody discovers this question down the road. I have fit a model using the biopsy data in the MASS package in R. The only adaptation to this data that I made was converting the character values from the outcome variable to a binary 0/1 value.

#### Load Libraries ####
library(mgcv)
library(dplyr)

#### Save Data From MASS Package ####
biopsy <- MASS::biopsy %>% 
  as_tibble() %>% 
  mutate(class = ifelse(class=="benign",0,1))
biopsy

I then fit the model with 6 predictors using cubic regression splines and REML fitting with a logistic regression model.

#### Fit Model ####
fit <- gam(
  class
  ~ s(V1, bs = "cr")
  + s(V2, bs = "cr")
  + s(V3, bs = "cr")
  + s(V4, bs = "cr")
  + s(V5, bs = "cr")
  + s(V6, bs = "cr"),
  data = biopsy,
  method = "REML",
  family = binomial
)

Finally, I plot the model with predicted probability. The first part of the plot function uses the model fit, the second part transforms the plotted values into predicted probability, the third part puts it all on one page, and the last argument includes standard error around the mean.

#### Plot Model by Predicted Probability ####
plot(fit,
     trans=plogis,
     pages=1,
     seWithMean = T)

Your plot should look like this:

enter image description here

Here you can see the values are now bounded between 0 and 1, with each decimal value directly interpretable as a percentage in the "class" outcome. As an example, the plot here shows that a zero value on V1 (tumor clump thickness) has a predicted probability of malign tumor growth of around 20%, whereas chances of having a malign tumor increase to near 100% at the maximum value of V1.

However, these are the probabilities when centered to an average value of .5. Including the intercept allows one to look at the probabilities when all other predictors are set to their average value. This can be achieved with the following code:

#### Include Intercept ####
plot(fit,
     trans=plogis,
     pages=1,
     seWithMean = T,
     shift = coef(fit)[1])

Giving you this plot:

enter image description here

Contrarily, simply removing the trans=plogis argument plots by log odds, which is likely what you saw when you plotted the model.

#### Removing Trans=Plogis Argument ####
plot(fit,
     pages=1,
     seWithMean = T)

Which looks like this:

enter image description here

Hopefully the difference between both plotting methods is more clear now.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.