christophsax / tempdisagg

Methods for Temporal Disaggregation and Interpolation of Time Series
http://cran.r-project.org/web/packages/tempdisagg
37 stars 5 forks source link

Fixed coefficients: couldn't get it to work #47

Open p-wegmueller opened 3 years ago

p-wegmueller commented 3 years ago
library(tempdisagg)

y <- structure(c(18691.9350106069, 23725.0240865596, 29853.1581017988, 
                 32003.4549435803, 33200.8537418478, 38286.1540749164, 33615.3428157064, 
                 31906.2390709211, 33095.951378047, 34386.2293769208, 37126.996082888, 
                 41297.9343390959, 45887.5788436728, 41080.7347546249, 38067.6795727664, 
                 37350.159542803, 36420.6764230098, 36362.4981994609, 37705.8249087362, 
                 36290.3781801797, 36140.9788515581, 35819.2638480061, 34899.0363118421, 
                 37183.8521727974, 38414.2796167376, 37906.9691437326), .Tsp = c(1995, 
                                                                                 2020, 1), class = "ts")

x1 <- structure(c(2459.0697238197, 2538.23897897465, 2759.51684335016, 
                  2734.41464236647, 3293.90687514282, 2999.80304031078, 2904.9549249169, 
                  3097.30620889485, 3376.00091396644, 3430.32073044274, 3628.62496537817, 
                  3461.66866189875, 3958.01656618385, 4052.5617784203, 3779.10710622417, 
                  3923.61321792485, 4415.76513876317, 4633.04688869669, 4354.49026807594, 
                  5477.07508995562, 6004.85257475316, 5605.03574198773, 5448.86357403468, 
                  5955.18880730166, 5121.83907224122, 5103.86226345354, 4849.01118792538, 
                  5203.40124008043, 4814.17888825664, 4366.72847424878, 4208.15214876877, 
                  4451.36471353213, 4073.89360824447, 4257.58686490394, 4444.74257603531, 
                  5004.87500304416, 4811.25354587078, 4534.41191515702, 4286.15194877101, 
                  4806.33989799025, 5098.72455975622, 5272.82326169709, 5531.90481663137, 
                  6159.98785074512, 6156.38306687486, 6082.30270064895, 5801.16663861468, 
                  6636.09370358238, 6909.71560577101, 7606.84822322776, 7535.86468976114, 
                  8064.67583220242, 7144.50500488944, 6734.74108124716, 6407.2084327608, 
                  5985.11407202057, 4980.67024785291, 5041.25736600109, 5190.47371556806, 
                  5179.90228267717, 4942.02202162744, 5035.41795582795, 4454.73589109969, 
                  4870.4973692423, 4743.16457068867, 4502.75230264163, 4037.18683516556, 
                  3994.15223011627, 3873.61980779957, 3838.06854201546, 3736.5384840466, 
                  3817.94313622289, 3858.73066868688, 3956.29589831057, 3641.32092986565, 
                  3768.19562145018, 3651.73345918684, 3683.22754297266, 3660.86581844283, 
                  3988.87038855604, 3869.05380782196, 3691.61631880675, 3528.96105304491, 
                  3740.28182840448, 3494.18604540302, 3520.21179444166, 3507.89290221038, 
                  3741.33632939017, 3498.91955289869, 3668.39475464806, 3486.64999322166, 
                  3893.15712245728, 3755.9953287631, 3875.80047616999, 3676.59306084251, 
                  3518.57303525799, 3509.74106534235, 3682.65890318139, 3597.7728943296, 
                  4092.60067343768, 4179.02899983676, 3727.3976026473, 3658.82177325913, 
                  3954.46024989633, 4173.63471845324), .Tsp = c(1995, 2021, 4), class = "ts")

x2 <- structure(c(3059.09641057284, 3128.00373361178, 3274.29385378618, 
                  3485.79772716295, 3808.96504537115, 3950.93028110034, 3898.14932839224, 
                  4001.59371596884, 4240.98880326348, 4514.21661821639, 4706.75204776512, 
                  4701.67258227762, 4778.13003444042, 4759.11003614242, 4674.85714155653, 
                  4608.25292407426, 4590.5474185002, 4709.6490213701, 4601.14550362534, 
                  4646.74741304103, 4699.65019681867, 4906.14933014281, 4658.5318524359, 
                  4722.68726884817, 4663.28407820035, 4731.45150085748, 4438.11745497395, 
                  4554.76985159302, 4482.20809558164, 4614.44058640147, 4793.9632274034, 
                  4819.94356322478, 4806.35290809146, 4970.90225841112, 4908.97913005212, 
                  4810.17742043323, 4766.00326947534, 4775.28307445084, 4753.16106380138, 
                  4649.58583575062, 4794.84873161139, 4914.31930468945, 5079.14350263922, 
                  5045.52006471175, 4998.87623687709, 5023.96147806184, 5050.75410993337, 
                  4981.76813669984, 4977.4234826368, 4878.04782345412, 4973.92945915636, 
                  5129.28256260097, 5059.63629478436, 4880.98613301251, 4897.93233386857, 
                  5226.81467980496, 5467.05083985466, 5548.41121201787, 5526.0347551776, 
                  5592.66113974952, 5446.3600504961, 5557.43063555345, 5386.73296176426, 
                  5359.76899994505, 5314.33586305104, 5243.2697250882, 5313.2070272824, 
                  5532.85562618568, 5586.54172206576, 5522.4390932017, 5535.22352845844, 
                  5464.35461900034, 5430.18574792958, 5576.53882298878, 5749.41301945906, 
                  5782.75600761936, 5737.39362613341, 5684.63849818815, 5631.23088144853, 
                  5570.93935236913, 5665.64475623909, 5718.4109857676, 5782.82315712475, 
                  5798.8036625625, 5736.40861819932, 5677.43090496038, 5579.35209572661, 
                  5630.43154660053, 5569.10187291087, 5613.29150112698, 5609.26526305528, 
                  5650.23079893164, 5660.05686451836, 5780.85608502238, 5793.59582567622, 
                  5857.63317792446, 5921.43170937923, 5930.6059117906, 5808.94633801011, 
                  5636.59305178978, 5470.1369930761, 5487.2197197698, 5263.41708331389, 
                  5202.38765188612, 5111.80220529039), .Tsp = c(1995, 2021, 4), class = "ts")

mod <- td(y ~ x1 + x2,
   method = "chow-lin-maxlog"
   )

summary(mod)

mod$coefficients

alternative <- td(y ~ x1 + x2, 
                  fixed.coef = c(1.241e+01, 1.339e-02), 
                  fixed.rho = 0, 
                  method = "chow-lin-fixed")
christophsax commented 3 years ago

Does it complain about 'unused argument (fixed.coef ...'?

You need to use the version from the experimental branch:

remotes::install_github("christophsax/tempdisagg", ref = "fixed-coef")
p-wegmueller commented 3 years ago

Habe die Entwicklerversion installiert. Die Fehlermeldung ist:

Fehler in X %*% z$coefficients : nicht passende Argumente

christophsax commented 3 years ago

Gotcha. The intercept needs also a coefficient. This works:

td(y ~ x1 + x2, 
                  fixed.coef = c(-2194.898, 1.241e+01, 1.339e-02), 
                  fixed.rho = 0, 
                  method = "chow-lin-fixed")
p-wegmueller commented 3 years ago

Cool! Danke! Related question: how do you optimally choose the coefficients in such a setting?