library(readxl)
dog_and_cat_data_<- read_excel("dog and cat data .xlsx")
##Question One: Load your chosen data set into R Markdown##
##Question Two: Create a linear model "lm()" from the variables, with a continuous dependent variable##
sheltermodel<- lm(`Animals Euthanized` ~Adoptions +Fosters, data= dog_and_cat_data_)
summary(sheltermodel)
##
## Call:
## lm(formula = `Animals Euthanized` ~ Adoptions + Fosters, data = dog_and_cat_data_)
##
## Residuals:
## 1 2 3 4 5 6 7 8
## -438.63 135.09 281.70 -639.13 186.85 52.47 246.64 175.01
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -922.8312 382.9713 -2.410 0.06089 .
## Adoptions 0.2290 0.1164 1.966 0.10643
## Fosters 2.8216 0.5093 5.541 0.00263 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 406.8 on 5 degrees of freedom
## Multiple R-squared: 0.9096, Adjusted R-squared: 0.8735
## F-statistic: 25.17 on 2 and 5 DF, p-value: 0.002454
##Question Three: ##
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(MASS)
library(car)
## Loading required package: carData
raintest(sheltermodel)
##
## Rainbow test
##
## data: sheltermodel
## Rain = 0.76003, df1 = 4, df2 = 1, p-value = 0.6847
##not linear##
durbinWatsonTest(sheltermodel)
## lag Autocorrelation D-W Statistic p-value
## 1 -0.3078198 2.346159 0.186
## Alternative hypothesis: rho != 0
##not significant##
bptest(sheltermodel)
##
## studentized Breusch-Pagan test
##
## data: sheltermodel
## BP = 0.16501, df = 2, p-value = 0.9208
##not significant##
##normality of residuals##
plot(sheltermodel,which = 3)

##not normal##
##multicolinearity##
vif(sheltermodel)
## Adoptions Fosters
## 1.172648 1.172648
##assumption is not violated##
##Question Five: the only model that does not violate the assumptions is the multicolinearity##
##Question Six: To mitigate the assumption of linearity, you could use a log transformation to transform the variables to see if this helps it become more linear. To mitigate independence of errors, you can run a RLM or robust linear model. To mitigate heteroscedasticity, you could conduct a log transformation of the depenedent variable. To mitigate non-normality of residuals, you could use a log transformation. To mitigate multicolinearity, you could remove the strongly correlated variables##