The estimate in the lm-function in R does not correspond to the correlation (data from NA)

I install the lm model

x <- c(0.1, 0.3, 0.2, 0.5, NA, 0.1, 0.8, 0.4)
y <- c(0.3, 0.2, 0.5, NA, 0.4, 0.5, 0.2, 0.4)
fit1<-lm(scale(y) ~ scale(x), na.action=na.omit)
summary(fit1)

This gives me a standard score of -0.593. When I use the cor function, it gives me a value of -0.577. If I multiplies the full cases of two vectors i.e.

x2 <- c(0.1, 0.3, 0.2, 0.1, 0.8, 0.4)
y2 <- c(0.3, 0.2, 0.5, 0.5, 0.2, 0.4)

and then install lm

fit2<-lm(scale(y2) ~ scale(x2))
summary(fit2)

the standardized score is the same as in the case of "cor" (- 0.577). I believe that the standard estimate and the correlation coefficient should be the same in a simple regression. The question is, what is the problem with fit1? (using "na.action = na.excluse" does not help).

+4
source share
1 answer

scale na.omit lm. :

DF <- data.frame(x, y) 
na.omit(scale(DF))
scale(na.omit(DF))

:

fit1<-lm(scale(y) ~ scale(x), data=na.omit(DF))

all.equal(unname(coef(fit1)[2]),
          cor(na.omit(DF))[1,2])
#[1] TRUE
+6

Source: https://habr.com/ru/post/1524941/


All Articles