I encountered a reproducible bug in piecewiseSEM::psem() when supplying model objects fitted with nlme::gls().
The call throws:
Error in max(sapply(nm[dfdetect], nrow)) :
invalid 'type' (list) of argument
Session info and a minimal reprex are provided below.
---------- Session info----------
R 4.5.0 (x86_64-w64-mingw32)
piecewiseSEM 2.3.0.1 (CRAN)
nlme 3.1-168
Reprex (data + script in one file)
---------- data ----------
dat <- structure(list(
Prein_ammo = c(19.7, 18.1, 19, 27.6, 26.9),
Dry_ammo = c(4.24, 3.04, 4.5, 5.44, 5.39),
Nmp_ratio = c(0.833, 0.741, 0.784, 0.634, 0.627),
SOC = c(13.6, 13.5, 13.6, 15.8, 15.7),
TN = c(1.14, 1.19, 1.16, 1.4, 1.39),
CEC = c(12.7, 12.5, 12.3, 14.9, 14.7),
pH = c(6.05, 5.59, 5.9, 5.59, 5.53),
Clay = c(14, 14, 14, 13, 13),
Sand = c(38.7, 38.7, 38.7, 44.5, 44.5),
FixedNH4 = c(270, 306, 288, 184, 180),
MBC = c(58.2, 58.2, 58.2, 123.5, 123.5),
MBN = c(3.79, 3.79, 3.79, 5.5, 5.5),
Soil_pretreatment_Temp = c(4, 4, 4, 4, 4)
), row.names = 1:5, class = "data.frame")
---------- model list ----------
library(nlme)
library(piecewiseSEM)
fit_fun <- function(formula, data) {
gls(formula, data = data)
}
m_Nmp <- fit_fun(Nmp_ratio ~ SOC + TN + pH , dat)
m_SOC <- fit_fun(SOC ~ Clay + pH, dat)
---------- SEM ----------
sem_mod <- psem(m_Nmp, m_SOC) # → triggers the reported error
Error in max(sapply(nm[dfdetect], nrow)) :
invalid 'type' (list) of argument
I encountered a reproducible bug in piecewiseSEM::psem() when supplying model objects fitted with nlme::gls().
The call throws:
Error in max(sapply(nm[dfdetect], nrow)) :
invalid 'type' (list) of argument
Session info and a minimal reprex are provided below.
---------- Session info----------
R 4.5.0 (x86_64-w64-mingw32)
piecewiseSEM 2.3.0.1 (CRAN)
nlme 3.1-168
Reprex (data + script in one file)
---------- data ----------
dat <- structure(list(
Prein_ammo = c(19.7, 18.1, 19, 27.6, 26.9),
Dry_ammo = c(4.24, 3.04, 4.5, 5.44, 5.39),
Nmp_ratio = c(0.833, 0.741, 0.784, 0.634, 0.627),
SOC = c(13.6, 13.5, 13.6, 15.8, 15.7),
TN = c(1.14, 1.19, 1.16, 1.4, 1.39),
CEC = c(12.7, 12.5, 12.3, 14.9, 14.7),
pH = c(6.05, 5.59, 5.9, 5.59, 5.53),
Clay = c(14, 14, 14, 13, 13),
Sand = c(38.7, 38.7, 38.7, 44.5, 44.5),
FixedNH4 = c(270, 306, 288, 184, 180),
MBC = c(58.2, 58.2, 58.2, 123.5, 123.5),
MBN = c(3.79, 3.79, 3.79, 5.5, 5.5),
Soil_pretreatment_Temp = c(4, 4, 4, 4, 4)
), row.names = 1:5, class = "data.frame")
---------- model list ----------
library(nlme)
library(piecewiseSEM)
fit_fun <- function(formula, data) {
gls(formula, data = data)
}
m_Nmp <- fit_fun(Nmp_ratio ~ SOC + TN + pH , dat)
m_SOC <- fit_fun(SOC ~ Clay + pH, dat)
---------- SEM ----------
sem_mod <- psem(m_Nmp, m_SOC) # → triggers the reported error
Error in max(sapply(nm[dfdetect], nrow)) :
invalid 'type' (list) of argument