piecewiseSEM icon indicating copy to clipboard operation
piecewiseSEM copied to clipboard

Error in `[.data.frame`(data, , var) : undefined columns selected when working with multigroup

Open silgonz opened this issue 1 year ago • 2 comments

I'm running a psem model in piecewiseSEM v 2.3.0. The model works but when applying the multigroup function I get the error:

Error in [.data.frame(data, , var) : undefined columns selected

I added the data argument to the psem() function, and the model output (model$data) includes the grouping variable 'group'.

model1 <- psem(lm(large_copepods ~ Chla_below5_50m + Chla_above5_50m + ciliate_50m + Temperature_50m, data=data_sub), lm(small_copepods ~ Chla_below5_50m + Chla_above5_50m + ciliate_50m + Temperature_50m, data=data_sub), lm(ciliate_50m ~ Chla_below5_50m + Chla_above5_50m + Temperature_50m, data=data_sub), lm(Chla_below5_50m ~ Temperature_50m, data=data_sub), lm(Chla_above5_50m ~ Temperature_50m, data=data_sub), data=data_sub) summary(model1) model works and got a good fit! model1$data (includes the grouping variable) groupmodel1 <- multigroup(model1, group = "group") Error in [.data.frame(data, , var) : undefined columns selected

Thanks!

silgonz avatar May 09 '23 19:05 silgonz

I am having the same issue.

jaronadkins avatar May 22 '24 15:05 jaronadkins

Hi, i ran into the same issue and played a bit with multigroup to see what could be the problem.

Looks like the current implementation of GetData removes columns from modelList$data when they are not used by the formulas in the model list. This results in the group column being undefined in the internal functions of multigroup.

A quick and dirty fix involves separately passing the grouping column to multigroup. With that i was able to reproduce the multigroup example from the documentation without error, but i'm not familiar with the inner methods of piecewiseSEM so i can't foresee possible side effects of the fix.

jguerber avatar Jun 10 '24 12:06 jguerber