Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set.seed(666)
- x1 = rnorm(1000,0,1) # some continuous variables
- x2 = rnorm(1000,0,1)
- z = 1 + 2*x1 + 3*x2 # linear combination with a bias
- pr = 1/(1+exp(-z)) # pass through an inv-logit function
- y = rbinom(length(x1),1,pr) # bernoulli response variable
- df = data.frame(y=y,x1=x1,x2=x2)
- glm( y~x1+x2,data=df,family="binomial")
- set.seed(666)
- x1 = rnorm(1000,0,1)
- z = 1 + 2*x1 + 3*x1^2
- pr = 1/(1+exp(-z))
- y = rbinom(length(x1),1,pr)
- df = data.frame(y=y,
- x1=x1,
- x2=x1^2)
- glm( y~x1+x2,
- data=df,
- family="binomial")
- Call: glm(formula = y ~ x1 + x2, family = "binomial", data = df)
- Coefficients:
- (Intercept) x1 x2
- 1.002 2.437 3.490
- Degrees of Freedom: 999 Total (i.e. Null); 997 Residual
- Null Deviance: 795.3
- Residual Deviance: 615.9 AIC: 621.9
- Warning message:
- glm.fit: fitted probabilities numerically 0 or 1 occurred
- set.seed(666)
- x1 = rnorm(1000,10,1)
- z = 1 + 2*x1 + 3*x1^2
- pr = 1/(1+exp(-z))
- y = rbinom(length(x1),1,pr)
- df = data.frame(y=y,
- x1=x1,
- x2=x1^2)
- glm( y~x1+x2,
- data=df,
- family="binomial")
- Call: glm(formula = y ~ x1 + x2, family = "binomial", data = df)
- Coefficients:
- (Intercept) x1 x2
- 2.657e+01 -2.351e-08 1.234e-09
- Degrees of Freedom: 999 Total (i.e. Null); 997 Residual
- Null Deviance: 0
- Residual Deviance: 5.802e-09 AIC: 6
- Warning message:
- glm.fit: algorithm did not converge
- set.seed(666)
- x1 = rnorm(1000,10,1)
- x1=scale(x1)
- z = 1 + 2*x1 + 3*(x1)^2
- pr = 1/(1+exp(-z))
- y = rbinom(length(x1),1,pr)
- df = data.frame(y=y,
- x1=x1,
- x2=x1^2)
- glm( y~x1+x2,
- data=df,
- family="binomial")
- Call: glm(formula = y ~ x1 + x2, family = "binomial", data = df)
- Coefficients:
- (Intercept) x1 x2
- 0.9872 2.4292 3.5237
- Degrees of Freedom: 999 Total (i.e. Null); 997 Residual
- Null Deviance: 787.8
- Residual Deviance: 605.7 AIC: 611.7
- Warning message:
- glm.fit: fitted probabilities numerically 0 or 1 occurred
Add Comment
Please, Sign In to add comment