linear regression result

Hi dears, I want to ask a question related to linear regression.
I want to do simple linear regression between the Response variable "GFR" and predictors g1 to g10 considering ZN as a covariate. When I see the result of the list I also saw length difference. Here upload the screenshot for clarity. Why is that happening?

data <- data.frame(B = c("m","m","m","m","m", "m", "f","f","f","f","f"),
                   G = c("s","s","s","u","u", "u", "k","k","k","r","r"),
                   ZN =c(78,82,34,67,98,56,37,45,27,18,34),
                   GFR=c(120,100,90,60,100,110,100,90,95,87,96),
                   g1 = c(35, 2, 3, 4, 5, 6, 7, 10, 12, 41, 76), 
                   g2 = c(20, 2, 7, 2, 8, 5, 5, 3, 7, 2, 12), 
                   g3 = c(5, 0, 4, 5, 2, 4, 8, 9, 20, 1, 11),
                   g4 = c(1,3,4,5,7,3,1,5,7,3,10),
                   g5 = c(20,23, 27, 35, 12, 10, 17, 24, 21, 15, 16),
                   g6 = c(13,13,115,17,14,12,19,6,7,8,4),
                   g7 = c(5, 0, 4, 5, 2, 4, 8, 9, 20, 1, 11),
                   g8 = c(1,3,4,5,7,3,1,5,7,3,10),
                   g9 = c(20,23, 27, 35, 12, 10, 17, 24, 21, 15, 16),
                   g10 =c(13,13,115,17,14,12,19,6,7,8,4))

zn1 <- lapply(data[,-c(1,2,4)], function(x) lm(GFR ~ x + ZN, data = data))
zn2 <- lapply(zn1, function(x) summary(x)$coefficients)

 lm(GFR ~ g1 + ZN, data = data) %>% summary() %>% .[["coefficients"]]
              Estimate Std. Error   t value     Pr(>|t|)
(Intercept) 82.6023205 13.8256596 5.9745663 0.0003327039
g1           0.1677824  0.2306430 0.7274551 0.4876876285
ZN           0.1834205  0.2079299 0.8821268 0.4034338970

when you normally get 3 coefficients , the intercept, one for Zn and one for x (i.e. g1-g10)
what about when your x is ALSO ZN (as your code would have it)

lm(GFR ~ ZN + ZN, data = data) %>% summary() %>% .[["coefficients"]]
              Estimate Std. Error   t value     Pr(>|t|)
(Intercept) 88.4226911 10.9764390 8.0556810 0.0000209407
ZN           0.1308167  0.1897831 0.6892957 0.5080171122
1 Like

Thank you so much for the clarification!!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.