leeper / cregg

Simple Conjoint Analyses, Tidying, and Visualization
Other
49 stars 7 forks source link

Why is it possible to get MMs but not AMCEs (same data set), "Error in svydesign.default(ids = id, weights = ~1, data = data) : Design has only one primary sampling unit" #43

Open bridgeovertroubledhuman opened 1 year ago

bridgeovertroubledhuman commented 1 year ago

I wonder if this is a possible bug, or just an error message that is not 100% user friendly.

Basically the MM is all fine, and the AMCE is not produced at all.

Do you need the reproducible example?

Put your code here:


## load package
library("cregg")

> all_mm <- mm(
+   datacj,
+   choice0 ~ location + reimburse + purchase + price + provider,
+   id = "userid",
+   weights = NULL,
+   feature_order = NULL,
+   feature_labels = my_labels,
+   level_order = c("descending"),
+ )
Warning messages:
1: In logLik.svyglm(x) : svyglm not fitted by maximum likelihood.
2: In logLik.svyglm(x) : svyglm not fitted by maximum likelihood.
3: In logLik.svyglm(x) : svyglm not fitted by maximum likelihood.
4: In logLik.svyglm(x) : svyglm not fitted by maximum likelihood.
5: In logLik.svyglm(x) : svyglm not fitted by maximum likelihood.

> amce(
+   datacj,
+   choice0 ~ location + reimburse + purchase + price + provider,
+   id = "userid",
+   weights = NULL,
+   feature_order = NULL,
+   feature_labels = my_labels,
+   level_order = c("descending")
+ )
Error in svydesign.default(ids = id, weights = ~1, data = data) : 
  Design has only one primary sampling unit
> traceback
function (x = NULL, max.lines = getOption("traceback.max.lines", 
    getOption("deparse.max.lines", -1L))) 
{
    n <- length(x <- .traceback(x, max.lines = max.lines))
    if (n == 0L) 
        cat(gettext("No traceback available"), "\n")
    else {
        for (i in 1L:n) {
            xi <- x[[i]]
            label <- paste0(n - i + 1L, ": ")
            m <- length(xi)
            srcloc <- if (!is.null(srcref <- attr(xi, "srcref"))) {
                srcfile <- attr(srcref, "srcfile")
                paste0(" at ", basename(srcfile$filename), "#", 
                  srcref[1L])
            }
            if (isTRUE(attr(xi, "truncated"))) {
                xi <- c(xi, " ...")
                m <- length(xi)
            }
            if (!is.null(srcloc)) {
                xi[m] <- paste0(xi[m], srcloc)
            }
            if (m > 1) 
                label <- c(label, rep(substr("          ", 1L, 
                  nchar(label, type = "w")), m - 1L))
            cat(paste0(label, xi), sep = "\n")
        }
    }
    invisible(x)
}
<bytecode: 0x12a605e78>
<environment: namespace:base>

## session info for your system

> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.6

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/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] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.5.1       Hmisc_4.7-1         Formula_1.2-4       lattice_0.20-44     labelled_2.10.0     tikzDevice_0.12.3.1 gridExtra_2.3      
 [8] readstata13_0.10.0  miceadds_3.15-21    mice_3.15.0         haven_2.4.3         dplyr_1.0.7         cregg_0.4.0         cjoint_2.1.0       
[15] survey_4.1-1        survival_3.2-11     Matrix_1.5-1        ggplot2_3.3.5       lmtest_0.9-38       zoo_1.8-9           sandwich_3.0-1     
[22] tidyr_1.1.4         pacman_0.5.1       

loaded via a namespace (and not attached):
 [1] splines_4.1.1       shiny_1.7.1         assertthat_0.2.1    latticeExtra_0.6-30 ggstance_0.3.5      pillar_1.6.3        backports_1.2.1    
 [8] glue_1.4.2          digest_0.6.28       RColorBrewer_1.1-2  promises_1.2.0.1    checkmate_2.1.0     colorspace_2.0-2    cowplot_1.1.1      
[15] htmltools_0.5.2     httpuv_1.6.3        plyr_1.8.6          pkgconfig_2.0.3     broom_0.7.9         purrr_0.3.4         xtable_1.8-4       
[22] scales_1.1.1        jpeg_0.1-9          later_1.3.0         tibble_3.1.5        htmlTable_2.4.1     generics_0.1.0      farver_2.1.0       
[29] ellipsis_0.3.2      withr_2.4.2         nnet_7.3-16         cli_3.0.1           magrittr_2.0.1      crayon_1.4.1        mime_0.12          
[36] deldir_1.0-6        fansi_0.5.0         foreign_0.8-81      data.table_1.14.2   tools_4.1.1         hms_1.1.1           mitools_2.4        
[43] lifecycle_1.0.1     stringr_1.4.0       interp_1.1-3        munsell_0.5.0       cluster_2.1.2       compiler_4.1.1      rlang_0.4.11       
[50] rstudioapi_0.13     htmlwidgets_1.5.4   filehash_2.4-3      base64enc_0.1-3     labeling_0.4.2      gtable_0.3.0        DBI_1.1.1          
[57] R6_2.5.1            knitr_1.36          fastmap_1.1.0       utf8_1.2.2          stringi_1.7.5       Rcpp_1.0.7          vctrs_0.3.8        
[64] rpart_4.1-15        png_0.1-7           xfun_0.26           tidyselect_1.1.1