Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中因子的连续水平之间的对比_R_Comparison_Compare Contrast - Fatal编程技术网

R中因子的连续水平之间的对比

R中因子的连续水平之间的对比,r,comparison,compare-contrast,R,Comparison,Compare Contrast,我写这篇文章是因为我被困在一个实验室实验数据文件的分析中 在这个实验中,我计算了在26个时间点(TP)特定环境中出现的雌性(小型节肢动物)的数量。但是,我想了解每个连续时间点的女性数量是否不同(例如,如果TP 1中计数的女性数量不同于TP 2;TP 2中计数的女性数量不同于TP 3;等等……) 数据框包含以下列: 复制(谁包含复制的数量,从1到8);时间点(雌性动物计数的日期,从1到26);雌性(每个时间点统计的雌性数量);和块(实验有2个块) 我试着做了一些连续的对比,但我认为这不是最好的方法

我写这篇文章是因为我被困在一个实验室实验数据文件的分析中

在这个实验中,我计算了在26个时间点(TP)特定环境中出现的雌性(小型节肢动物)的数量。但是,我想了解每个连续时间点的女性数量是否不同(例如,如果TP 1中计数的女性数量不同于TP 2;TP 2中计数的女性数量不同于TP 3;等等……)

数据框包含以下列:

复制(谁包含复制的数量,从1到8);时间点(雌性动物计数的日期,从1到26);雌性(每个时间点统计的雌性数量);和块(实验有2个块)

我试着做了一些连续的对比,但我认为这不是最好的方法。这是我的代码:

   
m1<-lmer(Females~TimePoint+(1|Block))


 Suc_contrasts2<-glht(m1,linfct=mcp(TimePoint=
                               c(
                                 "t1 - t2 == 0",
                                 "t2 - t3 == 0",
                                 "t3 - t4 == 0",
                                 "t4 - t5 == 0",
                                 "t5 - t6 == 0",
                                 "t6 - t7 == 0",
                                 "t7 - t8 == 0",
                                 "t8 - t9 == 0",
                                 "t9 - t10 == 0",
                                 "t10 - t11== 0",
                                 "t11 - t12 == 0",
                                 "t12 - t13 == 0",
                                 "t13 - t14 == 0",
                                 "t14 - t15 == 0",
                                 "t15 - t16 == 0",
                                 "t16 - t17 == 0",
                                 "t17 - t18 == 0",
                                 "t18 - t19 == 0",
                                 "t19 - t20 == 0",
                                 "t20 - t21== 0",
                                 "t21 - t22 == 0",
                                 "t22 - t23 == 0",
                                 "t23 - t24 == 0",
                                 "t24 - t25 == 0",
                                 "t25 - t26 == 0")))


summary(Suc_contrasts2)


summary(Suc_contrasts2, test=adjusted ("bonferroni"))



m1我想这个网站可以帮助你:

根据那里的信息,后续因子水平之间的差异对比可以这样设置(见下文)。请注意,我只使用了一个具有5个因子级别的简单示例

#create dummy data
df <- expand.grid(TimePoint = c("t01", "t02", "t03", "t04", "t05"),
                  Replicate = 1:8, Block = 1:2)
set.seed(2)
df$Females <- runif(nrow(df), min = 0, max = 100)

#set backward difference contrasts
contrasts(df$TimePoint) <- matrix(c(-4/5, 1/5, 1/5, 1/5, 1/5,
                                    -3/5, -3/5, 2/5, 2/5, 2/5, 
                                    -2/5, -2/5, -2/5, 3/5, 3/5,
                                    -1/5, -1/5, -1/5, -1/5, 4/5), ncol = 4)

#创建虚拟数据

df拟合连续差异对比的另一个选项:

m1 <- lmer(Females~TimePoint+(1|Block), contrasts=list(TimePoint=MASS::contr.sdif))

m1为“编辑1”添加了另一种对比方法,但在可视化绘图后,结果似乎不正确。非常感谢您的建议,它非常有效!如果其中一个答案解决了您的问题,我们鼓励您单击复选标记接受它…感谢您的建议和建议。此外,关于这些因素,你是对的,我已经改变了它们。非常感谢你!!这意味着我在评论中找到了很多帮助!
#fit linear model
m1 <- lm(Females ~  TimePoint, data = df)
coef(m1)

(Intercept)  TimePoint1  TimePoint2  TimePoint3  TimePoint4 
  50.295659  -10.116045    7.979465  -10.182389    2.209413 

#mean by time point
with(df, tapply(Females, TimePoint, mean))

     t01      t02      t03      t04      t05 
57.23189 47.11584 55.09531 44.91292 47.12233 

df$TimePoint <- factor(df$TimePoint, levels = paste0("t", 1:26),
                       labels = paste0("t", sprintf("%02d", 1:26)))
m1 <- lmer(Females~TimePoint+(1|Block), contrasts=list(TimePoint=MASS::contr.sdif))