I have the following model:

model = aov(y ~ treatment + Age, data = dt)

How I determine Age as a covariate (covariable) in r? Is there a code or R only knows?


By simply including another variable in your model statement, you've included it as a covariate in your model. So for example, a general model would look like this:

model = model_type(dependent_variable ~ independent_variable + covariate, data = dataset_name),

In the example you provided, you specified an ANOVA model_type (aov) by including Age on the right side of the tilde (~). By doing that, you have included it as a covariate when you've included some other variable as your independent variable of interest (in your example, treatment).

Examples are found all over the internet and throughout the r documentation. Try for example help(aov).

  • $\begingroup$ So, it's related of the variable format too. The format of covariate must be numeric. $\endgroup$ – Curious G. Apr 24 at 12:30
  • $\begingroup$ @CuriousG., Not necessarily. It can also be a factor. $\endgroup$ – StatsStudent Apr 24 at 15:19
  • $\begingroup$ I don't think so. I think that the trick is the format. Try to do an Anova using different formats, the Anova table will be totally different. $\endgroup$ – Curious G. Apr 24 at 15:34
  • $\begingroup$ The covariate can be in levels as a factor, but the format must be numeric. $\endgroup$ – Curious G. Apr 24 at 15:35
  • $\begingroup$ I'm not sure I know what you mean by "the trick." What trick? The trick for doing what? You simply include an additional variable, numeric or factor on the right side of the ~ to include it as a covariate. I've done hundreds, if not thousands of ANOVA's in R before. Of course you will get totally different ANOVA tables if you use different inputs. I have no idea what you mean by the format must be numeric. Covariates can be numeric or factors. $\endgroup$ – StatsStudent Apr 25 at 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.