author: Adhislacy

This is an R Markdown Notebook.

ASSIGNMENT THREE.

Valuations <- read.table("https://netfiles.umn.edu/users/nacht001/www/nachtsheim/Kutner/Chapter%20%208%20Data%20Sets/CH08PR24.txt")
colnames(Valuations)=c("SellingP", "AssessedV", "PlotL")
View(Valuations)
str(Valuations)
## 'data.frame':    64 obs. of  3 variables:
##  $ SellingP : num  78.8 73.8 64.6 76.2 87.2 70.6 86 83.1 94.5 71.2 ...
##  $ AssessedV: num  76.4 74.3 69.6 73.6 76.8 72.7 79.2 75.6 78.1 76.9 ...
##  $ PlotL    : int  0 0 0 0 0 1 0 0 0 1 ...
library(dummies)
## dummies-1.5.6 provided by Decision Patterns
?dummies
## starting httpd help server ...
##  done
library(mlr)
## Warning: package 'mlr' was built under R version 3.3.3
## Loading required package: ParamHelpers
## Warning: package 'ParamHelpers' was built under R version 3.3.3
cols <- c("PlotL")
Valuations[,cols] <- data.frame(apply(Valuations[cols], 2, as.factor))
levels(Valuations$PlotL) <- c("Non-Comer lots","Comer lots")
Valuations
##    SellingP AssessedV          PlotL
## 1      78.8      76.4 Non-Comer lots
## 2      73.8      74.3 Non-Comer lots
## 3      64.6      69.6 Non-Comer lots
## 4      76.2      73.6 Non-Comer lots
## 5      87.2      76.8 Non-Comer lots
## 6      70.6      72.7     Comer lots
## 7      86.0      79.2 Non-Comer lots
## 8      83.1      75.6 Non-Comer lots
## 9      94.5      78.1 Non-Comer lots
## 10     71.2      76.9     Comer lots
## 11     64.3      68.5 Non-Comer lots
## 12     73.1      73.2 Non-Comer lots
## 13     96.8      77.5 Non-Comer lots
## 14     82.4      76.2 Non-Comer lots
## 15     81.6      75.1 Non-Comer lots
## 16     76.8      77.0     Comer lots
## 17     77.2      73.0 Non-Comer lots
## 18     73.7      73.0     Comer lots
## 19     88.6      77.2 Non-Comer lots
## 20     74.7      73.4 Non-Comer lots
## 21     91.2      78.8 Non-Comer lots
## 22     86.6      77.3 Non-Comer lots
## 23     82.7      76.5 Non-Comer lots
## 24     87.8      76.8 Non-Comer lots
## 25     85.0      79.4     Comer lots
## 26     69.1      71.5 Non-Comer lots
## 27     69.6      70.0     Comer lots
## 28     71.2      71.9 Non-Comer lots
## 29     62.9      74.7     Comer lots
## 30     84.1      76.1 Non-Comer lots
## 31     67.0      72.6     Comer lots
## 32     83.2      77.6     Comer lots
## 33     63.9      70.7     Comer lots
## 34     85.3      76.3 Non-Comer lots
## 35     92.4      77.2 Non-Comer lots
## 36     90.3      77.9 Non-Comer lots
## 37     74.7      72.9 Non-Comer lots
## 38     73.3      73.6     Comer lots
## 39     83.1      75.0 Non-Comer lots
## 40     69.1      72.5 Non-Comer lots
## 41     75.0      74.1     Comer lots
## 42     67.4      70.3     Comer lots
## 43     68.4      70.6 Non-Comer lots
## 44     79.3      76.9     Comer lots
## 45     86.4      75.8 Non-Comer lots
## 46     75.8      71.9 Non-Comer lots
## 47     88.8      78.8 Non-Comer lots
## 48     72.7      73.5     Comer lots
## 49     88.9      78.4 Non-Comer lots
## 50     82.7      75.8 Non-Comer lots
## 51     86.6      74.6 Non-Comer lots
## 52     82.8      76.5 Non-Comer lots
## 53     87.9      77.3 Non-Comer lots
## 54     75.5      74.4 Non-Comer lots
## 55     81.0      71.3 Non-Comer lots
## 56     88.2      74.5 Non-Comer lots
## 57     63.9      69.5 Non-Comer lots
## 58     78.2      75.9 Non-Comer lots
## 59     63.3      68.2 Non-Comer lots
## 60     90.2      78.5 Non-Comer lots
## 61     74.3      73.2 Non-Comer lots
## 62     97.6      79.4 Non-Comer lots
## 63     84.4      74.7 Non-Comer lots
## 64     70.5      71.5     Comer lots
summary(Valuations)
##     SellingP       AssessedV                PlotL   
##  Min.   :62.90   Min.   :68.20   Non-Comer lots:48  
##  1st Qu.:72.33   1st Qu.:72.85   Comer lots    :16  
##  Median :79.05   Median :74.85                      
##  Mean   :79.02   Mean   :74.72                      
##  3rd Qu.:86.45   3rd Qu.:76.92                      
##  Max.   :97.60   Max.   :79.40
contrasts(Valuations$PlotL) 
##                Comer lots
## Non-Comer lots          0
## Comer lots              1
boxplot(Valuations$SellingP ~ Valuations$PlotL, main="Box Plot of Selling Price for each Plot Location", xlab="Plot Location", ylab="Selling Price")

valuations_lm2 = lm(SellingP ~ log(AssessedV)+factor(PlotL) + log(AssessedV)*factor(PlotL), data = Valuations)
summary(valuations_lm2)
## 
## Call:
## lm(formula = SellingP ~ log(AssessedV) + factor(PlotL) + log(AssessedV) * 
##     factor(PlotL), data = Valuations)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -10.925  -2.301  -0.043   1.940   9.954 
## 
## Coefficients:
##                                        Estimate Std. Error t value
## (Intercept)                             -805.42      62.90 -12.805
## log(AssessedV)                           205.41      14.57  14.096
## factor(PlotL)Comer lots                  347.04     130.12   2.667
## log(AssessedV):factor(PlotL)Comer lots   -82.03      30.21  -2.715
##                                        Pr(>|t|)    
## (Intercept)                             < 2e-16 ***
## log(AssessedV)                          < 2e-16 ***
## factor(PlotL)Comer lots                 0.00982 ** 
## log(AssessedV):factor(PlotL)Comer lots  0.00864 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.904 on 60 degrees of freedom
## Multiple R-squared:  0.8223, Adjusted R-squared:  0.8134 
## F-statistic: 92.54 on 3 and 60 DF,  p-value: < 2.2e-16

Analysis without interaction.

valuations_lm3 = lm(SellingP~log(AssessedV)+factor(PlotL), data = Valuations)
summary(valuations_lm3)
## 
## Call:
## lm(formula = SellingP ~ log(AssessedV) + factor(PlotL), data = Valuations)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.5339  -2.3599  -0.1399   1.8572   9.2790 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             -723.052     57.904  -12.49  < 2e-16 ***
## log(AssessedV)           186.327     13.415   13.89  < 2e-16 ***
## factor(PlotL)Comer lots   -6.231      1.196   -5.21 2.36e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.103 on 61 degrees of freedom
## Multiple R-squared:  0.8005, Adjusted R-squared:  0.7939 
## F-statistic: 122.3 on 2 and 61 DF,  p-value: < 2.2e-16

Testing if there is need for interaction.

anova(valuations_lm2, valuations_lm3)
## Analysis of Variance Table
## 
## Model 1: SellingP ~ log(AssessedV) + factor(PlotL) + log(AssessedV) * 
##     factor(PlotL)
## Model 2: SellingP ~ log(AssessedV) + factor(PlotL)
##   Res.Df     RSS Df Sum of Sq      F  Pr(>F)   
## 1     60  914.53                               
## 2     61 1026.89 -1   -112.36 7.3718 0.00864 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
par(mfrow=c(2,2))
plot(valuations_lm3, which=1:4)

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.3.3
ggplot(data = Valuations, aes(x = log(AssessedV), y = SellingP, colour = factor(PlotL))) + stat_smooth(method=lm, fullrange=FALSE) + geom_point()

Predicting the selling value of a corner house with an assessed value of $100,000 using a 95% confidence interval.

predict(lm(SellingP ~ AssessedV, data = Valuations), newdata = list(AssessedV = 100000), interval = "confidence", level = .95)
##        fit      lwr      upr
## 1 264619.3 222044.9 307193.8

Predicting the selling value of a corner house with an assessed value of $100,000 using a 95% confidence interval.

predict(lm(SellingP ~ AssessedV, data = Valuations), newdata = list(AssessedV = 100000), interval = "predict", level = .95)
##        fit      lwr      upr
## 1 264619.3 222044.9 307193.8

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).