[R] looking for formula parser that allows coefficients
Paul Johnson
p@uljohn32 @ending from gm@il@com
Wed Aug 22 00:45:33 CEST 2018
Can you point me at any packages that allow users to write a
formula with coefficients?
I want to write a data simulator that has a matrix X with lots
of columns, and then users can generate predictive models
by entering a formula that uses some of the variables, allowing
interactions, like
y ~ 2 + 1.1 * x1 + 3 * x3 + 0.1 * x1:x3 + 0.2 * x2:x2
Currently, in the rockchalk package, I have a function simulates
data (genCorrelatedData2), but my interface to enter the beta
coefficients is poor. I assumed user would always enter 0's as
place holder for the unused coefficients, and the intercept is
always first. The unnamed vector is too confusing. I have them specify:
c(2, 1.1, 0, 3, 0, 0, 0.2, ...)
I the documentation I say (ridiculously) it is easy to figure out from
the examples, but it really isnt.
It function prints out the equation it thinks you intended, thats
minimum protection against user error, but still not very good:
dat <- genCorrelatedData2(N = 10, rho = 0.0,
beta = c(1, 2, 1, 1, 0, 0.2, 0, 0, 0),
means = c(0,0,0), sds = c(1,1,1), stde = 0)
[1] "The equation that was calculated was"
y = 1 + 2*x1 + 1*x2 + 1*x3
+ 0*x1*x1 + 0.2*x2*x1 + 0*x3*x1
+ 0*x1*x2 + 0*x2*x2 + 0*x3*x2
+ 0*x1*x3 + 0*x2*x3 + 0*x3*x3
+ N(0,0) random error
But still, it is not very good.
As I look at this now, I realize expect just the vech, not the whole vector
of all interaction terms, so it is even more difficult than I thought to get the
correct input.Hence, I'd like to let the user write a formula.
The alternative for the user interface is to have named coefficients.
I can more or less easily allow a named vector for beta
beta = c("(Intercept)" = 1, "x1" = 2, "x2" = 1, "x3" = 1, "x2:x1" = 0.1)
I could build a formula from that. That's not too bad. But I still think
it would be cool to allow formula input.
Have you ever seen it done?
pj
--
Paul E. Johnson http://pj.freefaculty.org
Director, Center for Research Methods and Data Analysis http://crmda.ku.edu
To write to me directly, please address me at pauljohn at ku.edu.
More information about the R-help
mailing list