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
What commands should I input to perform the ANCOVA? Thank you very much!
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(output ~ input + category, data=data)
You can view the output with the summary
function
summary(mod)
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)
来源:https://stackoverflow.com/questions/27425977/how-to-do-ancova-in-r