如何在R中做ANCOVA? [英] How to do ANCOVA in R?

查看:296
本文介绍了如何在R中做ANCOVA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含三列的数据框:data $ input,data $ output和data $ category.输入和输出都是连续的数字,类别是离散的字符.我知道ANCOVA是一种在控制类别效果的同时分析输入对输出效果的方法.但是,我找不到在线执行此操作的确切命令.

I have a dataframe with three columns: data$input, data$output and data$category. Both input and output are continuous numerics, and categories are discrete characters. I know ANCOVA is a method that analyzes the effect of input on output while controlling for the effect of category. However I could not find the exact command to do for this online.

这是数据看起来像的一个小例子:

Here is a small example of how the data would look like:

   input output category

1    0.4   0.55        A

2    0.5   0.66        A

3    0.6   0.57        A

4    0.3   0.23        B

5    0.4   0.53        B

6    0.7   0.75        B

7    1.1   1.31        C

8    0.9   1.01        C

9    0.8   0.58        C

10   0.5   0.34        C

我应该输入什么命令来执行ANCOVA?非常感谢你!

What commands should I input to perform the ANCOVA? Thank you very much!

推荐答案

您可以使用函数lm,该函数运行线性回归(最后,ANOVA和ANCOVA只是线性模型的受限版本)./p>

You could use the function lm, which runs a linear regression (in the end, ANOVA and ANCOVA are just restricted versions of the linear model).

mod<-lm(输出〜输入+类别,数据=数据)

mod <- lm(output ~ input + category, data=data)

您可以使用summary函数查看输出

You can view the output with the summary function

摘要(修改)

summary(mod)

如果您确实需要输出'ANOVA样式',则可以在创建的模型上应用函数anova(我个人认为lm输出的信息更多,但也许有特定的限制).

If you really need to have the output 'ANOVA style', then you can apply the function anova on the model created (I personally find the lm output more informative, but maybe you have specific restrictions).

anova(mod)

anova(mod)

这篇关于如何在R中做ANCOVA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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