I can use the anova
function to get the ANOVA table for linear model. However this gives the individual effects of each explanatory variable on the response variable. I wonder if there is any function in R to get the overall ANOVA
where we can get the overall effect of all explanatory variables on response variable. Thanks in advance for your help.
set.seed(12345)
X1 <- 10*abs(rnorm(n=10, mean = 5, sd = 1))
X2 <- 20*abs(rnorm(n=10, mean = 4, sd = 2))
Y <- 50*abs(rnorm(n=10, mean = 10, sd = 4))
df <- data.frame(X1, X2, Y)
fm1 <- lm(formula=Y~X1+X2, data=df)
anova(fm1)
Analysis of Variance Table
Response: Y
Df Sum Sq Mean Sq F value Pr(>F)
X1 1 37842 37842 0.7815 0.406
X2 1 115774 115774 2.3910 0.166
Residuals 7 338941 48420
Edited (2017-10-23)
The required output is
Analysis of Variance Table
Response: Y
Df Sum Sq Mean Sq F value Pr(>F)
Regression 2 153616.587 76808.293 1.586 0.2703
Residuals 7 338940.570 48420.081
supernova
function from supernova package with option type = 1
gives the required output.
library(supernova)
supernova(fm1, type = 1, verbose = FALSE)
Analysis of Variance Table (Type I SS)
Model: Y ~ X1 + X2
SS df MS F PRE p
----- | ---------- - ---------- ----- ------ -----
Model | 153616.587 2 76808.293 1.586 0.3119 .2703
X1 | 37842.327 1 37842.327 0.782 0.1004 .4060
X2 | 115774.260 1 115774.260 2.391 0.2546 .1660
Error | 338940.570 7 48420.081
----- | ---------- - ---------- ----- ------ -----
Total | 492557.157 9 54728.573