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(at = ) fails when only one factor level is specified #121

Open
leeper opened this Issue Apr 10, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@leeper
Copy link
Owner

leeper commented Apr 10, 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
> m <- lm(Sepal.Length ~ Sepal.Width * Species, data = iris)
> margins(m, at = list(Species = c("setosa")))
Error in attributes(.Data) <- c(attributes(.Data), attrib) : 
  'names' attribute [1] must be the same length as the vector [0]
> traceback()
7: structure(rep(list(list()), length(levs)), class = "data.frame", 
       names = outcolnames, row.names = seq_len(nrow(data))) at dydx.R#171
6: dydx.factor(data = data, model = model, varslist$fnames[i], type = type, 
       fwrap = FALSE, as.data.frame = as.data.frame, ...) at marginal_effects_glm.R#29
5: marginal_effects.lm(model = model, data = data, variables = variables, 
       type = type, eps = eps, varslist = varslist, ...) at marginal_effects.R#61
4: marginal_effects(model = model, data = data, variables = variables, 
       type = type, eps = eps, varslist = varslist, ...) at build_margins.R#34
3: build_margins(model = model, data = data_list[[i]], variables = variables, 
       type = type, vcov = vcov, vce = vce, iterations = iterations, 
       unit_ses = unit_ses, eps = eps, varslist = varslist, ...) at margins_glm.R#37
2: margins.lm(m, at = list(Species = c("setosa"))) at margins.R#131
1: margins(m, at = list(Species = c("setosa")))

## session info for your system
> sessionInfo()
R version 3.5.3 (2019-03-11)
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    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.1252    

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

other attached packages:
[1] prediction_0.3.10

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1           rappdirs_0.3.1       bit_1.1-14           debugme_1.1.0        R6_2.4.0             blob_1.1.1           tools_3.5.3         
 [8] parsedate_1.1.3      data.table_1.12.2    DBI_1.0.0            remotes_2.0.4        bit64_0.9-7          assertthat_0.2.1     digest_0.6.18       
[15] rprojroot_1.3-2      crancache_0.0.0.9000 crayon_1.3.4         curl_3.3             memoise_1.1.0        RSQLite_2.1.1        cranlike_1.0.2      
[22] compiler_3.5.3       desc_1.2.0           backports_1.1.3
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.