structural equation model with "piecewiseSEM"

Dear forum members,

I would like to run a pathway analysis using the R-package piecewiseSEM. I used a very simple model structure that is very similar to the example in the piecewiseSEM description. Unfortunatley, once I execute the "as.psem" function I get the error "Error in [.data.frame(x$data, , vars) : undefined columns selected" . This souns like a simple error message. Yet, I checked my data and the model structure and all should be fine. I just can't figure out why the error appears. Does anybody know why I still get the error? I posted a simple code example and the data set below.

Many thanks

Mike

CODE

data2$Year<-as.factor(data2$Year)
data2$Drought<-as.factor(data2$Drought)
data2$Stratum<-as.factor(data2$Stratum)
mod1x<-lmer(N_pc~Stratum:Drought+Year:Drought+(1|Tree.ID),data2)

mod11a<-glmer(cbind(branch_suck_Yes,branch_suck_No)~N_pc+(1|Tree.ID),
              data=data2, family = binomial(link = "logit"))
modlist = list(
  mod1x, mod11a)
model<-as.psem(modlist)#Error: Error in `[.data.frame`(x$data, , vars) : undefined columns selected

model<-psem(modlist, data2)
coefs(modlist, data2, standardize = "none", intercept = FALSE)
model<-psem(mod1x, mod11a)```

DATA

structure(list(N_pc = c(2.39, 2.81, 2.48, 1.83, 1.91, 1.96, 2.32,
2.54, 2.19, 1.97, 2.29, 1.64, 2.03, 1.68, 2.145, 2.08, 1.99,
1.99, 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.77, 2.41, 2.74, 2.83,
2.51, 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), Stratum = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L,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, 2L, 2L,
2L), .Label = c("1", "2"), class = "factor"), Tree.ID = structure(c(2L,
15L, 19L, 21L, 22L, 23L, 25L, 28L, 29L, 29L, 30L, 31L, 32L,
33L, 34L, 34L, 35L, 36L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L,
5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 10L, 10L, 11L, 11L, 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, 32L, 32L,
33L, 33L, 34L, 34L, 35L, 35L, 36L, 36L, 37L, 37L), .Label = c("102_6",
"102_7", "102_8", "113_2", "113_4", "113_5", "114_7", "114_8",
"114_9", "116_6", "116_7", "116_9", "122_3", "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", "251_10", "251_8", "251_9",
"253_7", "253_8", "254_6", "254_7", "254_8", "267_10", "267_6",
"267_8"), class = "factor"), branch_suck_Yes = c(2L, 3L,
1L, 6L, 6L, 5L, 4L, 8L, 2L, 2L, 2L, 48L, 3L, 22L, 14L, 2L,
1L, 1L, 27L, 25L, 16L, 13L, 31L, 18L, 31L, 2L, 25L, 16L,
36L, 21L, 8L, 23L, 13L, 11L, 7L, 35L, 7L, 17L, 4L, 40L, 48L,
17L, 16L, 10L, 34L, 6L, 46L, 7L, 26L, 12L, 24L, 27L, 31L,
25L, 34L, 21L, 44L, 23L, 40L, 30L, 25L, 18L, 35L, 10L, 6L,
10L, 29L, 5L, 24L, 16L, 19L, 11L, 21L, 10L, 18L, 18L, 42L,
33L, 16L, 31L, 16L, 38L, 37L, 28L, 9L, 35L), branch_suck_No = c(48L,
47L, 49L, 44L, 44L, 45L, 46L, 42L, 48L, 48L, 48L, 2L, 47L,
28L, 36L, 48L, 49L, 49L, 23L, 25L, 34L, 37L, 19L, 32L, 19L,
48L, 25L, 34L, 14L, 29L, 42L, 27L, 37L, 39L, 43L, 15L, 43L,
33L, 46L, 10L, 2L, 33L, 34L, 40L, 16L, 44L, 4L, 43L, 24L,
38L, 26L, 23L, 19L, 25L, 16L, 29L, 6L, 27L, 10L, 20L, 25L,
32L, 15L, 40L, 44L, 40L, 21L, 45L, 26L, 34L, 31L, 39L, 29L,
40L, 32L, 32L, 8L, 17L, 34L, 19L, 34L, 12L, 13L, 22L, 41L,
15L)), row.names = c(3L, 43L, 51L, 55L, 57L, 59L, 63L, 76L,
77L, 78L, 80L, 81L, 86L, 87L, 89L, 90L, 92L, 93L, 97L, 98L, 99L,
100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L,
111L, 112L, 113L, 115L, 116L, 117L, 118L, 119L, 121L, 122L, 123L,
124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L,
135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L,
146L, 147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L,
157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L), na.action = structure(c(`1` = 1L,
`2` = 2L, `4` = 4L, `5` = 5L, `6` = 6L, `7` = 7L, `8` = 8L, `9` = 9L,
`10` = 10L, `11` = 11L, `12` = 12L, `13` = 13L, `14` = 14L, `15` = 15L,
`16` = 16L, `17` = 17L, `18` = 18L, `19` = 19L, `20` = 20L, `21` = 21L,
`22` = 22L, `23` = 23L, `24` = 24L, `25` = 25L, `26` = 26L, `27` = 27L,
`28` = 28L, `29` = 29L, `30` = 30L, `31` = 31L, `32` = 32L, `33` = 33L,
`34` = 34L, `35` = 35L, `36` = 36L, `37` = 37L, `38` = 38L, `39` = 39L,
`40` = 40L, `41` = 41L, `42` = 42L, `44` = 44L, `45` = 45L, `46` = 46L,
`47` = 47L, `48` = 48L, `49` = 49L, `50` = 50L, `52` = 52L, `53` = 53L,
`54` = 54L, `56` = 56L, `58` = 58L, `60` = 60L, `61` = 61L, `62` = 62L,
`64` = 64L, `65` = 65L, `66` = 66L, `67` = 67L, `68` = 68L, `69` = 69L,
`70` = 70L, `71` = 71L, `72` = 72L, `73` = 73L, `74` = 74L, `75` = 75L,
`79` = 79L, `82` = 82L, `83` = 83L, `84` = 84L, `85` = 85L, `88` = 88L,
`91` = 91L, `94` = 94L, `95` = 95L, `96` = 96L, `114` = 114L,
`120` = 120L), class = "omit"), class = "data.frame")
1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.