RE: [R] coefficient of partial determination...partial r square [ redux]

From: abunn <abunn_at_whrc.org>
Date: Wed 09 Mar 2005 - 07:54:47 EST


Dr. C:

I implemented this example of partial r square from Neter et al.'s big blue book. It's easily extendable to a three variable model (or more). I might write it to work with class lm or glm if there is interest.

HTH, Andy

Applied Linear Statistical Models by John Neter, Michael H Kutner, William Wasserman, Christopher J. Nachtsheim

Section 7.4 in my copy page 274:

# body fat example from Neter et al.

bf.dat <- read.csv("body.fat.data.csv", header = T)
#R > bf.dat
# x1 x2 x3 y
#1 19.5 43.1 29.1 11.9
#2 24.7 49.8 28.2 22.8
#3 30.7 51.9 37.0 18.7
#4 29.8 54.3 31.1 20.1
#5 19.1 42.2 30.9 12.9
#6 25.6 53.9 23.7 21.7
#7 31.4 58.5 27.6 27.1
#8 27.9 52.1 30.6 25.4
#9 22.1 49.9 23.2 21.3
#10 25.5 53.5 24.8 19.3
#11 31.1 56.6 30.0 25.4
#12 30.4 56.7 28.3 27.2
#13 18.7 46.5 23.0 11.7
#14 19.7 44.2 28.6 17.8
#15 14.6 42.7 21.3 12.8
#16 29.5 54.4 30.1 23.9
#17 27.7 55.3 25.7 22.6
#18 30.2 58.6 24.6 25.4
#19 22.7 48.2 27.1 14.8
#20 25.2 51.0 27.5 21.1
#R >
# Not run:
#names(bf.dat) <- c('Triceps Skinfold Thickness', x2 = 'Thigh
Circumference', x3 = 'Midarm Circumference', y = 'Body Fat') summary(bf.dat)

lm.x1 <- lm(y ~ x1, data = bf.dat)
lm.x2 <- lm(y ~ x2, data = bf.dat)
lm.x1.x2 <- lm(y ~ x1 + x2, data = bf.dat)

# SSR(x2|x1) = SSR(x1,x2) - SSR(x1)

ssr.x1.x2 <- sum(anova(lm.x1.x2)$"Sum Sq"[1:2])
ssr.x1    <- anova(lm.x1)$"Sum Sq"[1]
ssr.x2    <- anova(lm.x2)$"Sum Sq"[1]
ssr.x1.x2 - ssr.x1

# also

sse.x1 <- anova(lm.x1)$"Sum Sq"[2] # eq sum(lm.x1$resid^2) sse.x2 <- anova(lm.x2)$"Sum Sq"[2] # eq sum(lm.x2$resid^2)

# The partial r2 of x1 while controlling for x2 is 0.031
# pr2_1.2 = SSR(x1|x2) / SSE(x2)

(ssr.x1.x2 - ssr.x2) / sse.x2
# The partial r2 of x2 while controlling for x1 is 0.232
# pr2_2.1 = SSR(x2|x1) / SSE(x1)

(ssr.x1.x2 - ssr.x1) / sse.x1



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Mar 09 08:03:24 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:41 EST