genFormula: Generate a linear formula

Description Usage Arguments Value Examples

View source: R/genFormula.R

Description

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

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
genFormula(c(.5, 2, 4), c("A", "B", "C"))
genFormula(c(.5, 2, 4), c("A", "B"))

changeX <- c(7, 10)
genFormula(c(.5, 2, changeX[1]), c("A", "B"))
genFormula(c(.5, 2, changeX[2]), c("A", "B"))
genFormula(c(.5, 2, changeX[2]), c("A", "B", "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))

kgoldfeld/simstudy documentation built on Nov. 8, 2018, 7:41 p.m.