Guest User

Untitled

a guest
Jan 22nd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. lo.to.p = function(lo){ # we need this function to generate the data
  2. odds = exp(lo)
  3. prob = odds/(1+odds)
  4. return(prob)
  5. }
  6. set.seed(4649) # this makes the example exactly reproducible
  7. x1 = runif(100, min=0, max=10) # you have 3, largely uncorrelated predictors
  8. x2 = runif(100, min=0, max=10)
  9. x3 = runif(100, min=0, max=10)
  10. lo = -78 + 35*x1 - 3.5*(x1^2) + .1*x2 # there is a quadratic relationship w/ x1, a
  11. p = lo.to.p(lo) # linear relationship w/ x2 & no relationship
  12. y = rbinom(100, size=1, prob=p) # w/ x3
  13.  
  14. model = glm(y~x1+I(x1^2)+x2+x3, family=binomial)
  15. summary(model)
  16. # Call:
  17. # glm(formula = y ~ x1 + I(x1^2) + x2 + x3, family = binomial)
  18. #
  19. # Deviance Residuals:
  20. # Min 1Q Median 3Q Max
  21. # -1.74280 -0.00387 0.00000 0.04145 1.74573
  22. #
  23. # Coefficients:
  24. # Estimate Std. Error z value Pr(>|z|)
  25. # (Intercept) -53.65462 19.65288 -2.730 0.00633 **
  26. # x1 24.78164 8.92910 2.775 0.00551 **
  27. # I(x1^2) -2.49888 0.89344 -2.797 0.00516 **
  28. # x2 0.03318 0.20198 0.164 0.86952
  29. # x3 -0.09277 0.18650 -0.497 0.61890
  30. # ---
  31. # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  32. #
  33. # (Dispersion parameter for binomial family taken to be 1)
  34. #
  35. # Null deviance: 128.207 on 99 degrees of freedom
  36. # Residual deviance: 18.647 on 95 degrees of freedom
  37. # AIC: 28.647
  38. #
  39. # Number of Fisher Scoring iterations: 10
Add Comment
Please, Sign In to add comment