문제

Why aren't the correlation coefficients as given by the command

cor(t,g)

and as given by the command

summary(tgmodel, correlation=TRUE)

the same after running:

t<-c(0,1.2,2.3,3,4,5.2,6.3,7,8)
g<-c(12,10,8,11,6,7,2,3,3)
tgmodel<-lm(g~t)
도움이 되었습니까?

해결책

They differ because they're correlations between different things:

  1. cor() shows the correlation between the input variables, t and g.
  2. summary(lm(...), correlation=TRUE) shows the correlation between the estimated parameters, i.e. the slope and the intercept.

If you carefully examine the output of summary(), you'd notice that it shows the square of the correlation coefficient between t and g as Multiple R-squared:

> summary(lm(g~t))

...
Multiple R-squared: 0.8357, Adjusted R-squared: 0.8122 
...

> cor(t,g)**2
[1] 0.8356938
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top