Practical_Task_12
Preparing the data and loading packages
# Load necessary libraries
library(tidyverse)## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.0 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(car)## Loading required package: carData
##
## Attaching package: 'car'
##
## The following object is masked from 'package:dplyr':
##
## recode
##
## The following object is masked from 'package:purrr':
##
## some
library(multcomp)## Loading required package: mvtnorm
## Loading required package: survival
## Loading required package: TH.data
## Loading required package: MASS
##
## Attaching package: 'MASS'
##
## The following object is masked from 'package:dplyr':
##
## select
##
##
## Attaching package: 'TH.data'
##
## The following object is masked from 'package:MASS':
##
## geyser
# Load your data
library(readr)
Mustard <- read_csv("~/Documents/DATA ANALYTICS/Mustard.csv")## Rows: 108 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): light, medium
## dbl (2): weight, watering
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Comparing ANOVA results
ANOVA results
# Print ANOVA results
print(anova_result_1_2)## Analysis of Variance Table
##
## Model 1: weight ~ light + watering + medium
## Model 2: weight ~ (light + watering + medium)^2
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 98 25.047
## 2 87 21.670 11 3.377 1.2325 0.2782
print(anova_result_2_3)## Analysis of Variance Table
##
## Model 1: weight ~ (light + watering + medium)^2
## Model 2: weight ~ (light + watering + medium)^2 * light
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 87 21.670
## 2 81 20.678 6 0.99204 0.6477 0.6918
In interpreting the ANOVA results for Models 1 and 2, and Models 2 and 3, the pivotal factor is the p-value associated with the F-statistic. With p-values of 0.2782 and 0.6918, respectively, exceeding the 0.05 significance level, we fail to reject the null hypotheses.
This suggests no significant difference between linear and quadratic terms in Model 1 versus Model 2, and between quadratic terms in Model 2 versus interaction terms in Model 3.
AIC and BIC
Using the AIC() and BIC() functions to compare models and choose the one with the lowest AIC/BIC
## AIC:
## 163.4912 170.2845 177.3643
## BIC:
## 184.7229 220.7098 243.7133
We should choose the model with the lowest AIC and BIC values. In this case, Model 1 has the lowest AIC (163.4912) and BIC (184.7229), making it the preferred model according to both criteria.
Therefore, based on AIC and BIC, Model 1 is the preferred model among the three. It provides a good trade-off between model fit and complexity, according to these information criteria.
Choosing the variable combination that maximizes the weight of mustard plants
## (Intercept) lightnormal
## 0.27194444 -0.29333333
## lightred watering
## -0.10250000 0.51750000
## mediumnewspaper mediumsawdust
## 0.16841270 0.20694444
## mediumsoil lightnormal:watering
## 2.45805556 -0.09666667
## lightred:watering lightnormal:mediumnewspaper
## -0.07583333 -0.16740842
## lightred:mediumnewspaper lightnormal:mediumsawdust
## 0.34825397 -0.27083333
## lightred:mediumsawdust lightnormal:mediumsoil
## -0.16916667 -0.94500000
## lightred:mediumsoil watering:mediumnewspaper
## 0.35430556 -0.17666667
## watering:mediumsawdust watering:mediumsoil
## -0.18750000 -0.10583333
## lightnormal:watering:mediumnewspaper lightred:watering:mediumnewspaper
## 0.15006410 -0.01666667
## lightnormal:watering:mediumsawdust lightred:watering:mediumsawdust
## 0.12583333 0.07083333
## lightnormal:watering:mediumsoil lightred:watering:mediumsoil
## 0.14000000 -0.20291667
The variable combination that maximizes the weight of mustard plants can be determined by identifying the variables with the most positive coefficients in the model. In the provided model, the coefficients represent the effect of each variable on the estimated weight.
- mediumnewspaper: 0.16841270
- mediumsawdust: 0.20694444
- lightred:mediumnewspaper: 0.34825397
- watering:mediumnewspaper: 0.35430556
- lightred:mediumsawdust: 0.07083333
These variables have positive coefficients, suggesting that higher levels of these factors contribute positively to the estimated weight of mustard plants.