library(readxl)
## Warning: package 'readxl' was built under R version 4.1.3
bmi <- read_excel("C:/Users/Lab pc/Downloads/bmi.xlsx")
View(bmi)
attach(bmi)
names(bmi)
## [1] "BMI"    "Height" "Weight" "Gender"
full.model <- lm(BMI ~ Height + I(Height^2))
reduced.model <- lm(BMI ~ Height)
summary(full.model)
## 
## Call:
## lm(formula = BMI ~ Height + I(Height^2))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.9304 -1.7132 -0.1556  0.4968  5.2193 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) 339.20890  384.79566   0.882    0.407
## Height       -3.70155    4.54356  -0.815    0.442
## I(Height^2)   0.01073    0.01338   0.802    0.449
## 
## Residual standard error: 2.966 on 7 degrees of freedom
## Multiple R-squared:  0.1193, Adjusted R-squared:  -0.1324 
## F-statistic: 0.4739 on 2 and 7 DF,  p-value: 0.6412
summary(reduced.model)
## 
## Call:
## lm(formula = BMI ~ Height)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8669 -1.9828 -0.2591  1.2393  5.2955 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 31.06284   18.34377   1.693    0.129
## Height      -0.05974    0.10572  -0.565    0.588
## 
## Residual standard error: 2.899 on 8 degrees of freedom
## Multiple R-squared:  0.03838,    Adjusted R-squared:  -0.08182 
## F-statistic: 0.3193 on 1 and 8 DF,  p-value: 0.5875
#partial f test
anova(reduced.model , full.model)
## Analysis of Variance Table
## 
## Model 1: BMI ~ Height
## Model 2: BMI ~ Height + I(Height^2)
##   Res.Df    RSS Df Sum of Sq      F Pr(>F)
## 1      8 67.245                           
## 2      7 61.589  1    5.6558 0.6428  0.449
model1 <- lm(BMI ~ Height + Gender + Weight)
model2 <- lm(BMI ~ Height + Weight + Gender)
anova(model1,model2)
## Analysis of Variance Table
## 
## Model 1: BMI ~ Height + Gender + Weight
## Model 2: BMI ~ Height + Weight + Gender
##   Res.Df     RSS Df  Sum of Sq F Pr(>F)
## 1      6 0.52567                       
## 2      6 0.52567  0 8.8818e-16