The model I want to visualize is this one:

BZ ~ 1 + SV_DMW + SV_DIFF (1 + SV_DMW| VPN)

Do you have any ideas how to do this best?

This is how I visualized the model, where just SV_DMW was included.

enter image description here

The single lines are 5 random chosen subjects (VPN).

Do you have any idea how to visualize the model shown above similarly, or do you maybe have entirely different recommendations how to visualize the relationship?

Further information: SV_DMW and BZ are, in general, associated positively SV_DIFF and BZ are, in general, associated negatively

  • 1
    $\begingroup$ Welcome to the site. What are these variables? It helps to have context, but, in particular, are SV_Diff and SV_DMV continuous or categorical or integers or what? Are they always positive? $\endgroup$
    – Peter Flom
    Commented Jun 23, 2023 at 12:46
  • $\begingroup$ It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions. $\endgroup$ Commented Jun 25, 2023 at 13:07
  • $\begingroup$ @PeterFlom thanks for your questions. All variables are continuous. SV_Diff has a range from 1 to 6 and is associated negatively with BZ. SV_DMW has a range from 1 to 7 and is associted positively with BZ. BZ has a range from 1 to 9. BZ = relationship satisfaction SV_DMW = Jointly averaged level of sexual desire of a couple SV_Diff = Difference of sexual desire of persons of a couple $\endgroup$
    – Bila
    Commented Jun 25, 2023 at 13:16
  • $\begingroup$ Instead of plotting individuals, plot the predicted values. Use two graphs. For graph 1, the x axis is SV_DIFF and the y axis is BZ. Make lines for different values of DMW (maybe the quartiles). Graph 2, just the reverse. $\endgroup$
    – Peter Flom
    Commented Jun 25, 2023 at 14:11
  • $\begingroup$ Gelman's Data Analysis Using Regression and Multilevel/Hierarchical Models has many figures and visualizations wrt this class of models. Might be worth a look? google.com/books/edition/… $\endgroup$
    – user78229
    Commented Jun 27, 2023 at 11:52

1 Answer 1


The sjPlot package can get you there. You can use the plot_model function.

#> Loading required package: Matrix

# Data creation inspired by Ben Bolker's post at 
# https://stackoverflow.com/a/38296264/7050882

SV_DMW = runif(6000, 1, 24)
SV_DIFF = runif(6000, 5, 15) * -SV_DMW
VPN = as.factor(rep(seq(1:60), each = 100))
testdata <- data.frame(SV_DMW, SV_DIFF, VPN)
testdata$BZ <- testdata$SV_DIFF * -testdata$SV_DMW/10 * rnorm(300, mean=30, sd=20)

# Model
fit = lmer(BZ ~ 1 + SV_DMW + SV_DIFF + (1|VPN),
           data = testdata, REML = TRUE)
#> boundary (singular) fit: see help('isSingular')

plot_model(fit, type = "pred", terms = c("SV_DMW")) +
  ggtitle(element_blank()) +
  plot_model(fit, type = "pred", terms = c("SV_DIFF")) +
#> Warning: Ignoring unknown parameters: linewidth
#> Ignoring unknown parameters: linewidth

Created on 2023-06-27 with reprex v2.0.2

I simulated your data above. You can instead work directly on the plot_model part by replacing fit with the name of your model.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.