【发布时间】:2015-09-04 14:22:48
【问题描述】:
我正在使用 GLMM 在 R 中工作,该 GLMM 混合了连续变量和分类变量以及一些交互。我在 MuMIn 中使用了 dredge 和 model.avg 函数来获得每个变量的效果估计值。我的问题是如何最好地绘制结果。我想制作一个图表来显示一个变量(森林)对我的数据的影响,其中趋势线反映了森林参数估计,但我不知道如何将分类变量和交互变量保持在它们的“平均值”,以便趋势线只反映森林的影响。
这是模型和绘图设置:
#load packages and document
cuckoo<-read.table("http://www.acsu.buffalo.edu/~ciaranwi/home_range.txt",
header=T,sep="\t")
require(lme4)
require(MuMIn)
as.factor (cuckoo$ID)
as.factor (cuckoo$Sex)
as.factor(cuckoo$MS_bin)
options(na.action = "na.fail")
# create global model and fit
fm<- lmer(log(KD_95)~ MS_bin + Forest + NDVI + Sex + Precip + MS_bin*Forest
+ MS_bin*NDVI + MS_bin*Sex + MS_bin*Precip + Argos + Sample + (1|ID), data
= cuckoo, REML = FALSE)
# dredge but always include argos and sample
KD95<-dredge(fm,fixed=c("Argos","Sample"))
# model averaging
avgmod<-model.avg(KD95, fit=TRUE)
summary(avgmod)
#plot data
plot(cuckoo$Forest, (log(cuckoo$KD_95)),
xlab = "Mean percentage of forest cover",
ylab = expression(paste(plain("Log of Kernel density estimate, 95%
utilisation, km"^{2}))),
pch = c(15,17)[as.numeric(cuckoo$MS_bin)],
main = "Forest cover",
col="black",
ylim=c(14,23))
legend(80,22, c("Breeding","Nonbreeding"), pch=c(15, 17), cex=0.7)
然后我陷入了如何包含趋势线的问题。到目前为止,我有:
#parameter estimates from model.avg
argos_est<- -1.6
MS_est<- -1.77
samp_est<-0.01
forest_est<--0.02
sex_est<-0.0653
precip_est<-0.0004
ndvi_est<--0.00003
model_intercept<-22.7
#calculate mean values for parameters
argos_mean<-mean(cuckoo$Argos)
samp_mean<-mean(cuckoo$Sample)
forest_mean<-mean(cuckoo$Forest)
ndvi_mean<-mean(cuckoo$NDVI)
precip_mean<-mean(cuckoo$Precip)
#calculate the intercept and add trend line
intercept<-(model_intercept + (forest_est*cuckoo$Forest) +
(argos_est*argos_mean) + (samp_est * samp_mean) + (ndvi_est*ndvi_mean) +
(precip_est*precip_mean) )
abline(intercept, forest_est)
但这没有考虑交互作用或分类变量,截距看起来太高了。有什么想法吗?
【问题讨论】:
-
您不需要为每个参数创建一个新对象(
argos_est <- -1.6等)。你可以只做coef(avgmod),这会给你所有的系数。 -
谢谢!绝对是一种更简洁的估算方式……但我仍然遇到同样的问题。
标签: r plot data-visualization predict lme4