build_regression_data: Constructs a dataframe for use in regression functions

Description Usage Arguments Details Value Examples

View source: R/predictors.R

Description

'build_regression_data' construct a dataframe 'dat' from 'Y' and 'X' for use in a regression such as 'lm(form, data=dat)'.

Usage

1

Arguments

form

A formula.

Y

A vector.

X

A vector or a dataframe.

Details

The names of the columns of the dataframe constructed must correspond to the variables named in 'form', except in the case where the formula 'form' has a dot on the right-hand-side (e.g. Y1 ~ .). If 'X' is already a dataframe, not check is done. If it is a vector, then it is converted into a dataframe.

Value

A dataframe.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## Not run: 
A <- c(1, 2)
B <- c(3, 4)
C <- c(5, 6)

X <- data.frame(X1 = B, X2 = C)

build_regression_data(Y ~ X1, A, B)
# returns:
# Y X1
# 1 3
# 2 4 

build_regression_data(Y ~ ., A, B)
# returns:
# Y X
# 1 3
# 2 4

build_regression_data(Y ~ X1 + X2, A, X)
# returns:
# Y X1 X2 
# 1 3  5  
# 2 4  6

build_regression_data(Y ~ X1, A, X)
# returns:
# Y X1 X2 
# 1 3  5  
# 2 4  6

## End(Not run)

gwb/RGOB documentation built on May 14, 2021, 7:39 a.m.