Two flavours of residual are available. type = "structural" gives
xi = y - mu - P alpha - W beta, the residual of the causal model before the
copula terms are subtracted off; type = "augmented" gives
u = xi - C gamma, the residual of the full regression that was actually
fitted, including the copula control functions.
Value
A numeric vector of residuals, named by the row names of the model
frame so that observations stay identifiable after na.omit has
dropped some.
References
Qian, Y., A. Koschmann, and H. Xie (2025). A practical guide to endogeneity correction using copulas. Journal of Marketing.
Examples
set.seed(1)
n <- 150
w <- rnorm(n)
p <- 0.4 * w + rt(n, df = 3)
xi <- 0.5 * p + rnorm(n)
y <- 1 + 2 * p + 1.5 * w + xi
dat <- data.frame(y = y, p = p, w = w)
fit <- endogCopula:::.copreg_fit(
formula = y ~ p | w, data = dat,
ctor = endogCopula:::.ctor_twostage(TRUE),
method = "2sCOPE", cdf = "rank.n", ties = "max",
nboots = 25, verbose = FALSE)
residuals(fit, type = "structural")
#> 1 2 3 4 5 6
#> 0.27786325 0.71208591 0.96324482 0.54930140 -0.49189960 0.22646894
#> 7 8 9 10 11 12
#> 0.72643025 0.46079789 1.61889962 0.52818345 -0.63746567 1.33913999
#> 13 14 15 16 17 18
#> -2.30483100 1.00028062 0.20395440 -0.06476487 -0.65360298 0.08772584
#> 19 20 21 22 23 24
#> 0.32312394 0.39319613 -2.27796774 1.01516685 -0.77441876 -0.16300481
#> 25 26 27 28 29 30
#> -1.16596002 0.48395112 0.08821789 -2.24196542 0.26488031 1.50715007
#> 31 32 33 34 35 36
#> 0.44662562 0.57539417 -0.66913659 0.91487892 -0.61537818 1.00018322
#> 37 38 39 40 41 42
#> 0.56779604 -0.11087253 2.03986458 1.10092768 1.24049127 2.07336824
#> 43 44 45 46 47 48
#> -2.29741063 -1.05233317 -0.85978694 0.22114238 1.95520496 1.62122919
#> 49 50 51 52 53 54
#> 1.72993212 1.20301510 -0.95572716 -0.38838619 0.26601716 -0.21255063
#> 55 56 57 58 59 60
#> -0.44357831 -0.93810279 1.21782932 -1.36492445 -1.18889390 0.20815872
#> 61 62 63 64 65 66
#> -1.06436909 -0.28640438 0.52730135 -1.58022432 -0.77281419 1.13014468
#> 67 68 69 70 71 72
#> 1.85567884 0.84989040 -0.78888207 -1.01292467 -1.64856589 -0.27568567
#> 73 74 75 76 77 78
#> 2.41282270 0.06778927 0.25060228 0.72253097 -0.25646405 -1.07742500
#> 79 80 81 82 83 84
#> 2.13814051 -0.26977885 0.26149430 -1.60457269 -0.65274858 -0.26225064
#> 85 86 87 88 89 90
#> -0.12690417 -2.28468647 1.98915396 2.55468281 1.12385663 -0.35824018
#> 91 92 93 94 95 96
#> 1.79687102 0.49960115 0.02465637 1.92605410 -0.37673107 -0.95464705
#> 97 98 99 100 101 102
#> -1.38239574 -0.01740246 -1.53419666 -0.49455411 -0.17980350 0.64060673
#> 103 104 105 106 107 108
#> -0.70750008 0.81624339 -2.28864828 -1.45843019 0.52892991 -1.51405779
#> 109 110 111 112 113 114
#> 0.02223494 -0.67994943 0.86743970 -1.33249609 -0.30694579 -0.06441008
#> 115 116 117 118 119 120
#> -0.28790003 -1.05048299 1.99461104 -1.69352136 0.07857467 -2.72837777
#> 121 122 123 124 125 126
#> 0.20106581 0.73300741 -0.89700781 1.54937686 0.26167965 1.29597377
#> 127 128 129 130 131 132
#> -0.48060154 -0.20398524 -1.99827198 -0.20082327 -0.67494372 0.15033183
#> 133 134 135 136 137 138
#> 0.50727076 -1.13700923 -0.80544348 1.75187334 -0.08390764 -1.36851671
#> 139 140 141 142 143 144
#> 0.73231345 -2.01900030 1.16270940 -1.11467528 0.31948050 -0.49753553
#> 145 146 147 148 149 150
#> 2.10818789 -0.69543220 0.21129041 0.60286677 -0.62563042 0.23167712
residuals(fit, type = "augmented")
#> 1 2 3 4 5 6
#> 0.496161652 1.399325909 0.746864662 -0.231180915 -0.241207384 0.562042611
#> 7 8 9 10 11 12
#> 0.655178653 0.108753266 1.407279907 0.072806483 -0.570614384 0.619299392
#> 13 14 15 16 17 18
#> -2.015397249 0.582955861 0.557132777 -0.064682094 -0.994148570 -0.313441694
#> 19 20 21 22 23 24
#> 1.357496653 -0.528105290 -2.178896924 0.957406802 -0.357213109 -0.329614570
#> 25 26 27 28 29 30
#> -1.065069088 0.107886332 0.835502264 -0.853320359 -0.514511049 1.199036722
#> 31 32 33 34 35 36
#> -0.140371614 -0.020767082 -0.457606086 1.072450633 -0.840162984 1.008246671
#> 37 38 39 40 41 42
#> 0.970390255 -0.332593115 0.996059692 1.151501920 0.715164458 2.211102620
#> 43 44 45 46 47 48
#> -1.881385375 -1.000331835 -1.224925780 0.384617937 1.704306872 1.828509440
#> 49 50 51 52 53 54
#> 0.687821851 0.950825985 -0.150368233 0.460107443 0.533684866 -0.599807247
#> 55 56 57 58 59 60
#> -0.169377377 -0.146427217 1.563680641 -0.837283632 -2.043703506 0.865902913
#> 61 62 63 64 65 66
#> -0.774246050 -0.270801104 0.987815911 -0.776199051 -0.210818934 1.606746728
#> 67 68 69 70 71 72
#> 0.894510630 0.625827320 -0.049662927 -1.033086653 -1.352264137 -0.003694133
#> 73 74 75 76 77 78
#> 2.104029334 0.440764911 0.354308533 0.441940152 -0.204166199 -1.274418282
#> 79 80 81 82 83 84
#> 2.749748956 -0.266037085 -0.155328766 -1.657572102 -0.193634041 -0.029479483
#> 85 86 87 88 89 90
#> -0.092820794 -1.706725094 1.933162763 1.837851763 0.794605386 -0.955181197
#> 91 92 93 94 95 96
#> 0.860450401 -0.146978096 -0.255827669 1.465585478 -1.116698605 -0.450342049
#> 97 98 99 100 101 102
#> -0.594074151 0.216247786 -1.348621628 -0.583166511 0.770398462 0.621590371
#> 103 104 105 106 107 108
#> -0.815001828 0.651757509 -2.260062003 -0.593903108 0.839281156 -0.679373456
#> 109 110 111 112 113 114
#> 0.124762254 -1.567785257 1.061241000 -1.712077219 -0.177784946 -0.117762431
#> 115 116 117 118 119 120
#> 0.179797856 -0.660540730 1.985969784 -1.269688291 0.404439335 -2.811216461
#> 121 122 123 124 125 126
#> 0.133449691 0.662949106 -0.949347487 0.797860972 0.500459769 1.041769799
#> 127 128 129 130 131 132
#> -0.710185745 -0.867995135 -1.586746091 -0.131194093 -1.201861038 0.801624871
#> 133 134 135 136 137 138
#> 0.172706636 0.257687485 -1.031553384 1.346249934 -0.401394057 -1.254574896
#> 139 140 141 142 143 144
#> 0.715833174 -1.329591684 0.080940654 -0.683769290 0.375211642 -0.863632355
#> 145 146 147 148 149 150
#> 1.318893698 -1.038678944 0.332004231 0.269692882 -0.898985772 -0.310608267
