piecewiseSEM icon indicating copy to clipboard operation
piecewiseSEM copied to clipboard

Error: arguments imply different numbers of rows / object 'ret' not found-->Problem because of glmmTMB?

Open eimichae85 opened this issue 2 years ago • 18 comments

Dear piecewiseSEM developer,

We are trying to run a SEM with your package. Unfortunaley while running our code an error message popped up. We could not figure out how to solve it . We are hoping very much that you can help us: Why do we get the error message? We built our model structure using an example from the piecewise model package and we double checked that we do not have any "NAs" in our data set. I figured out that glmmTMB may cause some problems. If I run all models as a glmer (and if I remove the log()-transformation in "mod2X") the error does not appear. Howerver, running the models as glmer (instead of glmmTMB) and removing the necessary transformations is not an option for me from a statistical poitn of view.

Thanks a ton for your help.

Error1: Error in data.frame(..., check.names = FALSE) : arguments imply different numbers of rows: 166, 0

The last 3 lines from traceback()

10: stop(gettextf("arguments imply differing number of rows: %s", paste(unique(nrows), collapse = ", ")), domain = NA) 9: data.frame(..., check.names = FALSE) 8: cbind(deparse.level, ...) . . .

Below is our code and the data (as "dput()")

dataCode: (see dput(dataCode) at the very end

library (glmmTMB) library(lme4) library(DHARMa)#check for Overdispersion library(lavaan)

#Get the newest version of piecewise SEM that can handle glmmTMB library(devtools) install_github("jslefche/piecewiseSEM@devel", build_vignette = TRUE) library(piecewiseSEM)

str(dataCode) summary(dataCode)

str(dataCode) summary(dataCode)

#1x: mod1x<-lmer(N_pc~Stratum* Drought+Year*Drought+(1|Tree.ID),dataCode)

#2x: mod2x<-lmer(log(Fiber)~Stratum* Drought+Year*Drought+(1|Tree.ID),dataCode)

#3x: mod3x<-lmer(Lignin~Stratum* Drought+Year*Drought+(1|Tree.ID),dataCode)

#the proper specification is to collapse multiple pathways into a single multiple regression if the response is the same

modCOMBO<-glmer(prop_suck~N_pc+Fiber+Lignin+(1|Tree.ID), data=dataCode, family=binomial(link = "logit"), weights=weight_suck) newlist = list( mod1x, mod2x, mod3x, modCOMBO) model<-as.psem(newlist2) summary(model, .progressBar = F)# ERROR 'names' attribute [5] must be the same length as the vector [3] (model)

#DATA

dput(dataCode) dataCode<-structure(list(Tree.ID = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L, 13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L, 17L, 17L, 18L, 18L, 19L, 19L, 20L, 20L, 21L, 21L, 22L, 22L, 23L, 23L, 24L, 24L, 25L, 25L, 26L, 26L, 27L, 27L, 28L, 28L, 29L, 29L, 30L, 30L, 31L, 31L, 32L, 32L, 33L, 33L, 34L, 34L, 35L, 35L, 36L, 36L, 37L, 37L, 38L, 38L, 39L, 39L, 40L, 40L, 41L, 41L, 42L, 42L, 43L, 43L, 44L, 44L, 45L, 45L, 46L, 46L, 47L, 47L, 48L, 48L, 1L, 1L, 2L, 2L, 3L, 3L, 10L, 10L, 11L, 11L, 12L, 12L, 13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L, 17L, 17L, 18L, 18L, 19L, 19L, 21L, 21L, 22L, 22L, 23L, 23L, 24L, 24L, 25L, 25L, 26L, 26L, 27L, 27L, 28L, 28L, 29L, 29L, 30L, 30L, 31L, 31L, 32L, 32L, 33L, 33L, 37L, 37L, 38L, 38L, 39L, 39L, 43L, 43L, 44L, 44L, 45L, 45L, 46L, 46L, 47L, 47L, 48L, 48L), .Label = c("102_6", "102_7", "102_8", "105_1", "105_2", "105_4", "111_7", "111_8", "111_9", "113_2", "113_4", "113_5", "114_7", "114_8", "114_9", "116_6", "116_7", "116_9", "122_3", "122_4", "122_5", "132_3", "132_4", "132_5", "242_2", "242_4", "242_5", "243_1", "243_2", "243_4", "245_1", "245_2", "245_5", "246_1", "246_2", "246_3", "251_10", "251_8", "251_9", "253_7", "253_8", "253_9", "254_6", "254_7", "254_8", "267_10", "267_6", "267_8"), class = "factor"), Year = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.08, 0.02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.08, 0, 0, 0, 0.06, 0, 0, 0, 0, 0, 0, 0, 0.02, 0, 0, 0, 0.12, 0, 0.12, 0.04, 0.1, 0, 0.4, 0.7, 0.08, 0, 0.16, 0, 0, 0, 0, 0, 0, 0.02, 0, 0, 0, 0.16, 0.04, 0.04, 0, 0.04, 0.96, 0, 0, 0, 0, 0.06, 0.44, 0.46, 0.28, 0.04, 0, 0.02, 0.02, 0, 0, 0, 0.54, 0.5, 0.32, 0.26, 0.62, 0.36, 0.62, 0.04, 0.5, 0.32, 0.72, 0.42, 0.16, 0.46, 0.26, 0.22, 0.14, 0, 0.7, 0.14, 0.34, 0.08, 0.8, 0, 0.96, 0.34, 0.32, 0.2, 0.68, 0.12, 0.92, 0.14, 0.52, 0.24, 0.48, 0.54, 0.62, 0.5, 0.68, 0.42, 0.88, 0.46, 0.8, 0.6, 0.5, 0.36, 0.7, 0.2, 0.12, 0.2, 0.58, 0.1, 0.48, 0.32, 0.38, 0.22, 0.42, 0.2, 0.36, 0.36, 0.84, 0.66, 0.32, 0.62, 0.32, 0.76, 0.74, 0.56, 0.18, 0.7), N_pc = c(2.27, 2.37, 2.39, 1.9, 2.08, 2.65, 2.25, 2.04, 2.04, 1.81, 3.03, 2.9, 2.11, 2.26, 2.38, 2.51, 2, 2.31, 2.71, 2.02, 2.37, 2.04, 1.95, 2.21, 2.31, 2.39, 2.24, 2.2, 1.94, 2.12, 2.27, 2.15, 2.5, 2.36, 2.1, 2.29, 2.55, 2.39, 2.96, 2.26, 2.75, 2.71, 2.81, 2.79, 2.68, 2.51, 2.17, 2.18, 2.41, 2.19, 2.48, 2.19, 2.42, 1.82, 1.83, 1.65, 1.91, 2.04, 1.96, 1.88, 2.59, 1.85, 2.32, 1.95, 2.09, 1.97, 2.65, 1.8, 2.2, 2.26, 2.32, 1.5, 2.16, 2.37, 2.13, 2.54, 2.19, 1.97, 1.78, 2.29, 1.64, 1.67, 1.98, 1.79, 1.77, 2.03, 1.68, 2.08, 2.145, 2.08, 1.8, 1.99, 1.99, 2.07, 1.98, 2.41, 2.83, 2.83, 2.91, 2.61, 2.73, 2.54, 2.87, 1.91, 2.84, 2.74, 2.87, 2.6, 2.12, 2.64, 2.46, 1.83, 2.06, 2.01, 2.77, 2.41, 2.74, 2.83, 2.51, 2.23, 2.79, 2.66, 2.44, 2.26, 2.85, 2.39, 2.52, 2.13, 2.63, 2, 2.43, 2.36, 2.98, 2.28, 2.12, 2.2, 2.54, 1.28, 2.57, 2.17, 2.32, 2.41, 3.11, 2.591, 2.77, 2.53, 2.67, 2.45, 2.5, 2.52, 2.9, 3.03, 2.83, 2.52, 2.57, 2.62, 2.82, 2.62, 2.98, 3.01, 2.33, 2.11, 2.68, 2.74, 2.53, 2.43), weight_suck = c(50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L), Fiber = c(34.40884091, 35.2306534, 42.52377866, 42.6239323, 41.37861255, 39.60850525, 40.77050193, 43.93561888, 39.85530862, 47.96389221, 33.0164353, 30.40923171, 35.80926768, 38.81499295, 39.78981471, 37.98513805, 37.573016, 39.75442555, 43.30493722, 39.75062718, 42.44068598, 35.17589695, 35.56906323, 37.34316461, 40.01927247, 39.99513562, 36.10434999, 31.57573919, 37.76346099, 37.01815172, 35.59629643, 33.81374455, 37.7827112, 41.28445751, 44.78743608, 34.6394122, 36.30284612, 34.97437449, 41.00523545, 30.91747143, 32.55332568, 32.79375305, 37.51461304, 32.62951938, 40.22559027, 35.43271959, 39.22368591, 34.32029979, 36.41313697, 36.69822326, 37.82870726, 37.85527277, 33.87219095, 36.98176526, 38.04943022, 33.45063417, 36.48627741, 34.46249903, 40.17607643, 36.77713573, 37.98619139, 35.84260289, 37.21843053, 34.84469437, 34.85470551, 33.62314136, 35.04788627, 30.45543443, 43.14168551, 32.23039161, 37.60287057, 34.1427031, 36.52037605, 37.12821519, 43.96781779, 33.21707461, 43.03781432, 38.29479565, 40.07726219, 37.64961992, 48.82421591, 39.26134049, 37.62558769, 36.19289482, 41.39539765, 38.87860666, 36.05830446, 32.07757032, 42.788655, 33.86701205, 38.23211694, 37.89539959, 40.83433837, 38.98175173, 42.83170351, 32.28967624, 33.40239455, 30.92484799, 41.56156442, 34.52930045, 37.75300976, 35.11156393, 39.77687654, 37.98805055, 41.70620266, 31.89415684, 37.68184859, 34.08114509, 34.06411083, 32.23348721, 35.77634719, 21.0576573, 37.76348306, 33.53117231, 40.82264211, 31.19388514, 40.52910082, 27.5031154, 44.50618538, 34.4669349, 30.43628015, 29.89229346, 32.01075647, 35.07254143, 36.57868878, 28.81559417, 36.08462737, 32.86246536, 39.9152505, 36.25423072, 33.51569525, 34.1055226, 38.99118341, 34.53641033, 33.31288766, 31.55618034, 39.31931333, 33.72025274, 34.7083208, 26.84760505, 39.14884466, 34.79548574, 32.81360389, 27.78493879, 30.66829851, 31.03727751, 35.11616534, 29.20690552, 37.48964989, 39.94816985, 41.784186, 36.40317336, 38.77327649, 33.47088406, 35.79855367, 32.94104157, 37.22816497, 29.32884218, 41.30883178, 28.85842064, 39.21708069, 29.93973518, 33.68385156, 25.26360465, 40.07343771, 31.24653541 ), Lignin = c(15.77477865, 16.42526338, 17.81644946, 20.06733454, 17.33068939, 14.46313636, 19.26461698, 22.46710162, 18.35008435, 18.43243391, 13.03248943, 11.61623759, 15.40895691, 16.9786809, 16.54312915, 18.33763105, 12.25320976, 16.10339902, 16.68427585, 17.37699268, 11.72959086, 17.82961819, 10.33102761, 8.329309218, 16.75329644, 16.79263461, 14.56578061, 15.69875657, 9.275559568, 16.18115984, 13.28899644, 14.52231091, 14.33797056, 19.388317, 14.28128214, 12.86508109, 16.54174245, 16.88950337, 16.45236853, 7.719036205, 13.6909977, 11.48255674, 15.13737491, 15.3591499, 16.54946312, 16.14769987, 13.06144297, 11.9173863, 13.43299545, 16.00143957, 17.2118779, 18.19980232, 10.99738867, 13.63569839, 15.48144654, 16.1216259, 16.15568311, 17.6101268, 17.30451969, 14.02253261, 15.43141658, 16.181513, 17.15827242, 17.52861195, 12.35996713, 15.49034533, 13.97079366, 13.28841472, 17.82642197, 14.89135477, 15.27588696, 16.19873246, 11.99168197, 17.9882092, 18.70442548, 16.92756747, 17.30466149, 16.84557327, 16.57039627, 17.50814734, 21.76822852, 20.26882409, 9.727735965, 15.00439034, 17.12361186, 16.14717619, 12.68400834, 15.64995633, 17.8633547, 12.42028546, 14.25760982, 17.83796088, 18.18472772, 19.53135651, 18.08016466, 14.49582092, 13.52200059, 13.59905485, 18.16177538, 16.35014138, 14.96662393, 17.79704702, 14.62402094, 21.42942615, 16.86764575, 13.75565413, 14.82599948, 15.76083246, 11.45566254, 13.43780268, 12.93398942, 13.48983266, 15.65273017, 15.51102512, 16.26246545, 13.86332043, 16.06911693, 12.6946718, 18.10567384, 16.67871224, 10.8869382, 15.31810574, 14.50440655, 18.1268646, 14.02630853, 9.166241719, 14.59336183, 16.33293006, 16.055571, 18.51528605, 11.34765726, 15.06734566, 16.87036405, 17.46982479, 15.66135144, 13.71222274, 16.19165545, 16.624473, 15.57975641, 13.00605673, 14.73386658, 15.76925648, 14.04065352, 12.18372012, 12.05766404, 14.54563609, 14.26939499, 14.72744808, 14.11437465, 18.4789298, 18.01551264, 16.10259417, 14.02537363, 14.58450423, 11.04102835, 13.40957054, 16.8431013, 9.535932181, 16.83859843, 13.05088673, 15.5745046, 14.46076877, 11.98007904, 11.38534032, 15.20342847, 11.4316122)), class = "data.frame", row.names = c(NA, -166L))

eimichae85 avatar Dec 14 '22 13:12 eimichae85

I'm currently having a very similar issue with the piecewiseSEM package. Whenever I try to use the gam() function within the psem() function I get a similar error: Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 24, 0

This error does NOT occur when I run the GAM model by itself and I've also checked the data to make sure there are no issues there. Both the `piecewiseSEM' and the 'mgcv' packages are up-to-date.

laguir3 avatar Jan 20 '23 17:01 laguir3

I'm having a potentially similar problem, also using glmmTMB. When I try to run the psem() function on my glmmTMB objects I get

Error in .rowNamesDF<-(x, value = value) : invalid 'row.names' length

I do not have the same issue when I create the same models using lme4 instead (but we need to use glmmTMB due to other aspects of the analysis).

Koleos4 avatar Feb 03 '23 03:02 Koleos4

I am experiencing the same issue as @laguir3 whenever I use a model object from gam() as an argument for psem(). I've also tried the worked example here and run into the same error.

dcsuh avatar Feb 07 '23 21:02 dcsuh

Are you running the development version?


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: @.> Sent: Tuesday, February 7, 2023 4:13 PM To: @.> Cc: @.***> Subject: Re: [jslefche/piecewiseSEM] Error: arguments imply different numbers of rows / object 'ret' not found-->Problem because of glmmTMB? (Issue #270)

External Email - Exercise Caution

I am experiencing the same issue as @laguir3https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Flaguir3&data=05%7C01%7Clefcheckj%40si.edu%7C9695f5da1c1b48b469e508db09502f73%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638114012240299476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=80%2F0cy13tsrtojq2L4vDuC7HItZhiMslBEjNQk1cnt8%3D&reserved=0 whenever I use a model output from gam() as an argument for psem(). I've also tried the worked example herehttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fjslefche.github.io%2Fsem_book%2Flocal-estimation.html%23extensions-to-non-linear-models&data=05%7C01%7Clefcheckj%40si.edu%7C9695f5da1c1b48b469e508db09502f73%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638114012240299476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=aJVqy4Cydt4OiYdneMQyIx1S5HdNKUcvwG6tDrOilGI%3D&reserved=0 and run into the same error.

— Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjslefche%2FpiecewiseSEM%2Fissues%2F270%23issuecomment-1421459254&data=05%7C01%7Clefcheckj%40si.edu%7C9695f5da1c1b48b469e508db09502f73%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638114012240299476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=9vxudpHfZnkeZkEZ%2FZTHm5p7tDf%2FWsf731U8653G3oo%3D&reserved=0, or unsubscribehttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAR4AV65UEWNB43DAEZE5EDWWK3IHANCNFSM6AAAAAAS6PVUWM&data=05%7C01%7Clefcheckj%40si.edu%7C9695f5da1c1b48b469e508db09502f73%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638114012240299476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=u920uIThUnuy3l%2BCSK4NHsULjcoApLVmu1kbpid6sII%3D&reserved=0. You are receiving this because you are subscribed to this thread.Message ID: @.***>

jslefche avatar Feb 08 '23 15:02 jslefche

I am running to my knowledge the most up-to-date version: piecwiseSEM 2.1.2 Do I need to run the development version to make piecewiseSEM being able to deal with glmmTMB models? If so: How can I get the development version?

Thanks a ton Michael

eimichae85 avatar Feb 08 '23 16:02 eimichae85

Ah, install the devtools package and then run: @.***”)` And the version should be 2.3.0 IIRC Let me know if the issue persists! 😊


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: @.> Sent: Wednesday, February 8, 2023 11:33 AM To: @.> Cc: Lefcheck, @.>; @.> Subject: Re: [jslefche/piecewiseSEM] Error: arguments imply different numbers of rows / object 'ret' not found-->Problem because of glmmTMB? (Issue #270)

External Email - Exercise Caution

I am running to my knowledge the most up-to-date version: piecwiseSEM 2.1.2 Do I need to run the development version to make piecewiseSEM being able to deal with glmmTMB models? If so: How can I get the development version?

Thanks a ton Michael

— Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjslefche%2FpiecewiseSEM%2Fissues%2F270%23issuecomment-1422905561&data=05%7C01%7Clefcheckj%40si.edu%7C6e956b4f18c84fd93f3608db09f22ac1%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638114707959677967%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=lNhuj%2B2t0%2BI%2FLC8pvnFhfDp2pfmuySS02tcGwA1EAoU%3D&reserved=0, or unsubscribehttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAR4AVYACWU7PST534SPXYDWWPDENANCNFSM6AAAAAAS6PVUWM&data=05%7C01%7Clefcheckj%40si.edu%7C6e956b4f18c84fd93f3608db09f22ac1%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638114707959834213%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=1Oa%2FCF0%2FigJnr2KpXQ9SJeNzPUSphscITL0%2FgWAqCdg%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>

jslefche avatar Feb 08 '23 16:02 jslefche

Hi, I updated the package using the command: library(devtools) install_github("jslefche/piecewiseSEM@devel", build_vignette = TRUE) library(piecewiseSEM) The version displayed is now 2.3.0

I streamlined an re-ran my code (posted above). The inital error message "...imply different numbers of rows: 166, 0" is gone. However, when I want to look at the model summary ( i.e. "summary (model)") a new error pops up saying: 'names' attribute [5] must be the same length as the vector [3].

Why is that? Thanks a lot

eimichae85 avatar Feb 09 '23 07:02 eimichae85

Do you have interactions and/or factors in your model?


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: @.> Sent: Thursday, February 9, 2023 2:40 AM To: @.> Cc: Lefcheck, @.>; @.> Subject: Re: [jslefche/piecewiseSEM] Error: arguments imply different numbers of rows / object 'ret' not found-->Problem because of glmmTMB? (Issue #270)

External Email - Exercise Caution

Hi, I updated the package using the command: library(devtools) @.***", build_vignette = TRUE) library(piecewiseSEM) The version displayed is now 2.3.0

I streamlined an re-ran my code (posted above). The inital error message "...imply different numbers of rows: 166, 0" is gone. However, when I want to look at the model summary ( i.e. "summary (model)") a new error pops up saying: 'names' attribute [5] must be the same length as the vector [3]

Why is that? Thanks a lot

— Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjslefche%2FpiecewiseSEM%2Fissues%2F270%23issuecomment-1423761240&data=05%7C01%7Clefcheckj%40si.edu%7Cc07d141ef8d24d40b8d508db0a70f3bf%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638115252476019855%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=BsUWe%2BnXWEIAAmttCE0ExTUKVjapl991AYmahmPsqXo%3D&reserved=0, or unsubscribehttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAR4AVYL7K7LWQAK2LJMM4LWWSNPXANCNFSM6AAAAAAS6PVUWM&data=05%7C01%7Clefcheckj%40si.edu%7Cc07d141ef8d24d40b8d508db0a70f3bf%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638115252476019855%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2F0kcmXS8iBU0yJu1M4aRjKGKwoqZ5tKwv6hR2328%2Fa0%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>

jslefche avatar Feb 09 '23 14:02 jslefche

Yes I have mainly factors and interactions in my models see below (and in the example above):

Stratum, Drought and Year are all factors

mod1x<-lmer(N_pc~Stratum* Drought+Year*Drought+(1|Tree.ID),dataCode)

mod2x<-lmer(log(Fiber)~Stratum* Drought+Year*Drought+(1|Tree.ID),dataCode)

mod3x<-lmer(Lignin~Stratum* Drought+Year*Drought+(1|Tree.ID),dataCode)

modCOMBO<-glmer(prop_suck~N_pc+Fiber+Lignin+(1|Tree.ID),

eimichae85 avatar Feb 09 '23 15:02 eimichae85

Ah yes, this is the issue: the framework does not yet allow for interactions among continuous and non-continuous (ie, categorical variables) . Alas, you are just pushing the method too far. Is there a way to recode the factors as binary or ordinal?


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: @.> Sent: Thursday, February 9, 2023 10:17 AM To: @.> Cc: Lefcheck, @.>; @.> Subject: Re: [jslefche/piecewiseSEM] Error: arguments imply different numbers of rows / object 'ret' not found-->Problem because of glmmTMB? (Issue #270)

External Email - Exercise Caution

Yes I have mainly factors and interactions in my models see below: (Stratum, Drought, Year are all factors)

mod1x<-lmer(N_pcStratum* Drought+YearDrought+(1|Tree.ID),dataCode) mod2x<-lmer(log(Fiber)~Stratum Drought+YearDrought+(1|Tree.ID),dataCode) mod3x<-lmer(LigninStratum Drought+Year*Drought+(1|Tree.ID),dataCode) modCOMBO<-glmer(prop_suck~N_pc+Fiber+Lignin+(1|Tree.ID),

— Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjslefche%2FpiecewiseSEM%2Fissues%2F270%23issuecomment-1424353788&data=05%7C01%7Clefcheckj%40si.edu%7C55ae003988f54b9e57ba08db0ab0b254%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638115526252335125%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fuA5kFmYTGoBm8xrFdzjvqZp9oL6EBfJisEjSmr%2F%2Fa8%3D&reserved=0, or unsubscribehttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAR4AVZNGQPVBCNAYB4UPEDWWUC65ANCNFSM6AAAAAAS6PVUWM&data=05%7C01%7Clefcheckj%40si.edu%7C55ae003988f54b9e57ba08db0ab0b254%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638115526252335125%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Bk5g4hpEsRrz8p13oi1V4BoWYakr0a8H9xXDwvOd8ro%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>

jslefche avatar Feb 09 '23 15:02 jslefche

So for example instead of coding "Drought" as a factor with two levels "No water" and "Water" you suggest that I code "Drought" as "1" and "0"? Do I then need to specify drough "as.integer(..)"? Same question but for the random effects: "Tree.ID" would need to be coded as ordinals "1", "2", "3"... and then specified "as.integer(...)"?

eimichae85 avatar Feb 09 '23 15:02 eimichae85

Definitely for Drought, convert to 0 = no water and 1 = water. Might be best to code this directly into the data.frame or tibble, rather than specify as as.integer in the formula

Random effects are fine to keep as factors, in fact, probably better given the approach


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: @.> Sent: Thursday, February 9, 2023 10:23 AM To: @.> Cc: Lefcheck, @.>; @.> Subject: Re: [jslefche/piecewiseSEM] Error: arguments imply different numbers of rows / object 'ret' not found-->Problem because of glmmTMB? (Issue #270)

External Email - Exercise Caution

So for example instead of coding "Drought" as a factor with two levels "No water" and "Water" you suggest that I code "Drought" as "1" and "0"? Do I then need to specify drough "as.integer(..)"? Same question but for the random effects: "Tree.ID" would need to be coded as ordinals "1", "2", "3"... and then specified "as.integer(...)"?

— Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjslefche%2FpiecewiseSEM%2Fissues%2F270%23issuecomment-1424364434&data=05%7C01%7Clefcheckj%40si.edu%7C4f09ffb7877d41a5223508db0ab1a5d4%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638115530328313142%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=AJrFCYnQUaj%2BEepG%2FzvzlilCVIhS3kh93uwhg5banHM%3D&reserved=0, or unsubscribehttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAR4AVZC6PZHK2TEZMPB2ATWWUDYNANCNFSM6AAAAAAS6PVUWM&data=05%7C01%7Clefcheckj%40si.edu%7C4f09ffb7877d41a5223508db0ab1a5d4%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638115530328313142%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2CQvWl3O%2B7rNfTHIg9sjtVNhaebK3jEau546l4vVKos%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>

jslefche avatar Feb 09 '23 15:02 jslefche

My issue was resolved after installing the development version. Thanks!

dcsuh avatar Feb 09 '23 15:02 dcsuh

If I simply change the factor names in R e.g dataCode$Drought<-recode_factor(dataCode$Drought, "no"="0", "yes"="1") or dataCode$Drought <- factor(dataCode$Drought, levels = c("no", "yes"), labels = c('0', '1')) It does not work.

If I specify my factors "as.integer()" i.e. Drought "no" /"yes" will be changed to "1"/"2" I can produce a summary using piecewiseSEM. However, changing "factors" to "integegers" is not legit. The summary of the individual sumbmodels differ quite considerably depending on if the factors are coded as "factors" or as an "integer"

UPDATE: Finally I figured out how to 1. recode the data so that I still produces the correct summary output of the individual models but is also compatible with piecewiseSEM: I found the solution on this page:

As adviced I did not recode any random effects but only fixed effects that were coded as "factors"

The way of recoding a factor e.g. drought (yes / no) is to create a new factor with the desired levels and labels (1 /0): the forcats package comes in handy. recoded = forcats::fct_recode(data$Drought, 0 = 'no', 1 = 'yes')

But now we still have a factor; to get numeric values, we need to convert it: data$recoded = as.numeric(as.character(recoded))

These recoded values can be used in piecewiseSEM

eimichae85 avatar Feb 09 '23 16:02 eimichae85

Hi there,

Thanks for the information here.

Similarly and differently, "in data.frame(Independ.Claim = paste(b[[i]][2], "~", rhs), ct[, : ...imply different numbers of rows: 1, 0" occurs when I try "summary(model, .progressBac = F)", and "'names' attribute [8] must be the same length as the vector [5]" occurs when I want to plot(model).

I have check for the development version piecewiseSEM 2.3.0 but errors were still there. And There is no factor in my data but interactions among categorical variables, composites and continuous data. Is this the reason?

LeilaE avatar Feb 18 '23 05:02 LeilaE

Hey, suddenly I am having the same problem with some of my SEMs like @LeilaE using gams(mgcv) . I got errors saying: 'in data.frame(Independ.Claim = paste(b[[i]][2], "~", rhs), ct[, : arguments imply differing number of rows ...'

Wierdly, in once case a SEM works when including gams with the full set of predictor variables, while one SEM with a model including a subset of the predictor variables fails.

In another case no SEM is running with the error message anymore, despite using only continuous variables and the piecewiseSEM devel. version 2.3.0.

I would be so so grateful for any further advice... thank you already in advance!

annalenahendel avatar Mar 31 '23 14:03 annalenahendel

There is a known issue with gam and non-parametric smoothers with additional arguments (eg, k=). Not sure when a fix will be incoming. GAMs are tricky in SEM


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: @.> Sent: Friday, March 31, 2023 10:16 AM To: @.> Cc: Lefcheck, @.>; @.> Subject: Re: [jslefche/piecewiseSEM] Error: arguments imply different numbers of rows / object 'ret' not found-->Problem because of glmmTMB? (Issue #270)

External Email - Exercise Caution

Hey, suddenly I am having the same problem with some of my SEMs like @LeilaEhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FLeilaE&data=05%7C01%7Clefcheckj%40si.edu%7C2afa6837929f4e4b11e308db31f28d55%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638158690044694929%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=XO0tIXLbu%2BfrmOUsGShti0XPnXT6%2FOPgAp8yycpyLyo%3D&reserved=0 using gams(mgcv) . I got errors saying: 'in data.frame(Independ.Claim = paste(b[[i]][2], "~", rhs), ct[, : arguments imply differing number of rows ...'

Wierdly, in once case a SEM works when including gams with the full set of predictor variables, while one SEM with a model including a subset of the predictor variables fails.

In another case no SEM is running with the error message anymore, despite using only continuous variables and the piecewiseSEM devel. version 2.3.0.

I would be so so grateful for any further advice... thank you already in advance!

— Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjslefche%2FpiecewiseSEM%2Fissues%2F270%23issuecomment-1491994682&data=05%7C01%7Clefcheckj%40si.edu%7C2afa6837929f4e4b11e308db31f28d55%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638158690044694929%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=qci2%2Bs0iMtjam746iUIdRsaCIE5ZUZ3VqG6SMaMpNuI%3D&reserved=0, or unsubscribehttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAR4AV4Z2D2A2CRMXASRKR3W63RMVANCNFSM6AAAAAAS6PVUWM&data=05%7C01%7Clefcheckj%40si.edu%7C2afa6837929f4e4b11e308db31f28d55%7C989b5e2a14e44efe93b78cdd5fc5d11c%7C0%7C0%7C638158690044694929%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=i8QwmdPN5WWD1aRoOa1P2iJxotLRwtzNikzhYn7%2BMEk%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>

jslefche avatar Apr 03 '23 14:04 jslefche

I just managed to run the old developerVersion 2.2.1 again. Here the gams run in comparison to version 2.3.0....Its this version :ca0982e4ebbada02f58a8266b78060877dc2a987, To install it I used 'devtools::install_github("jslefche/piecewiseSEM@ca0982e4ebbada02f58a8266b78060877dc2a987")' in R.

annalenahendel avatar Apr 05 '23 13:04 annalenahendel