Skip to contents

Extract beta coefficient from FTM object

FTM objects allow you to view beta coefficients for all variables or for a subset of variables. The coef function can be used to extract coefficients from a fitted FTM object. The select argument can be used to extract coefficients for specific variables (accepts variable names or integers).

# Assuming ftmglm_model, ftmlm_model or ftmglmnet_model are pre-fitted model objects (see Create FTM Object vignette)

# Extract beta coefficients for all variables from a ftmlm model
coef(ftmlm_model)
#> (Intercept)         cyl          hp          wt 
#>  38.7517874  -0.9416168  -0.0180381  -3.1669731

# Extract beta coefficients for a reweighted model using a subset of variables from a ftmlm model
coef(ftmlm_model, select = c("cyl", "hp"))
#> (Intercept)         cyl          hp 
#>  36.9083305  -2.2646936  -0.0191217



# This works similarly for a ftmglm model
coef(ftmglm_model)
#> (Intercept)          hp          wt         cyl 
#> 19.70288279  0.03259168 -9.14947127  0.48759798

# Similarly, you can extract beta coefficients after reweighting for a subset of variables from a ftmglm model
coef(ftmglm_model, select = c("cyl", "hp"))
#> (Intercept)         cyl          hp 
#>  3.51747179 -1.05168913  0.01824552



# This also works for FTM objects made from glmnet models
coef(ftmglmnet_model)
#>   (Intercept)            hp            wt           cyl 
#>  1.166828e+01  1.943383e-02 -4.860874e+00 -1.016964e-13

# Finally, you can extract beta coefficients after reweighting for a subset of variables from a ftmglmnet model
coef(ftmglmnet_model, select = c("cyl", "hp"))
#> (Intercept)         cyl          hp 
#>  3.51627932 -1.04395036  0.01724091

Manually subset of FTM object

Although a FTM object contains information about all variables, it is possible to manually trim a FTM model to a subset of variables.

# Assuming ftmglm_model, ftmlm_model or ftmglmnet_model are pre-fitted model objects (see Create FTM Object vignette)

# Subset a ftmlm model, so it only contains a subset of variables
subset(ftmlm_model, subset = c("cyl", "hp"))
#> Flexible Transfer Model - Linear Model
#> ------------------------------------------------------
#>   Number of predictors: 2
#>   Optimal lambda: 0.000000
#> 
#> Formula:
#> mpg ~ `(Intercept)` + cyl + hp
#> 
#> Coefficients:
#> (Intercept)          cyl           hp  
#>     36.9083      -2.2647      -0.0191  
#> 
#>   R-squared: 0.740708



# Similarly, you can subset a ftmglm model
subset(ftmglm_model, subset = c("cyl", "hp"))
#> Flexible Transfer Model - Generalized Linear Model
#> ------------------------------------------------------
#>   Number of predictors: 2
#> 
#> Formula:
#> am ~ `(Intercept)` + hp + cyl
#> 
#> Coefficients:
#> (Intercept)           hp          cyl  
#>      3.5175       0.0182      -1.0517



# This also works for FTM objects made from glmnet models
subset(ftmglmnet_model, subset = c("cyl", "hp"))
#> Flexible Transfer Model - Generalized Linear Model
#> ------------------------------------------------------
#>   Number of predictors: 2
#> 
#> Formula:
#> am ~ `(Intercept)` + hp + cyl
#> 
#> Coefficients:
#> (Intercept)           hp          cyl  
#>      3.5163       0.0172      -1.0440