在R中对序数数据运行Friedman测试时遇到问题 [英] Having trouble running friedman test on ordinal data in R

查看:67
本文介绍了在R中对序数数据运行Friedman测试时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对R中的序数数据进行Friedman测试,但出现错误.可以在保管箱 https://www.dropbox.com/s/gh8crh18y1ueriy/seltoutput.xlsx?dl = 0 .

I am attempting to run a friedman test on ordinal data in R and am getting errors. The data can be found here on dropbox https://www.dropbox.com/s/gh8crh18y1ueriy/seltoutput.xlsx?dl=0.

作为数据描述:

group1:小组分配,2级
time1:时间点,2级
方法:顺序数据,共5个级别
distmeasure:连续数据
vectemp:参与者ID

group1: group assignments, 2 levels
time1: time points, 2 levels
loameasure: ordinal data, 5 levels
distmeasure: continuous data
vectemp: participant IDs

导入数据后,我运行以下命令正确格式化:

After importing the data I run the following to correctly format:

  selt$loameasure<-factor(selt$loameasure)  
  selt$distmeasure<-as.numeric(selt$distmeasure)  
  selt$time1<-factor(selt$time1)  

然后我跑:

 friedman_test(formula = loameasure ~ time1 | vectemp, data = selt)

然后我得到了错误:
Friedman.test.default(c(3L,2L,3L,2L,2L,5L,2L,1L,3L,4L,:不是一个不可复制的完整模块设计

Then I get the error:
Error in friedman.test.default(c(3L, 2L, 3L, 2L, 2L, 5L, 2L, 1L, 3L, 4L, : not an unreplicated complete block design

我认为loameasure和time1必须是因素,但我确实将它们尝试为数字,但得到了类似的错误:
Friedman.test.default(c(3,2,3,2,2,5,5,1,1,3,4,2,2,4,:不是一个不可复制的完整模块设计

I thought that loameasure and time1 had to be factors but I did try them as numeric and I get a similar error:
Error in friedman.test.default(c(3, 2, 3, 2, 2, 5, 2, 1, 3, 4, 2, 2, 4, : not an unreplicated complete block design

我已经玩了好几天了,还没弄清我的问题是什么.我希望得到一些帮助!预先谢谢你!

I've been playing around with this for days and haven't been able to figure out what my problem is. I would love some assistance! Thank you in advance!

推荐答案

据我所知,弗里德曼测试不适用于您的情况.我建议使用III型平方和求和方法对不平衡设计进行双向ANOVA测试.给出了残差和均一性的正态性假设.我试图指导您如何执行测试以及某些步骤的含义.它不完整(缺乏解释等.)但这应该是您的起点和方向.

As far as I can anticipate a Friedman test is not appropriate in your situation. I would suggest to perform a two-way ANOVA test for unbalanced designs with Type-III sums of square method. The assumptions of Normality of residuals and homogenity are given. I have tried to guide you how to perform the test and the meaning of some steps. It is not complete (lacking of interpretation etc..) But this should be a begin and direction for you.

  1. 我们想知道Loameasure是否取决于group1和time1
  2. 我们将基于两个因素进行双向方差分析
  3. 因变量: loameasure
  4. 自变量: group1 time1

library(readxl)
# load your data
df <- read_excel("C:/Users/coding/Downloads/seltoutput.xlsx", 
                 col_types = c("numeric", "numeric", "numeric")) 

# Prepare data
# group1 to factor 
df$group1 <- factor(df$group1,
                    levels = c(0, 1),
                    labels = c("Group_0", "Group_1"))
# time1 to factor
df$time1 <- factor(df$time1,
                      levels = c(1, 2),
                      labels = c("Time_1", "Time_2"))
----------------------------------------------------------------------------
# Visualize
library("ggpubr")
ggboxplot(df, x = "time1", y = "loameasure", color = "group1",
          palette = c("#00AFBB", "#E7B800"))

ggline(df, x = "time1", y = "loameasure", color = "group1",
       add = c("mean_se", "dotplot"),
       palette = c("#00AFBB", "#E7B800"))
-----------------------------------------------------------------------------
# first decide if balanced or unbalnced design
table(df$group1, df$time1)
# Output

# Time_1 Time_2
# Group_0     20     20
# Group_1     29     29

# Here it is a unbalance design 
# An unbalanced design has unequal numbers of subjects in each group!

## We will perform two-way ANOVA test in R for unbalanced designs !!!!!!!!!!!
# The recommended method are the Type-III sums of squares.
# you need `car` package
library(car)
# Our 2 way anova of unbalanced design (SS Type-III)

df_anova <- aov(loameasure ~ group1 * time1, data = df)
Anova(df_anova, type = "III")

## Output
# Anova Table (Type III tests)
# Response: loameasure
# Sum Sq Df F value    Pr(>F)    
# (Intercept)  120.050  1 83.9312 1.116e-14 ***
#   group1         0.700  1  0.4891   0.48607    
# time1         62.500  1 43.6960 2.301e-09 ***
#   group1:time1   5.716  1  3.9963   0.04849 *  
#   Residuals    134.452 94                      
# ---
#   Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


# Nomrality check ---------------------------------------------------------


# call residuals (difference between each indivdual and their group1/time1 combination mean)
res <- df_anova$residuals

# Histogram of residuals: Residuals should be normally distributed
hist(res,main="Histogram of residuals", xlab = "Residuals")
# # Extract the residuals

# Run Shapiro-Wilk test
shapiro.test(x = res )
# Output
# data:  res
# W = 0.97708, p-value = 0.08434
# P is > 0.05 therefore normality can be assumed.


# Homogenity test ---------------------------------------------------------

# Levene's test for equality of variances (in `car` package)
library(car)
leveneTest(loameasure~ time1 * group1,data=df)

# Output:
# Levene's Test for Homogeneity of Variance (center = median)
#       Df F value Pr(>F)
# group  3  0.3196 0.8112
#       94  
# P is > 0.05 therefore equal variances can be assumed.

这篇关于在R中对序数数据运行Friedman测试时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆