Skip to contents

Print the content of an 'est_change'-class object.

Usage

# S3 method for est_change
print(x, digits = 3, first = 10, sort_by = c("gcd", "est"), ...)

Arguments

x

An 'est_change'-class object.

digits

The number of digits after the decimal. Default is 3.

first

Numeric. If not NULL, it prints only the first k cases, k equal to first. Default is 10.

sort_by

String. Should be "est", "gcd", or NULL. If the output was generated by est_change_raw() or est_change_raw_approx() and sort_by is not NULL, then each column is sorted individually, with case IDs inserted before each column. If the output was generated by est_change() or est_change_approx() and sort_by is not NULL, then sort_by determines how the cases are sorted. If by is "est", the cases are sorted as for the output of est_change_raw(). If by is "gcd", the default for the output of est_change() or est_change_approx(), then cases are sorted by generalized Cook's distance or approximate generalized Cook's distance, depending on which column is available.

...

Other arguments. They will be ignored.

Value

x is returned invisibly. Called for its side effect.

Details

All the functions on case influence on parameter estimates, est_change(), est_change_approx(), est_change_raw(), and est_change_raw_approx(), return an est_change-class object. This method will print the output based on the type of changes and method used.

Examples


library(lavaan)

# A path model

dat <- pa_dat
mod <-
"
m1 ~ a1 * iv1 + a2 * iv2
dv ~ b * m1
a1b := a1 * b
a2b := a2 * b
"
# Fit the model
fit <- lavaan::sem(mod, dat)
summary(fit)
#> lavaan 0.6.17 ended normally after 1 iteration
#> 
#>   Estimator                                         ML
#>   Optimization method                           NLMINB
#>   Number of model parameters                         5
#> 
#>   Number of observations                           100
#> 
#> Model Test User Model:
#>                                                       
#>   Test statistic                                 6.711
#>   Degrees of freedom                                 2
#>   P-value (Chi-square)                           0.035
#> 
#> Parameter Estimates:
#> 
#>   Standard errors                             Standard
#>   Information                                 Expected
#>   Information saturated (h1) model          Structured
#> 
#> Regressions:
#>                    Estimate  Std.Err  z-value  P(>|z|)
#>   m1 ~                                                
#>     iv1       (a1)    0.215    0.106    2.036    0.042
#>     iv2       (a2)    0.522    0.099    5.253    0.000
#>   dv ~                                                
#>     m1         (b)    0.517    0.106    4.895    0.000
#> 
#> Variances:
#>                    Estimate  Std.Err  z-value  P(>|z|)
#>    .m1                0.903    0.128    7.071    0.000
#>    .dv                1.321    0.187    7.071    0.000
#> 
#> Defined Parameters:
#>                    Estimate  Std.Err  z-value  P(>|z|)
#>     a1b               0.111    0.059    1.880    0.060
#>     a2b               0.270    0.075    3.581    0.000
#> 

# Approximate case influence
out <- est_change_approx(fit)
out
#> 
#> -- Approximate Standardized Case Influence on Parameter Estimates --
#> 
#>     m1~iv1 m1~iv2  dv~m1 m1~~m1 dv~~dv gcd_approx
#> 16   0.052 -0.038 -0.228 -0.006  0.572      0.372
#> 43  -0.387 -0.249 -0.135  0.201  0.116      0.270
#> 65   0.150  0.189  0.355  0.071  0.148      0.203
#> 85  -0.170  0.211 -0.118  0.315 -0.054      0.187
#> 51   0.405 -0.052  0.094  0.075 -0.046      0.179
#> 34  -0.306 -0.186 -0.110  0.176  0.028      0.163
#> 32  -0.241  0.190 -0.189  0.181 -0.002      0.161
#> 20  -0.234  0.199 -0.140  0.172 -0.034      0.144
#> 18  -0.269  0.035  0.101  0.246 -0.048      0.143
#> 100 -0.001 -0.221 -0.069  0.290 -0.058      0.137
#> 
#> Note:
#> - Changes are approximate standardized raw changes if a case is included.
#> - Only the first 10 case(s) is/are displayed. Set ‘first’ to NULL to display all cases.
#> - Cases sorted by approximate generalized Cook's distance.
print(out, sort_by = "est")
#> 
#> -- Approximate Standardized Case Influence on Parameter Estimates --
#> 
#>    id m1~iv1  id m1~iv2 id  dv~m1  id m1~~m1 id dv~~dv  id gcd_approx
#> 1  51  0.405  43 -0.249 65  0.355  61  0.335 16  0.572  16      0.372
#> 2  43 -0.387  94  0.230 11 -0.254  85  0.315  9  0.272  43      0.270
#> 3  34 -0.306 100 -0.221 16 -0.228 100  0.290 76  0.267  65      0.203
#> 4  18 -0.269  85  0.211 32 -0.189  18  0.246 25  0.264  85      0.187
#> 5  13  0.267  20  0.199 99  0.187  42  0.225 91  0.230  51      0.179
#> 6  32 -0.241  32  0.190 79  0.176  43  0.201 17  0.209  34      0.163
#> 7  20 -0.234  65  0.189 93  0.169  32  0.181 26  0.151  32      0.161
#> 8  75  0.200  34 -0.186 22  0.161  34  0.176 65  0.148  20      0.144
#> 9  42 -0.194  64 -0.165 61 -0.151  40  0.175 62  0.145  18      0.143
#> 10 68  0.174  52  0.161 25 -0.147  20  0.172 90  0.127 100      0.137
#> 
#> Note:
#> - Changes are approximate standardized raw changes if a case is included.
#> - Only the first 10 case(s) is/are displayed. Set ‘first’ to NULL to display all cases.
#> - Cases sorted by the absolute values of change or approximate generalized Cook's distance.
out <- est_change_raw_approx(fit)
print(out, first = 3)
#> 
#> -- Approximate Case Influence on Parameter Estimates --
#> 
#>   id m1~iv1  id m1~iv2 id  dv~m1  id m1~~m1 id dv~~dv
#> 1 51  0.042  43 -0.025 65  0.037  61  0.042 16  0.106
#> 2 43 -0.040  94  0.023 11 -0.027  85  0.040  9  0.050
#> 3 34 -0.032 100 -0.022 16 -0.024 100  0.037 76  0.049
#> 
#> Note:
#> - Changes are approximate raw changes if a case is included.
#> - Only the first 3 case(s) is/are displayed. Set ‘first’ to NULL to display all cases.
#> - Cases sorted by the absolute changes for each variable.

# Examine four selected cases
fit_rerun <- lavaan_rerun(fit, parallel = FALSE,
                          to_rerun = c(2, 3, 5, 7))
#> The expected CPU time is 0.15 second(s).
#> Could be faster if run in parallel.
est_change(fit_rerun)
#> 
#> -- Standardized Case Influence on Parameter Estimates --
#> 
#>       a1     a2      b m1~~m1 dv~~dv   gcd
#> 7 -0.119  0.073  0.065 -0.002 -0.040 0.026
#> 5  0.067  0.028  0.033  0.050 -0.066 0.013
#> 3 -0.038 -0.040 -0.030 -0.063 -0.045 0.010
#> 2  0.007  0.003 -0.013 -0.067 -0.058 0.008
#> 
#> Note:
#> - Changes are standardized raw changes if a case is included.
#> - All stored cases are displayed.
#> - Cases sorted by generalized Cook's distance.
est_change_raw(fit_rerun)
#> 
#> -- Case Influence on Parameter Estimates --
#> 
#>   id m1~iv1 id m1~iv2 id  dv~m1 id m1~~m1 id dv~~dv id    a1b id    a2b
#> 1  7 -0.013  7  0.007  7  0.007  2 -0.009  5 -0.013  7 -0.005  7  0.007
#> 2  5  0.007  3 -0.004  5  0.004  3 -0.008  2 -0.011  5  0.004  3 -0.004
#> 3  3 -0.004  5  0.003  3 -0.003  5  0.006  3 -0.008  3 -0.003  5  0.003
#> 4  2  0.001  2  0.000  2 -0.001  7  0.000  7 -0.008  2  0.000  2 -0.001
#> 
#> Note:
#> - Changes are raw changes if a case is included.
#> - All stored cases are displayed.
#> - Cases sorted by the absolute changes for each variable.