sambrilleman / rstanarm

rstanarm R package for Bayesian applied regression modeling
http://mc-stan.org/interfaces/rstanarm.html
GNU General Public License v3.0
0 stars 1 forks source link

Have handle_assoc_mod pass a basic data frame to data.table, instead of passing a model frame to data.table #59

Closed sambrilleman closed 7 years ago

sambrilleman commented 7 years ago

Just noting some thoughts here for the record. I'll close this issue once I've made the changes described below.

Here a model frame is constructed for the longitudinal submodel, including the time variable, and this is then converted to a data.table and used for constructing the assoc_parts (i.e. the design matrices for the quadrature).

But, the model frame causes a headache, primarily because functions of variables are evaluated (e.g. sqrt(age), cbind(successes, failures), poly(time, 2)), some of which induce columns of the incorrect length (e.g. poly(time, 2) returns a 2-column matrix which is then treated as a single column in the model frame... and therefore data.table throws an error because the model frame has columns of differing lengths).

It would be much cleaner to pass data.table a data frame with the raw variables. The data frame would just be the longitudinal data (dataLong) but then row matched to the model frame for the longitudinal submodel (returned as part of handle_glmod). The row matching would make sure that any rows removed from dataLong (as a consequence of na.action I guess) are also removed from the data frame before making assoc_parts.

sambrilleman commented 7 years ago

The commit here should have dealt with this.