jslefche / piecewiseSEM

Piecewise Structural Equation Modeling in R
155 stars 48 forks source link

Predictors from lmer coded as 1 and 2 in coefficients table #171

Closed kdarras closed 5 years ago

kdarras commented 5 years ago

This looks related to #169 I know this is not a particularly beautiful example, but here it comes:

> SEM=psem(
+   lmer(cover_change~herbicide+(1|Site),plots.sem),
+   # lmer(herbivore~cover_change+(1|Site),plots.sem),
+   lme(herbivore~cover_change,random=~1|Site,plots.sem),
+   # lmer(decomposition_g~Diplopoda+(1|Site),plots.sem)
+   glm.nb(Diplopoda~cover_change,plots.sem),
+   # lmer(yield_kg~fertilizer+(1|Site),plots.sem),
+   lm(yield_kg~fertilizer,plots.sem),
+   lmer(infiltration_cm_h~cover_change+(1|Site),plots.sem),
+   Diplopoda %~~% herbivore,
+   growth_m %~~% yield_kg
+ )
> summary(SEM)
  |===============================================================================================| 100%
singular fit

Structural Equation Model of SEM 

Call:
  cover_change ~ herbicide
  herbivore ~ cover_change
  Diplopoda ~ cover_change
  yield_kg ~ fertilizer
  infiltration_cm_h ~ cover_change
  Diplopoda ~~ herbivore
  growth_m ~~ yield_kg

    AIC      BIC
 159.814   173.721

---
Tests of directed separation:

                          Independ.Claim Estimate Std.Error    DF Crit.Value P.Value    
            yield_kg  ~  herbicide + ... 329.0750  763.1128 13.00     0.4312  0.6734    
           herbivore  ~  herbicide + ... -31.3932   32.5105 10.00    -0.9656  0.3570    
           Diplopoda  ~  herbicide + ...  -0.2896    0.7302 13.00    -0.3966  0.6917    
   infiltration_cm_h  ~  herbicide + ...  -0.4957    0.4654 11.54    -1.0652  0.3352    
       cover_change  ~  fertilizer + ...   3.3250    4.8859 10.00     0.6805  0.5116    
          herbivore  ~  fertilizer + ...  34.4802   21.9981 10.00     1.5674  0.1481    
          Diplopoda  ~  fertilizer + ...   1.0003    0.1103 13.00     9.0659  0.0000 ***
  infiltration_cm_h  ~  fertilizer + ...   0.4100    0.3444 10.05     1.1904  0.2620    
         yield_kg  ~  cover_change + ... -57.3888   40.8075 12.00    -1.4063  0.1850    
            herbivore  ~  yield_kg + ...   0.0315    0.0091  9.00     3.4737  0.0070  **
            Diplopoda  ~  yield_kg + ...  -0.0001    0.0000 12.00    -2.1095  0.0349   *
    infiltration_cm_h  ~  yield_kg + ...   0.0000    0.0002  7.42     0.2575  0.8453    
   infiltration_cm_h  ~  herbivore + ...   0.0046    0.0030  5.95     1.5662  0.2660    
   infiltration_cm_h  ~  Diplopoda + ...  -0.0007    0.0080 12.43    -0.0914  0.9353    

Global goodness-of-fit:

  Fisher's C = 123.814 with P-value = 0 and on 28 degrees of freedom

---
Coefficients:

           Response    Predictor  Estimate Std.Error    DF Crit.Value P.Value Std.Estimate   
       cover_change            1   -0.5875    3.5898 11.00    -0.1637  0.0066      -0.0242 **
       cover_change            2  -15.9000    4.7652 11.00    -3.3367  0.0066      -0.6551 **
          herbivore cover_change    2.3631    1.0158 11.00     2.3264  0.0401       0.4379  *
          Diplopoda cover_change    0.0187    0.0229 14.00     0.8138  0.4158           NA   
           yield_kg   fertilizer -248.5275  740.5946 14.00    -0.3356  0.7422      -0.0893   
  infiltration_cm_h            1    2.1768    0.2528 13.01     8.6113  0.4814      37.5818   
  infiltration_cm_h            2    0.0115    0.0147 13.01     0.7803  0.4814       0.1983   
        ~~Diplopoda  ~~herbivore    0.1893        NA 16.00     0.6951  0.2496       0.1893   
         ~~growth_m   ~~yield_kg   -0.1322        NA 16.00    -0.4810  0.3192      -0.1322   

  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05

Individual R-squared:

           Response     method Marginal Conditional
       cover_change       none     0.41        0.45
          herbivore       none     0.16        0.61
          Diplopoda nagelkerke     0.04          NA
           yield_kg       none     0.01          NA
  infiltration_cm_h       none     0.04        0.16
Warning messages:
1: Some predictor variables are on very different scales: consider rescaling 
2: In (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  :
  row names were found from a short variable and have been discarded
3: In (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  :
  row names were found from a short variable and have been discarded

Predictors from lmer models are split into 2 rows and named 1 and 2 (actually, herbicide is a numerical variable with 0 and 1 values). It also happens with other variables, and never happens with lme, glm, and lm.

bbolker commented 5 years ago

if there's a reproducible example I will try to look for problems on the lme4 side. Surprising in that I can't think of any recent lme4 changes that would cause changes in output format/model object structure ...

kdarras commented 5 years ago

Here it comes:

data("shipley")
shipley.psem <- psem(

  lme(DD ~ lat, random = ~ 1 | site / tree, na.action = na.omit, 
      data = shipley),

  lmer(Date ~ DD +(1 | site / tree), na.action = na.omit, 
      data = shipley),

  lme(Growth ~ Date, random = ~ 1 | site / tree, na.action = na.omit, 
      data = shipley),

  glmer(Live ~ Growth + (1 | site) + (1 | tree), 
        family = binomial(link = "logit"), data = shipley) 

)
summary(shipley.psem)

I just replaced the lme with an lmer, and the predictor of the corresponding model is now split in 2 rows. Interestingly the glmer works.

whalend commented 5 years ago

Running into this same issue with lmer. As an additional note, if you have two predictor variables in the call e.g.,

lmer(Date ~ DD +(1 | site / tree), na.action = na.omit, 
      data = shipley)

then it throws an error: Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 3, 2

kdarras commented 5 years ago

I also have the same (additional?) problem

jslefche commented 5 years ago

Sorry everyone, this was my bad, it has to do with the new multigroup analysis that was integrated, not lme4 (sorry to cast shade ben!) Its now fixed…please reinstall the dev version from Github:

devtools::install_github(“jslefche/piecewiseSEM@devel”)

And 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: kdarrasmailto:notifications@github.com Sent: Tuesday, January 29, 2019 2:58 AM To: jslefche/piecewiseSEMmailto:piecewiseSEM@noreply.github.com Cc: Subscribedmailto:subscribed@noreply.github.com Subject: Re: [jslefche/piecewiseSEM] Predictors from lmer coded as 1 and 2 in coefficients table (#171)

I also have the same (additional?) problem

— 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/171#issuecomment-458442301, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACPAV6I3DinrxTEDDg7YQqdP4BoiEEY5ks5vH_8OgaJpZM4aPs6t.

kdarras commented 5 years ago

Many thanks Jon!!

bbolker commented 5 years ago

Glad I didn't get around to trying to figure it out yet :-)