The R Project SVN R

Rev

Rev 74690 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 74690 Rev 80080
Line 51... Line 51...
51
require(graphics)
51
require(graphics)
52
 
52
 
53
## using poly: this did not work in R < 1.5.0
53
## using poly: this did not work in R < 1.5.0
54
fm <- lm(weight ~ poly(height, 2), data = women)
54
fm <- lm(weight ~ poly(height, 2), data = women)
55
plot(women, xlab = "Height (in)", ylab = "Weight (lb)")
55
plot(women, xlab = "Height (in)", ylab = "Weight (lb)")
56
ht <- seq(57, 73, len = 200)
56
ht <- seq(57, 73, length.out = 200)
57
nD <- data.frame(height = ht)
57
nD <- data.frame(height = ht)
58
pfm <- predict(fm, nD)
58
pfm <- predict(fm, nD)
59
lines(ht, pfm)
59
lines(ht, pfm)
60
pf2 <- predict(update(fm, ~ stats::poly(height, 2)), nD)
60
pf2 <- predict(update(fm, ~ stats::poly(height, 2)), nD)
61
stopifnot(all.equal(pfm, pf2)) ## was off (rel.diff. 0.0766) in R <= 3.5.0
61
stopifnot(all.equal(pfm, pf2)) ## was off (rel.diff. 0.0766) in R <= 3.5.0