2022-02-16
## Loading required package: splines
## Loading required package: RcmdrMisc
## Loading required package: car
## Loading required package: carData
## Loading required package: sandwich
## Loading required package: effects
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.
## The Commander GUI is launched only in interactive sessions
##
## Attaching package: 'Rcmdr'
## The following object is masked from 'package:base':
##
## errorCondition
> HousePrices <- read.table("C:/gokul/3230/Datasets/HousePrices.csv",
+ header=TRUE, stringsAsFactors=TRUE, sep=",", na.strings="NA", dec=".",
+ strip.white=TRUE)
> normalityTest(~Price, test="shapiro.test", data=HousePrices)
Shapiro-Wilk normality test
data: Price
W = 0.98023, p-value = 0.05836
> summary(HousePrices)
Price SqFt Bedrooms Bathrooms
Min. : 69100 Min. :1450 Min. :2.000 Min. :2.000
1st Qu.:111325 1st Qu.:1880 1st Qu.:3.000 1st Qu.:2.000
Median :125950 Median :2000 Median :3.000 Median :2.000
Mean :130427 Mean :2001 Mean :3.023 Mean :2.445
3rd Qu.:148250 3rd Qu.:2140 3rd Qu.:3.000 3rd Qu.:3.000
Max. :211200 Max. :2590 Max. :5.000 Max. :4.000
Offers Brick Neighborhood
Min. :1.000 No :86 East :45
1st Qu.:2.000 Yes:42 North:44
Median :3.000 West :39
Mean :2.578
3rd Qu.:3.000
Max. :6.000
> library(e1071, pos=25)
> numSummary(HousePrices[,"Price", drop=FALSE], groups=HousePrices$Brick,
+ statistics=c("mean", "sd", "IQR", "quantiles"), quantiles=c(0,.25,.5,.75,1))
mean sd IQR 0% 25% 50% 75% 100% Price:n
No 121958.1 22589.26 31150 69100 106675 117650 137825 180900 86
Yes 147769.0 26829.38 40800 106100 125850 147500 166650 211200 42
> local({
+ .Table <- with(HousePrices, table(Brick))
+ cat("\ncounts:\n")
+ print(.Table)
+ cat("\npercentages:\n")
+ print(round(100*.Table/sum(.Table), 2))
+ })
counts:
Brick
No Yes
86 42
percentages:
Brick
No Yes
67.19 32.81
> local({
+ .Table <- with(HousePrices, table(Neighborhood))
+ cat("\ncounts:\n")
+ print(.Table)
+ cat("\npercentages:\n")
+ print(round(100*.Table/sum(.Table), 2))
+ })
counts:
Neighborhood
East North West
45 44 39
percentages:
Neighborhood
East North West
35.16 34.38 30.47
> local({
+ .Table <- with(HousePrices, table(Brick))
+ cat("\ncounts:\n")
+ print(.Table)
+ cat("\npercentages:\n")
+ print(round(100*.Table/sum(.Table), 2))
+ })
counts:
Brick
No Yes
86 42
percentages:
Brick
No Yes
67.19 32.81
> local({
+ .Table <- with(HousePrices, table(Neighborhood))
+ cat("\ncounts:\n")
+ print(.Table)
+ cat("\npercentages:\n")
+ print(round(100*.Table/sum(.Table), 2))
+ })
counts:
Neighborhood
East North West
45 44 39
percentages:
Neighborhood
East North West
35.16 34.38 30.47
> sapply(HousePrices, function(x)(sum(is.na(x)))) # NA counts
Price SqFt Bedrooms Bathrooms Offers Brick
0 0 0 0 0 0
Neighborhood
0
> cor(HousePrices[,c("Bathrooms","Bedrooms","Offers","Price","SqFt")],
+ use="complete")
Bathrooms Bedrooms Offers Price SqFt
Bathrooms 1.0000000 0.4145560 0.1437934 0.5232578 0.5227453
Bedrooms 0.4145560 1.0000000 0.1142706 0.5259261 0.4838071
Offers 0.1437934 0.1142706 1.0000000 -0.3136359 0.3369234
Price 0.5232578 0.5259261 -0.3136359 1.0000000 0.5529822
SqFt 0.5227453 0.4838071 0.3369234 0.5529822 1.0000000
> rcorr.adjust(HousePrices[,c("Bathrooms","Bedrooms","Offers","Price",
+ "SqFt")], type="pearson", use="complete")
Pearson correlations:
Bathrooms Bedrooms Offers Price SqFt
Bathrooms 1.0000 0.4146 0.1438 0.5233 0.5227
Bedrooms 0.4146 1.0000 0.1143 0.5259 0.4838
Offers 0.1438 0.1143 1.0000 -0.3136 0.3369
Price 0.5233 0.5259 -0.3136 1.0000 0.5530
SqFt 0.5227 0.4838 0.3369 0.5530 1.0000
Number of observations: 128
Pairwise two-sided p-values:
Bathrooms Bedrooms Offers Price SqFt
Bathrooms <.0001 0.1054 <.0001 <.0001
Bedrooms <.0001 0.1990 <.0001 <.0001
Offers 0.1054 0.1990 0.0003 0.0001
Price <.0001 <.0001 0.0003 <.0001
SqFt <.0001 <.0001 0.0001 <.0001
Adjusted p-values (Holm's method)
Bathrooms Bedrooms Offers Price SqFt
Bathrooms <.0001 0.2108 <.0001 <.0001
Bedrooms <.0001 0.2108 <.0001 <.0001
Offers 0.2108 0.2108 0.0009 0.0004
Price <.0001 <.0001 0.0009 <.0001
SqFt <.0001 <.0001 0.0004 <.0001
> indexplot(HousePrices[,'Price', drop=FALSE], type='h', id.method='y',
+ id.n=2)

[1] 104 117
> with(HousePrices, Dotplot(Price, bin=FALSE))

> with(HousePrices, Dotplot(Price, by=Brick, bin=FALSE))

> with(HousePrices, Hist(Price, scale="frequency", breaks="Sturges",
+ col="darkgray"))
