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

problem predicting with re.form #691

Open
bbolker opened this issue Jul 9, 2022 · 1 comment
Open

problem predicting with re.form #691

bbolker opened this issue Jul 9, 2022 · 1 comment

Comments

@bbolker
Copy link
Member

bbolker commented Jul 9, 2022

From StackOverflow

Dataone <- read.csv2("Dataone.csv")
library(lme4)
ModLMER = lmer(Var1~I(Var2)+I(Var2^2)+(1|Var3)+(0+dummy(Var4,"1")|Var5),
                Dataone, REML = TRUE,
                control=lmerControl(check.nobs.vs.nlev="ignore",
                check.nobs.vs.nRE="ignore"))
## attempt to predict excluding dummy term
predict(ModLMER, re.form = ~1|Var3)

Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels

Dataone.csv

@bdeonovic
Copy link

bdeonovic commented Apr 5, 2024

@bbolker Here is another one (with slighly simpler structure) with a slightly different error:

dfo <- read.csv("test.csv")
m1 <- lmer(
            yield ~ lc +
                (1 | g1) +
                (1 | g2) +
                (lc | g3),
            data = dfo
        )
     predict(m1, re.form = ~(1|g1))
Error in `contrasts<-`(`*tmp*`, value = orig.random.cntr[[fn]]) : 
  contrasts can be applied only to factors with 2 or more levels

test.csv

package version info:

r$> sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.6.4

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

other attached packages:
 [1] marginaleffects_0.12.0 ggbeeswarm_0.7.2       lme4_1.1-33            Matrix_1.5-3           readxl_1.4.2           here_1.0.1             lubridate_1.9.2        forcats_1.0.0         
 [9] stringr_1.5.0          dplyr_1.1.1            purrr_1.0.1            readr_2.1.4            tidyr_1.3.0            tibble_3.2.1           ggplot2_3.4.4          tidyverse_2.0.0       

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.12       vipor_0.4.5       nloptr_2.0.3      pillar_1.9.0      compiler_4.2.3    cellranger_1.1.0  tools_4.2.3       boot_1.3-28.1     nlme_3.1-162      jsonlite_1.8.8   
[11] lifecycle_1.0.4   gtable_0.3.4      timechange_0.2.0  lattice_0.20-45   pkgconfig_2.0.3   rlang_1.1.3       cli_3.6.2         beeswarm_0.4.0    withr_3.0.0       generics_0.1.3   
[21] vctrs_0.6.5       hms_1.1.3         rprojroot_2.0.3   grid_4.2.3        tidyselect_1.2.0  data.table_1.14.8 glue_1.7.0        R6_2.5.1          fansi_1.0.6       minqa_1.2.5      
[31] tzdb_0.3.0        magrittr_2.0.3    MASS_7.3-58.2     splines_4.2.3     scales_1.3.0      colorspace_2.1-0  utf8_1.2.4        stringi_1.7.12    munsell_0.5.0    

bbolker added a commit that referenced this issue Apr 21, 2024
bbolker added a commit that referenced this issue Apr 29, 2024
bbolker added a commit that referenced this issue Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants