Summary Statistics and Summary Statistics by Year:
sum1 <- j %>% summarize(n=length(v1), mean.v1 = mean(v1), mean.v2 = mean(v2),
sd.v1=sd(v1), sd.v2=sd(v2)
)
kable(sum1, digits=1)
| n | mean.v1 | mean.v2 | sd.v1 | sd.v2 |
|---|---|---|---|---|
| 43 | 6.2 | 8 | 1.9 | 2.3 |
sum2 <- j %>% group_by(year) %>% summarize(n=length(v1), mean.v1 = mean(v1), mean.v2 = mean(v2),
sd.v1=sd(v1), sd.v2=sd(v2)
)
kable(sum2, digits=1)
| year | n | mean.v1 | mean.v2 | sd.v1 | sd.v2 |
|---|---|---|---|---|---|
| 2011 | 10 | 5.7 | 7.0 | 1.8 | 2.6 |
| 2012 | 17 | 6.7 | 8.2 | 2.0 | 2.3 |
| 2013 | 3 | 7.3 | 7.3 | 1.2 | 0.6 |
| 2016 | 13 | 5.7 | 8.7 | 2.1 | 2.3 |
A Scatter Plot with points colored by year:
ggplot(j, aes(x=v1, y=v2, color=as.factor(year)))+geom_jitter()
A Scatter Plot with a best fit line:
Correlation and Slope of the Best Fit Line:
r <- with(j, cor(v1, v2))
slope <- r *with(j, sd(v2)/sd(v1))
r; slope
## [1] 0.1891664
## [1] 0.2249342
lm(v2 ~ v1, data=j)
##
## Call:
## lm(formula = v2 ~ v1, data = j)
##
## Coefficients:
## (Intercept) v1
## 6.6266 0.2249