Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard Errors lost with multicolinearity #127

Open
leeper opened this issue Sep 29, 2019 · 0 comments

Comments

@leeper
Copy link
Owner

commented Sep 29, 2019

Please specify whether your issue is about:

  • a possible bug
  • a question about package functionality
  • a suggested code or documentation change, improvement to the code, or feature request
## load package
library("margins")

## code goes here
library(margins)

y = rbinom(n=100, 1, .5)
x1 = rnorm(100)
x2 = runif(100)
x3 = 2*x2
sim_dat <- data.frame(cbind(y, x1, x2, x3))
mylogit <- glm(y ~ x1 + x2 + x3, data = sim_dat, family = "binomial"(link = logit))
sumout <- summary(margins(mylogit))
## There were 20 warnings (use warnings() to see them)
print(sumout)
##  factor    AME SE  z  p lower upper
##      x1 0.0776 NA NA NA    NA    NA
##      x2 0.1430 NA NA NA    NA    NA
##      x3 0.0000 NA NA NA    NA    NA
mylogit
## Call:  glm(formula = y ~ x1 + x2 + x3, family = binomial(link = logit), 
##     data = sim_dat)
## 
## Coefficients:
## (Intercept)           x1           x2           x3  
##     -0.3773       0.3205       0.5906           NA  
## 
## Degrees of Freedom: 99 Total (i.e. Null);  97 Residual
## Null Deviance:      138.5 
## Residual Deviance: 135.5        AIC: 141.5
vcov(mylogit)
##             (Intercept)          x1          x2 x3
## (Intercept)  0.14416731 -0.01185947 -0.21880287 NA
## x1          -0.01185947  0.04196244  0.01843671 NA
## x2          -0.21880287  0.01843671  0.46649843 NA
## x3                   NA          NA          NA NA
coef(mylogit)
## (Intercept)          x1          x2          x3 
##  -0.3773247   0.3204783   0.5905926          NA 
## margins(mylogit)
## Average marginal effects
## glm(formula = y ~ x1 + x2 + x3, family = binomial(link = logit),     data = sim_dat)
## 
##       x1    x2 x3
##  0.07761 0.143  0
## There were 20 warnings (use warnings() to see them)
## session info for your system
sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] margins_0.3.23

loaded via a namespace (and not attached):
[1] MASS_7.3-51.4     compiler_3.6.1    data.table_1.12.2 prediction_0.3.14
@leeper leeper added the bug label Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.