piecewiseSEM
piecewiseSEM copied to clipboard
Error using `multigroup()`, `dsep` fails because of differing number of rows
Looks like an error when dsep() is called from multigroup(). Below I included a reproducible example. Doesn't seem to matter if I use lm() or lme() and regular summary() works
Warning messages:
1: In j[which(j == global[i, "Predictor"])] <- paste0("offset(", ... :
number of items to replace is not a multiple of replacement length
set.seed(1)
test_df <- data.frame(
log_tab_and_branch = rnorm(100, mean = 1.8, sd = 1),
log_massive = rnorm(100, mean = 1.4, sd = 1),
total.storms = rpois(100, lambda = 1.3),
all_cot_sum = rnorm(100, mean = 2.8, sd = 4.1),
Primary = rnorm(100, mean = 0.01, 0.006),
CRS_NO3_SR = rnorm(100, mean = 0.20, sd = 0.08),
total_boat = rnorm(100, mean = 3.9, sd = 16.6),
pre_post = rep(c("pre", "post"), 50),
log_browsing = rnorm(100, mean = 8.6, sd = 1.4),
depth_bin = rep(c("0-5 m", "5-10 m"), 50),
Region = rep(c("A", "B", "C", "D"), 25)
)
test_mod <- psem(
lme(log_tab_and_branch ~ total.storms + total_boat + all_cot_sum + Primary + CRS_NO3_SR,
random = list(Region = ~1, depth_bin = ~1),
na.action = na.omit,
test_df),
lme(log_massive ~ total.storms + CRS_NO3_SR,
random = list(Region = ~1, depth_bin = ~1),
#na.action = na.omit,
test_df),
lme(log_browsing ~ log_tab_and_branch + log_massive + total_boat,
random = list(Region = ~1, depth_bin = ~1),
na.action = na.omit,
test_df),
#
data = test_df
)
test <- summary(test_mod)
test2 <- multigroup(test_mod, group = "pre_post")
Working on it...
Try now?
Still not working. I went poking around and think I've started to get closer to the problem?
I dropped a browser() on line 71 in dSep.R and then ran
test2 <- multigroup(test_mod, group = "pre_post")
By line 90, the bNewMod object is of class "lme" and ct <- unstdCoefs(bNewMod, data) returns an empty dataframe.
[1] Response Predictor Estimate Std.Error DF Crit.Value P.Value
<0 rows> (or 0-length row.names)
Can you provide a reproducible example with a fake dataset?
Jonathan S. Lefcheck, Ph.D. Coordinating Scientist, MarineGEO Smithsonian Institution https://marinegeo.si.edu/ Phone: +1 (443) 482-2443 https://jonlefcheck.net/
From: Jillian Dunicmailto:[email protected]
Sent: Thursday, December 6, 2018 1:55 PM
To: jslefche/piecewiseSEMmailto:[email protected]
Cc: Lefcheck, Jonathanmailto:[email protected]; Commentmailto:[email protected]
Subject: Re: [jslefche/piecewiseSEM] Error using multigroup(), dsep fails because of differing number of rows (#167)
Still not working. I went poking around and think I've started to get closer to the problem?
I dropped a browser() on line 71 in dSep.R and then ran
test2 <- multigroup(test_mod, group = "pre_post")
By line 90, the bNewMod object is of class "lme" and ct <- unstdCoefs(bNewMod, data) returns an empty dataframe.
[1] Response Predictor Estimate Std.Error DF Crit.Value P.Value <0 rows> (or 0-length row.names)
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jslefche/piecewiseSEM/issues/167#issuecomment-444986540, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACPAV6rZTyFcxaKIRrmwJRYZsx8s8MGNks5u2WgQgaJpZM4Y-xj_.
Yeah, the code above has a fake dataset test_df and model test_mod that throws the error.
D'oh sorry, didn't see that...but it works for me. Have you reinstalled from Github lately?
Hmm... I double checked and installed the latest dev version. The only thing that I do differently when using the package from github is I have copied the anova.psem() and run it in my environment to 'manually' export it. But I still get this error even after pulling the latest version of the devel branch, building the package in with load_all(), and then run my test case.
I did realise that I never pasted the actual error message. I don't know if this helps? I'll try it on another machine today and let you know if anything changes.
Error in data.frame(Independ.Claim = paste(b[[i]][2], "~", rhs), ct[, :
arguments imply differing number of rows: 1, 0
I still get the error even on a different machine. As another test case I shared the rls-sem repo with you and you should be able to run the <multigroup-analysis.R> script to see if you can get the error from the real data?
I'm not sure how else to try and share the but with you! This is weird! Here is my sessionInfo() of my latest test. For this test I didn't load nlme and just used lms in the model list.
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] piecewiseSEM_2.1.0 RevoUtils_11.0.1 RevoUtilsMath_11.0.0
loaded via a namespace (and not attached):
[1] zip_1.0.0 Rcpp_0.12.18 nloptr_1.0.4 compiler_3.5.1 pillar_1.3.0 cellranger_1.1.0 git2r_0.23.0
[8] forcats_0.3.0 tools_3.5.1 digest_0.6.15 lme4_1.1-17 nlme_3.1-137 memoise_1.1.0 tibble_1.4.2
[15] lattice_0.20-35 pkgconfig_2.0.1 rlang_0.2.1 Matrix_1.2-14 openxlsx_4.1.0 rstudioapi_0.7 parallel_3.5.1
[22] curl_3.2 yaml_2.2.0 haven_1.1.2 rio_0.5.10 withr_2.1.2 httr_1.3.1 knitr_1.20
[29] devtools_1.13.6 hms_0.4.2 grid_3.5.1 data.table_1.11.4 R6_2.2.2 readxl_1.1.0 foreign_0.8-70
[36] minqa_1.2.4 carData_3.0-1 car_3.0-0 magrittr_1.5 MASS_7.3-50 splines_3.5.1 pbkrtest_0.4-7
[43] abind_1.4-5 crayon_1.3.4
Here is the modified anova.psem() function that I am using to make multigroup() work for me in case this is the problem? It shouldn't be because I just copied and pasted the anova.psem() function and then specify piecewiseSEM:::removeData() and piecewiseSEM:::isSig().
anova.psem <- function(object, ..., test.type = "III") {
l <- list(object, ...)
if(length(l) == 1) {
object <- piecewiseSEM:::removeData(object, formulas = 1)
ret <- lapply(object, function(x) car::Anova(x, type = test.type))
ret <- list(do.call(rbind, lapply(ret, function(i) {
response <- gsub("Response: ", "", attr(i, "heading")[grepl("Response:", attr(i, "heading"))])
dat <- as.data.frame(i)
predictors <- rownames(dat)[-nrow(dat)]
ret <- data.frame(
Response = response,
Predictor = predictors,
Test.Stat = round(dat[-nrow(dat), 1], 1),
DF = dat[-nrow(dat), "Df"],
P.Value = round(dat[-nrow(dat), ncol(dat)], 4)
)
ret <- cbind.data.frame(ret, piecewiseSEM:::isSig(ret$P.Value))
names(ret)[ncol(ret)] <- ""
# ret[, which(sapply(ret, is.numeric))] <- round(ret[, which(sapply(ret, is.numeric))], 4)
return(ret)
} ) ) )
} else {
# need to stop if fit to different datasets
# lapply(l, function(x) GetData(x))
combos <- combn(length(l), 2)
combos <- split(t(combos), seq(ncol(combos)))
ret <- lapply(combos, function(i) {
nm1 <- deparse(substitute(l[[i[1]]]))
nm2 <- deparse(substitute(l[[i[2]]]))
model1 <- l[[i[1]]]
model2 <- l[[i[2]]]
model1.summary <- summary(model1, .progressBar = FALSE)
model2.summary <- summary(model2, .progressBar = FALSE)
Cdiff <- abs(model1.summary$Cstat$Fisher.C - model2.summary$Cstat$Fisher.C)
dfdiff <- abs(model1.summary$Cstat$df - model2.summary$Cstat$df)
pvalue <- round(1 - pchisq(Cdiff, df = dfdiff), 4)
ret <- data.frame(
AIC = c(model1.summary$IC$AIC, model2.summary$IC$AIC),
BIC = c(model1.summary$IC$BIC, model2.summary$IC$BIC),
Fisher.C = c(model1.summary$Cstat$Fisher.C, model2.summary$Cstat$Fisher.C),
Fisher.C.Diff = c("", Cdiff),
DF.diff = c("", dfdiff),
P.value = c("", pvalue),
sig = c("", piecewiseSEM:::isSig(pvalue))
)
colnames(ret)[ncol(ret)] <- ""
rownames(ret) <- c(paste(i[1]), paste("vs", i[2]))
return(ret)
} )
}
class(ret) <- "anova.psem"
return(ret)
}
Hmm, try the new anova.psem function: I broke it up to play better with S3methods. See the most recent update on Github.
If that doesn’t work, can you email me your session? Maybe I can see what’s going on if I load that on my or another computer
PS are you on PC or Mac?
Jonathan S. Lefcheck, Ph.D. Coordinating Scientist, MarineGEO Smithsonian Institution https://marinegeo.si.edu/ Phone: +1 (443) 482-2443 https://jonlefcheck.net/
From: Jillian Dunicmailto:[email protected]
Sent: Wednesday, December 12, 2018 6:42 PM
To: jslefche/piecewiseSEMmailto:[email protected]
Cc: Lefcheck, Jonathanmailto:[email protected]; Commentmailto:[email protected]
Subject: Re: [jslefche/piecewiseSEM] Error using multigroup(), dsep fails because of differing number of rows (#167)
I still get the error even on a different machine. As another test case I shared the rls-sem repo with you and you should be able to run the <multigroup-analysis.R> script to see if you can get the error from the real data?
I'm not sure how else to try and share the but with you! This is weird! Here is my sessionInfo() of my latest test. For this test I didn't load nlme and just used lms in the model list.
R version 3.5.1 (2018-07-02) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] piecewiseSEM_2.1.0 RevoUtils_11.0.1 RevoUtilsMath_11.0.0
loaded via a namespace (and not attached): [1] zip_1.0.0 Rcpp_0.12.18 nloptr_1.0.4 compiler_3.5.1 pillar_1.3.0 cellranger_1.1.0 git2r_0.23.0 [8] forcats_0.3.0 tools_3.5.1 digest_0.6.15 lme4_1.1-17 nlme_3.1-137 memoise_1.1.0 tibble_1.4.2 [15] lattice_0.20-35 pkgconfig_2.0.1 rlang_0.2.1 Matrix_1.2-14 openxlsx_4.1.0 rstudioapi_0.7 parallel_3.5.1 [22] curl_3.2 yaml_2.2.0 haven_1.1.2 rio_0.5.10 withr_2.1.2 httr_1.3.1 knitr_1.20 [29] devtools_1.13.6 hms_0.4.2 grid_3.5.1 data.table_1.11.4 R6_2.2.2 readxl_1.1.0 foreign_0.8-70 [36] minqa_1.2.4 carData_3.0-1 car_3.0-0 magrittr_1.5 MASS_7.3-50 splines_3.5.1 pbkrtest_0.4-7 [43] abind_1.4-5 crayon_1.3.4
Here is the modified anova.psem() function that I am using to make multigroup() work for me in case this is the problem? It shouldn't be because I just copied and pasted the anova.psem() function and then specify piecewiseSEM:::removeData() and piecewiseSEM:::isSig().
anova.psem <- function(object, ..., test.type = "III") {
l <- list(object, ...)
if(length(l) == 1) {
object <- piecewiseSEM:::removeData(object, formulas = 1)
ret <- lapply(object, function(x) car::Anova(x, type = test.type))
ret <- list(do.call(rbind, lapply(ret, function(i) {
response <- gsub("Response: ", "", attr(i, "heading")[grepl("Response:", attr(i, "heading"))])
dat <- as.data.frame(i)
predictors <- rownames(dat)[-nrow(dat)]
ret <- data.frame(
Response = response,
Predictor = predictors,
Test.Stat = round(dat[-nrow(dat), 1], 1),
DF = dat[-nrow(dat), "Df"],
P.Value = round(dat[-nrow(dat), ncol(dat)], 4)
)
ret <- cbind.data.frame(ret, piecewiseSEM:::isSig(ret$P.Value))
names(ret)[ncol(ret)] <- ""
# ret[, which(sapply(ret, is.numeric))] <- round(ret[, which(sapply(ret, is.numeric))], 4)
return(ret)
} ) ) )
} else {
# need to stop if fit to different datasets
# lapply(l, function(x) GetData(x))
combos <- combn(length(l), 2)
combos <- split(t(combos), seq(ncol(combos)))
ret <- lapply(combos, function(i) {
nm1 <- deparse(substitute(l[[i[1]]]))
nm2 <- deparse(substitute(l[[i[2]]]))
model1 <- l[[i[1]]]
model2 <- l[[i[2]]]
model1.summary <- summary(model1, .progressBar = FALSE)
model2.summary <- summary(model2, .progressBar = FALSE)
Cdiff <- abs(model1.summary$Cstat$Fisher.C - model2.summary$Cstat$Fisher.C)
dfdiff <- abs(model1.summary$Cstat$df - model2.summary$Cstat$df)
pvalue <- round(1 - pchisq(Cdiff, df = dfdiff), 4)
ret <- data.frame(
AIC = c(model1.summary$IC$AIC, model2.summary$IC$AIC),
BIC = c(model1.summary$IC$BIC, model2.summary$IC$BIC),
Fisher.C = c(model1.summary$Cstat$Fisher.C, model2.summary$Cstat$Fisher.C),
Fisher.C.Diff = c("", Cdiff),
DF.diff = c("", dfdiff),
P.value = c("", pvalue),
sig = c("", piecewiseSEM:::isSig(pvalue))
)
colnames(ret)[ncol(ret)] <- ""
rownames(ret) <- c(paste(i[1]), paste("vs", i[2]))
return(ret)
} )
}
class(ret) <- "anova.psem"
return(ret)
}
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jslefche/piecewiseSEM/issues/167#issuecomment-446786562, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACPAVwWRmjShsKySuMciKbTAvl01t2oaks5u4ZRZgaJpZM4Y-xj_.
Did you do that today? Last commit online is from 8 days ago.
Right now I'm on a Mac, but I tested it using windows and ubuntu yesterday and got the same error.
No that is the latest commit but the code you shared earlier was from an older version. Anova is no broken into anovaLRT and anovaSingleModel (or something like that)
Jonathan S. Lefcheck, Ph.D. Coordinating Scientist, MarineGEO Smithsonian Institution https://marinegeo.si.edu/ Phone: +1 (443) 482-2443 https://jonlefcheck.net/
From: Jillian Dunicmailto:[email protected]
Sent: Thursday, December 13, 2018 2:00 PM
To: jslefche/piecewiseSEMmailto:[email protected]
Cc: Lefcheck, Jonathanmailto:[email protected]; Commentmailto:[email protected]
Subject: Re: [jslefche/piecewiseSEM] Error using multigroup(), dsep fails because of differing number of rows (#167)
Did you do that today? Last commit online is from 8 days ago.
Right now I'm on a Mac, but I tested it using windows and ubuntu yesterday and got the same error.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jslefche/piecewiseSEM/issues/167#issuecomment-447081456, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACPAV93RD73HmWjYGu7MZoWRPtZfMmJOks5u4qPNgaJpZM4Y-xj_.
OMG. This bug is because I'm using lme4 1.1-19. multigroup() works with lme4 1.1-18.
WOAH weird. Glad you got it sorted. Can you share the output, etc. when you’ve run it on actual data. I want to ensure that everything is performing/looking as it should
J
Jonathan S. Lefcheck, Ph.D. Coordinating Scientist, MarineGEO Smithsonian Institution https://marinegeo.si.edu/ Phone: +1 (443) 482-2443 https://jonlefcheck.net/
From: Jillian Dunicmailto:[email protected]
Sent: Thursday, December 13, 2018 9:32 PM
To: jslefche/piecewiseSEMmailto:[email protected]
Cc: Lefcheck, Jonathanmailto:[email protected]; Commentmailto:[email protected]
Subject: Re: [jslefche/piecewiseSEM] Error using multigroup(), dsep fails because of differing number of rows (#167)
OMG. This bug is because I'm using lme4 1.1-19. multigroup() works with lme4 1.1-18.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jslefche/piecewiseSEM/issues/167#issuecomment-447192477, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACPAV48ntf2qdy7I9k8e6eFP73MFtdftks5u4w2wgaJpZM4Y-xj_.
Wait - does it not work the newer version? If so, that’s something we should work out.
-Jarrett On Dec 14, 2018, 9:02 AM -0500, Jon Lefcheck [email protected], wrote: WOAH weird. Glad you got it sorted. Can you share the output, etc. when you’ve run it on actual data. I want to ensure that everything is performing/looking as it should
J
Jonathan S. Lefcheck, Ph.D. Coordinating Scientist, MarineGEO Smithsonian Institution https://marinegeo.si.edu/ Phone: +1 (443) 482-2443 https://jonlefcheck.net/
From: Jillian Dunicmailto:[email protected]
Sent: Thursday, December 13, 2018 9:32 PM
To: jslefche/piecewiseSEMmailto:[email protected]
Cc: Lefcheck, Jonathanmailto:[email protected]; Commentmailto:[email protected]
Subject: Re: [jslefche/piecewiseSEM] Error using multigroup(), dsep fails because of differing number of rows (#167)
OMG. This bug is because I'm using lme4 1.1-19. multigroup() works with lme4 1.1-18.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jslefche/piecewiseSEM/issues/167#issuecomment-447192477, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACPAV48ntf2qdy7I9k8e6eFP73MFtdftks5u4w2wgaJpZM4Y-xj_.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/jslefche/piecewiseSEM/issues/167#issuecomment-447334223, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAuOoqf0Wl9ggD_abY3bOkZ1BRqm_7eIks5u469zgaJpZM4Y-xj_.
Whoops I read this backwards…yes. I just updated…I’ll try and chase it down
Jonathan S. Lefcheck, Ph.D. Coordinating Scientist, MarineGEO Smithsonian Institution https://marinegeo.si.edu/ Phone: +1 (443) 482-2443 https://jonlefcheck.net/
From: Jarrett Byrnesmailto:[email protected]
Sent: Monday, December 17, 2018 10:45 AM
To: jslefche/piecewiseSEMmailto:[email protected]
Cc: Lefcheck, Jonathanmailto:[email protected]; Commentmailto:[email protected]
Subject: Re: [jslefche/piecewiseSEM] Error using multigroup(), dsep fails because of differing number of rows (#167)
Wait - does it not work the newer version? If so, that’s something we should work out.
-Jarrett On Dec 14, 2018, 9:02 AM -0500, Jon Lefcheck [email protected], wrote: WOAH weird. Glad you got it sorted. Can you share the output, etc. when you’ve run it on actual data. I want to ensure that everything is performing/looking as it should
J
Jonathan S. Lefcheck, Ph.D. Coordinating Scientist, MarineGEO Smithsonian Institution https://marinegeo.si.edu/ Phone: +1 (443) 482-2443 https://jonlefcheck.net/
From: Jillian Dunicmailto:[email protected]
Sent: Thursday, December 13, 2018 9:32 PM
To: jslefche/piecewiseSEMmailto:[email protected]
Cc: Lefcheck, Jonathanmailto:[email protected]; Commentmailto:[email protected]
Subject: Re: [jslefche/piecewiseSEM] Error using multigroup(), dsep fails because of differing number of rows (#167)
OMG. This bug is because I'm using lme4 1.1-19. multigroup() works with lme4 1.1-18.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jslefche/piecewiseSEM/issues/167#issuecomment-447192477, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACPAV48ntf2qdy7I9k8e6eFP73MFtdftks5u4w2wgaJpZM4Y-xj_.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/jslefche/piecewiseSEM/issues/167#issuecomment-447334223, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAuOoqf0Wl9ggD_abY3bOkZ1BRqm_7eIks5u469zgaJpZM4Y-xj_.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jslefche/piecewiseSEM/issues/167#issuecomment-447891049, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACPAV5mauTM07EGf2hrzm5STHy06ObO5ks5u57wRgaJpZM4Y-xj_.
Ok fixed it...see if it works and/or if anything else broke!
Thank you so much! This made multigroup() run. But now I don't think that it is behaving correctly on the real data. This might be because I still don't understand the process, but when I test multigroup on the example dataset I posted above I get the kind of output I am expecting.
The two oddities that I have noticed are:
- The model-wide interactions gives me n-1 of each response pathway. So if I had a model: a = b + c + d + e
model-wide interactions looked like (with e:group missing): b:group c:group d:group
This happened for each pathway, the last predictor:group is missing.
- When I look at the model-wide interactions in my dataset, it identifies four paths that vary depending on group. However, these four paths are not the four paths that are left unconstrained between the two models. Instead the four paths that are unconstrained are four seemingly response variables but the predictors are all the same: i.e., they are all total_boat but total_boat was never a predictor shown to interact with the grouping variable and total_boat was always written last in my models. (I just did a quick check where I switched the position of total_boat to the penultimate position in a model and now it's constraining every pathway between the two groups.)
Is a path only constrained when both the predictor*grouping interaction and that path in at least one of the groups is an important predictor? Even if this is the case I have one instance where multigroup() identified log_tab_branch <- total.storms as varying between groups and total.storms is a significant predictor of log_tab_branch but it was constrained between the two group models.
Unfortunately I have not been able to make a reproducible example such as I used before. I've modified the test data and models but the most that happens is that every parameter is constrained even when a significant predictor*group interaction has been identified (which might be what is supposed to happen in this case?).
set.seed(1)
test_df <- data.frame(
log_tab_and_branch = rnorm(150, mean = 1.8, sd = 1),
log_massive = rnorm(150, mean = 1.4, sd = 1),
log_turf = rnorm(150, mean = 3.1, sd = 1),
total.storms = rpois(150, lambda = 1.3),
all_cot_sum = rnorm(150, mean = 2.8, sd = 4.1),
Primary = rnorm(150, mean = 0.01, 0.006),
CRS_NO3_SR = rnorm(150, mean = 0.20, sd = 0.08),
total_boat = rnorm(150, mean = 3.9, sd = 16.6),
pre_post = rep(c("pre", "post"), 75),
log_browsing = rnorm(150, mean = 8.6, sd = 1.4),
log_scraping = rnorm(150, mean = 7.7, sd = 1.8),
depth_bin = rep(c("0-5 m", "5-10 m"), 75),
Region = rep(c("A", "B", "C"), 50)
)
test_mod <- psem(
lm(log_tab_and_branch ~ total.storms + all_cot_sum + Primary + CRS_NO3_SR + total_boat,
#random = list(Region = ~1, depth_bin = ~1),
#na.action = na.omit,
test_df),
lm(log_massive ~ total.storms + CRS_NO3_SR + Primary + total_boat,
#random = list(Region = ~1, depth_bin = ~1),
#na.action = na.omit,
test_df),
lm(log_turf ~ total.storms + CRS_NO3_SR + total_boat,
#random = list(Region = ~1, depth_bin = ~1),
#na.action = na.omit,
test_df),
lm(log_browsing ~ log_tab_and_branch + log_massive + total.storms,
#random = list(Region = ~1, depth_bin = ~1),
#na.action = na.omit,
test_df),
#
data = test_df
)
test <- summary(test_mod)
test2 <- multigroup(test_mod, group = "pre_post")
test2
Sorry for the slow reply....I see what you're saying: if the interaction is significant, the parameter estimate should vary by group. If not, it should be constrained and the same for every group. I tried to play around with this, but the package is now behaving as it should:
data <- data.frame(
a = runif(100),
b = runif(100),
c = runif(100),
d = runif(100),
e = c(runif(50, 0, 1), runif(50, 100, 200)),
group = letters[1:4]
)
modelList <- psem(
lm(a ~ b + c + d + e, data)
)
multigroup(modelList, group = "group")
Perhaps yours is a more complicated example? Or something i've changed in another update has inadvertently fixed the issue? Let me know if you're still encountering it...
Thanks I know you are super busy!
The first problem has been fixed. All the predictors now show up. The second problem with everything being constrained is still happening.
Strange, in the dummy models I put together, I see alternately constrained and unconstrainted paths which align with the results of the type III ANOVA. Do you have an example? Email me directly if you don’t want to share
Jonathan S. Lefcheck, Ph.D. Tennenbaum Coordinating Scientist MarineGEO: https://marinegeo.si.edu/ Smithsonian Institution Phone: +1 (443) 482-2443 www.jonlefcheck.nethttp://www.jonlefcheck.net
From: Jillian Dunicmailto:[email protected]
Sent: Friday, February 8, 2019 2:45 PM
To: jslefche/piecewiseSEMmailto:[email protected]
Cc: Lefcheck, Jonathanmailto:[email protected]; Commentmailto:[email protected]
Subject: Re: [jslefche/piecewiseSEM] Error using multigroup(), dsep fails because of differing number of rows (#167)
Thanks I know you are super busy!
The first problem has been fixed. All the predictors now show up. The second problem with everything being constrained is still happening.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jslefche/piecewiseSEM/issues/167#issuecomment-461923580, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACPAV8Nf1aO0ZrgQIQ4fNh8KuJiHKDBsks5vLdPDgaJpZM4Y-xj_.
Take a look now. I noticed a bug in anova.psem that was causing misalignment between predictors and responses. I also implemented a few other anova.psem functions to make it flexible, but in a first glance, it looks like it hasn't broken anything here.
Although - hrm - now that I'm looking things get odd.
Jon, I wonder if this version of multi group just automates too much - that the better option is to have a global model and an interaction model. FYI, the global model could still have an additive term for grazed - dropping it altogether is yet a third hypothesis. I think we should really let the user decide, and provide them with tools for proper model comparison - so, the proper coefficient tables, std coefficients, and the like.
Let’s discuss when you return…
Jonathan S. Lefcheck, Ph.D. Tennenbaum Coordinating Scientist MarineGEO: https://marinegeo.si.edu/ Smithsonian Institution Phone: +1 (443) 482-2443 www.jonlefcheck.nethttp://www.jonlefcheck.net
From: Jarrett Byrnesmailto:[email protected]
Sent: Tuesday, February 12, 2019 3:58 PM
To: jslefche/piecewiseSEMmailto:[email protected]
Cc: Lefcheck, Jonathanmailto:[email protected]; Commentmailto:[email protected]
Subject: Re: [jslefche/piecewiseSEM] Error using multigroup(), dsep fails because of differing number of rows (#167)
Jon, I wonder if this version of multi group just automates too much - that the better option is to have a global model and an interaction model. FYI, the global model could still have an additive term for grazed - dropping it altogether is yet a third hypothesis. I think we should really let the user decide, and provide them with tools for proper model comparison - so, the proper coefficient tables, std coefficients, and the like.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jslefche/piecewiseSEM/issues/167#issuecomment-462931768, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACPAV1OL_9oxDow760LxXsczFKQiKDImks5vMyrdgaJpZM4Y-xj_.
BTW: Just ran the original model here (from the top post) and it still throws an error
test2 <- multigroup(test_mod, group = "pre_post")
Warning messages:
1: In `[<-.factor`(`*tmp*`, iseq, value = c(1L, 1L, 1L, 1L, 1L, 1L, :
invalid factor level, NA generated
2: In `[<-.factor`(`*tmp*`, thisvar, value = "-") :
invalid factor level, NA generated
Should work now, was an issue in slotting the global coefs into each data.frame
Jonathan S. Lefcheck, Ph.D. Tennenbaum Coordinating Scientist MarineGEO: https://marinegeo.si.edu/ Smithsonian Institution Phone: +1 (443) 482-2443 www.jonlefcheck.nethttp://www.jonlefcheck.net
From: Jarrett Byrnesmailto:[email protected]
Sent: Monday, December 9, 2019 10:30 AM
To: jslefche/piecewiseSEMmailto:[email protected]
Cc: Lefcheck, Jonathanmailto:[email protected]; State changemailto:[email protected]
Subject: Re: [jslefche/piecewiseSEM] Error using multigroup(), dsep fails because of differing number of rows (#167)
External Email - Exercise Caution
BTW: Just ran the original model here (from the top post) and it still throws an error
test2 <- multigroup(test_mod, group = "pre_post")
Warning messages:
1: In [<-.factor(*tmp*, iseq, value = c(1L, 1L, 1L, 1L, 1L, 1L, :
invalid factor level, NA generated
2: In [<-.factor(*tmp*, thisvar, value = "-") :
invalid factor level, NA generated
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjslefche%2FpiecewiseSEM%2Fissues%2F167%3Femail_source%3Dnotifications%26email_token%3DAAR4AV4GHS6GBWX34NHP4W3QXZQBLA5CNFSM4GH3DD72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGJSWOY%23issuecomment-563292987&data=02%7C01%7Clefcheckj%40si.edu%7C8ba36c7374e84d5d920c08d77cbcb968%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C637115022319677343&sdata=Keoqc8WYp3VrT1d6h%2BgHhDmBufXuE0RVr4o6g0XfWCI%3D&reserved=0, or unsubscribehttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAR4AV2TEXD3K7YJWLIMOFDQXZQBLANCNFSM4GH3DD7Q&data=02%7C01%7Clefcheckj%40si.edu%7C8ba36c7374e84d5d920c08d77cbcb968%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C637115022319677343&sdata=pP6hc2qHN8Y4D94mrWnBKWf6J5Gsb4zMtFJ6%2BidQbg4%3D&reserved=0.