make.formula: Convert strings to a formula

Description Usage Arguments Value Author(s) Examples

View source: R/make.formula.R

Description

make.formula is a function that easily converts a set of strings into a formula. It requires two arguments: a single response variable, and a vector of strings. See examples.

Usage

1
make.formula(response, predictors, random = NULL)

Arguments

response

a single string used on the left side of a formula

predictors

a string (or a vector of strings) representing the predictors. Each will be separated by a plus sign.

random

a string that indicates the random component in an lmer-like object (e.g., "(1|group)"). Defaults to NULL.

Value

a formula object

Author(s)

Dustin Fife

Examples

1
2
3
4
5
6
7
k = data.frame(matrix(rnorm(100), ncol=5))
names(k) = LETTERS[1:5]
formula = make.formula("A", LETTERS[2:5])
formula
lm(formula, data=k)
#do a random model
make.formula("A", LETTERS[2:5], random="(1|group)")

Example output

Loading required package: MASS
A ~ B + C + D + E
<environment: 0x9cd5bb8>

Call:
lm(formula = formula, data = k)

Coefficients:
(Intercept)            B            C            D            E  
   -0.43997      0.16605     -0.07028      0.09567      0.17710  

A ~ B + C + D + E + (1 | group)
<environment: 0x9e91330>

fifer documentation built on May 30, 2017, 7:40 a.m.

Related to make.formula in fifer...