# Data input
> Shigeru<-c(2,3,6,10,15,18,26)
> Hanano<-c(3,7,9,15,25,28,30)
# Data plot
> plot(Shigeru,Hanano)
# Pearson's correlation
> cor(Shigeru, Hanano, method="pearson")
[1] 0.9626748
# Pearson's product-moment correlation test
> cor.test(Shigeru, Hanano, alternative="two.sided",method="pearson")
Pearson's product-moment correlation
data: Shigeru and Hanano
t = 7.9532, df = 5, p-value = 0.0005067
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.7621040 0.9946566
sample estimates:
cor
0.9626748
# Decide parameters, "a" and "b" of Hanano =a * Shigeru +b
> lm(Hanano~Shigeru)
Call:
lm(formula = Hanano ~ Shigeru)
Coefficients:
(Intercept) Shigeru
2.970 1.203
Thus, Hanano = 0.08778 * Shigeru + 29.67667.
# add the formula "Hanano = 0.08778 * Shigeru + 29.67667" on Shigeru-Hanano plot.
> plot(Shigeru,Hanano)
> abline(lm(Hanano~Shigeru), lty=1)
# Summary
> result<-lm(Hanano~Shigeru)
> summary(result)
Call:
lm(formula = Hanano ~ Shigeru)
Residuals:
1 2 3 4 5 6 7
-2.375388 0.422001 -1.185830 0.003729 3.990677 3.382846 -4.238036
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.9702 2.1185 1.402 0.219839
Shigeru 1.2026 0.1512 7.953 0.000507 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.242 on 5 degrees of freedom
Multiple R-squared: 0.9267, Adjusted R-squared: 0.9121
F-statistic: 63.25 on 1 and 5 DF, p-value: 0.0005067
# Residuals
> residuals(result)
1 2 3 4 5 6 7
-2.375388440 0.422001243 -1.185829708 0.003729024 3.990677439 3.382846489 -4.238036047
# Histogram of residuals
> hist(residuals(result))
# plot of residuals
> plot(x, residuals(result))
# theoretical values of the "Hanano"
> predict(result)
1 2 3 4 5 6 7
5.375388 6.577999 10.185830 14.996271 21.009323 24.617154 34.238036
# make theoretical data with theoretical lines
> theoretical<-c(5.375388, 6.577999,10.185830, 14.996271, 21.009323, 24.617154, 34.238036)
> plot(Shigeru, theoretical)
> abline(lm(Hanano~Shigeru), lty=1)