Guest User

Untitled

a guest
Aug 14th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. set.seed(666)
  2. x1 = rnorm(1000,0,1) # some continuous variables
  3. x2 = rnorm(1000,0,1)
  4. z = 1 + 2*x1 + 3*x2 # linear combination with a bias
  5.  
  6. pr = 1/(1+exp(-z)) # pass through an inv-logit function
  7. y = rbinom(length(x1),1,pr) # bernoulli response variable
  8.  
  9. df = data.frame(y=y,x1=x1,x2=x2)
  10. glm( y~x1+x2,data=df,family="binomial")
  11.  
  12. set.seed(666)
  13. x1 = rnorm(1000,0,1)
  14. z = 1 + 2*x1 + 3*x1^2
  15. pr = 1/(1+exp(-z))
  16. y = rbinom(length(x1),1,pr)
  17. df = data.frame(y=y,
  18. x1=x1,
  19. x2=x1^2)
  20. glm( y~x1+x2,
  21. data=df,
  22. family="binomial")
  23.  
  24. Call: glm(formula = y ~ x1 + x2, family = "binomial", data = df)
  25.  
  26. Coefficients:
  27. (Intercept) x1 x2
  28. 1.002 2.437 3.490
  29.  
  30. Degrees of Freedom: 999 Total (i.e. Null); 997 Residual
  31. Null Deviance: 795.3
  32. Residual Deviance: 615.9 AIC: 621.9
  33. Warning message:
  34. glm.fit: fitted probabilities numerically 0 or 1 occurred
  35.  
  36. set.seed(666)
  37. x1 = rnorm(1000,10,1)
  38. z = 1 + 2*x1 + 3*x1^2
  39. pr = 1/(1+exp(-z))
  40. y = rbinom(length(x1),1,pr)
  41.  
  42. df = data.frame(y=y,
  43. x1=x1,
  44. x2=x1^2)
  45. glm( y~x1+x2,
  46. data=df,
  47. family="binomial")
  48. Call: glm(formula = y ~ x1 + x2, family = "binomial", data = df)
  49.  
  50. Coefficients:
  51. (Intercept) x1 x2
  52. 2.657e+01 -2.351e-08 1.234e-09
  53.  
  54. Degrees of Freedom: 999 Total (i.e. Null); 997 Residual
  55. Null Deviance: 0
  56. Residual Deviance: 5.802e-09 AIC: 6
  57. Warning message:
  58. glm.fit: algorithm did not converge
  59.  
  60. set.seed(666)
  61. x1 = rnorm(1000,10,1)
  62. x1=scale(x1)
  63. z = 1 + 2*x1 + 3*(x1)^2
  64. pr = 1/(1+exp(-z))
  65. y = rbinom(length(x1),1,pr)
  66.  
  67. df = data.frame(y=y,
  68. x1=x1,
  69. x2=x1^2)
  70. glm( y~x1+x2,
  71. data=df,
  72. family="binomial")
  73. Call: glm(formula = y ~ x1 + x2, family = "binomial", data = df)
  74.  
  75. Coefficients:
  76. (Intercept) x1 x2
  77. 0.9872 2.4292 3.5237
  78.  
  79. Degrees of Freedom: 999 Total (i.e. Null); 997 Residual
  80. Null Deviance: 787.8
  81. Residual Deviance: 605.7 AIC: 611.7
  82. Warning message:
  83. glm.fit: fitted probabilities numerically 0 or 1 occurred
Add Comment
Please, Sign In to add comment