How to add residus value in my data frame?

I've residus value in my model result. I would like to transform and add them in my data frame.That's means, to have results with low residus. I'm using FE model. So, i've tried to add but my method doesn't work. Here my R details:

fixed = plm(sp ~lag(debt)+lag(I(debt^2))+outgp++bcour+gvex+vlexp+vlimp, data=bdata, index=c("country", "year"), model="within")

method for adding my residus values:

bdata$resid = fixed$resid

Try broom::augment()

@phiggins thanks for answering, kendly please give me more details btw?please please

In the example below, using the starwars data

library(tidyverse)
library(broom)

model <- lm(height ~ gender + species + birth_year, 
            data = starwars) %>% 
  broom::augment()

model
#> # A tibble: 40 x 12
#>    .rownames height gender species birth_year .fitted .se.fit    .resid   .hat
#>    <chr>      <int> <chr>  <chr>        <dbl>   <dbl>   <dbl>     <dbl>  <dbl>
#>  1 1            172 male   Human         19      178.    3.07 -6.41e+ 0 0.141 
#>  2 4            202 male   Human         41.9    181.    2.04  2.13e+ 1 0.0622
#>  3 5            150 female Human         19      156.    4.11 -5.84e+ 0 0.252 
#>  4 6            178 male   Human         52      182.    1.84 -3.73e+ 0 0.0507
#>  5 7            165 female Human         47      159.    3.66  6.34e+ 0 0.200 
#>  6 9            183 male   Human         24      179.    2.80  4.09e+ 0 0.117 
#>  7 10           182 male   Human         57      182.    1.83 -2.35e- 1 0.0502
#>  8 11           188 male   Human         41.9    181.    2.04  7.28e+ 0 0.0622
#>  9 12           180 male   Human         64      183.    1.93 -2.94e+ 0 0.0554
#> 10 13           228 male   Wookiee      200      228.    8.18  5.77e-15 1     
#> # ... with 30 more rows, and 3 more variables: .sigma <dbl>, .cooksd <dbl>,
#> #   .std.resid <dbl>

Created on 2020-07-15 by the reprex package (v0.3.0)

1 Like

Thanks, , i've tried the broom function , but how could i get the below information:

lm(formula = sp ~ lag(debt) + lag(I(debt^2)) + outgp + +bcour + 
    gvex + vlexp + vlimp, data = bdata, index = c("country", 
    "year"))

Residuals:
    Min      1Q  Median      3Q     Max 
-7.7946 -1.8998 -0.5945  1.3142 29.2998 

Coefficients:
                 Estimate Std. Error t value Pr(>|t|)    
(Intercept)    -4.902e-02  6.212e-01  -0.079  0.93715    
lag(debt)       2.416e-02  1.552e-02   1.557  0.12056    
lag(I(debt^2)) -1.629e-05  7.232e-05  -0.225  0.82198    
outgp           1.197e-02  1.311e-02   0.913  0.36212    
bcour           3.048e-01  2.696e-02  11.306  < 2e-16 ***
gvex           -6.354e-01  7.479e-02  -8.496 8.61e-16 ***
vlexp          -5.924e-02  1.971e-02  -3.006  0.00286 ** 
vlimp           3.777e-02  1.625e-02   2.323  0.02081 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.946 on 307 degrees of freedom
Multiple R-squared:  0.4922,	Adjusted R-squared:  0.4807 
F-statistic: 42.52 on 7 and 307 DF,  p-value: < 2.2e-16

A different broom function - tidy().
Please read the vignette at https://cran.r-project.org/web/packages/broom/vignettes/broom.html

1 Like

thanks a lot, now im reading the document

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.