Anda di halaman 1dari 2

Ques1 : Compute the Pearsons correlation between the clay contents of the topsoil and subsoil.

Test whether this correlation is signicant. First we compute the correlation from the sample covariance (computed with the cov method) and standard deviations (computed with the sd method), to show how the denition works, then we use the cor.test method to compute a condence interval.

> sum((Clay2 - mean(Clay2)) * (Clay1 - mean(Clay1)))/(length(Clay2) + 1) [1] 190.74 > cov(Clay1, Clay2) [1] 190.74 > sd(Clay1)

[1] 13.936 > sd(Clay2) [1] 14.626

> cov(Clay1, Clay2)/(sd(Clay1) * sd(Clay2)) [1] 0.9358 > cor(Clay1, Clay2) [1] 0.9358

For further details visit us at www.statisticsassignmentexperts.com Email us at - info@statisticsassignmentexperts.com or call us at - +1 520 8371215

> cor.test(Clay1, Clay2) Pearson's product-moment correlation data: Clay1 and Clay2 t = 31.964, df = 145, p-value < 2.2e-16 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.91208 0.95327 sample estimates: cor 0.9358

Ques2 : Compute the sample variance for both variables, and their sample covariance. These will be used to compute the regressions.
> s2x <- var(Clay1) > s2x [1] 194.21 > s2y <- var(Clay2) > s2y [1] 213.92 > sxy <- var(Clay1, Clay2) > sxy [1] 190.74

Note that the variances are of similar magnitude. We can compute the variances and co-variances directly from their denitions, just to check that R is doing the right thing. This is a nice illustration of Rs implicit vector arithmetic:
> sum((Clay1 - mean(Clay1))^2)/(length(Clay1) - 1) [1] 194.21 > sum((Clay2 - mean(Clay2))^2)/(length(Clay2) - 1) [1] 213.92 > sum((Clay2 - mean(Clay2)) * (Clay1 - mean(Clay1)))/(length(Clay1) + 1) [1] 190.74

For further details visit us at www.statisticsassignmentexperts.com Email us at - info@statisticsassignmentexperts.com or call us at - +1 520 8371215

Anda mungkin juga menyukai