# Computing regression between different groups

I have four groups of Age data changing with altitude. I need to do the linear regression between different groups according to altitude . I wonder if using just lm is meaning for my case.

Altitude Age
100     22
100     24
100     35
200     41
200     24
200     14
300    25
300     18
300     25

model<- lm(Age~Altitude, data=DF)
summary(model1)

• What do you mean by "regression between different groups according to altitude" and "if using just lm is meaning for my case"? Could you clarify and provide better example? Commented Jul 19, 2017 at 6:48
• Where is altitude in your data? What exactly is "Age" here? Commented Jul 19, 2017 at 6:52
• I edited my question. I need to know if the age is changing with altitude in a linear trend or not?
– Mori
Commented Jul 19, 2017 at 6:53
• Then linear regression will work in this case. Commented Jul 19, 2017 at 6:55
• You can just make simple scatter plot to see the relationship and add regression line to it. Commented Jul 19, 2017 at 7:03

Altitude <- factor(rep(c(100, 200, 300), each = 3))
Age <- c(22, 24, 35, 41, 24, 14, 25, 18, 25)
df <- data.frame(Altitude, Age)


You can check the p-value of the significance of the Altitude factor.

model <- lm(Age ~ Altitude, data = df)
summary(model)


Or you can just see it on a boxplot.

library(ggplot2)
ggplot(df, aes(x = Altitude, y = Age)) + geom_boxplot()