r2mlm
r2mlm copied to clipboard
r2mlm3_manual(): Error in seq(max(as.numeric(data[, l2clusterID_noncmc])))
Hello! Wonderful package here, so grateful for your work on this. I'm trying to use the r2mlm3_manual() function and I'm running into an error. It's possible I've just made a mistake in the manual function input somewhere, but I wanted to raise in case it was an issue with the function.
Here's the error I get:
Error in seq(max(as.numeric(data[, l2clusterID_noncmc]))) : 'list' object cannot be coerced to type 'double'
My model is:
wai_early <- lmer(WAI.Total ~ 1 + Session_c_early + Session_c_early_quad + Early_Affirm_c + Early_Affirm_c*Session_c_early + (1 | ParticipantID) + (1 | TherapistID), REML = T, data = apps_alliance)
And this is what I entered into the function:
r2mlm3_manual(
apps_alliance,
l1_covs = c("Session_c_early", "Session_c_early_quad"), # vector of variable names for level-1 predictors
l2_covs = c("Early_Affirm_c"), # samesies for level-2 predictors
l3_covs = NULL,
random_covs12 = NULL,
random_covs13 = NULL,
random_covs23 = NULL,
gamma_1 = c(0.940, -0.043), # level 1 fixed effect estimates: linear & quad slope
gamma_2 = c(1.173, -0.060), # level 2 fixed effect estimates: APPS and interaction
gamma_3 = NULL,
Tau12 = NULL,
Tau13 = NULL,
Tau23 = NULL,
sigma2 = 31.60462,
clustermeancentered = F,
Tau2_noncmc = c(63.71232),
Tau3_noncmc = c(31.56192),
l2clusterID_noncmc = "ParticipantID",
l3clusterID_noncmc = "TherapistID",
bargraph = F
)
In my dataset, both the cluster IDs are stored as numeric variables already so I'm not sure why it's saying this.
Also, I am new to the realm of Github (this is my first time posting an issue!) so please let me know if you need additional info. Happy to provide!
Hi @tj-sullivan, there are some other typos in the function that might be causing that error, which will be addressed this week. I'll update you when the fixes are up on CRAN, and we'll see if the issue persists.
@tj-sullivan New version is on CRAN, want to try re-installing the package and running your code again?
Hi @mkshaw, thanks for that! I just re-ran it with the updated package and I'm still getting the same error.
I have the same issue. Is there a solution to this?
@Luc447 are you able to share any data (even a subset or simulated) that replicates the problem?
Hi Mairead,
Thank you very much for your help! Here is the R Code and sample data.
Is this enough to reproduce the problem?
Best, Luciano
Modellanpassung ds Modells mit Interaktionseffekt
fit_ELFE <- lmer(ELFE ~ 1 + sex + Grade + Index1 * Interv_Cond + Sprache_TI_T2 + (1 | Class_ID) + (1 | Class_ID:student_id), data = daten3, control = lmerControl(), REML = TRUE) summary(fit_ELFE)
Extrahieren der festen Effekte (Gammas)
gamma_1 <- fixef(fit)[c("Index1")] # Level-1 Prädiktor gamma_2 <- fixef(fit)[c("sex", "Sprache_TI_T2")] # Level-2 Prädiktoren gamma_3 <- fixef(fit)[c("Grade", "Interv_Cond")] # Level-3 Prädiktoren
Extrahieren der Varianz-Kovarianz-Matrizen für Level 2 und Level 3
random_effects <- VarCorr(fit_ELFE)
Konvertieren der zufälligen Effekte in einfache numerische Matrizen
Tau2_noncmc <- matrix(as.numeric(random_effects$Class_ID:student_id
[1, 1]), nrow = 1, ncol = 1)
Tau3_noncmc <- matrix(as.numeric(random_effects$Class_ID[1, 1]), nrow = 1, ncol = 1)
Extrahieren der Residualvarianz
sigma2 <- sigma(fit_ELFE)^2
r2_values <- r2mlm3_manual( data = daten3, l1_covs = c("Index1"), l2_covs = c("sex", "Sprache_TI_T2"), l3_covs = c("Grade", "Interv_Cond"), random_covs12 = NULL, random_covs13 = NULL, random_covs23 = NULL, gamma_1 = gamma_1, gamma_2 = gamma_2, gamma_3 = gamma_3, Tau2_noncmc = Tau2_noncmc, Tau3_noncmc = Tau3_noncmc, sigma2 = sigma2, clustermeancentered = FALSE, l2clusterID_noncmc = 2, # Direkte numerische Vektoren verwenden l3clusterID_noncmc = 1 # Direkte numerische Vektoren verwenden )
Von: Mairead Shaw @.> Gesendet: Dienstag, 20 August 2024 20:53 An: mkshaw/r2mlm @.> Cc: Gasser, Luciano @.>; Mention @.> Betreff: Re: [mkshaw/r2mlm] r2mlm3_manual(): Error in seq(max(as.numeric(data[, l2clusterID_noncmc]))) (Issue #61)
Sie erhalten nicht oft eine E-Mail von @.@.>. Erfahren Sie, warum dies wichtig isthttps://aka.ms/LearnAboutSenderIdentification
@Luc447https://github.com/Luc447 are you able to share any data (even a subset or simulated) that replicates the problem?
— Reply to this email directly, view it on GitHubhttps://github.com/mkshaw/r2mlm/issues/61#issuecomment-2299537552, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BKUGCEFJ57B2XN3TUTZLCCDZSOF67AVCNFSM6AAAAABMZHQUKWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJZGUZTONJVGI. You are receiving this because you were mentioned.Message ID: @.@.>>
@Luc447 I can't reproduce it without the data (daten3
in this case). If you want, you can email it to me (mairead dot shaw at mail dot mcgill dot ca) or just a subset of it that reproduces the problem.