Guest User

Untitled

a guest
Jan 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. glm(Decision ~ Thoughts, family = binomial, data = data)
  2.  
  3. exp(coef(results))
  4.  
  5. library('MASS')
  6. data("menarche")
  7. m<-glm(cbind(Menarche, Total-Menarche) ~ Age, family=binomial, data=menarche)
  8. summary(m)
  9.  
  10. Call:
  11. glm(formula = cbind(Menarche, Total - Menarche) ~ Age, family = binomial,
  12. data = menarche)
  13.  
  14. Deviance Residuals:
  15. Min 1Q Median 3Q Max
  16. -2.0363 -0.9953 -0.4900 0.7780 1.3675
  17.  
  18. Coefficients:
  19. Estimate Std. Error z value Pr(>|z|)
  20. (Intercept) -21.22639 0.77068 -27.54 <2e-16 ***
  21. Age 1.63197 0.05895 27.68 <2e-16 ***
  22. ---
  23. Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  24.  
  25. (Dispersion parameter for binomial family taken to be 1)
  26.  
  27. Null deviance: 3693.884 on 24 degrees of freedom
  28. Residual deviance: 26.703 on 23 degrees of freedom
  29. AIC: 114.76
  30.  
  31. Number of Fisher Scoring iterations: 4
  32.  
  33. #predict gives the predicted value in terms of logits
  34. plot.dat <- data.frame(prob = menarche$Menarche/menarche$Total,
  35. age = menarche$Age,
  36. fit = predict(m, menarche))
  37. #convert those logit values to probabilities
  38. plot.dat$fit_prob <- exp(plot.dat$fit)/(1+exp(plot.dat$fit))
  39.  
  40. library(ggplot2)
  41. ggplot(plot.dat, aes(x=age, y=prob)) +
  42. geom_point() +
  43. geom_line(aes(x=age, y=fit_prob))
  44.  
  45. exp(coef(m))
  46.  
  47. (Intercept) Age
  48. 6.046358e-10 5.113931e+00
  49.  
  50. exp(intercept + coef*THOUGHT_Value)/(1+(exp(intercept+coef*THOUGHT_Value))
  51.  
  52. library(oddsratio)
  53. fit_glm <- glm(admit ~ gre + gpa + rank, data = data_glm, family = "binomial")
  54.  
  55. # Calculate OR for specific increment step of continuous variable
  56. or_glm(data = data_glm, model = fit_glm,
  57. incr = list(gre = 380, gpa = 5))
  58.  
  59. predictor oddsratio CI.low (2.5 %) CI.high (97.5 %) increment
  60. 1 gre 2.364 1.054 5.396 380
  61. 2 gpa 55.712 2.229 1511.282 5
  62. 3 rank2 0.509 0.272 0.945 Indicator variable
  63. 4 rank3 0.262 0.132 0.512 Indicator variable
  64. 5 rank4 0.212 0.091 0.471 Indicator variable
Add Comment
Please, Sign In to add comment