Search code examples
rmatrixregressionmodelinglm

Specifying lag in `dlnm` when passing arguments to `crossbasis`


I am using the dlnm package to build a finite distribute lag non linear model. I intend on testing the model-fit based on various lag levels to assess which lag is suitable. Needless to mention I will apply some domain knowledge to make a good call. I am using these two available resources to carry out this rather complex exercise: http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3191524/

http://cran.r-project.org/web/packages/dlnm/vignettes/dlnmOverview.pdf

I first created a Matrix to include non-linear effects of both my predictors using this: ImpressionsA.x<-onebasis(locanatmodelset$ImpressionsA.x, fun="poly", degree=2) ImpressionsA.y<-onebasis(locanatmodelset$ImpressionsA.y, fun="poly", degree=2)

Since my non-linear relationship is tending to be quadratic, I am using 2nd degree polynomials. Now I need to factor in the lags for each variable by calling crossbasis. This is where I am confused. The function as per the package documentation is of the format: cb <- crossbasis(chicagoNMMAPS$temp,lag=30,argvar=list("thr",thr.value=c(10,20)), arglag=list(knots=c(1,4,12)))

my doubts are :

1) in lag=30 is 30 of the same units as my response variable or will it be in the units of my predictor variable? In my case, my lag is specified in days. I want to specify 5 days as lag before fitting the model. How should I pass the argument?

2) Since I have already created my basis matrix for predictor variables using onebasis, how should I pass the arguments argvar and arglag?

3) I also wanted to extract the lagged values of my predictor variables (ImpressionsA.x and ImpressionsA.y) in their original units. The matrix itself is not helpful. It transforms everything into negative values on some other scale all together.

I've used tag lm & glm to the Q because dlnm has not been created.


Solution

  • Just occasionally see this post, and hopefully my experience of using the dlnm package can help you.

    1) The lag= argument in the crossbasis() function is for predictors. In your case, you can just use lag = 5.

    2) The onebasis() function has no direct use for fitting a DLNM. What you really need to adopt is the crossbasis() function, and the arguments argvar and arglag are very important to set up basis functions for your exposure and lag inside the cross-basis function. Thus, they are not ignorable.

    3) I am uncertain what is the main purpose of extracting the lagged values of your predictor variables, but you can just use a lag() function to accomplish externally. There is no need to use the dlnm to do such thing.