rcspline.restate(knots, coef,
type=c("ordinary","integral"),
x="X", lx=nchar(x),
norm=2, columns=65, before="& &", after="\",
begin="", nbegin=0, digits=max(8, .Options$digits))
coef is
k-1, where
k=length(knots), the first coefficient must be
for the linear term and remaining
k-2 coefficients
must be for the constructed terms (e.g., from
rcspline.eval).
If the length of
coef is
k, an intercept is assumed to be in
the first element.
type="integral" to instead represent
its anti-derivative.
x to count with respect to
columns. Default is length
of character string contained by
x. You may want to set
lx
smaller than this if it includes non-printable LaTeX commands.
rcspline.eval for definitions.
"& &" for an equation
array environment in LaTeX where you want to have a left-hand prefix
e.g.
f(X) & = & or using
\lefteqn.
begin
knots is a vector of knots,
latex is a vector of text strings
with the LaTeX representation of the formula.
columns.used
is the number of columns used in the output string
since the last newline command.
function is an S function, which is
also return in character string format as the
text attribute.
Frank Harrell
Department of Biostatistics, Vanderbilt University
f.harrell@vanderbilt.edu
set.seed(1)
x <- 1:100
y <- x + rnorm(100, 0, 5)
xx <- rcspline.eval(x, inclx=TRUE, nk=4)
knots <- attr(xx, "knots")
coef <- lsfit(xx, y)$coef
options(digits=4)
# rcspline.restate must ignore intercept
w <- rcspline.restate(knots, coef[-1], x="{\\rm BP}")
# could also have used coef instead of coef[-1], to include intercept
cat(attr(w,"latex"), sep="\n")
xtrans <- eval(attr(w, "function"))
# This is an S function of a single argument
plot(x, xtrans(x), type="l")
# Plots fitted transformation
#x <- blood.pressure
xx.simple <- cbind(x, pmax(x-knots[1],0)^3, pmax(x-knots[2],0)^3,
pmax(x-knots[3],0)^3, pmax(x-knots[4],0)^3)
pred.value <- coef[1] + xx.simple %*% w
plot(x, pred.value, type='l') # same as above