rtexreg

How to export 'flexmix' model (in R) into Tex?


I have used the R package 'flexmix' to create some regression models. I now want to export the results to Tex.

Unlike conventional models created with lm(), the flexmix models are not saved as named numerics but as FLXRoptim objects.

When I now use the normal syntax from the 'texreg' package in order to create Tex code from the model results, I am getting error messages:

"unable to find an inherited method for function ‘extract’ for signature ‘"FLXRoptim"’"

I have to access the models directly, these are stored as 'Coefmat' and I did not manage to make this usable for texreg().

library(flexmix)
library(texreg)
data("patent")

## 1. Flexmix model ##
flex.model <- flexmix(formula = Patents ~ lgRD, data = patent, k = 3, 
  model = FLXMRglm(family = "poisson"), concomitant = FLXPmultinom(~RDS))
re.flex.model <- refit(flex.model)

## 2. Approach of results extraction ##
comp1.flex <- re.flex.model@components[[1]][["Comp.1"]]

## 3. Not working: Tex Export ## 
texreg(comp1.flex)

Do you guys have an idea how to make these model results usable for Tex export?


Solution

  • I have now found a workaround: 'Texreg' allows us to create Texreg models with manually specified columns.

    createTexreg(coef.names, coef, se, pvalues)
    

    Using the example from above:

    ## Take estimates, SEs, and p-values for Comp1 ##
    est1 <- re.flex.model@components[[1]][["Comp.1"]][,1]
    se1 <- re.flex.model@components[[1]][["Comp.1"]][,2]
    pval1 <- re.flex.model@components[[1]][["Comp.1"]][,4]
    
    ## Take estimates, SEs, and p-values for Comp2 ##
    est2 <- re.flex.model@components[[1]][["Comp.2"]][,1]
    se2 <- re.flex.model@components[[1]][["Comp.2"]][,2]
    pval2 <- re.flex.model@components[[1]][["Comp.2"]][,4]
    
    
    ## Create Texreg objects and export into Tex ##
    mymodel1 <- createTexreg(row.names(comp1.flex), est1, se1, pval1)
    mymodel2 <- createTexreg(row.names(comp1.flex), est2, se2, pval2)
    models.flex = list(mymodel1, mymodel2)
    texreg(models.flex)
    

    That's probably the most practical way to turn such specific models into a conventional Tex output.