I have data frames in Excel, that I'd like to run models on and return predictions and summary stats. Currently, I export the data to R, run a linear model and return the coefficients using XLConnect. While this works for linear models, it does not work well for more complicated models, like generalized additive models as the coefficients are not fully usable. I was wondering if there was a better way to do the operation above.
Example of what I do now, that is non-optimal:
library(XLConnect)
dat <- data.frame(rsp = rnorm(100, 0, 1),
pred1 = rnorm(100, 0, 1),
pred2 = rnorm(100, 0, 1))
model <- lm(rsp ~ pred1 + pred2, data = dat)
writeWorksheetToFile("model1.xlsx",
data = summary(dat),
sheet = "summary",
header = TRUE,
clearSheets = TRUE)