Formulas for additive linear models can be generated with specified coefficient values and variable names.

genFormula(coefs, vars)

Arguments

coefs

A numerical vector that contains the values of the coefficients. If length(coefs) == length(vars), then no intercept is assumed. Otherwise, an intercept is assumed.

vars

A vector of strings that specify the names of the explanatory variables in the equation.

Value

A string that represents the desired formula

Examples

genFormula(c(.5, 2, 4), c("A", "B", "C"))
#> [1] "0.5 * A + 2 * B + 4 * C"
genFormula(c(.5, 2, 4), c("A", "B"))
#> [1] "0.5 + 2 * A + 4 * B"
changeX <- c(7, 10) genFormula(c(.5, 2, changeX[1]), c("A", "B"))
#> [1] "0.5 + 2 * A + 7 * B"
genFormula(c(.5, 2, changeX[2]), c("A", "B"))
#> [1] "0.5 + 2 * A + 10 * B"
genFormula(c(.5, 2, changeX[2]), c("A", "B", "C"))
#> [1] "0.5 * A + 2 * B + 10 * C"
newForm <- genFormula(c(-2, 1), c("A")) def1 <- defData(varname = "A", formula = 0, variance = 3, dist = "normal") def1 <- defData(def1, varname = "B", formula = newForm, dist = "binary", link = "logit") set.seed(2001) dt <- genData(500, def1) summary(glm(B ~ A, data = dt, family = binomial))
#> #> Call: #> glm(formula = B ~ A, family = binomial, data = dt) #> #> Deviance Residuals: #> Min 1Q Median 3Q Max #> -2.2468 -0.4865 -0.2761 -0.0920 2.8527 #> #> Coefficients: #> Estimate Std. Error z value Pr(>|z|) #> (Intercept) -2.3700 0.2046 -11.586 <2e-16 *** #> A 1.1457 0.1186 9.662 <2e-16 *** #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #> #> (Dispersion parameter for binomial family taken to be 1) #> #> Null deviance: 483.31 on 499 degrees of freedom #> Residual deviance: 317.32 on 498 degrees of freedom #> AIC: 321.32 #> #> Number of Fisher Scoring iterations: 6 #>