Wenn Sie ein Multilevel-Modell mit vielen Faktoren und Interaktionen haben, kann die Größe der Korrelation von Fixed-Effects-Matrix ziemlich groß und unklar werden.Wie extrahiere ich die Korrelation von festen Effekten Teil der lmer Ausgabe
kann ich die symbolic.cor=T
Parameter in der Druckmethode verwenden, um einen klareren Druck der Zusammenfassung wie unten zu machen:
ratbrain <-
within(read.delim("http://www-personal.umich.edu/~bwest/rat_brain.dat"),
{
treatment <- factor(treatment,
labels = c("Basal", "Carbachol"))
region <- factor(region,
labels = c("BST", "LS", "VDB"))
})
print(mod<-lmer(activate ~ region * treatment + (0 + treatment | animal),ratbrain),symbolic.cor=T)
Dies zeichnet eine etwas klarere Korrelationsmatrix für große Matrizen. Obwohl die Matrix dieses Beispiels nicht so groß ist. Aber es wäre schön, wenn ich eine Heatmap der Korrelationen erstellen könnte.
Wie extrahiere ich die Korrelation von fixierten Effekten, um diese Heatmap zu erstellen?
EDIT:
Hier ist die Funktion, die ich dank der Antworten erstellt.
fixeff.plotcorr<-function(mod,...)
{
#require(GGally) # contains another correlation plot using ggplot2
require(lme4)
fixNames<-names(fixef(mod))
# Simon O'Hanlon's answer:
# so <- summary(mod)
# df<-as.matrix([email protected]@factors$correlation) for version lme4<1.0
# df<-as.matrix([email protected]$correlation) # lme4 >= 1.0
df<-as.matrix(cov2cor(vcov(mod))) #Ben Bolker's solution
rownames(df)<-fixNames
colnames(df)<-abbreviate(fixNames, minlength = 11)
colsc=c(rgb(241, 54, 23, maxColorValue=255), 'white', rgb(0, 61, 104, maxColorValue=255))
colramp = colorRampPalette(colsc, space='Lab')
colors = colramp(100)
cols=colors[((df + 1)/2) * 100]
# I'm using function my.plotcorr which you can download here:
# http://hlplab.wordpress.com/2012/03/20/correlation-plot-matrices-using-the-ellipse-library/
my.plotcorr(df, col=cols, diag='none', upper.panel="number", mar=c(0,0.1,0,0),...)
# Another possibility is the corrplot package:
# cols <- colorRampPalette(c("#67001F", "#B2182B", "#D6604D", "#F4A582", "#FDDBC7",
# "#FFFFFF", "#D1E5F0", "#92C5DE", "#4393C3", "#2166AC", "#053061"))
# require(corrplot,quiet=T)
# corrplot(df, type="upper", method="number", tl.pos='tl', tl.col='black', tl.cex=0.8, cl.pos='n', col=cols(50))
# corrplot(df,add=TRUE, method='ellipse', type='lower', tl.pos='n', tl.col='black', cl.pos='n', col=cols(50), diag=FALSE)
}
Sie haben die my.plotcorr Funktion von here zum Download bereit. Das resultierende Diagramm des obigen Beispiels Befehl fixeff.plotcorr(mod)
sieht nun wie folgt aus:
+1 für was ich nicht eine Abhilfe, aber die mathematische Ableitung der Korrelation aus der V-Cov-Matrix wäre !! :-) –