Reconciling one-way ANOVA in MATLAB with Results from R I'm used to work in MATLAB but want to be able to use R as well.
Currently, I'm trying to run a one-way ANOVA in R using the following example from MATLAB using the hogg dataset showed here: https://mathworks.com/help/stats/one-way-anova.html
In MATLAB I get the exact right p-value but when I load the data in R it does not give me the same p-value.
I have done the following:

*

*Copied the data to an excel file containing the data like this:




*Run the following code:

library(readxl)

hogg <- read_excel("hogg.xlsx")



*Run the following code:

install.packages("car")

library(car)

fit2=aov(Values ~ Group, hogg)

Anova(fit2, type="III")

However, this gives me the following results:
Response: Values
             Sum Sq Df F value    Pr(>F)    
(Intercept) 2185.46  1 50.8520 9.266e-08 ***
Group        156.82  1  **3.6489**    0.0664 .  
Residuals   1203.35 28  

Here, the correct answer should be "F = 9.01".

Does anyone know what the problem may be?

As a demo, I typed (but did not proofread) your data. In R:
x1 = c(24,15,21,27,33,23)
x2 = c(14, 7,12,17,14,16)
x3 = c(11, 9, 7,13,12,12)
x4 = c( 7, 7, 4, 7,12,18)
x5 = c(19,24,19,15,10,20)
x = c(x1,x2,x3,x4,x5)
gp = as.factor(rep(1:5,each=6)) ## Notice, Warnung, Aviso

So your ANOVA table should look (something) like this:
anova(lm(x~gp))
Analysis of Variance Table

Response: x
          Df Sum Sq Mean Sq F value    Pr(>F)    
gp         4 849.80 212.450   10.39 4.253e-05 ***
Residuals 25 511.17  20.447                      
---
Signif. codes:  
  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Note: Here is a quick way to check computation for analysis of a balanced one-way ANOVA in a new software implementation:
In a balanced one-way ANOVA MSE(Gp) and MSE(Res) should
be number of replications times the variance of the group means and the mean of the group variances, respectively.
mse.gp = 
 6*var(c(mean(x1),mean(x2),mean(x3),mean(x4),mean(x5)));  
mse.gp
[1] 212.45
mse.res= 
 mean(c(var(x1),var(x2),var(x3),var(x4),var(x5))); 
mse.res
[1] 20.44667

Also, if you are not sure variances are the same in each group, you might use oneway.test in R, which does not require equal group variances (analogous to
using a Welch two-sample t test instead of a pooled two-sample t test); denominator DF are decreased as a 'correction' for unequal group means.
oneway.test(x ~ gp)

    One-way analysis of means 
    (not assuming equal variances)

data:  x and gp
F = 7.5998, num df = 4.000, denom df = 12.012,
 p-value = 0.002718

