Format model display in texreg or stargazer R as scientific

后端 未结 3 953
感动是毒
感动是毒 2021-02-08 18:59

I just ran a statisitical model and i want it to display the results of the model as a table using stargazer. However, the large numbers are displayed in full.

         


        
3条回答
  •  死守一世寂寞
    2021-02-08 19:36

    The problem is not that these packages cannot display scientific notation. The problem is rather that your independent variables are on an extremely small scale. You should rescale them before you use them in your model by multiplying the values by some constant. For example, when you deal with the size of persons in kilometers, you may want to rescale them to meters or centimeters. This would make the table much easier to read than displaying the results in scientific notation.

    Consider the following example:

    a <- c(4.17, 5.58, 5.18, 6.11, 4.50, 4.61, 5.17, 4.53, 5.33, 5.14)
    b <- c(0.00020, 0.00024, 0.00024, 0.00026, 0.00021, 0.00022, 0.00023, 
        0.00022, 0.00023, 0.00022)
    model.1 <- lm(a ~ b)
    

    Next, create your table with texreg:

    library("texreg")
    screenreg(model.1)
    

    This yields the following table:

    =========================
                 Model 1     
    -------------------------
    (Intercept)     -2.27 *  
                    (0.94)   
    b            32168.58 ***
                 (4147.00)   
    -------------------------
    R^2              0.88    
    Adj. R^2         0.87    
    Num. obs.       10       
    =========================
    *** p < 0.001, ** p < 0.01, * p < 0.05
    

    So the coefficients are pretty large. Let's try the same thing with stargazer:

    library("stargazer")
    stargazer(model.1, type = "text")
    

    The resulting table:

    ===============================================
                            Dependent variable:    
                        ---------------------------
                                     a             
    -----------------------------------------------
    b                          32,168.580***       
                                (4,146.999)        
    
    Constant                     -2.270**          
                                  (0.944)          
    
    -----------------------------------------------
    Observations                    10             
    R2                             0.883           
    Adjusted R2                    0.868           
    Residual Std. Error       0.212 (df = 8)       
    F Statistic            60.172*** (df = 1; 8)   
    ===============================================
    Note:               *p<0.1; **p<0.05; ***p<0.01
    

    Same problem: large coefficients. Now rescale your original variable b and recompute the model:

    b <- b * 10000
    model.2 <- lm(a ~ b)
    

    Try it again with texreg:

    screenreg(model.2)
    
    ======================
                 Model 1  
    ----------------------
    (Intercept)  -2.27 *  
                 (0.94)   
    b             3.22 ***
                 (0.41)   
    ----------------------
    R^2           0.88    
    Adj. R^2      0.87    
    Num. obs.    10       
    ======================
    *** p < 0.001, ** p < 0.01, * p < 0.05
    

    And with stargazer:

    stargazer(model.2, type = "text")
    
    ===============================================
                            Dependent variable:    
                        ---------------------------
                                     a             
    -----------------------------------------------
    b                            3.217***          
                                  (0.415)          
    
    Constant                     -2.270**          
                                  (0.944)          
    
    -----------------------------------------------
    Observations                    10             
    R2                             0.883           
    Adjusted R2                    0.868           
    Residual Std. Error       0.212 (df = 8)       
    F Statistic            60.172*** (df = 1; 8)   
    ===============================================
    Note:               *p<0.1; **p<0.05; ***p<0.01
    

    Now the coefficients look nicer and you do not need scientific notation.

提交回复
热议问题