The objectives of this problem set is to orient you to a number of activities in R. And to conduct a thoughtful exercise in appreciating the importance of data visualization. For each question create a code chunk or text response that completes/answers the activity or question requested. Finally, upon completion name your final output .html file as: YourName_ANLY512-Section-Year-Semester.html and upload it to the “Problem Set 2” assignment to your R Pubs account and submit the link to Moodle. Points will be deducted for uploading the improper format.
anscombe data that is part of the library(datasets) in R. And assign that data to a new object called data.data<-anscombe
fBasics() package!)library(fBasics)
## Loading required package: timeDate
## Loading required package: timeSeries
colAvgs(data)
## x1 x2 x3 x4 y1 y2 y3 y4
## 9.000000 9.000000 9.000000 9.000000 7.500909 7.500909 7.500000 7.500909
colVars(data)
## x1 x2 x3 x4 y1 y2 y3
## 11.000000 11.000000 11.000000 11.000000 4.127269 4.127629 4.122620
## y4
## 4.123249
paste0("Correlation of X1-Y1 is ",cor(data[,1],data[,5]))
## [1] "Correlation of X1-Y1 is 0.81642051634484"
paste0("Correlation of X2-Y2 is ",cor(data[,2],data[,6]))
## [1] "Correlation of X2-Y2 is 0.816236506000243"
paste0("Correlation of X3-Y3 is ",cor(data[,3],data[,7]))
## [1] "Correlation of X3-Y3 is 0.816286739489598"
paste0("Correlation of X4-Y4 is ",cor(data[,4],data[,8]))
## [1] "Correlation of X4-Y4 is 0.816521436888503"
plot(data[,1],data[,5], xlab="X1",ylab="Y1",main="Scatterplot between x1-y1")
plot(data[,2],data[,6], xlab="X2",ylab="Y2",main="Scatterplot between x2-y2")
plot(data[,3],data[,7], xlab="X3",ylab="Y3",main="Scatterplot between x3-y3")
plot(data[,4],data[,8], xlab="X4",ylab="Y4",main="Scatterplot between x4-y4")
par(mfrow=c(2,2))
plot(data[,1],data[,5], main="Scatterplot between x1-y1",xlab="X1",ylab="Y1",pch=19)
plot(data[,2],data[,6], main="Scatterplot between x2-y2",xlab="X2",ylab="Y2",pch=19)
plot(data[,3],data[,7], main="Scatterplot between x3-y3",xlab="X3",ylab="Y3",pch=19)
plot(data[,4],data[,8], main="Scatterplot between x4-y4",xlab="X4",ylab="Y4",pch=19)
lm() function.model1<-lm(data[,1]~data[,5])
model2<-lm(data[,2]~data[,6])
model3<-lm(data[,3]~data[,7])
model4<-lm(data[,4]~data[,8])
par(mfrow=c(2,2))
plot(data[,1],data[,5], main="Scatterplot between x1-y1",xlab="X1",ylab="Y1",pch=19,abline(model1))
plot(data[,2],data[,6], main="Scatterplot between x2-y2",xlab="X2",ylab="Y2",pch=19,abline(model2))
plot(data[,3],data[,7], main="Scatterplot between x3-y3",xlab="X3",ylab="Y3",pch=19,abline(model3))
plot(data[,4],data[,8], main="Scatterplot between x4-y4",xlab="X4",ylab="Y4",pch=19,abline(model4))
summary(model1)
Call: lm(formula = data[, 1] ~ data[, 5])
Residuals: Min 1Q Median 3Q Max -2.6522 -1.5117 -0.2657 1.2341 3.8946
Coefficients: Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.9975 2.4344 -0.410 0.69156
data[, 5] 1.3328 0.3142 4.241 0.00217 ** — Signif. codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ‘’ 1
Residual standard error: 2.019 on 9 degrees of freedom Multiple R-squared: 0.6665, Adjusted R-squared: 0.6295 F-statistic: 17.99 on 1 and 9 DF, p-value: 0.00217
summary(model2)
Call: lm(formula = data[, 2] ~ data[, 6])
Residuals: Min 1Q Median 3Q Max -1.8516 -1.4315 -0.3440 0.8467 4.2017
Coefficients: Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.9948 2.4354 -0.408 0.69246
data[, 6] 1.3325 0.3144 4.239 0.00218 ** — Signif. codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ‘’ 1
Residual standard error: 2.02 on 9 degrees of freedom Multiple R-squared: 0.6662, Adjusted R-squared: 0.6292 F-statistic: 17.97 on 1 and 9 DF, p-value: 0.002179
summary(model3)
Call: lm(formula = data[, 3] ~ data[, 7])
Residuals: Min 1Q Median 3Q Max -2.9869 -1.3733 -0.0266 1.3200 3.2133
Coefficients: Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.0003 2.4362 -0.411 0.69097
data[, 7] 1.3334 0.3145 4.239 0.00218 ** — Signif. codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ‘’ 1
Residual standard error: 2.019 on 9 degrees of freedom Multiple R-squared: 0.6663, Adjusted R-squared: 0.6292 F-statistic: 17.97 on 1 and 9 DF, p-value: 0.002176
summary(model4)
Call: lm(formula = data[, 4] ~ data[, 8])
Residuals: Min 1Q Median 3Q Max -2.7859 -1.4122 -0.1853 1.4551 3.3329
Coefficients: Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.0036 2.4349 -0.412 0.68985
data[, 8] 1.3337 0.3143 4.243 0.00216 ** — Signif. codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ‘’ 1
Residual standard error: 2.018 on 9 degrees of freedom Multiple R-squared: 0.6667, Adjusted R-squared: 0.6297 F-statistic: 18 on 1 and 9 DF, p-value: 0.002165
From the summary of Models, their Coefficients, R Squared, REsidual Standard errors, and p-values are very close (almost the same). However, when we look at the plots, we can see that they totally different models. Data visualization can show some summarized information that is easily ignored by the summary. Also, we also need summary which can show us detailed metrics.