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.library(datasets)
data <- anscombe
fBasics() package!)colMeans(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
c(var(data$x1), var(data$y1), var(data$x2), var(data$y2), var(data$x3), var(data$y3), var(data$x4), var(data$y4))
## [1] 11.000000 4.127269 11.000000 4.127629 11.000000 4.122620 11.000000
## [8] 4.123249
plot(data$x1, data$y1, main="Scatter plot for (x1, y1)", xlab="x1", ylab="y1")
plot(data$x2, data$y2, main="Scatter plot for (x2, y2)", xlab="x2", ylab="y2")
plot(data$x3, data$y3, main="Scatter plot for (x3, y3)", xlab="x3", ylab="y3")
plot(data$x4, data$y4, main="Scatter plot for (x4, y4)", xlab="x4", ylab="y4")
op <- par(mfcol = c(2, 2))
c11 <- plot(data$x1, data$y1, main="Scatter plot for (x1, y1)", xlab="x1", ylab="y1", pch=19)
c21 <- plot(data$x2, data$y2, main="Scatter plot for (x2, y2)", xlab="x2", ylab="y2", pch=19)
c12 <- plot(data$x3, data$y3, main="Scatter plot for (x3, y3)", xlab="x3", ylab="y3", pch=19)
c22 <- plot(data$x4, data$y4, main="Scatter plot for (x4, y4)", xlab="x4", ylab="y4", pch=19)
lm() function.lm(formula = data$y1 ~ data$x1, data = data)
##
## Call:
## lm(formula = data$y1 ~ data$x1, data = data)
##
## Coefficients:
## (Intercept) data$x1
## 3.0001 0.5001
lm(formula = data$y2 ~ data$x2, data = data)
##
## Call:
## lm(formula = data$y2 ~ data$x2, data = data)
##
## Coefficients:
## (Intercept) data$x2
## 3.001 0.500
lm(formula = data$y3 ~ data$x3, data = data)
##
## Call:
## lm(formula = data$y3 ~ data$x3, data = data)
##
## Coefficients:
## (Intercept) data$x3
## 3.0025 0.4997
lm(formula = data$y4 ~ data$x4, data = data)
##
## Call:
## lm(formula = data$y4 ~ data$x4, data = data)
##
## Coefficients:
## (Intercept) data$x4
## 3.0017 0.4999
op <- par(mfcol = c(2, 2))
c11 <- plot(data$x1, data$y1, main="Scatter plot for (x1, y1)", xlab="x1", ylab="y1", pch=19)
abline(lm(data$y1 ~ data$x1))
c21 <- plot(data$x2, data$y2, main="Scatter plot for (x2, y2)", xlab="x2", ylab="y2", pch=19)
abline(lm(data$y2 ~ data$x2))
c12 <- plot(data$x3, data$y3, main="Scatter plot for (x3, y3)", xlab="x3", ylab="y3", pch=19)
abline(lm(data$y3 ~ data$x3))
c22 <- plot(data$x4, data$y4, main="Scatter plot for (x4, y4)", xlab="x4", ylab="y4", pch=19)
abline(lm(data$y4 ~ data$x4))
summary(lm(data$y1 ~ data$x1))$adj.r.squared
[1] 0.6294916
summary(lm(data$y2 ~ data$x2))$adj.r.squared
[1] 0.6291578
summary(lm(data$y3 ~ data$x3))$adj.r.squared
[1] 0.6292489
summary(lm(data$y4 ~ data$x4))$adj.r.squared
[1] 0.6296747
Data visualization shows some information which may not be available from the summary itself. To be more specific, the coefficients, R squared, residual standard errors, and p-values are roughtly the same for the data sets. However, looking at plots, we will be able to see the differences.