bsFormu {erer}R Documentation

Generating Formula for Models

Description

Generate a single formula for models like lm or a list of formula for models like systemfit.

Usage

bsFormu(name.y, name.x, intercept = TRUE, ...)

Arguments

name.y

a character vector of variables names for dependent variables; when the length is more than one, there will a list of formula generated for each variable in the name.

name.x

a character vector of indepedent variables.

intercept

a logical value (default of TRUE) of whether to include intercept or not.

...

additional arguments to be passed.

Details

This function can generate a single formula for simple model like lm or a list of formula for systems (systemfit. Note that the right-hand side variables are the same for each dependent variable. If different, a for loop can be added by users to address that, as demonstrated by the example below.

Value

a single formula object or a list of formula objects.

Author(s)

Changyou Sun (cs258@msstate.edu)

Examples


# fake data
y  <- c("y")
ym <- c("y1", "y2", "y3")
x <- c("x")
xAll <- c("x", "xx", "xxx", "xxxx")

bsFormu(name.y = y, name.x = x)
bsFormu(name.y = ym, name.x = xAll)
fm.ym <- bsFormu(name.y = ym, name.x = xAll, intercept = FALSE)
fm.ym

# If independent variables differ by equation,
# add a loop to address the differentiation.
xInd <- c("x1", "x2", "x3")
fm.ym <- list()
for (i in 1:length(ym)) {
    ny <- ym[i]
    nx <- c(xInd[i], xAll)
    fm.ym[[i]] <- bsFormu(name.y = ny, name.x = nx, intercept = FALSE)
}
fm.ym

# real data
data(daIns)
(xx <- colnames(daIns)[-c(1, 14)])
fm.ins <- bsFormu(name.y = "Y", name.x = xx, intercept = TRUE)
fm.ins
(ra <- glm(formula = fm.ins,
          family = binomial(link="logit"),
          data = daIns, x = TRUE))

[Package erer version 3.1 Index]