0
votes

I am running a mixed-effects model with lmer in R and am having trouble plotting the models by groups and pulling out the equations of the line.

I thought I needed to look at the fixed and random effects make my equation of the line for the final conditional model below (i.e., cond_ind_waterxsilver). When I pull these values out for the model, I get intercept values much higher than I expect. Would someone please provide me with some guidance on pulling the values of the model from the output to make the line and how to plot the model results?

#conditional model     
cond_waterxsilver <- lmer(LnAg ~ LnVolume + (LnVolume | FilterID) + SilverType + WaterType + SilverType*WaterType + SilverType*LnVolume +  WaterType*LnVolume, data=capwater_removed.data)
aov_cond_ind_waterxsilver <- anova(cond_ind_waterxsilver)
summary(cond_ind_waterxsilver)
aov_cond_ind_waterxsilver

As I mentioned the equations that I calculated for each group (by SilverType and WaterType) have an intercept much higher than expected.

Here is a portion of the output that I am trying to interpret:

Random effects:
 Groups   Name        Variance Std.Dev. Corr 
 FilterID (Intercept) 1.84693  1.3590        
          LnVolume    0.07073  0.2660   -0.91
 Residual             0.75533  0.8691        
Number of obs: 187, groups:  FilterID, 33

Fixed effects:
                             Estimate Std. Error       df t value Pr(>|t|)    
(Intercept)                   5.36298    0.67452 25.81163   7.951 2.09e-08 ***
LnVolume                     -1.10424    0.16764 22.59782  -6.587 1.11e-06 ***
SilverTypeCitrate             1.42888    0.90853 27.98025   1.573   0.1270    
SilverTypePVP                -1.68084    0.91226 37.20240  -1.842   0.0734 .  
WaterTypeB                    1.42923    0.78770 26.11938   1.814   0.0811 .  
SilverTypeCitrate:WaterTypeB -1.81514    0.67120 24.94076  -2.704   0.0122 *  
SilverTypePVP:WaterTypeB     -0.03597    0.70150 31.06516  -0.051   0.9594    
LnVolume:SilverTypeCitrate    0.14857    0.20368 14.34068   0.729   0.4775    
LnVolume:SilverTypePVP        0.42758    0.25071 25.73948   1.705   0.1001    
LnVolume:WaterTypeB          -0.14359    0.19678 17.43737  -0.730   0.4753    
1
It's much easier to help if you can post a representative sample of your data and a minimal amount of code. See suggestions. It's seems also like the major part of your question is on extracting coefficients from a model, not necessarily plotting.camille
@camille thanks for the suggestion. I edited it to include the output.stets
Try to give a minimal complete example : stackoverflow.com/help/mcve that reproduce the problem you are facing. Try to give the data in your post directlydenis
@denis I simplified the code a bit by taking out the unnecessary parts. Can you help me now please?stets

1 Answers

0
votes

I'm not 100% sure what you're trying to do, but I think the ranef function in lmer is what you're looking for.

Something like this might work:

library(tidyverse)
rand_effects <- ranef(cond_ind_waterxsilver)
rand_tbl <- rand_effects$FilterID %>%
  rownames_to_column() %>%
  as_tibble()

That should give you a tibble with a random intercept and a random slope of LnVolume for each group in your data. Is that what you're looking for?

Also, if that doesn't work as is, try inspecting the rand_effects object -- the name of the data.frame in it should be (I think) FilterID since this is your grouping variable, but it might be something different?