Using R, build a multiple regression model for data that interests you. Include in this model at least one quadratic term, one dichotomous term, and one dichotomous vs. quantitative interaction term. Interpret all coefficients. Conduct residual analysis. Was the linear model appropriate? Why or why not?

# to load the Iris dataset
data(iris)

# Quadratic
iris$Petal.Length_Squared <- iris$Petal.Length*iris$Petal.Length
# Dichotomous
iris$Species_Dichotomous <- ifelse(iris$Species == "setosa", 1, 0)

# (dichotomous * petal width)
iris$inter_term <- iris$Species_Dichotomous * iris$Petal.Width

# Fit a multiple regression model
model <- lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width +
            Petal.Length_Squared + Species_Dichotomous + inter_term,
            data = iris)

# to interpret coefficients
summary(model)
## 
## Call:
## lm(formula = Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + 
##     Petal.Length_Squared + Species_Dichotomous + inter_term, 
##     data = iris)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.79160 -0.20985  0.00803  0.18908  0.74591 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)    
## (Intercept)           3.20620    0.65383   4.904 2.52e-06 ***
## Sepal.Width           0.57060    0.08242   6.923 1.38e-10 ***
## Petal.Length          0.17058    0.26928   0.633   0.5275    
## Petal.Width          -0.55886    0.12814  -4.361 2.46e-05 ***
## Petal.Length_Squared  0.06130    0.02638   2.324   0.0215 *  
## Species_Dichotomous  -0.60231    0.38509  -1.564   0.1200    
## inter_term            0.81854    0.43890   1.865   0.0642 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3068 on 143 degrees of freedom
## Multiple R-squared:  0.8683, Adjusted R-squared:  0.8627 
## F-statistic: 157.1 on 6 and 143 DF,  p-value: < 2.2e-16
# Scatter plot with best-fit line 
plot(iris$Sepal.Length ~ iris$Sepal.Width, main = "Scatter Plot with Best Fit Line",
     xlab = "Sepal Width", ylab = "Sepal Length")
abline(model, col = "red")
## Warning in abline(model, col = "red"): only using the first two of 7 regression
## coefficients

plot(model)

  1. Assumption of linearity has been met by the model.

  2. Largelly meets the assumption of normality due to most risiduals falling on the line.

  3. The equality of variances may not be met, because the line formes a visible shape.

  4. No strong outliers.

Conclusion:

The model was mostly appropriate. But its not a constant variance.