Error when applying comb_CSR function in R

Viewed 10

my aim is to estimate a complete subset regression using the function comb_CSR() in R. My data set is the following:


    str(df_na)
    Classes ‘fredmd’ and 'data.frame':  360 obs. of  128 variables:
     $ date           : Date, format: "1992-03-01" "1992-04-01" "1992-05-01" "1992-06-01" ...
     $ RPI            : num  0.001653 0.00373 0.005329 0.004173 -0.000796 ...
     $ W875RX1        : num  0.000812 0.002751 0.005493 0.004447 -0.001346 ...
     $ DPCERA3M086SBEA: num  0.001824 0.000839 0.005146 0.002696 0.003342 ...
     $ CMRMTSPLx      : num  0.00402 0.00664 -0.00874 0.01049 0.0133 ...
     $ RETAILx        : num  -0.003 0.00602 0.00547 0.0028 0.00708 ...
     $ INDPRO         : num  0.008279 0.007593 0.003221 0.000539 0.008911 ...
     $ IPFPNSS        : num  0.00851 0.00743 0.0055 -0.00244 0.00998 ...
     $ IPFINAL        : num  0.00899 0.0076 0.0058 -0.00309 0.01129 ...
     $ IPCONGD        : num  0.00911 0.00934 0.00648 -0.0049 0.01298 ...
     $ IPDCONGD       : num  0.0204 0.0185 0.0308 -0.0138 0.0257 ...
     $ IPNCONGD       : num  0.00518 0.00612 -0.00219 -0.00172 0.00843 ...
     $ IPBUSEQ        : num  0.01174 0.00958 0.00792 0.00247 0.01016 ...
     $ IPMAT          : num  0.007989 0.007794 0.000352 0.004296 0.007562 ...
     $ IPDMAT         : num  0.0113 0.00652 0.01044 0.00211 0.01118 ...
     $ IPNMAT         : num  0.014042 0.001707 -0.004866 0.010879 0.000204 ...
     $ IPMANSICS      : num  0.01014 0.00538 0.00579 0.00327 0.0089 ...
     $ IPB51222S      : num  -0.00883 0.04244 -0.02427 -0.04027 0.00958 ...
     $ IPFUELS        : num  0.0048 0.00603 -0.00854 -0.00383 0.00329 ...
     $ CUMFNS         : num  0.6213 0.2372 0.2628 0.0569 0.5077 ...
     $ HWI            : num  140 -104 94 -36 -20 68 -91 55 98 3 ...
     $ HWIURATIO      : num  0.014611 -0.009559 -0.000538 -0.012463 0.003537 ...
     $ CLF16OV        : num  0.003116 0.001856 0.002172 0.00265 0.000809 ...
     $ CE16OV         : num  0.003315 0.002384 -0.000431 0.000372 0.00248 ...
     $ UNRATE         : num  0 0 0.2 0.2 -0.1 ...
     $ UEMPMEAN       : num  0.4 0.3 0.4 0.4 -0.1 ...
     $ UEMPLT5        : num  0.0404 -0.0346 0.0361 0.0291 -0.023 ...
     $ UEMP5TO14      : num  -0.05285 0.00711 -0.01177 0.0075 0.00815 ...
     $ UEMP15OV       : num  0.00439 -0.02087 0.0956 0.08725 -0.03907 ...
     $ UEMP15T26      : num  -0.0365 -0.0321 0.0564 0.0966 -0.0762 ...
     $ UEMP27OV       : num  0.0386 -0.0119 0.1255 0.0804 -0.0122 ...
     $ CLAIMSx        : num  -0.02914 -0.02654 -0.00203 0.00323 0.05573 ...
     $ PAYEMS         : num  0.000498 0.00142 0.001197 0.000607 0.000717 ...
     $ USGOOD         : num  -0.000678 0.000226 0.000136 -0.001718 -0.001041 ...
     $ CES1021000001  : num  -0.00225 -0.00628 -0.00486 -0.01144 -0.00296 ...
     $ USCONS         : num  0.00195 -0.003903 0.000434 -0.004571 -0.003059 ...
     $ MANEMP         : num  -0.001427 0.001546 0.000238 -0.000535 -0.000416 ...
     $ DMANEMP        : num  -0.002104 0.000802 0.0002 -0.001304 -0.002009 ...
     $ NDMANEMP       : num  -0.000439 0.00263 0.000292 0.000583 0.001893 ...
     $ SRVPRD         : num  0.0008 0.00173 0.00147 0.0012 0.00117 ...
     $ USTPU          : num  4.52e-05 4.97e-04 -6.78e-04 1.36e-04 -1.95e-03 ...
     $ USWTRADE       : num  -0.000509 -0.002313 -0.002043 -0.001476 -0.003649 ...
     $ USTRADE        : num  1.56e-05 1.47e-03 -1.17e-04 5.22e-04 -1.68e-03 ...
     $ USFIRE         : num  0.000153 0.001379 0.001835 0.001222 -0.000153 ...
     $ USGOVT         : num  0.00139 0.001282 0.000747 0.00048 0.002927 ...
     $ CES0600000007  : num  40.3 40.5 40.4 40.3 40.3 40.3 40.2 40.3 40.3 40.3 ...
     $ AWOTMAN        : num  0.1 0 0.2 -0.1 0 ...
     $ AWHMAN         : num  40.7 40.8 40.9 40.8 40.8 40.8 40.7 40.8 40.9 40.9 ...
     $ HOUST          : num  7.17 7 7.1 7.04 7.04 ...
     $ HOUSTNE        : num  4.92 4.81 4.82 4.74 4.81 ...
     $ HOUSTMW        : num  5.79 5.47 5.7 5.62 5.6 ...
     $ HOUSTS         : num  6.27 6.17 6.22 6.14 6.16 ...
     $ HOUSTW         : num  5.72 5.57 5.67 5.68 5.61 ...
     $ PERMIT         : num  6.99 6.96 6.96 6.96 6.99 ...
     $ PERMITNE       : num  4.81 4.77 4.83 4.8 4.86 ...
     $ PERMITMW       : num  5.58 5.49 5.55 5.49 5.53 ...
     $ PERMITS        : num  6.1 6.05 6.04 6.08 6.09 ...
     $ PERMITW        : num  5.52 5.59 5.54 5.55 5.59 ...
     $ ACOGNO         : num  0.04458 0.00165 0.02271 0.01092 -0.00382 ...
     $ AMDMNOx        : num  0.04682 0.03636 0.0108 -0.02403 -0.00199 ...
     $ ANDENOx        : num  0.0931 0.0104 0.0242 -0.0371 -0.0105 ...
     $ AMDMUOx        : num  -0.00481 0.00194 0.00191 -0.00509 -0.00927 ...
     $ BUSINVx        : num  0.003853 0.003351 -0.000536 0.006642 0.005653 ...
     $ ISRATIOx       : num  -0.03 0 -0.01 0 -0.01 ...
     $ M1SL           : num  -0.003773 -0.004802 -0.000372 -0.003294 0.005502 ...
     $ M2SL           : num  -0.004398 -0.002381 0.000911 -0.001208 0.001679 ...
     $ M2REAL         : num  -0.00245 -0.0034 -0.00246 -0.00441 -0.00269 ...
     $ BOGMBASE       : num  0.01892 -0.02067 0.01167 0.00355 0.002 ...
     $ TOTRESNS       : num  0.0305 -0.1304 0.0784 0.0465 -0.0082 ...
     $ NONBORRES      : num  0.02896 -0.12317 0.06947 0.04605 -0.00826 ...
     $ BUSLOANS       : num  0.00237 -0.00104 0.00132 0.00173 -0.00106 ...
     $ REALLN         : num  -0.00132 0.0058 -0.00663 -0.00338 0.00177 ...
     $ NONREVSL       : num  -6.43e-05 -4.49e-03 3.65e-03 -2.72e-03 5.74e-03 ...
     $ CONSPI         : num  -0.000498 -0.001173 -0.000825 -0.001014 -0.000115 ...
     $ S&P 500        : num  -0.012684 0.000123 0.018001 -0.015892 0.01647 ...
     $ S&P: indust    : num  -0.01236 -0.000681 0.012694 -0.018013 0.010731 ...
     $ S&P div yield  : num  0.047815 -0.000371 -0.053946 0.047576 -0.04368 ...
     $ S&P PE ratio   : num  0.00689 0.02343 0.0377 -0.00193 0.02857 ...
     $ FEDFUNDS       : num  -0.08 -0.25 0.09 -0.06 -0.51 ...
     $ CP3Mx          : num  0.19 -0.26 -0.16 0.04 -0.48 ...
     $ TB3MS          : num  0.2 -0.29 -0.12 0.03 -0.45 ...
     $ TB6MS          : num  0.25 -0.31 -0.12 0.02 -0.49 ...
     $ GS1            : num  0.34 -0.33 -0.11 -0.02 -0.57 ...
     $ GS5            : num  0.37 -0.17 -0.09 -0.21 -0.64 ...
     $ GS10           : num  0.2 -0.06 -0.09 -0.13 -0.42 ...
     $ AAA            : num  0.06 -0.02 -0.05 -0.06 -0.15 ...
     $ BAA            : num  0.02 -0.04 -0.08 -0.08 -0.21 ...
     $ COMPAPFFx      : num  0.32 0.31 0.06 0.16 0.19 0.08 0.02 0.23 0.57 0.75 ...
     $ TB3SMFFM       : num  0.06 0.02 -0.19 -0.1 -0.04 -0.17 -0.31 -0.24 0.04 0.3 ...
     $ TB6SMFFM       : num  0.2 0.14 -0.07 0.01 0.03 -0.09 -0.26 -0.06 0.25 0.44 ...
     $ T1YFFM         : num  0.65 0.57 0.37 0.41 0.35 0.17 -0.04 0.2 0.59 0.79 ...
     $ T5YFFM         : num  2.97 3.05 2.87 2.72 2.59 2.3 2.16 2.5 2.95 3.16 ...
     $ T10YFFM        : num  3.56 3.75 3.57 3.5 3.59 3.29 3.2 3.49 3.78 3.85 ...
     $ AAAFFM         : num  4.37 4.6 4.46 4.46 4.82 4.65 4.7 4.89 5.01 5.06 ...
     $ BAAFFM         : num  5.27 5.48 5.31 5.29 5.59 5.35 5.4 5.74 5.87 5.89 ...
     $ TWEXAFEGSMTHx  : num  0.02529 -0.00399 -0.01238 -0.02224 -0.02363 ...
     $ EXSZUSx        : num  0.036 0.0066 -0.0191 -0.0451 -0.0655 ...
     $ EXJPUSx        : num  0.03964 0.00508 -0.02095 -0.03056 -0.00755 ...
     $ EXUSUKx        : num  -0.0308 0.0188 0.0297 0.0249 0.0332 ...
      [list output truncated]
     - attr(*, "na.action")= 'omit' Named int [1:402] 1 2 3 4 5 6 7 8 9 10 ...
      ..- attr(*, "names")= chr [1:402] "2" "3" "4" "5" ...

The code is the following so far:


    #define response variable
    y <- df_na$PAYEMS
    #define matrix of predictor variables
    x <- data.matrix(df_na[, !names(df_na) %in% c("PAYEMS", "date")])
    
    # break data into in-sample and out-of-smple
    y.in = y[1:190]; y.out = y[-c(1:190)]
    x.in = x[1:190, ]; x.out = x[-c(1:190), ]
    
    trial <- foreccomb(y.in, x.in, y.out, x.out)
    result <- comb_CSR(trial)

However, as soon as I run the last line, I get the following error:


    > result <- comb_CSR(trial)
    Error in matrix(0, ndiff_models, 4) : 
      invalid 'nrow' value (too large or NA)
    In addition: Warning message:
    In matrix(0, ndiff_models, 4) : NAs introduced by coercion to integer range

The data set does not have any NA values as I get rid of them beforehand. Unfortunately, I do not understand where the error comes from. Does anyone have an idea?

0 Answers
Related