LME_tutorial
LME tutorial 1
- 想要探究男性 VS 女性的 voice pitch 是否有差别
- 如果有差别,差别是多大?
- 招募一群男性和一群女性,让两组人都发音“mama”, 测量并记录下他们的 voice pitch
- Hz 的值越大,pitch 越高
Linear model comes in
- Give you some values about voice pitch for males and females
- Also give you probability value as to how likely those values are
# pitch predicted by sex
pitch ~ sex
-
The left is the dependent var (the thing you measure), the right one is the independent var (the fixed effect)
-
但是,决定 pitch 的因素又不止性别,还有 language, dialect, personality 等因素,所以我们的 model 要加上代表 random factors 的 ε
pitch ~ sex + ε
- 这个 linear model 就是我们想要构建的,右边由两部分因素组成
- Sex 就是 fixed effect, 是这个 model 的 structural or systematic part
- ε 是 random part, 是这个 model 的 probabilistic part
Start in R
- Input the data
setwd("E:/R/lme_learning")
library(lme4)
library(ggplot2)
library(dplyr)
pitch = c(233, 204, 242, 130, 112, 142)
sex = c(rep("female", 3), rep("male", 3))
my.df = data.frame(sex, pitch)
- Proceed with the linear model, feed it into the
lm()function
xmdl <- lm(pitch ~ sex, my.df)
summary(xmdl)

- Call: remind you of the model formula that you entered
- Residuals: discuss later
- Coefficients of the fixed effects: discuss later
- Overall results
- Multiple R-squared: 即 R2 , which is a measure of "variance explained"
- R2 values range from 0 to 1
- Our R2 is 0.921, quite high, means "92.1% of the stuff that is happening in our dataset is explained by our model"
- → so R2 reflects 92.1% variance in our data is explained by differences between males and females
- Adjusted R-squared: R2adj, it not only looks at how much variance is explained, but also how many fixed effects you used to do the explaining
- 当你有很多 fixed effects 的时候,R2adj有可能会变低
- Significance
- P-value: the probability under the condition that the null hypothesis is true
原假设(“sex has NO effect on pitch”)为真的概率 - 但注意区别 significance of the overall model VS p-value of individual coefficients
- Significance of the overall model 是最底部的这个 p-value

- P-value of individual coefficients 是 Coefficients table 里面的

- 由于现在的 model 只有一个 fixed effect,所以 p-value for this individual coefficient 与 p-value for the overall model 是相同的,都是 0.00241
- 如果你有好几个 fixed effects, p-values for individual coefficient 会与 p-value for the overall model 有差异
- 但是为什么这里是 sexmale, 而不是 sex?
- Female 去哪里了?
- 因为 Estimate for " (Intercept)" 是 estimate for the female category
- 而 Estimate for "sexmale" 是 estimate for the difference between the male and the female category
mean(my.df[my.df$sex == "female", ]$pitch算出 female 组的 mean pitch = 226.33- 同理,算出 male 组的 mean pitch = 128
- Estimate for "sexmale" = $$128 - 226.33 = -98.33 $$
- Significance of the overall model 是最底部的这个 p-value
- P-value: the probability under the condition that the null hypothesis is true
- F-value and degrees of freedom
- 如果你用的是 general linear model analysis,这个 F-value 在汇报结果时要用到
- 如果你想汇报你的结果 is significant, 可以照这么写:
- We constructed a linear model of pitch as a function of sex. This model was significant (F (1, 4) = 46.61, p < 0.01).
- Multiple R-squared: 即 R2 , which is a measure of "variance explained"