Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.1 Intercept of logistic GAM #27

Open
cardiomoon opened this issue Mar 30, 2020 · 1 comment
Open

4.1 Intercept of logistic GAM #27

cardiomoon opened this issue Mar 30, 2020 · 1 comment

Comments

@cardiomoon
Copy link

Here, the value of the intercept is 0.733. We can use the plogis() logistic function to convert it to a probability.
Converted, the intercept is about 0.67.
This means that the model predicts a 67 percent baseline chance of a positive outcome. This is what we would expect if x1 and x2 were at their average values.

-> But, when I predict the model with average value of predictor variable, it is different from intercept. Followings are reproducible example.

> csale=readRDS("csale.RDS")
> log_mod <- gam(purchase ~ s(n_acts),data=csale,family=binomial,method="REML")
> coef(log_mod)[1]

(Intercept)
-1.593984

> predict(log_mod,newdata=data.frame(n_acts=mean(csale$n_acts)))
1 

-1.194276

@gimickwu
Copy link

Hello,
[in case some people get to this (late) as I did]

I noticed the same thing and suspect that the solution might not be correct. The intercept would give the fitted value for the mean predictor variables only if the predictors were centered before running the analysis.

library(mgcv)
csale <- readRDS("csale.rds")

# Examine the predictor and centre it
mean(csale$mortgage_age)
csale$cmortgage_age <- csale$mortgage_age - mean(csale$mortgage_age)

137.821795060209

# Fit a logistic model
log_mod <- gam(purchase ~ cmortgage_age, data = csale,
               family = binomial,
               method = "REML")

# Calculate the probability at the mean
plogis(coef(log_mod)[1])
plogis(predict(log_mod, newdata = data.frame(cmortgage_age = mean(csale$cmortgage_age))))

(Intercept): 0.210661569042337
1: 0.210661569042337

So 21% probability for the average mortgage_age

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants