为什么eval(parse(text=string))为类aov的对象提供更短的输出?
为什么这为什么eval(parse(text=string))为类aov的对象提供更短的输出?,r,parsing,eval,R,Parsing,Eval,为什么这 B.aov2<- eval(parse(text=StringforEvaluation)) summary(B.aov2) B.aov2% {.->>异常反馈} 格式表(异常值反馈) b%>% 选择(异常值存在、IV1、IV2、参与者)%>% pivot_wide(name_from=c(IV1,IV2),value_from=OutlierPresent,name_sep=“”,id_cols=Participant)%>% 下拉菜单()%>% pivot_longer(-
B.aov2<- eval(parse(text=StringforEvaluation))
summary(B.aov2)
B.aov2%
{.->>异常反馈}
格式表(异常值反馈)
b%>%
选择(异常值存在、IV1、IV2、参与者)%>%
pivot_wide(name_from=c(IV1,IV2),value_from=OutlierPresent,name_sep=“”,id_cols=Participant)%>%
下拉菜单()%>%
pivot_longer(-Participant,names_to=c(“IV1”、“IV2”),names_sep=“”,values_to=“DV”)%>%
{.->>AnovaAnalysisData}
###计算无离群值数据的方差分析
#设置向上的iStofficedFactors
工厂模型1,工厂模型请包括一个。我们没有stringforevaluation或您的数据。我感谢您的编辑。一个可复制的示例也应该加载代码所需的包。对于summary(B.aov2)
和summary(res.aov2)
,格式表(异常反馈)
在您的代码中不需要解决此问题。但是,作为@Stibu,我得到的两个aov的汇总结果完全相同。同样相同(B.aov2,res.aov2)
返回TRUE,因此它们完全相同。您可能需要重新启动R会话。那可能会有帮助。真的!天哪,现在它对我也有用了!谢谢大家,请附上一份。我们没有stringforevaluation或您的数据。我感谢您的编辑。一个可复制的示例也应该加载代码所需的包。对于summary(B.aov2)
和summary(res.aov2)
,格式表(异常反馈)
在您的代码中不需要解决此问题。但是,作为@Stibu,我得到的两个aov的汇总结果完全相同。同样相同(B.aov2,res.aov2)
返回TRUE,因此它们完全相同。您可能需要重新启动R会话。那可能会有帮助。真的!天哪,现在它对我也有用了!谢谢大家。。
res.aov2 <- aov(DV ~ IV1*IV2+Error(Participant/(IV1*IV2), data = AnovaAnalysisData))
summary(res.aov2)
library(tidyverse)
DV <- c(1,1, 5,6, 1, 2, 7, 7, 1, 4, 9, 9)
IV1 <- c("A","B", "A", "B","A","B", "A", "B","A","B", "A", "B" )
IV2 <- c("C","C","D","D", "C","C", "D","D", "C","C", "D","D")
Participant <- c("A", "A", "A", "A", "B","B","B","B","C","C","C","C")
IV3 <- "no_data" #remove the word "no_data" and add c("A","B", "C", etc.. )
IV4 <- "no_data" #remove the word "no_data" and add c("A","B", "C", etc.. )
##### You have to tell the computer if the variable is within!
IV1_iswithin <-"Y"
IV2_iswithin <-"Y"
IV3_iswithin <-"N"
IV4_iswithin <-"N"
####### Your JOB is DONE
data <- data.frame(DV,Participant,IV1,IV2)
#Grouping the dataframe
data %>%group_by(IV2, IV1)%>% #subsetting the data set to calculate 4 different stats
mutate(MAD = median(abs(DV-median(DV))*2.5*1.4826))%>% #calculates 4 differnet mad numbers
mutate(MADLL = median(DV)-MAD)%>% #cacluates UL of MAD, pipe output to next command
mutate(MADUL = median(DV)+MAD)%>% #calculates the LL of MAD
mutate(OutlierPresent = ifelse(DV<MADLL | DV>MADUL, NA, DV))%>% #Creates NA values if it is an outlier
ungroup()%>% #converts back to big data set
mutate(OutlierPresent = ifelse(DV<MADLL | DV>MADUL, NA, DV))%>% #Creates NA
mutate(whichgroup <- paste(IV1,IV2))%>%
mutate(observation = 1:n()) %>%
{. ->> b }
b %>%
select(DV,OutlierPresent) %>%
{. ->> outlierfeedback }
formattable(outlierfeedback)
b %>%
select(OutlierPresent,IV1,IV2,Participant) %>%
pivot_wider(names_from = c(IV1,IV2), values_from = OutlierPresent, names_sep = "_", id_cols = Participant)%>%
drop_na()%>%
pivot_longer(-Participant, names_to = c("IV1","IV2"), names_sep = "_", values_to = "DV")%>%
{. ->> AnovaAnalysisData }
### Calculating the ANOVA for our outlier free data AnovaAnalysisData
#SettingUpTheListofFixedFactors
FactorModel <- list()
ifelse(length(IV1)> 1, FactorModel<- c(FactorModel, "IV1"), FactorModel<-FactorModel)
ifelse(length(IV2)> 1, FactorModel<- c(FactorModel, "IV2"), FactorModel<-FactorModel)
ifelse(length(IV3)> 1, FactorModel<- c(FactorModel, "IV3"), FactorModel<-FactorModel)
ifelse(length(IV4)> 1, FactorModel<- c(FactorModel, "IV4"), FactorModel<-FactorModel)
#SettingUPTheListofErrorFactors
ErrorModel <-list()
ErrorModel <- list()
ifelse(IV1_iswithin== "Y", ErrorModel<- c(ErrorModel, "IV1"), ErrorModel<-ErrorModel)
ifelse(IV2_iswithin== "Y", ErrorModel<- c(ErrorModel, "IV2"), ErrorModel<-ErrorModel)
ifelse(IV3_iswithin== "Y",ErrorModel<- c(ErrorModel, "IV3"), ErrorModel<-ErrorModel)
ifelse(IV4_iswithin== "Y", ErrorModel<- c(ErrorModel, "IV4"), ErrorModel<-ErrorModel)
StrStart = "aov(DV ~"
StrFactor<-paste(ErrorModel, collapse='*' )
StrErrorStart<-("+Error(Participant/(")
StrError<-paste(ErrorModel, collapse='*' )
StrErrorEnd<- ("),data=AnovaAnalysisData))")
StringforEvaluation<- paste(StrStart, StrFactor,StrErrorStart,StrError,StrErrorEnd)
B.aov2<- eval(parse(text=StringforEvaluation))
summary(B.aov2)
res.aov2 <- aov(DV ~ IV1*IV2+Error(Participant/(IV1*IV2), data = AnovaAnalysisData))
summary(res.aov2)