Fit several models with different response variables

fit_models(
  df = NULL,
  yname = NULL,
  xname = NULL,
  modeltype = NULL,
  drop_non_numeric = FALSE,
  ...
)

Arguments

df

A data.frame object

yname

The outcome variable

xname

The predictor variable(s)

modeltype

A character specifying the model type e.g lm for linear model

drop_non_numeric

Should non numeric columns be dropped? Defaults to FALSE

...

Other arguments to specific model types.

Value

A list of model objects that can be used later.

Examples

data("yields", package="manymodelr")
fit_models(df=yields,yname=c("height","yield"),xname="weight",modeltype="lm")
#> [[1]]
#> [[1]][[1]]
#> 
#> Call:
#> lm(formula = height ~ weight, data = use_df)
#> 
#> Coefficients:
#> (Intercept)       weight  
#>      0.5661      -0.2174  
#> 
#> 
#> [[1]][[2]]
#> 
#> Call:
#> lm(formula = yield ~ weight, data = use_df)
#> 
#> Coefficients:
#> (Intercept)       weight  
#>     519.142        1.793  
#> 
#> 
#> 
#many model types
fit_models(df=yields,yname=c("height","yield"),xname="weight",
modeltype=c("lm", "glm"))
#> [[1]]
#> [[1]][[1]]
#> 
#> Call:
#> lm(formula = height ~ weight, data = use_df)
#> 
#> Coefficients:
#> (Intercept)       weight  
#>      0.5661      -0.2174  
#> 
#> 
#> [[1]][[2]]
#> 
#> Call:
#> lm(formula = yield ~ weight, data = use_df)
#> 
#> Coefficients:
#> (Intercept)       weight  
#>     519.142        1.793  
#> 
#> 
#> 
#> [[2]]
#> [[2]][[1]]
#> 
#> Call:  glm(formula = height ~ weight, data = use_df)
#> 
#> Coefficients:
#> (Intercept)       weight  
#>      0.5661      -0.2174  
#> 
#> Degrees of Freedom: 999 Total (i.e. Null);  998 Residual
#> Null Deviance:	    45.82 
#> Residual Deviance: 44.37 	AIC: -271.4
#> 
#> [[2]][[2]]
#> 
#> Call:  glm(formula = yield ~ weight, data = use_df)
#> 
#> Coefficients:
#> (Intercept)       weight  
#>     519.142        1.793  
#> 
#> Degrees of Freedom: 999 Total (i.e. Null);  998 Residual
#> Null Deviance:	    91170 
#> Residual Deviance: 91080 	AIC: 7356
#> 
#>