[R-sig-ME] lme4: plotting profile density (not Zeta) manually not by lattice

Daniel Lüdecke d@|uedecke @end|ng |rom uke@de
Mon Oct 26 08:16:36 CET 2020


Dear Simon,
you could use the "estimate_density()" function from the bayestestR package
(see examples here:
https://easystats.github.io/see/articles/bayestestR.html), which works on
data frames (like the object returned by "profile()") and has an own
plot()-method. Another approach that *might* come close to what you would
like to achieve is simulating parameters from a multivariate normal
distribution, based on MASS:: mvrnorm(). This can be done with the
"simulate_parameters()" function from the parameters package, which also has
a print()-method (see visual examples here:
https://easystats.github.io/see/articles/parameters.html#simulated-model-par
ameters-1).

Here is some working code, I hope I got your point and provided a useful
answer...

library(lme4)
library(bayestestR)
library(parameters)
library(ggplot2)

theme_set(theme_classic())
hsb <-
read.csv('https://raw.githubusercontent.com/rnorouzian/e/master/hsb.csv')
m31 <- lmer(math ~ ses*meanses + (ses | sch.id), data = hsb)
mp <- profile(m31)

# some profiled densities have very high spikes, so plot is probably less
useful...
d1 <- estimate_density(mp[c("ses", "meanses", "ses:meanses")])
d2 <- estimate_density(mp$ses)
d3 <- estimate_density(mp[c("ses", "ses:meanses")])

plot(d1) + ggplot2::xlim(c(0, 4))
plot(d2) + ggplot2::xlim(c(2.15, 2.25))
plot(d3) + ggplot2::xlim(c(0, 3))

sp <- simulate_parameters(m31)
plot(sp)
plot(sp, stack = FALSE)

Best
Daniel


-----Ursprüngliche Nachricht-----
Von: R-sig-mixed-models <r-sig-mixed-models-bounces using r-project.org> Im
Auftrag von Simon Harmel
Gesendet: Montag, 26. Oktober 2020 01:55
An: r-sig-mixed-models <r-sig-mixed-models using r-project.org>
Betreff: [R-sig-ME] lme4: plotting profile density (not Zeta) manually not
by lattice

Dear All,

I'm trying to plot the sampling distributions of my model parameters using `
densityplot()` from the `lattice` package but lattice often throws an error
even if one of the estimate's density distribution is highly skewed or
funny-looking.

Is there a better package or a better way (even manually) to plot the
densities (not Zeta) from a `profile()` call?

library(lattice)
library(lme4)

hsb <- read.csv('
https://raw.githubusercontent.com/rnorouzian/e/master/hsb.csv')
m31 <- lmer(math ~ ses*meanses + (ses | sch.id), data = hsb)

p <-  profile(m31)
densityplot(p)
Error in UseMethod("predict") :
  no applicable method for 'predict' applied to an object of class "NULL"

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-mixed-models using r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models

--

_____________________________________________________________________

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Joachim Prölß, Prof. Dr. Blanche Schwappach-Pignataro, Marya Verdel
_____________________________________________________________________

SAVE PAPER - THINK BEFORE PRINTING



More information about the R-sig-mixed-models mailing list