Code Monkey home page Code Monkey logo

Comments (2)

sj-perry avatar sj-perry commented on May 29, 2024

I think the confusion here just stems from what the estimates in the regression table mean. This can get sort of tricky, which is why I always tell students to visualize model predictions with something like sjPlot ;)

This is what the four lines of the fixed effects are telling you:

(Intercept) - The predicted value of log_Grazing_Percentage when Period and Count_RSSI_GE_Minus50 are at zero. I'm assuming that Period is only really ever 1 or 2 in your data, so this value isn't easily interpretable.

Period - The difference in log_Grazing_Percentage for a change of 1 in Period when Count_RSSI_GE_Minus50 is at zero

Count_RSSI_GE_Minus50 - The estimated slope of this variable when Period is at zero. This isn't directly interpretable, because it is extrapolating beyond the observed values of Period to guess what the effect would be if the linear trends fit by the data continued.

Period:Count_RSSI_GE_Minus50 - Interactions can always be thought of in two reversible ways, so this is both how the effect of Period changes based on the values of Count_RSSI_GE_Minus50, and how the slope of the effect for Count_RSSI_GE_Minus50 changes based on Period.

So, to get the slope of Count_RSSI_GE_Minus50 when Period=1, you need to add multiply the interaction term by one (for Period = 1) and add it to the slope of your continuous variable estimated for when Period = 0.

# Slope of Count RSSI for Period = 1
0.006633 + (-0.003454*1)
[1] 0.003179

Then to get the slope when Period = 2, you multiply the interaction term by 2

# Slope of Count RSSI for Period = 2
> 0.006633 + (-0.003454*2)
[1] -0.000275

The following code tests some values to make predictions manually, and it looks like everything checks out:

Intercept <- 1.274435
Period <- -0.012244
Count_RSSI <- 0.006633
Interaction <- -0.003454

# Slope of Count RSSI for Period = 1
Count_RSSI + (Interaction*1)

# Slope of Count RSSI for Period = 2
Count_RSSI + (Interaction*2)

# Predicted log grazing when Period = 1 and RSSI = 0
Intercept + (Period*1) + (Count_RSSI*0) + (Interaction*0*1)

# Predicted log grazing when Period = 1 and RSSI = 80
Intercept + (Period*1) + (Count_RSSI*80) + (Interaction*80*1)

# Predicted log grazing when Period = 2 and RSSI = 0
Intercept + (Period*2) + (Count_RSSI*0) + (Interaction*0*2)

# Predicted log grazing when Period = 2 and RSSI = 80
Intercept + (Period*2) + (Count_RSSI*80) + (Interaction*80*2)

Also, I think you may want to fit Period as a random slope instead of the structure you currently have. Something like this may be more appropriate, although I would definitely check with someone in your field who has domain knowledge who is comfortable with using mixed models

lmer(log_Grazing_Percentage ~ Period + Count_RSSI_GE_Minus50 + Period:Count_RSSI_GE_Minus50 +
(1 + Period| Animal_id)

from sjplot.

strengejacke avatar strengejacke commented on May 29, 2024

By default, predict() is used, however, you could also switch to a different package. The main points are:

  1. plot_model(type = "pred") plots adjusted predictions (sometimes "estimated marginal means") for the response value, i.e. it shows you the predicted value of your outcome, depending on meaningful (or representative) values of certain predictors (so called focal terms).

    The formula (by default) is just: y = b0 + b1*x1 + b2*x2 + ... bn*xn, where you vary the value of your focal terms, and hold the other values constant.

  2. Results may differ, depending on how you hold constant the non-focal terms. You can answer slightly different question based on this decision. I suggest reading this vignette for details.

Furthermore, if you're interested in predictions, I suggest using the ggeffects package directly. sjPlot::plot_model(type = "pred") is just a wrapper around that package, but less flexible.

The situation with mixed models is slightly more complicated, because you can condition on random effects or not. There's also a vignette here.

from sjplot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.