1.A very basic tutorial for performing linear mixed effects analyses(入门极品)
Tutorial 1: http://www.bodowinter.com/tutorial/bw_LME_tutorial1.pdf
Tutorial 2: http://www.bodowinter.com/tutorial/bw_LME_tutorial.pdf
nlme (Non-Linear Mixed Effects), lme4 (Linear Mixed Effects) and asreml (average spatial real)
2.其它资料(Google搜索即有)
Mixed-Eects Models in R (较好)
An Appendix to An R Companion to Applied Regression, Second Edition
John Fox & Sanford Weisberg
Linear Mixed-Effects Models Using R(一本教材,进阶选用)
A Step-by-Step Approach
Andrzej Ga?ecki ? Tomasz Burzykowski
3.R中的线性混合模型介绍(简单了解不同的包)
http://blog.sciencenet.cn/blog-2577109-949820.html
https://www.r-bloggers.com/linear-mixed-models-in-r/
3.语法备忘
- 三种模型:
- AOD固定斜率,DAY随机截距:LMM.model = lmer(PM25 ~ AOD + (1|Day) , data=LMMexcdata)
- AOD随机斜率,DAY固定截距:LMM.model3 = lmer(PM25 ~ AOD + (0 + AOD|Day) , data=LMMexcdata)
- AOD随机斜率,DAY随机截距:LMM.model2 = lmer(PM25 ~ AOD + (1 + AOD|Day) , data=LMMexcdata)
- 师姐发来的查看斜率和截距的程序:
sslopef=as.numeric(as.matrix(lme4::fixef(fm1)[2]))
sloper=as.numeric(LMM.model(lme4::ranef(fm1)$Day[,2]))
intersf= as.numeric(LMM.model(lme4::fixef(fm1)[1]))
intersr=as.numeric(LMM.model(lme4::ranef(fm1)$Day[,1]))
lme4::fixef(yourmodle)读取固定截距和斜率
lme4::fixef(yourmodle)读取随机截距和斜率
文档中示例(A very basic tutorial for performing linear mixed effects analyses):
-----------------------------------------
#load data into R
politeness=read.csv("http://www.bodowinter.com/tutorial/politeness_data.csv")
#================view the dataset======================
#show the head of politeness
head(politeness)
#show the tail of politeness
tail(politeness)
# other commands you may use
summary(politeness)
str(politeness)
colnames(politeness)
#================check for missing values======================
which(!complete.cases(politeness))
#======look at the relationship between politeness and pitch by means of a boxplot==========
boxplot(frequency ~ attitude*gender,
col=c("white","lightgray"),politeness)
#================A random intercept model======================
library(Matrix)
library(lme4)
lmer(frequency ~ attitude, data=