Xvec <- rnorm(200)
Yvec <- 2.6*Xvec + rnorm(200)
lmodxy <- lm(Xvec ~ Yvec)
lmodyx <- lm(Yvec ~ Xvec)
summary(lmodxy)
Output
Call:
lm(formula = Xvec ~ Yvec)
Residuals:
Min 1Q Median 3Q Max
-0.85820 -0.24244 0.01888 0.23892 0.75319
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.015986 0.023954 0.667 0.505
Yvec 0.336546 0.009412 35.758 <2e-16 ***
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.3379 on 198 degrees of freedom
Multiple R-squared: 0.8659, Adjusted R-squared: 0.8652
F-statistic: 1279 on 1 and 198 DF, p-value: < 2.2e-16
Code
lmodxy$coefficients[2]*lmodyx$coefficients[2]
# Yvec: 0.865911394725732
cor(Yvec,Xvec)^2
0.865911394725732
lmodxy2 <- lm(Xvec ~ Yvec-1)
lmodyx2 <- lm(Yvec ~ Xvec-1)
summary(lmodxy2)
Output
Call:
lm(formula = Xvec ~ Yvec - 1)
Residuals:
Min 1Q Median 3Q Max
-0.84247 -0.22664 0.03424 0.25282 0.76821
Coefficients:
Estimate Std. Error t value Pr(>|t|)
Yvec 0.336094 0.009374 35.85 <2e-16 ***
Signif. codes: 0 ‘*’ 0.001 ‘’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.3374 on 199 degrees of freedom
Multiple R-squared: 0.8659, Adjusted R-squared: 0.8653
F-statistic: 1285 on 1 and 199 DF, p-value: < 2.2e-16
Code
lmodxy2$coefficients[1]*lmodyx2$coefficients[1]
# Yvec: 0.865940634163253
Why the correlation squared is not the same as the product of slopes without intercepts whereas it is the same in the case of products with intercepts
it should be --------
Y_hat = bX + a and X_hat = BY + A then Cor(Y,X)^2 = (b*)(B*)