#Bespiel zur verdeckten / Scheinkorrelation zeit <- 1:10 x <- c(38,37,37,37,35,34,34,34,33,31) y <- c(49,48,47,46,46,46,44,44,43,40) #a) (xbar <- mean(x)) (ybar <- mean(y)) (sxy <- sum((x-xbar)*(y-ybar))) (sx2 <- sum((x-xbar)^2)) (sy2 <- sum((y-ybar)^2)) sxy/sqrt(sx2*sy2) rxy <- round(cor(x, y), 2) #b) tbar <- mean(zeit) (st2 <- sum((zeit-tbar)^2)) (stx <- sum((zeit-tbar)*(x-xbar))) (sty <- sum((zeit-tbar)*(y-ybar))) (bx <- stx/st2) (ax <- xbar - bx*tbar) (by <- sty/st2) (ay <- ybar - by*tbar) lm(x~zeit) residuals(lm(x~zeit)) lm(y~zeit) residuals(lm(y~zeit)) cor(residuals(lm(x~zeit)),residuals(lm(y~zeit))) # Alternativ: partieller Korrelationskoeffizient: stx/sqrt(st2*sx2) rxt <- round(cor(x, zeit),2) sty/sqrt(st2*sy2) ryt <- round(cor(y, zeit),2) (cor_b <- (rxy - rxt*ryt)/sqrt((1-rxt^2)*(1-ryt^2))) (cor(x,y) - cor(x,zeit)*cor(y,zeit))/sqrt((1-cor(x,zeit)^2)*(1-cor(y,zeit)^2))