tylermorganwall / skpr

Generates and evaluates D, I, A, Alias, E, T, G, and custom optimal designs. Supports generation and evaluation of mixture and split/split-split/N-split plot designs. Includes parametric and Monte Carlo power evaluation functions. Provides a framework to evaluate power using functions provided in other packages or written by the user.
https://tylermorganwall.github.io/skpr/
GNU General Public License v3.0
115 stars 15 forks source link

model specification in skipr functions #43

Closed rgriff35 closed 6 years ago

rgriff35 commented 6 years ago

I'm loving skpr but I have some frustration with model specification limitations I've found.

skpr models don't recognize a period (".") as an additive model of all terms in the RunMatrix like other R functions I frequently use (e.g. lm and optFederov). I can spell out each term but that can get tedious for models with many independent variables.

I have an additional issue: eval_design doesn't accept a model with a two way interaction between a categorical variable and a squared term. I can add the squared term manually to the candidate set and then add the interaction, but I wish skpr could hand this. It's interesting that gen_design doesn't give an error with that interaction term in the model.

Example: study1.cand <- expand.grid(Material = c('A', 'B', 'C'), Mass = c(7, 8), Gap = c(0, 25), Velocity.q = c(25, 50, 75)) model1 <- as.formula("~ (Material + Mass + Gap + Velocity.q)^2 + I(Velocity.q^2)") model2 <- as.formula("~ (Material + Mass + Gap + Velocity.q)^2 + I(Velocity.q^2) + Material:I(Velocity.q^2)")

study1.gendesign <- gen_design(study1.cand, model2, 32) eval_design(study1.gendesign, model2, alpha = .1, effectsize = 1.5) Error in eval_design(study1.gendesign, model2, alpha = 0.1, effectsize = 1.5, : Wrong number of anticipated coefficients

but model1 works in eval_design

GeorgeMKhoury commented 6 years ago

Interesting, looks like our function to generate anticipated coefficients isn't working right. In the meantime, if you manually specify your anticipated coefficients (anticoef = ...) it should work for you, like so:

eval_design(study1.gendesign, model2, alpha = .1,
            anticoef = 0.75*c(1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, 1, 1, -1),
            detailedoutput=T)

I'm surprised to hear that the period isn't working for you. It should. Can you provide an example?

tylermorganwall commented 6 years ago

Thanks, George, for the temporary fix advice.

Right now the way we handle the . term isn't very flexible, so I'll look into changing it for the next version to more easily specify the models you are interested in.

I'll also take a look at the anticipated coefficient generation for interactions between categoricals and polynomial terms.

tylermorganwall commented 6 years ago

The first issue (more flexible . handling in formulas) should be addressed in the latest version, 0.48.0.

tylermorganwall commented 6 years ago

I just uploaded a fix in v0.48.1 for the anticipated coefficient bug as well. You should be able to specify interactions between higher order terms and main effects in the evaluation functions now.