Error in ANOVA contrast commands


#1
  rownames    T x1 x2
1        1  7.50 1 1
2        2 11.20 1 1
3        3 10.29 1 1
4        4 17.69 1 1
5        5 19.92 1 1
6        6 22.40 1 1      

Error in ANOVA contrast commands

In total there are 730 observations with 4 variables rownames, T, X1 and X2.; T is numerical variable;X1 and X2 are integers.
I have provided a few observations.
X1 has five levels: 1,2,3,4 and 5.

I am finding the contrast for the mean of factor X1= 1 vs means of all the levels of X1 (including the 1)

I installed the multcomp library without any problem. Please find below my code. I received an error mesage below the summary code

install.packages("multcomp")

library(multcomp)

mod <- aov(T~A, data = res)
 
k <- rbind ("L"=c(1,-0.25,-0.25,-0.25,-0.25))#L Ho:mean of group X1 vs.mean of other groups of X
summary(glht(mod, linfct = mcp(X1=k), alternative="two.sided"), test=adjusted("none"))
Error in mcp2matrix(model, linfct = linfct) : 
  Variable(s) ‘X1’ of class ‘integer’ is/are not contained as a factor in ‘model’.

Can someone help me solve the above-mentioned problem. Thanks in advance.

ak


#2

Could you please turn this into a self-contained reprex (short for minimal reproducible example)? It will help us help you if we can be sure we’re all working with/looking at the same stuff.

If you’ve never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don’ts are also useful.

For pointers specific to the community site, check out the reprex FAQ, linked to below.