# DLNM and crossreduce(): getting the coefficients behind the cross-basis

I am using the R package dlnm to fit a distributed lag non-linear model estimated with lm(). One can specify both the exposure and the lag functions.

In the distributed lag non-linear model, how can we move from the regression estimates of the cross-basis to the parameters before the cross-basis transformation?

The following example might help clarify. We run a dlnm where the exposure function is specified as a quadratic and the lag structure is linear:

library(dlnm)
cb <- crossbasis(chicagoNMMAPS$temp,lag=30, argvar=list("poly",degree=2), arglag=list("lin")) model <- lm(cvd~cb,chicagoNMMAPS) pred <- crosspred(cb,model,at=-20:30) plot(pred,"slices",lag=0)  I would like to get the coefficients corresponding to this curve. My dirty way is the following: LAG<-0 SCALE<-attributes(cb)$argvar$scale ce<-attributes(cb)$argvar$cen B1<-(summary(model)$coeff[2,1]+summary(model)$coeff[4,1]*LAG)/SCALE B2<-(summary(model)$coeff[3,1]+summary(model)$coeff[5,1]*LAG)/(SCALE^2) B0<--(ce*B1+(ce^2)*B2)  where B's are the parameters as shown on the graph below: xx<-(-20:30) xx2<-xx^2 length(xx) length(xx2) yhat<-B0+B1*xx+B2*xx2 lines(-20:30,yhat,lty=2,col="blue")  Is there a better way of finding the B's, either a general formula or a command? Would the crossreduce() function work? I would like to get the B's when the lag structure is specified as a spline. For instance: cb <- crossbasis(chicagoNMMAPS$temp,lag=30,
argvar=list("poly",degree=2),
arglag=list("ns",knots=(1,8))


The solution is to set the scale parameter in the argvar function to 1. The crossreduce function then gives the parameters in the original scale. Below a an example:
# with a poly of degree 2 with natural splines at knots 3 and 10
cb <- crossbasis(chicagoNMMAPS$temp,lag=30, argvar=list("poly",degree=2,scale=1), arglag=list("ns",knots=c(3,10))) model <- lm(cvd~cb,chicagoNMMAPS) pred <- crosspred(cb,model,at=-20:30) plot(pred,"slices",lag=3) ce<-attributes(cb)$argvar$cen xx<-(-20:30) xx2<-xx^2 redvar<-crossreduce(cb, model,type="lag",value=3) b1<-redvar$coefficients[1]
b2<-redvar$coefficients[2] b0<--(ce*b1+(ce^2)*b2) yhat<-b0+b1*xx+b2*xx2 lines(-20:30,yhat2,lty=2,col="green")  You can find the coefficients in pred$matfit.