YouTip LogoYouTip

R Func Aov

# R aov() Function – Analysis of Variance [![Image 3: R Language Examples](#) R Language Examples](#) The R `aov()` function is used to perform analysis of variance (ANOVA), comparing whether the means of three or more groups differ significantly. When comparing more than two groups, ANOVA is more appropriate than conducting multiple t-tests. The syntax of the `aov()` function is as follows: aov(formula, data) **Parameter Description:** * **formula**: Formula, in the format `response_variable ~ grouping_variable`. * **data**: Data frame containing the variables in the formula. ## Example # Effect of three types of fertilizer on crop yield fertilizer <- factor(rep(c("A", "B", "C"), each = 5)) yield <- c(18, 20, 19, 22, 21, # Fertilizer A 25, 27, 24, 26, 28, # Fertilizer B 15, 17, 16, 14, 18) # Fertilizer C # Create data frame df <- data.frame(fertilizer, yield) print("Data Preview:") print(df) # Perform ANOVA result F) fertilizer 2 190.0 95.00 28.61 2.73e-05 ***Residuals 12 39.9 3.32---Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 The p-value is much less than 0.001, indicating a highly significant difference in yield among the three fertilizers. [![Image 4: R Language Examples](#) R Language Examples](#)
← R Func ApplyR Func Abline β†’