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)
data <- anscombe
data
fBasics() package!)library(fBasics)
## Warning: package 'fBasics' was built under R version 3.6.3
## Loading required package: timeDate
## Loading required package: timeSeries
## Warning: package 'timeSeries' was built under R version 3.6.3
x1<-data[,1];x2<-data[,2];x3<-data[,3];x4<-data[,4]
y1<-data[,5];y2<-data[,6];y3<-data[,7];y4<-data[,8]
mean(x1);var(x1)
## [1] 9
## [1] 11
mean(x2);var(x2)
## [1] 9
## [1] 11
mean(x3);var(x3)
## [1] 9
## [1] 11
mean(x4);var(x4)
## [1] 9
## [1] 11
mean(y1);var(y1)
## [1] 7.500909
## [1] 4.127269
mean(y2);var(y2)
## [1] 7.500909
## [1] 4.127629
mean(y3);var(y3)
## [1] 7.5
## [1] 4.12262
mean(y4);var(y4)
## [1] 7.500909
## [1] 4.123249
correlationTest(x1,y1);correlationTest(x2,y2);correlationTest(x3,y3);correlationTest(x4,y4)
##
## Title:
## Pearson's Correlation Test
##
## Test Results:
## PARAMETER:
## Degrees of Freedom: 9
## SAMPLE ESTIMATES:
## Correlation: 0.8164
## STATISTIC:
## t: 4.2415
## P VALUE:
## Alternative Two-Sided: 0.00217
## Alternative Less: 0.9989
## Alternative Greater: 0.001085
## CONFIDENCE INTERVAL:
## Two-Sided: 0.4244, 0.9507
## Less: -1, 0.9388
## Greater: 0.5113, 1
##
## Description:
## Wed May 20 14:15:26 2020
##
## Title:
## Pearson's Correlation Test
##
## Test Results:
## PARAMETER:
## Degrees of Freedom: 9
## SAMPLE ESTIMATES:
## Correlation: 0.8162
## STATISTIC:
## t: 4.2386
## P VALUE:
## Alternative Two-Sided: 0.002179
## Alternative Less: 0.9989
## Alternative Greater: 0.001089
## CONFIDENCE INTERVAL:
## Two-Sided: 0.4239, 0.9506
## Less: -1, 0.9387
## Greater: 0.5109, 1
##
## Description:
## Wed May 20 14:15:26 2020
##
## Title:
## Pearson's Correlation Test
##
## Test Results:
## PARAMETER:
## Degrees of Freedom: 9
## SAMPLE ESTIMATES:
## Correlation: 0.8163
## STATISTIC:
## t: 4.2394
## P VALUE:
## Alternative Two-Sided: 0.002176
## Alternative Less: 0.9989
## Alternative Greater: 0.001088
## CONFIDENCE INTERVAL:
## Two-Sided: 0.4241, 0.9507
## Less: -1, 0.9387
## Greater: 0.511, 1
##
## Description:
## Wed May 20 14:15:26 2020
##
## Title:
## Pearson's Correlation Test
##
## Test Results:
## PARAMETER:
## Degrees of Freedom: 9
## SAMPLE ESTIMATES:
## Correlation: 0.8165
## STATISTIC:
## t: 4.243
## P VALUE:
## Alternative Two-Sided: 0.002165
## Alternative Less: 0.9989
## Alternative Greater: 0.001082
## CONFIDENCE INTERVAL:
## Two-Sided: 0.4246, 0.9507
## Less: -1, 0.9388
## Greater: 0.5115, 1
##
## Description:
## Wed May 20 14:15:26 2020
pairs(data)
plot(x1,y1, main="Scatter plot x1,y1")
plot(x2,y2, main="Scatter plot x2,y2")
plot(x3,y3, main="Scatter plot x3,y3")
plot(x4,y4, main="Scatter plot x4,y4")
par(mfrow=c(2,2))
plot(x1,y1, main="Scatter plot for x1,y1",pch=19)
plot(x2,y2, main="Scatter plot for x2,y2",pch=19)
plot(x3,y3, main="Scatter plot for x3,y3",pch=19)
plot(x4,y4, main="Scatter plot for x4,y4",pch=19)
lm() function.model1<-lm(y1~x1)
model2<-lm(y2~x2)
model3<-lm(y3~x3)
model4<-lm(y4~x4)
par(mfrow=c(2,2))
plot(x1,y1, main="Scatter plot for x1,y1",pch=19)
abline(model1, col="blue")
plot(x2,y2, main="Scatter plot for x2,y2",pch=19)
abline(model2, col="red")
plot(x3,y3, main="Scatter plot for x3,y3",pch=19)
abline(model3, col="green")
plot(x4,y4, main="Scatter plot for x4,y4",pch=19)
abline(model4)
anova(model1);anova(model2);anova(model3);anova(model4)
## It tells us that both statistical calculation and graph shoud be considered when we are trying to do analysis, and they all have their pro and con. Some assumption of statistical calculation could be right and that's why we need data visualization to help us to have a better understanding.