dewittpe / cpr

Control Polygon Reduction: Methods for quick and efficient placement of internal knots for B-splines and tensor products of B-splines.
http://www.peteredewitt.com/cpr/
2 stars 0 forks source link

predict method does not return expected values #49

Closed dewittpe closed 9 months ago

dewittpe commented 9 months ago
acp <- cp(log10(pdg) ~ bsplines(age, df = 12, bknots = c(45, 53)), data = spdg) 
alm <- lm(log10(pdg) ~ bsplines(age, df = 12, bknots = c(45, 53)) + 0, data = spdg) 

identical(acp$coef, alm$coef)
# [1] TRUE

nd <- data.frame(pdg = NA_real_,
                 age = runif(n = 123, min = 45, max = 53))

acp_pred <- predict(acp, newdata = nd)
alm_pred <- predict(alm, newdata = nd, se.fit = TRUE)

acp_pred$pre |> summary()
#      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 

# -0.048209 -0.024675 -0.011499 -0.004155  0.017590  0.066905 
alm_pred$fit |> summary()
#       Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
# -0.0478838 -0.0226767 -0.0076978 -0.0009263  0.0228366  0.0785533