Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- glm(Decision ~ Thoughts, family = binomial, data = data)
- exp(coef(results))
- library('MASS')
- data("menarche")
- m<-glm(cbind(Menarche, Total-Menarche) ~ Age, family=binomial, data=menarche)
- summary(m)
- Call:
- glm(formula = cbind(Menarche, Total - Menarche) ~ Age, family = binomial,
- data = menarche)
- Deviance Residuals:
- Min 1Q Median 3Q Max
- -2.0363 -0.9953 -0.4900 0.7780 1.3675
- Coefficients:
- Estimate Std. Error z value Pr(>|z|)
- (Intercept) -21.22639 0.77068 -27.54 <2e-16 ***
- Age 1.63197 0.05895 27.68 <2e-16 ***
- ---
- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
- (Dispersion parameter for binomial family taken to be 1)
- Null deviance: 3693.884 on 24 degrees of freedom
- Residual deviance: 26.703 on 23 degrees of freedom
- AIC: 114.76
- Number of Fisher Scoring iterations: 4
- #predict gives the predicted value in terms of logits
- plot.dat <- data.frame(prob = menarche$Menarche/menarche$Total,
- age = menarche$Age,
- fit = predict(m, menarche))
- #convert those logit values to probabilities
- plot.dat$fit_prob <- exp(plot.dat$fit)/(1+exp(plot.dat$fit))
- library(ggplot2)
- ggplot(plot.dat, aes(x=age, y=prob)) +
- geom_point() +
- geom_line(aes(x=age, y=fit_prob))
- exp(coef(m))
- (Intercept) Age
- 6.046358e-10 5.113931e+00
- exp(intercept + coef*THOUGHT_Value)/(1+(exp(intercept+coef*THOUGHT_Value))
- library(oddsratio)
- fit_glm <- glm(admit ~ gre + gpa + rank, data = data_glm, family = "binomial")
- # Calculate OR for specific increment step of continuous variable
- or_glm(data = data_glm, model = fit_glm,
- incr = list(gre = 380, gpa = 5))
- predictor oddsratio CI.low (2.5 %) CI.high (97.5 %) increment
- 1 gre 2.364 1.054 5.396 380
- 2 gpa 55.712 2.229 1511.282 5
- 3 rank2 0.509 0.272 0.945 Indicator variable
- 4 rank3 0.262 0.132 0.512 Indicator variable
- 5 rank4 0.212 0.091 0.471 Indicator variable
Add Comment
Please, Sign In to add comment