# Identifying contrasts between groups in R

I have some doubts which R function choose for my task. Lets imagine we have two types of objects "tree" and "grass" . I've estimated the height of both multiple independent trees and grasses. And i would like to understand whether is there a statistical significant contrast of height between trees and grasses? Which R function will be appropriate in my case? Also i have exactly the same task but with four groups of objects (trees,conifers,grasses,flowers). Which function should i use in that case? I used for both tasks lm() R function. Is it correct? Also the problem that my linear models very often look like:

Call:
lm(formula = count ~ type, data = table_lm)

Residuals:
Min      1Q  Median      3Q     Max
-0.9032  0.0000  0.0000  0.0000  1.0968

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)  2.00000    0.08406  23.792  < 2e-16 ***
typeother   -1.09677    0.13837  -7.926 9.78e-12 ***
---
Residual standard error: 0.612 on 82 degrees of freedom
Multiple R-squared:  0.4338,    Adjusted R-squared:  0.4269
F-statistic: 62.82 on 1 and 82 DF,  p-value: 9.78e-12


Both p-values of F-statistic and t-statistic are significantly lower then 0.05. But the Multiple R-squared value is too low and because of that i can not say that i have statistically significant contrast between groups under investigation, the overall model quality too bad. How i can solve the problem?

• Questions solely about how to use software are off topic here, but you may have a real statistical question buried here. You may want to edit your question to clarify the underlying statistical issue. You may find that when you understand the statistical concepts involved, the software-specific elements are self-evident or at least easy to get from the documentation. – gung - Reinstate Monica Jul 7 '15 at 14:34
• @gung: I've updated the question. – Denis Jul 7 '15 at 14:45
• @Denis do either of these answers answer your question ? If so, please consider marking one as the accepted answer, if not, perhaps you can clarify what else might help ? – Robert Long Apr 14 '19 at 17:22

Both p-values of F-statistic and t-statistic are significantly lower then 0.05

This does not actually make sense. In the null hypothesis significance testing framework, we set a "significance level", which is often 0.05 by convention. It is sufficient to say that the p-values are lower than 0.05 (not significantly lower). How much lower is not really the point, since p-values are uniformly distributed under the null hypothesis.

But the Multiple R-squared value is too low and because of that i can not say that i have statistically significant contrast between groups under investigation, the overall model quality too bad

This statement is incorrect. A p-value is the probability that, if there was really no difference between the means of the groups, that we would observe these data, or data more extreme, if the study was repeated. More informally it indicates that really is a difference between the two groups. So in this case, there is a significant difference between the groups, contrary to the assertion in the OP.

The $$R^2$$ statistic, on the other hand, is a measure of how much of the total variance in the response variable is explained by the model. There is no adequate rule of thumb that says what is "too low".

How i can solve the problem?

There is no problem to solve. The results indicate a significant difference between the groups, which appears to be the research question. If the desire is for a higher $$R^2$$ then it would be advisable to include other independent variables that have an association with the height of trees and grasses.

Yes, lm() is correct for 4 groups, if I'm understanding you correctly. You're looking to perform ANOVA, which is testing for differences between means of different groups in your data. If you only had 2 groups, then a simple t-test would suffice. Here's an example:

set.seed(1)
# Make sure you set your plants variable as a factor! It's categorical, not numeric.
Plants <- factor(c(rep('T', 5), rep('C', 5), rep('G', 5), rep('F', 5)))
Height <- c(rnorm(5, 20, 6), rnorm(5, 6, 3), rnorm(5, 2, 0.5), rnorm(5, 3, 1))

PlantsData <- data.frame(Height, Plants)
summary(lm(data = PlantsData, Height ~ Object))

• I wonder, if my factor looks like: t2=factor(c(rep('T', 5), rep('C', 5), rep('G', 5), rep('F', 5),rep('T', 5))) Should i sort it before calling lm function? I mean: sort(t2) I've tried both possibilities and it seems that order is important. In both cases the models were different. – Denis Jul 9 '15 at 16:40