从具有 rcs 项的模型中获取拟合效果

Get fitted effects from a model with an rcs term

我想从包含通过 rms::rcs() 拟合的受限三次样条项的线性模型中获取拟合值,以传递到效果图中。问题是当我尝试传递带有 rcs 项的模型时,我通常用来获取拟合值 effects 的包会抛出错误。

这是一个最小的代表:

library(rms)
library(effects)
mod <- lm(Sepal.Length ~ rcs(Sepal.Width, 3), iris)
Effect("Sepal.Width", mod)
##Error in rcspline.eval(x, nk = nknots, inclx = TRUE, pc = pc, fractied = fractied) : knots not specified, and < 6 non-missing observations

我试过调试这个错误,但我无法理解 rcspline.eval() 如何在 x 和未指定的 nknots 中获得 6+ 个 NA。我该如何处理这个错误?或者,是否有另一个包可以从具有 rcs 项的模型中获得拟合效果?

rms 环境的用户将需要使用支持其活动的专门功能:

 library(rms)
 ddist <- datadist(iris)  # need both datadist and options 
 options(datadist='ddist')
 mod <- ols(Sepal.Length ~ rcs(Sepal.Width, 3), iris)  # need ols rather than lm
 plot( Predict(mod, Sepal.Width))  # Predict can be done in 2 or 3 dimension
        # gives a lattice output