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!)install.packages(“fBasics”)
library(fBasics)
## Warning: package 'fBasics' was built under R version 3.3.3
## Loading required package: timeDate
## Warning: package 'timeDate' was built under R version 3.3.3
## Loading required package: timeSeries
## Warning: package 'timeSeries' was built under R version 3.3.3
##
## Rmetrics Package fBasics
## Analysing Markets and calculating Basic Statistics
## Copyright (C) 2005-2014 Rmetrics Association Zurich
## Educational Software for Financial Engineering and Computational Science
## Rmetrics is free software and comes with ABSOLUTELY NO WARRANTY.
## https://www.rmetrics.org --- Mail to: info@rmetrics.org
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 X1-Y1:",cor(data[,1],data[,5]))
## [1] "Correlation X1-Y1:0.81642051634484"
paste0("Correlation X2-Y2:",cor(data[,2],data[,6]))
## [1] "Correlation X2-Y2:0.816236506000243"
paste0("Correlation X3-Y3:",cor(data[,3],data[,7]))
## [1] "Correlation X3-Y3:0.816286739489598"
paste0("Correlation X4-Y4:",cor(data[,4],data[,8]))
## [1] "Correlation X4-Y4:0.816521436888503"
plot(data[,1],data[,5], xlab="X1",ylab="Y1",main="Scatterplot 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 X1-Y1",xlab="X1",ylab="Y1",pch=19)
plot(data[,2],data[,6], main="Scatterplot X2-Y2",xlab="X2",ylab="Y2",pch=19)
plot(data[,3],data[,7], main="Scatterplot X3-Y3",xlab="X3",ylab="Y3",pch=19)
plot(data[,4],data[,8], main="Scatterplot 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 X1-Y1",xlab="X1",ylab="Y1",pch=19,abline(model1))
plot(data[,2],data[,6], main="Scatterplot X2-Y2",xlab="X2",ylab="Y2",pch=19,abline(model2))
plot(data[,3],data[,7], main="Scatterplot X3-Y3",xlab="X3",ylab="Y3",pch=19,abline(model3))
plot(data[,4],data[,8], main="Scatterplot 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