Quiz March 30

Dario DeBlasis

2022-03-30

> Dataset$isOwn <- with(Dataset, ifelse(OwnHome=="Own", 1, 0))
> Dataset$isRent <- with(Dataset, ifelse(OwnHome=="Rent", 1, 0))
> Dataset$isMale <- with(Dataset, ifelse(Children=="Male", 1, 0))
> Dataset$isFemale <- with(Dataset, ifelse(Children=="Female", 1, 0))
> Dataset$isSingle <- with(Dataset, ifelse(Married=="Single", 1, 0))
> Dataset$isMarried <- with(Dataset, ifelse(Married=="Married", 1, 0))
> Dataset$isFar <- with(Dataset, ifelse(Location=="Far", 1, 0))
> Dataset$isClose <- with(Dataset, ifelse(Location=="Close", 1, 0))
> Dataset$isHigh <- with(Dataset, ifelse(History=="High", 1, 0))
> Dataset$isMedium <- with(Dataset, ifelse(History=="Medium", 1, 0))
> Dataset$isLow <- with(Dataset, ifelse(History=="Low", 1, 0))
> Dataset$isMale <- with(Dataset, ifelse(Gender=="Male", 1, 0))
> Dataset$isFemale <- with(Dataset, ifelse(Gender=="Female", 1, 0))
> RegModel.2 <-
+ lm(AmountSpent~Catalogs+Children+isClose+isFemale+isHigh+isLow+isMarried+isOwn+Salary,
+   
+ data=Dataset)
> summary(RegModel.2)

Call:
lm(formula = AmountSpent ~ Catalogs + Children + isClose + isFemale + 
    isHigh + isLow + isMarried + isOwn + Salary, data = Dataset)

Residuals:
     Min       1Q   Median       3Q      Max 
-1573.90  -285.08   -22.51   217.67  2808.80 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept)  2.818e+01  7.910e+01   0.356   0.7217    
Catalogs     4.032e+01  2.865e+00  14.074  < 2e-16 ***
Children    -2.758e+02  2.279e+01 -12.098  < 2e-16 ***
isClose     -6.135e+02  4.386e+01 -13.987  < 2e-16 ***
isFemale     5.322e+01  3.732e+01   1.426   0.1544    
isHigh       3.460e+02  5.989e+01   5.778 1.15e-08 ***
isLow        1.014e+02  5.669e+01   1.789   0.0741 .  
isMarried    2.162e+00  4.713e+01   0.046   0.9634    
isOwn        9.905e+00  3.970e+01   0.249   0.8031    
Salary       1.819e-02  1.175e-03  15.489  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 463.6 on 687 degrees of freedom
  (303 observations deleted due to missingness)
Multiple R-squared:  0.788, Adjusted R-squared:  0.7852 
F-statistic: 283.7 on 9 and 687 DF,  p-value: < 2.2e-16

When looking at the summary of my linear regression model, the adjusted R-squared value is 0.785 which means there is a strong correlation between the variables I made. isClose and isHigh are two of the created variables that are significant at the 0.001 level.

> confint(RegModel.2)
                    2.5 %        97.5 %
(Intercept) -127.12521232  183.49086621
Catalogs      34.69914725   45.94993230
Children    -320.50314986 -230.99709491
isClose     -699.63959359 -527.39679481
isFemale     -20.06243251  126.50306496
isHigh       228.43758981  463.61855322
isLow         -9.90229766  212.70533984
isMarried    -90.38145469   94.70493996
isOwn        -68.04717645   87.85781842
Salary         0.01588792    0.02050067

When looking at the confidence intervals, there is a possibility of 0 being between the variables on each side of the distribution. For this reason, we fail to reject the null hypothesis.

> RegModel.3 <- 
+   lm(AmountSpent~Catalogs+Children+isFar+isMale+isMedium+isRent+isSingle+Salary,
+    data=Dataset)
> summary(RegModel.3)

Call:
lm(formula = AmountSpent ~ Catalogs + Children + isFar + isMale + 
    isMedium + isRent + isSingle + Salary, data = Dataset)

Residuals:
    Min      1Q  Median      3Q     Max 
-1716.7  -293.6   -20.7   219.1  2708.0 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -4.203e+02  8.474e+01  -4.959 8.92e-07 ***
Catalogs     4.187e+01  2.825e+00  14.821  < 2e-16 ***
Children    -3.176e+02  1.733e+01 -18.322  < 2e-16 ***
isFar        6.676e+02  3.960e+01  16.857  < 2e-16 ***
isMale      -4.757e+01  3.746e+01  -1.270    0.205    
isMedium    -2.177e+02  3.885e+01  -5.604 3.03e-08 ***
isRent      -1.792e+01  3.980e+01  -0.450    0.653    
isSingle    -8.260e+00  4.732e+01  -0.175    0.861    
Salary       2.041e-02  8.737e-04  23.359  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 465.9 on 688 degrees of freedom
  (303 observations deleted due to missingness)
Multiple R-squared:  0.7856,    Adjusted R-squared:  0.7831 
F-statistic: 315.1 on 8 and 688 DF,  p-value: < 2.2e-16

When creating another linear regression model using the variables that were not used in the first regression model, isMedium and isFar are significant at the 0.001 level. This means that Location factor variable and History factor variable are good estimators of Amount Spent. Even in the last regression model, their counterparts isHigh and isClose were both significant.

> confint(RegModel.3)
                    2.5 %        97.5 %
(Intercept) -586.63721685 -253.87164463
Catalogs      36.32747340   47.42193770
Children    -351.58551898 -283.52475709
isFar        589.80119513  745.31291430
isMale      -121.10582331   25.97413722
isMedium    -293.99004593 -141.43269985
isRent       -96.05303636   60.22209089
isSingle    -101.16478327   84.64479777
Salary         0.01869461    0.02212564

Again, when looking at the confidence intervals, there is a possibility of 0 being between the variables on each side of the distribution. For this reason, we fail to reject the null hypothesis.