利用R进行方差分析和贝叶斯方差分析
overview
本文将开一个新坑,用于介绍如何用R完成一般线性模型(ANOVA) 以及 混合线性模型(lined mixed model,LMM) 等主流或者非主流的方法,由于内容较多而自己的时间与精力有限,整个写作不会一蹴而就。更有可能是 写新内容 - 删改 - 写新内容 - 删改 …… 如此反复。希望对该主题感兴趣的读者可以先增加收藏,随时观看是否有更新。
目前的计划是先随心所欲地写,而不是考虑内容的系统性。目前市面上关于该主题的内容五花八门,人们更需要甄别有效信息的能力。于我而言,我预期先搜寻出自认为有效、可靠的方法,将其放置在该处,等后期内容足够时,再思考如何系统性地组织内容。我相信只有积累一定的素材后才能真正理解整个领域。所以在此之前,信息的繁杂和冗余性也可能会劝退一部分读者,对此十分抱歉!
事实上,目前市面上已有较多可以用于该主题的工具,如最流行的JASP软件,由于它的简易性和开放性,目前已成为心理学研究中的主流。对我自己而言,在某些事件上为了图方便,或是为了保证与前人研究的一致性,也会偷懒使用JASP完成统计分析。
我自己的背景是心理学博士在读,因此所有的数据分析取向都是基于心理学的实验设计,这基本上都是基于单变量或多变量(很少超过4因素)的数据分析,而在该领域中,又通常会考虑被试(人)本身的变异性与刺激材料对研究结果的变异性。
afex(analysis of factorial experiments)包
该 packages 主要用于分析因子型实验,包括方差分析和混合模型等,里面提供了诸如aov_ez(), aov_car(), aov_4()等函数用于分析组间、组内和混合设计的方差分析,数据是采用长数据格式(long format),它能够自动整合被试、条件处理下的多个观测值。mixed()函数能够调用lme4::lmer函数的混合模型,并且计算所有固定效应中的p值,还能够采用不同Kenward-Roger或者Satterthwaite估计的方法调整自由度。 afex_plot() provides a high-level interface for interaction or one-way plots using ggplot2, combining raw data and model estimates. afex uses type 3 sums of squares as default (imitating commercial statistical software)
anova_car 函数还要求输入提供了误差项的输入(组内变量)。
aov_car(formula, data, fun_aggretate = NULL,type= afex_options("type"),factorize = afex_options("factorize"),observed = NULL,anova_table = list(),indlude_aov = afex_options("include_aovv"),return = afex_options("return_aov"))
以下两个函数则是采用不同的写法
aov_4(
formula,
data,
observed = NULL,
fun_aggregate = NULL,
type = afex_options("type"),
factorize = afex_options("factorize"),
return = afex_options("return_aov"),
anova_table = list(),
include_aov = afex_options("include_aov"),
...,
print.formula = FALSE
)
aov_ez(
id,
dv,
data,
between = NULL,
within = NULL,
covariate = NULL,
observed = NULL,
fun_aggregate = NULL,
transformation,
type = afex_options("type"),
factorize = afex_options("factorize"),
return = afex_options("return_aov"),
anova_table = list(),
include_aov = afex_options("include_aov"),
...,
print.formula = FALSE
)
temp <- md_12.1result <- aov_ez("id","rt",md_12.1,within = c("noise","angle"))
BayesFactor 包
library(BayesFactor)
library(bayestestR)
set.seed(47)
exp1_plot <- as.data.frame(exp1_plot)
exp1_plot$filename <- factor(exp1_plot$filename)
exp1_plot$phase <- factor(exp1_plot$phase)
exp1_plot$test <- factor(exp1_plot$test)RT_anova_bayes <- function(RT_df){Bayes_RT <- anovaBF( formula = RT ~ test * phase + filename ,data = RT_df,whichRandom = "filename")return(Bayes_RT)
}
exp1_bayes <- RT_anova_bayes(exp1_plot)
summary(exp1_bayes)
print(bayesfactor_inclusion(RT_anova_bayes(exp1_plot), match_models=TRUE))
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
