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

Margins for clustered standard errors - new error #122

Open
jonlatner opened this issue May 24, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@jonlatner
Copy link

commented May 24, 2019

Please specify whether your issue is about:

There appears to be a new issue with combining clustered standard error with miceadds and margins.

As published in the following two links, the code below used to work, but not any more:

https://stackoverflow.com/questions/51260518/how-to-get-the-marginal-effects-after-lm-robust-with-clustered-standard-errors
#97

The following code produces the following error:
Error in data[[variable]] : object of type 'closure' is not subsettable

Put your code here:

## load package
library("margins")
library(fabricatr)
library(randomizr)
library(miceadds)

## code goes here
set.seed(42)
dat <- fabricate(
        N = 100,                        # sample size
        x = runif(N, 0, 1),             # pre-treatment covariate
        y0 = rnorm(N, mean = x),        # control potential outcome
        y1 = y0 + 0.35,                 # treatment potential outcome
        z = complete_ra(N),             # complete random assignment to treatment
        y = ifelse(z, y1, y0),          # observed outcome
        
        # We will also consider clustered data
        clust = sample(rep(letters[1:20], each = 5)),
        z_clust = cluster_ra(clust),
        y_clust = ifelse(z_clust, y1, y0)
)

lmout_cl <- lm.cluster(y_clust ~ z_clust + x, data=dat, cluster="clust")
mar_cl <- with(lmout_cl, margins(lm_res, vcov=vcov))

## session info for your system
sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] margins_0.3.23   miceadds_3.3-33  mice_3.5.0       lattice_0.20-38  randomizr_0.18.0 fabricatr_0.8.0 
@leeper

This comment has been minimized.

Copy link
Owner

commented May 24, 2019

This is not a supported model type currently.

@leeper leeper added the question label May 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.