Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8102339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:13:09+00:00 2026-06-05T23:13:09+00:00

I’ve been running a bunch of different regression models and would now like to

  • 0

I’ve been running a bunch of different regression models and would now like to get their estimates into a LaTeX table. To make the different specifications comparable I would like to use the kind of table that outreg from the rockchalk package or mtable from memisc produce, i.e. one in which the different models are shown in columns and parameter estimates from those models are shown in the appropriate rows. This is what I’ve got:

df <- data.frame(x=rnorm(20),
                 z=rnorm(20),
                 group=gl(5,4,20,labels=paste('group',rep(1:5))))
df$y = 5 + 2*df$x + 5*df$z + rep(c(3.2,5,6.2,8.2,5),each=4) + rnorm(20)

model1 <- lm(y ~ x + z + factor(group),data=df)
model2 <- lm(y ~ x + factor(group),data=df)
model3 <- lm(y ~ x + z,data=df)

library(memisc)

reg.table <- mtable("Model 1"=model1,"Model 2"=model2,"Model 3"=model3,
                summary.stats=c("sigma","R-squared","F","p","N"))

toLatex(reg.table)

This works well enough, but I’ve got a factor with roughly 200 levels and a correspondingly large number of coefficients. What I’d like to do is to either omit the coefficients associated with this factor from the table or (for bonus points!) to show that the factor was used in the model with a simple ‘yes’ or ‘no’. So, my ideal output would be this:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    %
%
% Calls:
% Model 1:  lm(formula = y ~ x + z + factor(group), data = df) 
% Model 2:  lm(formula = y ~ x + factor(group), data = df) 
% Model 3:  lm(formula = y ~ x + z, data = df) 
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    %
\begin{tabular}{lcD{.}{.}{7}cD{.}{.}{7}cD{.}{.}{7}}
\toprule
&&\multicolumn{1}{c}{Model 1} && \multicolumn{1}{c}{Model 2} && \multicolumn{1}{c}{Model 3}\\
\midrule
(Intercept)                    &  &  8.315^{***} &&    4.235     && 10.338^{***}\\
                               &  &  (0.537)     &&   (3.276)    &&  (0.468)    \\
x                              &  &  1.976^{***} &&    2.398     &&  1.858^{***}\\
                               &  &  (0.238)     &&   (1.530)    &&  (0.443)    \\
z                              &  &  5.389^{***} &&              &&  5.359^{***}\\
                               &  &  (0.226)     &&              &&  (0.463)    \\
group                          &  &   yes        &&    yes       &&     no      \\
\midrule
sigma                          &  &     0.929    &&     5.981    &&     2.092   \\
R-squared                      &  &     0.984    &&     0.265    &&     0.891   \\
F                              &  &   129.485    &&     1.009    &&    69.306   \\
p                              &  &     0.000    &&     0.448    &&     0.000   \\
N                              &  &    20        &&    20        &&    20       \\
\bottomrule
\end{tabular}

Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:13:11+00:00Added an answer on June 5, 2026 at 11:13 pm

    Just selecting the first three coefficients is pretty simple:

    reg.table$coefficients <- reg.table$coefficients[,,1:3,,drop=FALSE]
    toLatex(reg.table)
    

    The “bonus” question (i.e. adding a hand-built 4th row describing “group”) requires a bit more work:

    ## Select the first three coeffients + one to be modified
    reg.table$coefficients <- reg.table$coefficients[,,1:4,,drop=FALSE]
    
    ## Make a copy of all the coefficients, and in the copy, modify the 4th
    j <- reg.table$coefficients
    j[,,4,] <- c("yes", "", "yes", "", "no", "")
    dimnames(j)[[3]][4] <- "group"
    
    ## Put the modified coefficients back into `reg.table`
    reg.table$coefficients <- j
    

    et voila

    toLatex(reg.table)
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % Calls:
    % Model 1:  lm(formula = y ~ x + z + factor(group), data = df) 
    % Model 2:  lm(formula = y ~ x + factor(group), data = df) 
    % Model 3:  lm(formula = y ~ x + z, data = df) 
    %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{tabular}{lcD{.}{.}{7}cD{.}{.}{7}cD{.}{.}{7}}
    \toprule
    &&\multicolumn{1}{c}{Model 1} && \multicolumn{1}{c}{Model 2} && \multicolumn{1}{c}{Model 3}\\
    \midrule
    (Intercept) &  &   8.830^{***} &&   9.846^{**}  && 10.342^{***} \\
                &  &   (0.626)     &&    (3.272)    &&   (0.442)    \\
    x           &  &   2.047^{***} &&     1.765     &&  1.937^{***} \\
                &  &   (0.244)     &&    (1.276)    &&   (0.319)    \\
    z           &  &   5.138^{***} &&               &&  4.847^{***} \\
                &  &   (0.267)     &&               &&   (0.372)    \\
    group       &  &  yes          &&   yes         &&   no         \\
                &  &               &&               &&              \\
    \midrule
    sigma       &  &     1.204     &&     6.310     &&      1.812   \\
    R-squared   &  &     0.975     &&     0.270     &&      0.927   \\
    F           &  &    85.576     &&     1.033     &&    107.717   \\
    p           &  &     0.000     &&     0.436     &&      0.000   \\
    N           &  &    20         &&    20         &&     20       \\
    \bottomrule
    \end{tabular}
    

    Edit:

    Here’s a version I like even better. It addresses the OP’s 1st comment below, and uses abind() (like rbind() for arrays) to add the group info to the array, which I find to be cleaner:

    library(abind)
    
    j <- reg.table$coefficients
    
    groupFac <- array(c("yes", "", "yes", "", "no", ""), dim=c(2,1,3))
    nonGroupFacs <- which(!grepl("group", dimnames(j)[[3]]))
    j <- j[,,nonGroupFacs,,drop=FALSE]
    j <- abind(j, groupFac, along=3)
    dimnames(j)[[3]][length(nonGroupFacs)+1] <- "group"
    
    reg.table$coefficients <- j
    
    toLatex(reg.table)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.