loop through column names of a data frame with shift - r

all, I'm working on a data set looks like below,
I want create new columns which are lags of variables interested in.
my current code like this,:
library(data.table)
setDF(final)
final.consec<-final[final$priva.consec.count>4 | final$unpriva.consec.count>4,]
interesting.vars<-c("IR", "sales","totalasset","GM","Export","Leverage","ROA")
for (i in interesting.vars) {
#i=as.name(i)
setDT(final.consec)[,paste("L.1.",i):=shift(i,n=1),firmid]
setDT(final.consec)[,paste("L.2.",i):=shift(i,n=2),firmid]
}
but this will produce all NAs instead of the lags and leads I want
I searched google and here, some suggest to use
shift(final.consec[[i]],n=1)
or
shift(as.name(i),n=1)
but none them work.
final = structure(list(year = c(2002, 2003, 2004, 2005, 2006, 2007, 2003,
2004, 2005, 2006, 2007, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007), firmid = c("016016226", "016016226", "016016226", "016016226",
"016016226", "016016226", "101100393", "101100393", "101100393",
"101100393", "101100393", "101100481", "101100481", "101100481",
"101100481", "101100481", "101100481", "101100481", "101100481",
"101100481", "101100588", "101100588", "101100588", "101100588",
"101100588", "101100588", "101100588", "101100588", "101100588",
"101100588"), provinceid = c(610000, 610000, 610000, 610000,
610000, 610000, 110000, 110000, 110000, 110000, 110000, 110000,
110000, 110000, 110000, 110000, 110000, 110000, 110000, 110000,
110000, 110000, 110000, 110000, 110000, 110000, 110000, 110000,
110000, 110000), industrycode2 = c(3100, 3100, 3100, 3100, 3100,
3100, 3100, 3100, 3100, 3100, 3100, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300), sales = c(1998, 2995, 2902, 5006, 5291, 6241,
98670, 60643, 79075, 93600, 55591, 6525, 7984, 7654, 7432, 7596,
8410, 7359, 5456, 6645, 10355, 9498, 8967, 11551, 13647, 14008,
20647, 21437, 20155, 14535), cogs = c(1602, 898, 1301, 1453,
2615, 2835, 66143, 40037, 55971, 66167, 46862, 7430, 7487, 6820,
7482, 7436, 7905, 7243, 6560, 6605, 8126, 7868, 8722, 8700, 11222,
11521, 18282, 20322, 17859, 12913), inventory = c(1034, 1012,
896, 653, 1685, 2036, 16690, 29623, 28770, 27124, 6712, 0, 0,
0, 93, 21, 79, 78, 18, 797, 1778, 1588, 2785, 3414, 4435, 4147,
5874, 5339, 3991, 3345), fixedasset = c(29577, 30856, 28250,
28245, 28168, 27919, 77646, 101803, 94984, 84585, 54935, 18418,
17192, 17518, 13219, 16600, 14132, 20737, 21332, 25192, 15423,
7028, 5513, 11679, 9364, 35778, 59804, 65344, 69266, 73777),
totalasset = c(74278, 74358, 74000, 74006, 74011, 73913,
273642, 321636, 357791, 373095, 340400, 31312, 31242, 35461,
42755, 47784, 43798, 41565, 40220, 45753, 30114, 31164, 31347,
31526, 32244, 61842, 87170, 88730, 98821, 104000), stateshare = c(1,
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1), foreignshare = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0), privateshare = c(0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0), stateown = c(1, 1, 1, 1, 1, 1, 1, 1, 0,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1), foreignown = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), privateown = c(0,
0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0), mixown = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0), stateonly = c(1, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1), mixonly = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), foreignonly = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0), privateonly = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0), gs = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1), gm = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), gf = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0), privatize = c(0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0), IR = c(0.645443201065063, 1.12694883346558,
0.688700973987579, 0.449414998292923, 0.644359469413757,
0.718165755271912, 0.25233206152916, 0.739890575408936, 0.514016211032867,
0.409932434558868, 0.143229052424431, 0.0191550496965647,
0.0137506183236837, 0.0117767816409469, 0.0124298315495253,
0.00526109151542187, 0.00999367516487837, 0.0107690179720521,
0.00274390238337219, 0.120666161179543, 0.218803837895393,
0.201830193400383, 0.319307506084442, 0.392413794994354,
0.395205855369568, 0.3599514067173, 0.321299642324448, 0.262720197439194,
0.223472759127617, 0.259041279554367), GM = c(0.24719101190567,
0.807359278202057, 0.702536523342133, 0.714905440807343,
0.717204809188843, 0.731220781803131, 0.491767823696136,
0.514673948287964, 0.412785202264786, 0.41460245847702, 0.186270326375961,
-0.0678684562444687, 0.0663817301392555, 0.122287392616272,
-0.00668270513415337, 0.0215169452130795, 0.0638836175203323,
0.016015462577343, 0.00807300768792629, 0.014724993146956,
0.274304687976837, 0.207168281078339, 0.0280898883938789,
0.327701151371002, 0.216093391180038, 0.215866684913635,
0.129362210631371, 0.0548666454851627, 0.12856262922287,
0.125609844923019), CI = c(0.398193269968033, 0.414965450763702,
0.381756752729416, 0.381658256053925, 0.380592077970505,
0.377727866172791, 0.283750295639038, 0.316516190767288,
0.265473425388336, 0.226711690425873, 0.161383673548698,
0.588208973407745, 0.550284862518311, 0.494007498025894,
0.309180200099945, 0.347396612167358, 0.322663128376007,
0.498905330896378, 0.530382871627808, 0.550608694553375,
0.512153804302216, 0.225516617298126, 0.175870105624199,
0.370456129312515, 0.290410608053207, 0.578538835048676,
0.68606173992157, 0.728544950485229, 0.700923919677734, 0.709394216537476
), WACC = c(0.000888553797267377, 0.000511041202116758, 0.000527027004864067,
0.000459422240965068, 0.000513437204062939, 0.000608823902439326,
0.0238377153873444, 0.030428808182478, 0.0118085695430636,
0.0155402785167098, 0.00844594556838274, -0.0610947869718075,
-0.0143076628446579, -0.0111107975244522, 0.00177756987977773,
-0.0173279754817486, -0.0689300894737244, -0.0779983177781105,
-0.0916144475340843, -0.0209603756666183, -0.00126187154091895,
0.000481324619613588, 0.000191405866644345, 0.000348918343661353,
0.00533432560041547, -3.23404929076787e-05, -0.000206493074074388,
-0.0318719707429409, -0.0211898274719715, 0.00500000035390258
), Salesgrowth = c(NA, 0.404797554016113, -0.301691830158234,
0.210879027843475, 0.648279845714569, 0.0701394379138947,
NA, -0.486776739358902, 0.265392541885376, 0.168633610010147,
-0.496754705905914, NA, 0.201798588037491, -0.042211152613163,
-0.029433386400342, 0.0218267906457186, 0.101799681782722,
-0.133497416973114, -0.299208134412766, 0.197148770093918,
NA, -0.0863882452249527, -0.0575300790369511, 0.253220856189728,
0.166747704148293, 0.0261088777333498, 0.3879414498806, 0.0375483706593513,
-0.0616660043597221, -0.326892852783203), Export = c(0, 0,
0, 0, 0, 0, 0.0718493312597275, 0.0859285816550255, 0.113112106919289,
0.287075728178024, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0), Leverage = c(10.397575378418, 10.444974899292,
11.0325202941895, 10.0521974563599, 1.022047996521, 1.01452708244324,
1.45040833950043, 1.67869281768799, 1.03448712825775, 1.11970138549805,
0.892383217811584, 1.10642445087433, 1.03876268863678, 1.37419652938843,
1.84710657596588, 3.55129051208496, 4.52725887298584, 7.83046531677246,
10.0521974563599, 9.32586765289307, 0.210126578807831, 0.234657898545265,
0.242646470665932, 0.251528382301331, 0.28160896897316, 1.45746076107025,
2.464350938797, 2.97518038749695, 3.88535690307617, 0.26302495598793
), Current = c(1.55197286605835, 1.69315719604492, 2.29052948951721,
2.24755930900574, 2.20689654350281, 2.10811376571655, 1.25970602035522,
1.65375781059265, 1.66235971450806, 1.39208269119263, 1.29157769680023,
0.969440996646881, 0.790197372436523, 0.650628983974457,
0.69122976064682, 1.09663212299347, 1.12163543701172, 1.6644686460495,
1.97333335876465, 2.0823986530304, 0.435712337493896, 0.577177941799164,
0.511789321899414, 0.731555223464966, 0.587089836597443,
2.40473389625549, 2.29052948951721, 2.24755930900574, 2.20689654350281,
1.11392271518707), Cover = c(0.395348846912384, 0.260869562625885,
0.209302321076393, 0.0377358496189117, 0.00228310492821038,
0.00416666688397527, 0.952529191970825, 0.885167479515076,
0.762962937355042, 0.727603793144226, -0.188469097018242,
0.00704225338995457, 0.0597014911472797, 0.0273972600698471,
-0.0126262623816729, 0.0230215825140476, 0.0177725125104189,
0.00775716686621308, -0.00155763234943151, 0.0120259020477533,
0.0303643718361855, 0, 0.00171057134866714, 0.00918484479188919,
0.389791190624237, -0.0153139354661107, -0.0214592274278402,
-0.00146555935498327, 0.00122399022802711, -0.00661703897640109
), Bank = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1), Inctaxrate = c(0,
0, 0.0666666701436043, 0, 0, 0, 0, 0.0026208502240479, 0.0247787609696388,
0.0154994260519743, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.142857149243355,
0.200000002980232, 0.181818187236786, 0.335363984107971,
0.333333343267441, 0.333333343267441, 0.33047690987587, 0,
0, 0), ROA = c(0.000659683893900365, 0.000430350453825668,
0.000405405415222049, 0.00043239738442935, 0.000499925692565739,
0.000595294462982565, 0.0148917194455862, 0.021353330463171,
0.00473740277811885, 0.00933810416609049, 0.00366333732381463,
-0.0607434846460819, -0.0158440563827753, -0.0109415976330638,
0.00189451524056494, -0.0169931352138519, -0.067902646958828,
-0.077444963157177, -0.0968421399593353, -0.0206762403249741,
0.000232450023759156, 0.000481324619613588, 0.000350910762790591,
9.51595502556302e-05, 0.000124054087791592, 0.000129361927974969,
2.29436736844946e-05, -0.0319057814776897, -0.0211797095835209,
0.00492307683452964), ROS = c(0.02452452480793, 0.0106844743713737,
0.0135440183803439, 0.0117001831531525, 0.00707456981763244,
0.00784313771873713, 0.0412992797791958, 0.113252975046635,
0.0214353464543819, 0.037222221493721, 0.0224316883832216,
-0.291494250297546, -0.0619989968836308, -0.0506924502551556,
0.0108988154679537, -0.106898367404938, -0.241563051939011,
-0.216171622276306, -0.163818180561066, -0.142362684011459,
0.000676001945976168, 0.00157927989494056, 0.00122672016732395,
0.000259717780863866, 0.000293104705633596, 0.000571102253161371,
9.68663734965958e-05, -0.132061392068863, -0.103845201432705,
0.0352253168821335), num_ID = c(66, 66, 66, 66, 66, 66, 95,
95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 96, 96, 96, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100), priva = c(0L,
0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
priva.year = c(0, 0, 0, 0, 0, 0, 2005, 2005, 2005, 2005,
2005, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0), relative.year = c(NA, NA, NA, NA, NA, NA, -2, -1,
0, 1, 2, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA), priva.consec.count = c(0L, 0L,
0L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 5L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), unpriva.consec.count = c(5,
5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9), `L.1. IR` = c(NA, 0.645443201065063,
1.12694883346558, 0.688700973987579, 0.449414998292923, 0.644359469413757,
NA, 0.25233206152916, 0.739890575408936, 0.514016211032867,
0.409932434558868, NA, 0.0191550496965647, 0.0137506183236837,
0.0117767816409469, 0.0124298315495253, 0.00526109151542187,
0.00999367516487837, 0.0107690179720521, 0.00274390238337219,
NA, 0.218803837895393, 0.201830193400383, 0.319307506084442,
0.392413794994354, 0.395205855369568, 0.3599514067173, 0.321299642324448,
0.262720197439194, 0.223472759127617), `L.2. IR` = c(NA,
NA, 0.645443201065063, 1.12694883346558, 0.688700973987579,
0.449414998292923, NA, NA, 0.25233206152916, 0.739890575408936,
0.514016211032867, NA, NA, 0.0191550496965647, 0.0137506183236837,
0.0117767816409469, 0.0124298315495253, 0.00526109151542187,
0.00999367516487837, 0.0107690179720521, NA, NA, 0.218803837895393,
0.201830193400383, 0.319307506084442, 0.392413794994354,
0.395205855369568, 0.3599514067173, 0.321299642324448, 0.262720197439194
), `H.1. IR` = c(1.12694883346558, 0.688700973987579, 0.449414998292923,
0.644359469413757, 0.718165755271912, NA, 0.739890575408936,
0.514016211032867, 0.409932434558868, 0.143229052424431,
NA, 0.0137506183236837, 0.0117767816409469, 0.0124298315495253,
0.00526109151542187, 0.00999367516487837, 0.0107690179720521,
0.00274390238337219, 0.120666161179543, NA, 0.201830193400383,
0.319307506084442, 0.392413794994354, 0.395205855369568,
0.3599514067173, 0.321299642324448, 0.262720197439194, 0.223472759127617,
0.259041279554367, NA), `H.2. IR` = c(0.688700973987579,
0.449414998292923, 0.644359469413757, 0.718165755271912,
NA, NA, 0.514016211032867, 0.409932434558868, 0.143229052424431,
NA, NA, 0.0117767816409469, 0.0124298315495253, 0.00526109151542187,
0.00999367516487837, 0.0107690179720521, 0.00274390238337219,
0.120666161179543, NA, NA, 0.319307506084442, 0.392413794994354,
0.395205855369568, 0.3599514067173, 0.321299642324448, 0.262720197439194,
0.223472759127617, 0.259041279554367, NA, NA), `L.1. sales` = c(NA,
1998, 2995, 2902, 5006, 5291, NA, 98670, 60643, 79075, 93600,
NA, 6525, 7984, 7654, 7432, 7596, 8410, 7359, 5456, NA, 10355,
9498, 8967, 11551, 13647, 14008, 20647, 21437, 20155), `L.2. sales` = c(NA,
NA, 1998, 2995, 2902, 5006, NA, NA, 98670, 60643, 79075,
NA, NA, 6525, 7984, 7654, 7432, 7596, 8410, 7359, NA, NA,
10355, 9498, 8967, 11551, 13647, 14008, 20647, 21437), `H.1. sales` = c(2995,
2902, 5006, 5291, 6241, NA, 60643, 79075, 93600, 55591, NA,
7984, 7654, 7432, 7596, 8410, 7359, 5456, 6645, NA, 9498,
8967, 11551, 13647, 14008, 20647, 21437, 20155, 14535, NA
), `H.2. sales` = c(2902, 5006, 5291, 6241, NA, NA, 79075,
93600, 55591, NA, NA, 7654, 7432, 7596, 8410, 7359, 5456,
6645, NA, NA, 8967, 11551, 13647, 14008, 20647, 21437, 20155,
14535, NA, NA), `L.1. totalasset` = c(NA, 74278, 74358, 74000,
74006, 74011, NA, 273642, 321636, 357791, 373095, NA, 31312,
31242, 35461, 42755, 47784, 43798, 41565, 40220, NA, 30114,
31164, 31347, 31526, 32244, 61842, 87170, 88730, 98821),
`L.2. totalasset` = c(NA, NA, 74278, 74358, 74000, 74006,
NA, NA, 273642, 321636, 357791, NA, NA, 31312, 31242, 35461,
42755, 47784, 43798, 41565, NA, NA, 30114, 31164, 31347,
31526, 32244, 61842, 87170, 88730), `H.1. totalasset` = c(74358,
74000, 74006, 74011, 73913, NA, 321636, 357791, 373095, 340400,
NA, 31242, 35461, 42755, 47784, 43798, 41565, 40220, 45753,
NA, 31164, 31347, 31526, 32244, 61842, 87170, 88730, 98821,
104000, NA), `H.2. totalasset` = c(74000, 74006, 74011, 73913,
NA, NA, 357791, 373095, 340400, NA, NA, 35461, 42755, 47784,
43798, 41565, 40220, 45753, NA, NA, 31347, 31526, 32244,
61842, 87170, 88730, 98821, 104000, NA, NA), `L.1. GM` = c(NA,
0.24719101190567, 0.807359278202057, 0.702536523342133, 0.714905440807343,
0.717204809188843, NA, 0.491767823696136, 0.514673948287964,
0.412785202264786, 0.41460245847702, NA, -0.0678684562444687,
0.0663817301392555, 0.122287392616272, -0.00668270513415337,
0.0215169452130795, 0.0638836175203323, 0.016015462577343,
0.00807300768792629, NA, 0.274304687976837, 0.207168281078339,
0.0280898883938789, 0.327701151371002, 0.216093391180038,
0.215866684913635, 0.129362210631371, 0.0548666454851627,
0.12856262922287), `L.2. GM` = c(NA, NA, 0.24719101190567,
0.807359278202057, 0.702536523342133, 0.714905440807343,
NA, NA, 0.491767823696136, 0.514673948287964, 0.412785202264786,
NA, NA, -0.0678684562444687, 0.0663817301392555, 0.122287392616272,
-0.00668270513415337, 0.0215169452130795, 0.0638836175203323,
0.016015462577343, NA, NA, 0.274304687976837, 0.207168281078339,
0.0280898883938789, 0.327701151371002, 0.216093391180038,
0.215866684913635, 0.129362210631371, 0.0548666454851627),
`H.1. GM` = c(0.807359278202057, 0.702536523342133, 0.714905440807343,
0.717204809188843, 0.731220781803131, NA, 0.514673948287964,
0.412785202264786, 0.41460245847702, 0.186270326375961, NA,
0.0663817301392555, 0.122287392616272, -0.00668270513415337,
0.0215169452130795, 0.0638836175203323, 0.016015462577343,
0.00807300768792629, 0.014724993146956, NA, 0.207168281078339,
0.0280898883938789, 0.327701151371002, 0.216093391180038,
0.215866684913635, 0.129362210631371, 0.0548666454851627,
0.12856262922287, 0.125609844923019, NA), `H.2. GM` = c(0.702536523342133,
0.714905440807343, 0.717204809188843, 0.731220781803131,
NA, NA, 0.412785202264786, 0.41460245847702, 0.186270326375961,
NA, NA, 0.122287392616272, -0.00668270513415337, 0.0215169452130795,
0.0638836175203323, 0.016015462577343, 0.00807300768792629,
0.014724993146956, NA, NA, 0.0280898883938789, 0.327701151371002,
0.216093391180038, 0.215866684913635, 0.129362210631371,
0.0548666454851627, 0.12856262922287, 0.125609844923019,
NA, NA), `L.1. Export` = c(NA, 0, 0, 0, 0, 0, NA, 0.0718493312597275,
0.0859285816550255, 0.113112106919289, 0.287075728178024,
NA, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0
), `L.2. Export` = c(NA, NA, 0, 0, 0, 0, NA, NA, 0.0718493312597275,
0.0859285816550255, 0.113112106919289, NA, NA, 0, 0, 0, 0,
0, 0, 0, NA, NA, 0, 0, 0, 0, 0, 0, 0, 0), `H.1. Export` = c(0,
0, 0, 0, 0, NA, 0.0859285816550255, 0.113112106919289, 0.287075728178024,
1, NA, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0,
0, NA), `H.2. Export` = c(0, 0, 0, 0, NA, NA, 0.113112106919289,
0.287075728178024, 1, NA, NA, 0, 0, 0, 0, 0, 0, 0, NA, NA,
0, 0, 0, 0, 0, 0, 0, 0, NA, NA), `L.1. Leverage` = c(NA,
10.397575378418, 10.444974899292, 11.0325202941895, 10.0521974563599,
1.022047996521, NA, 1.45040833950043, 1.67869281768799, 1.03448712825775,
1.11970138549805, NA, 1.10642445087433, 1.03876268863678,
1.37419652938843, 1.84710657596588, 3.55129051208496, 4.52725887298584,
7.83046531677246, 10.0521974563599, NA, 0.210126578807831,
0.234657898545265, 0.242646470665932, 0.251528382301331,
0.28160896897316, 1.45746076107025, 2.464350938797, 2.97518038749695,
3.88535690307617), `L.2. Leverage` = c(NA, NA, 10.397575378418,
10.444974899292, 11.0325202941895, 10.0521974563599, NA,
NA, 1.45040833950043, 1.67869281768799, 1.03448712825775,
NA, NA, 1.10642445087433, 1.03876268863678, 1.37419652938843,
1.84710657596588, 3.55129051208496, 4.52725887298584, 7.83046531677246,
NA, NA, 0.210126578807831, 0.234657898545265, 0.242646470665932,
0.251528382301331, 0.28160896897316, 1.45746076107025, 2.464350938797,
2.97518038749695), `H.1. Leverage` = c(10.444974899292, 11.0325202941895,
10.0521974563599, 1.022047996521, 1.01452708244324, NA, 1.67869281768799,
1.03448712825775, 1.11970138549805, 0.892383217811584, NA,
1.03876268863678, 1.37419652938843, 1.84710657596588, 3.55129051208496,
4.52725887298584, 7.83046531677246, 10.0521974563599, 9.32586765289307,
NA, 0.234657898545265, 0.242646470665932, 0.251528382301331,
0.28160896897316, 1.45746076107025, 2.464350938797, 2.97518038749695,
3.88535690307617, 0.26302495598793, NA), `H.2. Leverage` = c(11.0325202941895,
10.0521974563599, 1.022047996521, 1.01452708244324, NA, NA,
1.03448712825775, 1.11970138549805, 0.892383217811584, NA,
NA, 1.37419652938843, 1.84710657596588, 3.55129051208496,
4.52725887298584, 7.83046531677246, 10.0521974563599, 9.32586765289307,
NA, NA, 0.242646470665932, 0.251528382301331, 0.28160896897316,
1.45746076107025, 2.464350938797, 2.97518038749695, 3.88535690307617,
0.26302495598793, NA, NA), `L.1. ROA` = c(NA, 0.000659683893900365,
0.000430350453825668, 0.000405405415222049, 0.00043239738442935,
0.000499925692565739, NA, 0.0148917194455862, 0.021353330463171,
0.00473740277811885, 0.00933810416609049, NA, -0.0607434846460819,
-0.0158440563827753, -0.0109415976330638, 0.00189451524056494,
-0.0169931352138519, -0.067902646958828, -0.077444963157177,
-0.0968421399593353, NA, 0.000232450023759156, 0.000481324619613588,
0.000350910762790591, 9.51595502556302e-05, 0.000124054087791592,
0.000129361927974969, 2.29436736844946e-05, -0.0319057814776897,
-0.0211797095835209), `L.2. ROA` = c(NA, NA, 0.000659683893900365,
0.000430350453825668, 0.000405405415222049, 0.00043239738442935,
NA, NA, 0.0148917194455862, 0.021353330463171, 0.00473740277811885,
NA, NA, -0.0607434846460819, -0.0158440563827753, -0.0109415976330638,
0.00189451524056494, -0.0169931352138519, -0.067902646958828,
-0.077444963157177, NA, NA, 0.000232450023759156, 0.000481324619613588,
0.000350910762790591, 9.51595502556302e-05, 0.000124054087791592,
0.000129361927974969, 2.29436736844946e-05, -0.0319057814776897
), `H.1. ROA` = c(0.000430350453825668, 0.000405405415222049,
0.00043239738442935, 0.000499925692565739, 0.000595294462982565,
NA, 0.021353330463171, 0.00473740277811885, 0.00933810416609049,
0.00366333732381463, NA, -0.0158440563827753, -0.0109415976330638,
0.00189451524056494, -0.0169931352138519, -0.067902646958828,
-0.077444963157177, -0.0968421399593353, -0.0206762403249741,
NA, 0.000481324619613588, 0.000350910762790591, 9.51595502556302e-05,
0.000124054087791592, 0.000129361927974969, 2.29436736844946e-05,
-0.0319057814776897, -0.0211797095835209, 0.00492307683452964,
NA), `H.2. ROA` = c(0.000405405415222049, 0.00043239738442935,
0.000499925692565739, 0.000595294462982565, NA, NA, 0.00473740277811885,
0.00933810416609049, 0.00366333732381463, NA, NA, -0.0109415976330638,
0.00189451524056494, -0.0169931352138519, -0.067902646958828,
-0.077444963157177, -0.0968421399593353, -0.0206762403249741,
NA, NA, 0.000350910762790591, 9.51595502556302e-05, 0.000124054087791592,
0.000129361927974969, 2.29436736844946e-05, -0.0319057814776897,
-0.0211797095835209, 0.00492307683452964, NA, NA)), .Names = c("year",
"firmid", "provinceid", "industrycode2", "sales", "cogs", "inventory",
"fixedasset", "totalasset", "stateshare", "foreignshare", "privateshare",
"stateown", "foreignown", "privateown", "mixown", "stateonly",
"mixonly", "foreignonly", "privateonly", "gs", "gm", "gf", "privatize",
"IR", "GM", "CI", "WACC", "Salesgrowth", "Export", "Leverage",
"Current", "Cover", "Bank", "Inctaxrate", "ROA", "ROS", "num_ID",
"priva", "priva.year", "relative.year", "priva.consec.count",
"unpriva.consec.count", "L.1. IR", "L.2. IR", "H.1. IR", "H.2. IR",
"L.1. sales", "L.2. sales", "H.1. sales", "H.2. sales", "L.1. totalasset",
"L.2. totalasset", "H.1. totalasset", "H.2. totalasset", "L.1. GM",
"L.2. GM", "H.1. GM", "H.2. GM", "L.1. Export", "L.2. Export",
"H.1. Export", "H.2. Export", "L.1. Leverage", "L.2. Leverage",
"H.1. Leverage", "H.2. Leverage", "L.1. ROA", "L.2. ROA", "H.1. ROA",
"H.2. ROA"), row.names = c(NA, 30L), class = "data.frame")
==================================update=================================
according to Frank's answer, the solution to this problem is :
setDT(final.consec)#### with out this, below won'r work
interesting.vars<-c("IR", "sales","totalasset","GM","Export","Leverage","ROA")
##### lead 1
anscols.Lead1 = paste("Lead.1", interesting.vars, sep="_")
final.consec[, (anscols.Lead1 ) := shift(.SD, 1,NA,type = "lead"), .SDcols=interesting.vars,by = firmid]

Related

Marginal Effect Plot with ggeffects package

The command predict <- ggpredict(fit_tw1, terms = "pko_dummy") does not work and it gives me the following error. Do you know how to solve my problem?
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : factor as.factor(pa_dummy) has new level 0.0906593406593407
Can you help me?
Model: (The Model has fixed effects for countries (cown) and years (year))
fit_tw1 <- lm(parl_wom.per ~ as.factor(pko_dummy)*as.factor(pa_dummy) + as.factor(cown) + as.factor(year) + female_pko.per + lf_wom.per + ss.per + fdi.per + jud_ind.per + polity + as.factor(intensity_level) + as.factor(cons_ref),
data = subset(data9, rownames!="639"))
Reproducible sample of the dataset
structure(list(cown = c(432, 432, 432, 432, 432, 432, 432, 432,
432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432),
year = c(1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
2008, 2009), intensity_level = c("1", "1", "0", "0", "1",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"1", "1", "1"), pa_dummy = c(0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0), pko_dummy = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), parl_wom.per = c(NA,
NA, 0.023, 0.023, 0.023, 0.023, 0.023, 0.122449, 0.122449,
0.122449, 0.122449, 0.122449, 0.1020408, 0.1020408, 0.1020408,
0.1020408, 0.1020408, 0.1020408, 0.1020408, 0.1020408), exe_wom.per = c(0.0588235,
0.1052632, 0.0526316, 0.0952381, 0.1111111, 0.0555556, 0.125,
0.1176471, 0.2608696, 0.2727273, 0.45, 0.4210526, 0.15, 0.15,
0.15, 0.1923077, 0.1923077, 0.1923077, 0.1851852, 0.1785714
), gender_mean = c(0, 0, 1.75, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0), gender_art = c(0, 0, 7, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), female_pko.per = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
lf_wom.per = c(0.60855, 0.60834, 0.6082, 0.60815, 0.6082,
0.60838, 0.60806, 0.60798, 0.60804, 0.60811, 0.60813, 0.60782,
0.60752, 0.60725, 0.60701, 0.60681, 0.60616, 0.60564, 0.60525,
0.60495), ss.per = c(0.0679798984527588, 0.0723097991943359,
0.0827134037017822, 0.0837932968139648, 0.0957365036010742,
0.107322397232056, 0.112752199172974, 0.122838802337646,
0.133676099777222, 0.151076498031616, 0.174537200927734,
NA, NA, 0.221253795623779, 0.239939594268799, 0.25832540512085,
0.277074604034424, 0.303055400848389, 0.33731990814209, 0.36671989440918
), fdi.per = c(0.0021364, 0.0004424, -0.0077276, 0.001441,
0.0083661, 0.0411724, 0.009786, 0.0275705, 0.0032724, 0.0090061,
0.0203215, 0.0602065, -0.0031506, 0.0153489, 0.015555, 0.0256452,
0.0214593, 0.0252638, 0.0270809, 0.0631946), ele.sy = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
polity = c(-7, NA, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
7, 7, 7, 7, 7), mus.per = c(0.944, 0.944, 0.944, 0.944, 0.944,
0.944, 0.944, 0.944, 0.944, 0.944, 0.944, 0.944, 0.944, 0.944,
0.944, 0.944, 0.944, 0.944, 0.944, 0.944), cons_ref = c(0,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
jud_ind.per = c(0.476311308991478, 0.523786338536123, 0.557528417528326,
0.548066004702523, 0.548066004702523, 0.548066004702523,
0.548066004702523, 0.548066004702523, 0.548066004702523,
0.548066004702523, 0.548066004702523, 0.548066004702523,
0.548066004702523, 0.548066004702523, 0.548066004702523,
0.539288342106394, 0.539288342106394, 0.548066004702523,
0.539288342106394, 0.539288342106394)), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))

How to set NA values from a matrix to black-coloured tiles in a ggplot heatmap

I am working on the following structure and the following plotting code:
structure(c(NA, 11, 9, 9, 21, 7, 2, 5, 3, 0, 0, 1, 31, NA, 3,
2, 1, 0, 0, 10, 3, 0, 0, 0, 31, 16, NA, 2, 2, 10, 0, 5, 0, 0,
0, 0, 59, 65, 1, NA, 2, 4, 0, 4, 0, 0, 0, 0, 156, 23, 7, 17,
NA, 3, 2, 4, 7, 0, 0, 0, 31, 84, 0, 10, 16, NA, 0, 6, 0, 0, 2,
0, 129, 0, 2, 1, 0, 0, NA, 0, 0, 0, 0, 0, 41, 41, 0, 3, 4, 5,
0, NA, 0, 0, 0, 1, 16, 4, 1, 2, 0, 0, 0, 3, NA, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 1, 12, 2, 0, 0, 6, 0, 0, 0, 0,
NA, 0, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), .Dim = c(12L,
12L), .Dimnames = list(c("WILL_", "WOULD_", "MAY_", "MIGHT_",
"CAN_", "COULD_", "SHALL_", "SHOULD_", "MUST_", "OUGHT TO_",
"USED TO_", "HAVE TO_"), c("_WILL", "_WOULD", "_MAY", "_MIGHT",
"_CAN", "_COULD", "_SHALL", "_SHOULD", "_MUST", "_OUGHT TO",
"_USED TO", "_HAVE TO")))
breaks <- c(0,1,5,10,50,100,500,100000)
reshape2::melt(structure, value.name = "Freq") %>%
mutate(label = ifelse(is.na(Freq) | Freq == 0, "", as.character(Freq))) %>%
ggplot(aes(Var2, fct_rev(Var1))) +
geom_tile(aes(fill = Freq), color = "black") +
geom_text(aes(label = label), color = "black") +
scale_fill_steps(low = "white", high = "purple", breaks = breaks, na.value = "grey",trans = "log")+
scale_x_discrete(NULL, expand = c(0, 0), position="top") +
scale_y_discrete(NULL, expand = c(0, 0)) +
theme(axis.text.x = element_text(angle=60,vjust = 0.5, hjust = 0))
I am trying to tweak the code so that original NA values (seen on the plot as the tiles forming a diagonal line from the co-occurrence of WILL WILL to HAVE TO HAVE TO, and the X HAVE TO column) are represented as black tiles separately from the other tiles which I would like to keep as they are.
Looking for tips on how to do this as I think I'm doing something wrong with the representation of values at the beginning of my code.
All the best
Cameron

daily time series containing both 0 and NA to monthly conversion using xts

I am having daily time-series data with both 0 and NA values. I want to convert it into monthly data using xts package in R. I am using the following code
xx=as.Date(dat$Date)
yy=dat$Value
Rain <- xts(yy, order.by = xx)
apply.monthly(Rain, FUN=sum, na.rm=TRUE)
It is returning me zeros for NA values. As the data also contains zeros, it is difficult to distinguish between Zeros and NA values. When I am using na.pass=Tlike
apply.monthly(Rain, FUN=sum, na.pass=TRUE)
It is giving me NAs but the zeros are replaced by 1.
I want the monthly values should contain NA, where there are NAs in the original time-series and 0s in the time-series, should remain 0. How to achieve it?
Here is the data
dat <-structure(list(Date = structure(1:1310, .Label = c("1991-06-01",
"1991-06-02", "1991-06-03", "1991-06-04", "1991-06-05", "1991-06-06",
"1991-06-07", "1991-06-08", "1991-06-09", "1991-06-10", "1991-06-11",
"1991-06-12", "1991-06-13", "1991-06-14", "1991-06-15", "1991-06-16",
"1991-06-17", "1991-06-18", "1991-06-19", "1991-06-20", "1991-06-21",
"1991-06-22", "1991-06-23", "1991-06-24", "1991-06-25", "1991-06-26",
"1991-06-27", "1991-06-28", "1991-06-29", "1991-06-30", "1991-07-01",
"1991-07-02", "1991-07-03", "1991-07-04", "1991-07-05", "1991-07-06",
"1991-07-07", "1991-07-08", "1991-07-09", "1991-07-10", "1991-07-11",
"1991-07-12", "1991-07-13", "1991-07-14", "1991-07-15", "1991-07-16",
"1991-07-17", "1991-07-18", "1991-07-19", "1991-07-20", "1991-07-21",
"1991-07-22", "1991-07-23", "1991-07-24", "1991-07-25", "1991-07-26",
"1991-07-27", "1991-07-28", "1991-07-29", "1991-07-30", "1991-07-31",
"1991-08-01", "1991-08-02", "1991-08-03", "1991-08-04", "1991-08-05",
"1991-08-06", "1991-08-07", "1991-08-08", "1991-08-09", "1991-08-10",
"1991-08-11", "1991-08-12", "1991-08-13", "1991-08-14", "1991-08-15",
"1991-08-16", "1991-08-17", "1991-08-18", "1991-08-19", "1991-08-20",
"1991-08-21", "1991-08-22", "1991-08-23", "1991-08-24", "1991-08-25",
"1991-08-26", "1991-08-27", "1991-08-28", "1991-08-29", "1991-08-30",
"1991-08-31", "1991-09-01", "1991-09-02", "1991-09-03", "1991-09-04",
"1991-09-05", "1991-09-06", "1991-09-07", "1991-09-08", "1991-09-09",
"1991-09-10", "1991-09-11", "1991-09-12", "1991-09-13", "1991-09-14",
"1991-09-15", "1991-09-16", "1991-09-17", "1991-09-18", "1991-09-19",
"1991-09-20", "1991-09-21", "1991-09-22", "1991-09-23", "1991-09-24",
"1991-09-25", "1991-09-26", "1991-09-27", "1991-09-28", "1991-09-29",
"1991-09-30", "1991-10-01", "1991-10-02", "1991-10-03", "1991-10-04",
"1991-10-05", "1991-10-06", "1991-10-07", "1991-10-08", "1991-10-09",
"1991-10-10", "1991-10-11", "1991-10-12", "1991-10-13", "1991-10-14",
"1991-10-15", "1991-10-16", "1991-10-17", "1991-10-18", "1991-10-19",
"1991-10-20", "1991-10-21", "1991-10-22", "1991-10-23", "1991-10-24",
"1991-10-25", "1991-10-26", "1991-10-27", "1991-10-28", "1991-10-29",
"1991-10-30", "1991-10-31", "1991-11-01", "1991-11-02", "1991-11-03",
"1991-11-04", "1991-11-05", "1991-11-06", "1991-11-07", "1991-11-08",
"1991-11-09", "1991-11-10", "1991-11-11", "1991-11-12", "1991-11-13",
"1991-11-14", "1991-11-15", "1991-11-16", "1991-11-17", "1991-11-18",
"1991-11-19", "1991-11-20", "1991-11-21", "1991-11-22", "1991-11-23",
"1991-11-24", "1991-11-25", "1991-11-26", "1991-11-27", "1991-11-28",
"1991-11-29", "1991-11-30", "1991-12-01", "1991-12-02", "1991-12-03",
"1991-12-04", "1991-12-05", "1991-12-06", "1991-12-07", "1991-12-08",
"1991-12-09", "1991-12-10", "1991-12-11", "1991-12-12", "1991-12-13",
"1991-12-14", "1991-12-15", "1991-12-16", "1991-12-17", "1991-12-18",
"1991-12-19", "1991-12-20", "1991-12-21", "1991-12-22", "1991-12-23",
"1991-12-24", "1991-12-25", "1991-12-26", "1991-12-27", "1991-12-28",
"1991-12-29", "1991-12-30", "1991-12-31", "1992-01-01", "1992-01-02",
"1992-01-03", "1992-01-04", "1992-01-05", "1992-01-06", "1992-01-07",
"1992-01-08", "1992-01-09", "1992-01-10", "1992-01-11", "1992-01-12",
"1992-01-13", "1992-01-14", "1992-01-15", "1992-01-16", "1992-01-17",
"1992-01-18", "1992-01-19", "1992-01-20", "1992-01-21", "1992-01-22",
"1992-01-23", "1992-01-24", "1992-01-25", "1992-01-26", "1992-01-27",
"1992-01-28", "1992-01-29", "1992-01-30", "1992-01-31", "1992-02-01",
"1992-02-02", "1992-02-03", "1992-02-04", "1992-02-05", "1992-02-06",
"1992-02-07", "1992-02-08", "1992-02-09", "1992-02-10", "1992-02-11",
"1992-02-12", "1992-02-13", "1992-02-14", "1992-02-15", "1992-02-16",
"1992-02-17", "1992-02-18", "1992-02-19", "1992-02-20", "1992-02-21",
"1992-02-22", "1992-02-23", "1992-02-24", "1992-02-25", "1992-02-26",
"1992-02-27", "1992-02-28", "1992-02-29", "1992-03-01", "1992-03-02",
"1992-03-03", "1992-03-04", "1992-03-05", "1992-03-06", "1992-03-07",
"1992-03-08", "1992-03-09", "1992-03-10", "1992-03-11", "1992-03-12",
"1992-03-13", "1992-03-14", "1992-03-15", "1992-03-16", "1992-03-17",
"1992-03-18", "1992-03-19", "1992-03-20", "1992-03-21", "1992-03-22",
"1992-03-23", "1992-03-24", "1992-03-25", "1992-03-26", "1992-03-27",
"1992-03-28", "1992-03-29", "1992-03-30", "1992-03-31", "1992-04-01",
"1992-04-02", "1992-04-03", "1992-04-04", "1992-04-05", "1992-04-06",
"1992-04-07", "1992-04-08", "1992-04-09", "1992-04-10", "1992-04-11",
"1992-04-12", "1992-04-13", "1992-04-14", "1992-04-15", "1992-04-16",
"1992-04-17", "1992-04-18", "1992-04-19", "1992-04-20", "1992-04-21",
"1992-04-22", "1992-04-23", "1992-04-24", "1992-04-25", "1992-04-26",
"1992-04-27", "1992-04-28", "1992-04-29", "1992-04-30", "1992-05-01",
"1992-05-02", "1992-05-03", "1992-05-04", "1992-05-05", "1992-05-06",
"1992-05-07", "1992-05-08", "1992-05-09", "1992-05-10", "1992-05-11",
"1992-05-12", "1992-05-13", "1992-05-14", "1992-05-15", "1992-05-16",
"1992-05-17", "1992-05-18", "1992-05-19", "1992-05-20", "1992-05-21",
"1992-05-22", "1992-05-23", "1992-05-24", "1992-05-25", "1992-05-26",
"1992-05-27", "1992-05-28", "1992-05-29", "1992-05-30", "1992-05-31",
"1992-06-01", "1992-06-02", "1992-06-03", "1992-06-04", "1992-06-05",
"1992-06-06", "1992-06-07", "1992-06-08", "1992-06-09", "1992-06-10",
"1992-06-11", "1992-06-12", "1992-06-13", "1992-06-14", "1992-06-15",
"1992-06-16", "1992-06-17", "1992-06-18", "1992-06-19", "1992-06-20",
"1992-06-21", "1992-06-22", "1992-06-23", "1992-06-24", "1992-06-25",
"1992-06-26", "1992-06-27", "1992-06-28", "1992-06-29", "1992-06-30",
"1992-07-01", "1992-07-02", "1992-07-03", "1992-07-04", "1992-07-05",
"1992-07-06", "1992-07-07", "1992-07-08", "1992-07-09", "1992-07-10",
"1992-07-11", "1992-07-12", "1992-07-13", "1992-07-14", "1992-07-15",
"1992-07-16", "1992-07-17", "1992-07-18", "1992-07-19", "1992-07-20",
"1992-07-21", "1992-07-22", "1992-07-23", "1992-07-24", "1992-07-25",
"1992-07-26", "1992-07-27", "1992-07-28", "1992-07-29", "1992-07-30",
"1992-07-31", "1992-08-01", "1992-08-02", "1992-08-03", "1992-08-04",
"1992-08-05", "1992-08-06", "1992-08-07", "1992-08-08", "1992-08-09",
"1992-08-10", "1992-08-11", "1992-08-12", "1992-08-13", "1992-08-14",
"1992-08-15", "1992-08-16", "1992-08-17", "1992-08-18", "1992-08-19",
"1992-08-20", "1992-08-21", "1992-08-22", "1992-08-23", "1992-08-24",
"1992-08-25", "1992-08-26", "1992-08-27", "1992-08-28", "1992-08-29",
"1992-08-30", "1992-08-31", "1992-09-01", "1992-09-02", "1992-09-03",
"1992-09-04", "1992-09-05", "1992-09-06", "1992-09-07", "1992-09-08",
"1992-09-09", "1992-09-10", "1992-09-11", "1992-09-12", "1992-09-13",
"1992-09-14", "1992-09-15", "1992-09-16", "1992-09-17", "1992-09-18",
"1992-09-19", "1992-09-20", "1992-09-21", "1992-09-22", "1992-09-23",
"1992-09-24", "1992-09-25", "1992-09-26", "1992-09-27", "1992-09-28",
"1992-09-29", "1992-09-30", "1992-10-01", "1992-10-02", "1992-10-03",
"1992-10-04", "1992-10-05", "1992-10-06", "1992-10-07", "1992-10-08",
"1992-10-09", "1992-10-10", "1992-10-11", "1992-10-12", "1992-10-13",
"1992-10-14", "1992-10-15", "1992-10-16", "1992-10-17", "1992-10-18",
"1992-10-19", "1992-10-20", "1992-10-21", "1992-10-22", "1992-10-23",
"1992-10-24", "1992-10-25", "1992-10-26", "1992-10-27", "1992-10-28",
"1992-10-29", "1992-10-30", "1992-10-31", "1992-11-01", "1992-11-02",
"1992-11-03", "1992-11-04", "1992-11-05", "1992-11-06", "1992-11-07",
"1992-11-08", "1992-11-09", "1992-11-10", "1992-11-11", "1992-11-12",
"1992-11-13", "1992-11-14", "1992-11-15", "1992-11-16", "1992-11-17",
"1992-11-18", "1992-11-19", "1992-11-20", "1992-11-21", "1992-11-22",
"1992-11-23", "1992-11-24", "1992-11-25", "1992-11-26", "1992-11-27",
"1992-11-28", "1992-11-29", "1992-11-30", "1992-12-01", "1992-12-02",
"1992-12-03", "1992-12-04", "1992-12-05", "1992-12-06", "1992-12-07",
"1992-12-08", "1992-12-09", "1992-12-10", "1992-12-11", "1992-12-12",
"1992-12-13", "1992-12-14", "1992-12-15", "1992-12-16", "1992-12-17",
"1992-12-18", "1992-12-19", "1992-12-20", "1992-12-21", "1992-12-22",
"1992-12-23", "1992-12-24", "1992-12-25", "1992-12-26", "1992-12-27",
"1992-12-28", "1992-12-29", "1992-12-30", "1992-12-31", "1993-01-01",
"1993-01-02", "1993-01-03", "1993-01-04", "1993-01-05", "1993-01-06",
"1993-01-07", "1993-01-08", "1993-01-09", "1993-01-10", "1993-01-11",
"1993-01-12", "1993-01-13", "1993-01-14", "1993-01-15", "1993-01-16",
"1993-01-17", "1993-01-18", "1993-01-19", "1993-01-20", "1993-01-21",
"1993-01-22", "1993-01-23", "1993-01-24", "1993-01-25", "1993-01-26",
"1993-01-27", "1993-01-28", "1993-01-29", "1993-01-30", "1993-01-31",
"1993-02-01", "1993-02-02", "1993-02-03", "1993-02-04", "1993-02-05",
"1993-02-06", "1993-02-07", "1993-02-08", "1993-02-09", "1993-02-10",
"1993-02-11", "1993-02-12", "1993-02-13", "1993-02-14", "1993-02-15",
"1993-02-16", "1993-02-17", "1993-02-18", "1993-02-19", "1993-02-20",
"1993-02-21", "1993-02-22", "1993-02-23", "1993-02-24", "1993-02-25",
"1993-02-26", "1993-02-27", "1993-02-28", "1993-03-01", "1993-03-02",
"1993-03-03", "1993-03-04", "1993-03-05", "1993-03-06", "1993-03-07",
"1993-03-08", "1993-03-09", "1993-03-10", "1993-03-11", "1993-03-12",
"1993-03-13", "1993-03-14", "1993-03-15", "1993-03-16", "1993-03-17",
"1993-03-18", "1993-03-19", "1993-03-20", "1993-03-21", "1993-03-22",
"1993-03-23", "1993-03-24", "1993-03-25", "1993-03-26", "1993-03-27",
"1993-03-28", "1993-03-29", "1993-03-30", "1993-03-31", "1993-04-01",
"1993-04-02", "1993-04-03", "1993-04-04", "1993-04-05", "1993-04-06",
"1993-04-07", "1993-04-08", "1993-04-09", "1993-04-10", "1993-04-11",
"1993-04-12", "1993-04-13", "1993-04-14", "1993-04-15", "1993-04-16",
"1993-04-17", "1993-04-18", "1993-04-19", "1993-04-20", "1993-04-21",
"1993-04-22", "1993-04-23", "1993-04-24", "1993-04-25", "1993-04-26",
"1993-04-27", "1993-04-28", "1993-04-29", "1993-04-30", "1993-05-01",
"1993-05-02", "1993-05-03", "1993-05-04", "1993-05-05", "1993-05-06",
"1993-05-07", "1993-05-08", "1993-05-09", "1993-05-10", "1993-05-11",
"1993-05-12", "1993-05-13", "1993-05-14", "1993-05-15", "1993-05-16",
"1993-05-17", "1993-05-18", "1993-05-19", "1993-05-20", "1993-05-21",
"1993-05-22", "1993-05-23", "1993-05-24", "1993-05-25", "1993-05-26",
"1993-05-27", "1993-05-28", "1993-05-29", "1993-05-30", "1993-05-31",
"1993-06-01", "1993-06-02", "1993-06-03", "1993-06-04", "1993-06-05",
"1993-06-06", "1993-06-07", "1993-06-08", "1993-06-09", "1993-06-10",
"1993-06-11", "1993-06-12", "1993-06-13", "1993-06-14", "1993-06-15",
"1993-06-16", "1993-06-17", "1993-06-18", "1993-06-19", "1993-06-20",
"1993-06-21", "1993-06-22", "1993-06-23", "1993-06-24", "1993-06-25",
"1993-06-26", "1993-06-27", "1993-06-28", "1993-06-29", "1993-06-30",
"1993-07-01", "1993-07-02", "1993-07-03", "1993-07-04", "1993-07-05",
"1993-07-06", "1993-07-07", "1993-07-08", "1993-07-09", "1993-07-10",
"1993-07-11", "1993-07-12", "1993-07-13", "1993-07-14", "1993-07-15",
"1993-07-16", "1993-07-17", "1993-07-18", "1993-07-19", "1993-07-20",
"1993-07-21", "1993-07-22", "1993-07-23", "1993-07-24", "1993-07-25",
"1993-07-26", "1993-07-27", "1993-07-28", "1993-07-29", "1993-07-30",
"1993-07-31", "1993-08-01", "1993-08-02", "1993-08-03", "1993-08-04",
"1993-08-05", "1993-08-06", "1993-08-07", "1993-08-08", "1993-08-09",
"1993-08-10", "1993-08-11", "1993-08-12", "1993-08-13", "1993-08-14",
"1993-08-15", "1993-08-16", "1993-08-17", "1993-08-18", "1993-08-19",
"1993-08-20", "1993-08-21", "1993-08-22", "1993-08-23", "1993-08-24",
"1993-08-25", "1993-08-26", "1993-08-27", "1993-08-28", "1993-08-29",
"1993-08-30", "1993-08-31", "1993-09-01", "1993-09-02", "1993-09-03",
"1993-09-04", "1993-09-05", "1993-09-06", "1993-09-07", "1993-09-08",
"1993-09-09", "1993-09-10", "1993-09-11", "1993-09-12", "1993-09-13",
"1993-09-14", "1993-09-15", "1993-09-16", "1993-09-17", "1993-09-18",
"1993-09-19", "1993-09-20", "1993-09-21", "1993-09-22", "1993-09-23",
"1993-09-24", "1993-09-25", "1993-09-26", "1993-09-27", "1993-09-28",
"1993-09-29", "1993-09-30", "1993-10-01", "1993-10-02", "1993-10-03",
"1993-10-04", "1993-10-05", "1993-10-06", "1993-10-07", "1993-10-08",
"1993-10-09", "1993-10-10", "1993-10-11", "1993-10-12", "1993-10-13",
"1993-10-14", "1993-10-15", "1993-10-16", "1993-10-17", "1993-10-18",
"1993-10-19", "1993-10-20", "1993-10-21", "1993-10-22", "1993-10-23",
"1993-10-24", "1993-10-25", "1993-10-26", "1993-10-27", "1993-10-28",
"1993-10-29", "1993-10-30", "1993-10-31", "1993-11-01", "1993-11-02",
"1993-11-03", "1993-11-04", "1993-11-05", "1993-11-06", "1993-11-07",
"1993-11-08", "1993-11-09", "1993-11-10", "1993-11-11", "1993-11-12",
"1993-11-13", "1993-11-14", "1993-11-15", "1993-11-16", "1993-11-17",
"1993-11-18", "1993-11-19", "1993-11-20", "1993-11-21", "1993-11-22",
"1993-11-23", "1993-11-24", "1993-11-25", "1993-11-26", "1993-11-27",
"1993-11-28", "1993-11-29", "1993-11-30", "1993-12-01", "1993-12-02",
"1993-12-03", "1993-12-04", "1993-12-05", "1993-12-06", "1993-12-07",
"1993-12-08", "1993-12-09", "1993-12-10", "1993-12-11", "1993-12-12",
"1993-12-13", "1993-12-14", "1993-12-15", "1993-12-16", "1993-12-17",
"1993-12-18", "1993-12-19", "1993-12-20", "1993-12-21", "1993-12-22",
"1993-12-23", "1993-12-24", "1993-12-25", "1993-12-26", "1993-12-27",
"1993-12-28", "1993-12-29", "1993-12-30", "1993-12-31", "1994-01-01",
"1994-01-02", "1994-01-03", "1994-01-04", "1994-01-05", "1994-01-06",
"1994-01-07", "1994-01-08", "1994-01-09", "1994-01-10", "1994-01-11",
"1994-01-12", "1994-01-13", "1994-01-14", "1994-01-15", "1994-01-16",
"1994-01-17", "1994-01-18", "1994-01-19", "1994-01-20", "1994-01-21",
"1994-01-22", "1994-01-23", "1994-01-24", "1994-01-25", "1994-01-26",
"1994-01-27", "1994-01-28", "1994-01-29", "1994-01-30", "1994-01-31",
"1994-02-01", "1994-02-02", "1994-02-03", "1994-02-04", "1994-02-05",
"1994-02-06", "1994-02-07", "1994-02-08", "1994-02-09", "1994-02-10",
"1994-02-11", "1994-02-12", "1994-02-13", "1994-02-14", "1994-02-15",
"1994-02-16", "1994-02-17", "1994-02-18", "1994-02-19", "1994-02-20",
"1994-02-21", "1994-02-22", "1994-02-23", "1994-02-24", "1994-02-25",
"1994-02-26", "1994-02-27", "1994-02-28", "1994-03-01", "1994-03-02",
"1994-03-03", "1994-03-04", "1994-03-05", "1994-03-06", "1994-03-07",
"1994-03-08", "1994-03-09", "1994-03-10", "1994-03-11", "1994-03-12",
"1994-03-13", "1994-03-14", "1994-03-15", "1994-03-16", "1994-03-17",
"1994-03-18", "1994-03-19", "1994-03-20", "1994-03-21", "1994-03-22",
"1994-03-23", "1994-03-24", "1994-03-25", "1994-03-26", "1994-03-27",
"1994-03-28", "1994-03-29", "1994-03-30", "1994-03-31", "1994-04-01",
"1994-04-02", "1994-04-03", "1994-04-04", "1994-04-05", "1994-04-06",
"1994-04-07", "1994-04-08", "1994-04-09", "1994-04-10", "1994-04-11",
"1994-04-12", "1994-04-13", "1994-04-14", "1994-04-15", "1994-04-16",
"1994-04-17", "1994-04-18", "1994-04-19", "1994-04-20", "1994-04-21",
"1994-04-22", "1994-04-23", "1994-04-24", "1994-04-25", "1994-04-26",
"1994-04-27", "1994-04-28", "1994-04-29", "1994-04-30", "1994-05-01",
"1994-05-02", "1994-05-03", "1994-05-04", "1994-05-05", "1994-05-06",
"1994-05-07", "1994-05-08", "1994-05-09", "1994-05-10", "1994-05-11",
"1994-05-12", "1994-05-13", "1994-05-14", "1994-05-15", "1994-05-16",
"1994-05-17", "1994-05-18", "1994-05-19", "1994-05-20", "1994-05-21",
"1994-05-22", "1994-05-23", "1994-05-24", "1994-05-25", "1994-05-26",
"1994-05-27", "1994-05-28", "1994-05-29", "1994-05-30", "1994-05-31",
"1994-06-01", "1994-06-02", "1994-06-03", "1994-06-04", "1994-06-05",
"1994-06-06", "1994-06-07", "1994-06-08", "1994-06-09", "1994-06-10",
"1994-06-11", "1994-06-12", "1994-06-13", "1994-06-14", "1994-06-15",
"1994-06-16", "1994-06-17", "1994-06-18", "1994-06-19", "1994-06-20",
"1994-06-21", "1994-06-22", "1994-06-23", "1994-06-24", "1994-06-25",
"1994-06-26", "1994-06-27", "1994-06-28", "1994-06-29", "1994-06-30",
"1994-07-01", "1994-07-02", "1994-07-03", "1994-07-04", "1994-07-05",
"1994-07-06", "1994-07-07", "1994-07-08", "1994-07-09", "1994-07-10",
"1994-07-11", "1994-07-12", "1994-07-13", "1994-07-14", "1994-07-15",
"1994-07-16", "1994-07-17", "1994-07-18", "1994-07-19", "1994-07-20",
"1994-07-21", "1994-07-22", "1994-07-23", "1994-07-24", "1994-07-25",
"1994-07-26", "1994-07-27", "1994-07-28", "1994-07-29", "1994-07-30",
"1994-07-31", "1994-08-01", "1994-08-02", "1994-08-03", "1994-08-04",
"1994-08-05", "1994-08-06", "1994-08-07", "1994-08-08", "1994-08-09",
"1994-08-10", "1994-08-11", "1994-08-12", "1994-08-13", "1994-08-14",
"1994-08-15", "1994-08-16", "1994-08-17", "1994-08-18", "1994-08-19",
"1994-08-20", "1994-08-21", "1994-08-22", "1994-08-23", "1994-08-24",
"1994-08-25", "1994-08-26", "1994-08-27", "1994-08-28", "1994-08-29",
"1994-08-30", "1994-08-31", "1994-09-01", "1994-09-02", "1994-09-03",
"1994-09-04", "1994-09-05", "1994-09-06", "1994-09-07", "1994-09-08",
"1994-09-09", "1994-09-10", "1994-09-11", "1994-09-12", "1994-09-13",
"1994-09-14", "1994-09-15", "1994-09-16", "1994-09-17", "1994-09-18",
"1994-09-19", "1994-09-20", "1994-09-21", "1994-09-22", "1994-09-23",
"1994-09-24", "1994-09-25", "1994-09-26", "1994-09-27", "1994-09-28",
"1994-09-29", "1994-09-30", "1994-10-01", "1994-10-02", "1994-10-03",
"1994-10-04", "1994-10-05", "1994-10-06", "1994-10-07", "1994-10-08",
"1994-10-09", "1994-10-10", "1994-10-11", "1994-10-12", "1994-10-13",
"1994-10-14", "1994-10-15", "1994-10-16", "1994-10-17", "1994-10-18",
"1994-10-19", "1994-10-20", "1994-10-21", "1994-10-22", "1994-10-23",
"1994-10-24", "1994-10-25", "1994-10-26", "1994-10-27", "1994-10-28",
"1994-10-29", "1994-10-30", "1994-10-31", "1994-11-01", "1994-11-02",
"1994-11-03", "1994-11-04", "1994-11-05", "1994-11-06", "1994-11-07",
"1994-11-08", "1994-11-09", "1994-11-10", "1994-11-11", "1994-11-12",
"1994-11-13", "1994-11-14", "1994-11-15", "1994-11-16", "1994-11-17",
"1994-11-18", "1994-11-19", "1994-11-20", "1994-11-21", "1994-11-22",
"1994-11-23", "1994-11-24", "1994-11-25", "1994-11-26", "1994-11-27",
"1994-11-28", "1994-11-29", "1994-11-30", "1994-12-01", "1994-12-02",
"1994-12-03", "1994-12-04", "1994-12-05", "1994-12-06", "1994-12-07",
"1994-12-08", "1994-12-09", "1994-12-10", "1994-12-11", "1994-12-12",
"1994-12-13", "1994-12-14", "1994-12-15", "1994-12-16", "1994-12-17",
"1994-12-18", "1994-12-19", "1994-12-20", "1994-12-21", "1994-12-22",
"1994-12-23", "1994-12-24", "1994-12-25", "1994-12-26", "1994-12-27",
"1994-12-28", "1994-12-29", "1994-12-30", "1994-12-31"), class = "factor"),
Value = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 2.8, 2.933, 3.6, 4.233, 3.2,
2.5, 3.2, 3.2, 3.5, 4, 4.167, 4.333, 3.5, 5.2, 4.933, 4,
3.667, 3.833, 4, 4.733, 6.5, 6.5, 6.5, 7.4, 7, 7.4, 3.667,
3.2, 4.637, 4, 3.667, 3.467, 3.067, 2.933, 4.6, 5.8, 5.8,
4.5, 4.5, 5.567, 6.1, 3.467, 3.067, 2.933, 4.6, 5.8, 5.8,
4.5, 4.5, 5.567, 6.1, 5.7, 5.8, 5.8, 5.667, 5.933, 4.8, 4.89,
6.033, 6.15, 6.267, 5.2, 3.667, 3.863, 4, 4, 4.167, 4.167,
4.5, 3.2, 4.167, 4.8, 6.2, 4, 3.2, 2.967, 2.8, 3.2, 3.067,
2.8, 3.2, 3.2, 3.7, 3.3, 4.067, 3.833, 3.667, 3.5, 3.2, 3.2,
4, 4, 3.2, 3.833, 3.5, 3.2, 4, 3.5, 3.5, 3.5, 3.2, 4, 4,
4, 4, 4.6, 4.533, 4, 5.2, 4.533, 7.1, 8.2, 8.7, 9.1, 8.7,
9.2, 7.1, 7.4, 7.1, 7.1, 6.5, 6.5, 6.5, 6.033, 5.2, 4.6,
4.8, 4.8, 4.533, 7.1, 6.5, 7.4, 6.9, 6.5, 6.5, 7.233, 11.57,
11.8, 11.2, 11.93, 13.17, 11.2, 10.03, 11.2, 11.2, 6.367,
6.367, 7.133, 13.37, 12.73, 14.4, 12.7, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0.347, 3.43, 0.837, 0.392, 96.04,
27.32, 22.01, 14.48, 13.43, 11.79, 9.62, 13.9, 19.02, 15.18,
0, 134.2, 50.2, 24.43, 15.41, 10.98, 8.693, 7.147, 6.053,
8.027, 6.351, 26.03, 15.16, 11.43, 13.66, 39.58, 57.88, 82.22,
308.7, 522.4, 290.9, 213.7, 169.8, 98.35, 86.81, 86.59, 223.2,
183.4, 93.31, 64.89, 46.83, 39.42, 34.78, 28.7, 27.8, 77.59,
72.42, 51.45, 39.48, 31.93, 46.77, 32.84, 162.4, 355.2, 110,
108, 151, 242.2, 92.26, 91.55, 92.46, 80.54, 80.21, 135.5,
73.15, 57.35, 34.86, 29.23, 60.8, 86.53, 62.78, 56.79, 48.17,
41.46, 53.46, 98.46, 93.91, 160.6, 133.6, 83.39, 72.11, 72.68,
62.78, 40.64, 27.75, 19.47, 11.85, 9, 7.547, 6.013, 5.067,
4.013, 2.967, 2.46, 2.03, 1.75, 1.325, 1.2, 1.32, 1.015,
1.385, 5.01, 10.85, 11.51, 6.307, 8.013, 17.86, 8.653, 6.093,
4.28, 2.92, 2.68, 58.54, 20.24, 29.1, 20.1, 14.92, 12.26,
9.72, 7.8, 6.2, 5.453, 4.28, 3.24, 2.36, 1.8, 1.48, 1.48,
1.88, 3.053, 2.76, 1.92, 1.44, 1.24, 0.96, 0.84, 0.84, 0.72,
0.6, 0.56, 0.44, 0.44, 0.36, 0.24, 0.2, 0.12, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22.76, 45.19, 58.88, 83.48, 125, 88.22, 71.05, 41.08, 33.05,
30.94, 28.85, 34.23, 34.29, 32.87, 50.43, 35.76, 32.74, 33.84,
34.63, 229.7, 153.3, 87.31, 67.73, 52.9, 44.45, 71.29, 149.8,
146.5, 133.4, 179, 89.96, 74.66, 75.81, 77.72, 72.84, 75.13,
63.54, 52.29, 46.05, 88.07, 181.4, 156.8, 171.6, 101.9, 163.3,
133.9, 117.4, 106.8, 99.63, 164.1, 276.4, 131.7, 67.7, 57.1,
50.08, 43.54, 42.28, 35.44, 36, 66.81, 86.23, 77.09, 88.63,
108.3, 76.16, 59.27, 60.06, 126.9, 80.39, 61.17, 57.14, 51.47,
89.8, 80.4, 63.95, 55.5, 48.83, 46.18, 35.65, 34.74, 37.57,
45.49, 56.34, 79.82, 75.6, 63.65, 58.02, 54.37, 48.09, 44.67,
38.08, 34.24, 32.77, 33.36, 31.75, 32.63, 31.45, 33.07, 30.72,
26.69, 29.4, 29.4, 40.76, 93.01, 74.24, 79, 65.4, 52.99,
45.36, 47.79, 38.08, 36.05, 41.55, 34.39, 32.33, 34.39, 31.75,
31.6, 46.75, 52.29, 65.06, 80.73, 56.8, 53.68, 56.8, 51.25,
62.31, 52.28, 43.97, 36.89, 34.39, 32.92, 31.6, 34.83, 31.16,
29.99, 29.55, 28.52, 26.91, 26.17, 27.35, 24, 23.4, 23.2,
23.2, 23, 22.6, 22, 22, 21.8, 21, 20.8, 20.2, 20.2, 20.2,
20.2, 19.6, 19.6, 19.6, 19, 19, 19, 19, 18.4, 18.4, 18.4,
17.8, 17.8, 17.2, 17.2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7.294, 8.278, 6.037,
7, 5.6, 5.6, 28.39, 4.657, 8, 7.86, 8, 8, 6, 4, 4, 3.5, 2,
1.8, 2, 0.8, 0.8, 0.5, 0.5, 0.8, 1.3, 0.4, 0.8, 0.3, 0, 0,
0, 0, 6, 6, 4, 4.5, 4, 4, 2, 1.5, 1, 0.8, 0.8, 0.8, 0.8,
0.8, 1.5, 0.4, 0.3, 0.4, 0.3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0, 0, 0, 2, 2, 0, 2, 0, 2, 2, 2, 0, 0, 0,
0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 20, 95, 125,
150, 205, 155, 100, 85, 32, 23, 17, 14, 16, 12, 29, 205,
470, 266, 204, 170, 200, 205, 100, 110, 130, 95, 110, 155,
300, 325, 236.2, 214, 192.5, 150, 161.2, 154.8, 143.5, 134.8,
144.9, 151.4, 172.6, 158.9, 131.6, 146.5, 127.6, 122.5, 169.8,
116, 106.7, 103, 106, 101.2, 78.1, 34, 28, 24, 19, 16, 15,
16, 70, 65, 38, 27.61, 26.9, 33.86, 70.51, 102.1, 88.38,
102.5, 99.18, 117.1, 135, 150.1, 250.3, 209.5, 163.1, 211.1,
203.1, 192.7, 179.9, 164.6, 145, 129, 162, 130.2, 131.5,
125, 109.6, 110, 100.3, 93.37, 79.81, 31.07, 16.31, 15.64,
15, 13.37, 12.29, 10.03, 8.826, 8.168, 7.148, 7, 6.017, 5.334,
4.768, 11.19, 9.315, 9, 8, 14, 14, 16, 16, 14, 9, 9, 8, 8,
9, 9, 8, 8, 7, 7, 6, 7, 6, 5, 9, 9, 8, 8, 8, 7, 8, 8, 9,
7, 5, 5, 4, 4, 3, 3, 3, 3, 3, 2.5, 2.5, 2.5, 2.5, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), class = "data.frame", row.names = c(NA,
-1310L))
Issue stems from the fact that a sum a vector of length zero gives you zero instead of NA.
> sum(vector("numeric",0))
[1] 0
A simple solution would then be to roll your own version of sum to return NA in such case:
mysum <- function(x) if(length(x)==0) return(NA) else return(sum(x))
Then:
head(apply.monthly(Rain, FUN=mysum), 20)
[,1]
1991-06-30 NA
1991-07-31 NA
1991-08-31 NA
1991-09-30 NA
1991-10-31 NA
1991-11-30 NA
1991-12-31 NA
1992-01-31 136.003
1992-02-29 143.441
1992-03-31 119.099
1992-04-30 160.499
1992-05-31 267.466
1992-06-30 247.796
1992-07-31 2945.751
1992-08-31 2654.740
1992-09-30 1035.112
1992-10-31 279.582
1992-11-30 6.320
1992-12-31 0.000
1993-01-31 0.000

R: constructing bootstrap t confidence interval for 3 parameter estimates

I am trying to construct a bootstrap t confidence interval for 3 parameter estimates but I only able to construct for first parameter. Attached below is my code:
beta0<--8
beta1<-0.03
gamma<-0.0105
alpha<-0.05
n<-100
N<-10
for (i in 1:N)
{
u<-runif(n)
x<-rnorm(n)
c<-rexp(n,1/1255)
t1<-(1/gamma)*log(1-((gamma/exp(beta0+beta1*x))*log(1-u)))
t<-pmin(t1,c)
delta<-1*(t1>c)
length(delta)
delta[delta==1]<-ifelse(rbinom(length(delta[delta==1]),1,0.75),1,2)
deltae<-ifelse(delta==0, 1,0)
deltar<-ifelse(delta==1, 1,0)
deltai<-ifelse(delta==2, 1,0)
dat=data.frame(t,delta, deltae,deltar,deltai,x)
dat$interval[delta==2] <- as.character(cut(dat$t[delta==2], breaks=seq(0, 600, 100)))
labs <- cut(dat$t[delta==2], breaks=seq(0, 600, 100))
dat$lower[delta==2]<-as.numeric( sub("\\((.+),.*", "\\1", labs) )
dat$upper[delta==2]<-as.numeric( sub("[^,]*,([^]]*)\\]", "\\1", labs) )
beta0hat.boot <- function(data,j)
{
dat<-data[j,]
data0<-dat[which(dat$delta==0),]#uncensored data
data1<-dat[which(dat$delta==1),]#right censored data
data2<-dat[which(dat$delta==2),]#interval censored data
library(maxLik)
#without imputataion
ll<-function(para)
{
b0<-para[1]
b1<-para[2]
g<-para[3]
e<-sum((b0+b1*data0$x)+g*data0$t+(1/g)*exp(b0+b1*data0$x)*(1-exp(g*data0$t)))
r<-sum((1/g)*exp(b0+b1*data1$x)*(1-exp(g*data1$t)))
i<-sum(log(exp((1/g)*exp(b0+b1*data2$x)*(1-exp(g*data2$lower)))-exp((1/g)*exp(b0+b1*data2$x)*(1-exp(g*data2$upper)))))
l<-e+r+i
return(l)
}
est<-maxLik(logLik=ll,start=c(para<-c(-8,0.03,0.0105)))
beta0hat<-est$estimate[1]
beta1hat<-est$estimate[2]
gammahat<-est$estimate[3]
observed<-solve(-est$hessian)
return(c(beta0hat,beta1hat,gammahat,observed[1,1],observed[2,2],observed[3,3]))
}
library(boot)
out<- boot(dat,beta0hat.boot,100)
ci<-boot.ci(out,type =c("stud","perc"),var.t0= out$t0[4],var.t=out$t[,4])
ci1<-boot.ci(out,type = c("stud","perc"),var.t0= out$t0[4],var.t=out$t[,4],index=1)
}
I am only able to construct the confidence interval for the first parameter only without using index=1 which is as follow
ci<-boot.ci(out,type =c("stud","perc"),var.t0= out$t0[4],var.t=out$t[,4])
when i add in index=1,
ci1<-boot.ci(out,type = c("stud","perc"),var.t0= out$t0[4],var.t=out$t[,4],index=1)
i got warnings:
In boot.ci(out, type = c("stud", "perc"), var.t0 = out$t0[4], var.t = out$t[, :
bootstrap variances needed for studentized intervals.
which caused the confidence interval cannot be built.
I want to add index=1 because I need to construct confidence interval for 2nd and 3rd parameter as well by using index=2 and index=3 but after I add in the index, i cannot get the confidence interval. Any idea how to get bootstrap t confidence interval for more than one statistics? I am able to get the percentile interval only by using the above code but not able to get bootstrap t interval.
dput(head(dat, 30)):
structure(list(t = c(143.786081550783, 104.647251273501, 65.5655695306165,
322.260530195967, 307.324160556309, 123.725827237157, 143.083942557736,
426.646805286557, 360.799323547846, 246.295906287976, 315.638222801499,
421.155652813492, 374.160625875751, 123.570819609099, 389.553807438155,
449.110810924173, 162.547725691726, 296.674617375856, 229.680453578098,
343.823664337269, 268.797764971971, 205.704838761594, 14.8630247008987,
91.6607201565057, 260.886289739501, 193.278377859747, 143.269719508224,
27.4780640122481, 267.191708749538, 39.8027657018974), delta = c(1,
0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 0, 1, 0, 1, 0, 1), deltae = c(0, 1, 1, 1, 0, 1, 1, 1, 1,
1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0
), deltar = c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1), deltai = c(0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0), x = c(-0.377643157724086, 0.218708630964153,
0.153162542263512, 1.28222373181234, 1.1423312203422, -1.04726335577352,
-0.360028857222088, 0.336098821643731, 0.758860540656158, 0.0533940581013279,
-0.0562132826178519, 0.0798656325287969, -0.748956798800072,
-0.235929730488004, -0.737049993834757, 1.05819046250488, 1.28776064495481,
0.457930197196181, -1.45563588128583, -1.1074384621643, -0.829026816498185,
-1.3824961444269, -1.58951008909026, -0.95052226776903, 0.0145909317659764,
-0.198775419436042, 0.0481467746529365, -0.136098038815233, -0.118319488454131,
-0.498263758291143), interval = c(NA, NA, NA, NA, "(300,400]",
NA, NA, NA, NA, NA, "(300,400]", NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), lower = c(NA,
NA, NA, NA, 300, NA, NA, NA, NA, NA, 300, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), upper = c(NA,
NA, NA, NA, 400, NA, NA, NA, NA, NA, 400, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), .Names = c("t",
"delta", "deltae", "deltar", "deltai", "x", "interval", "lower",
"upper"), row.names = c(NA, 30L), class = "data.frame")

Mapping content of one matrix onto structure of another matrix

I have two matrices sourced from the same dataset but with different amounts of data available for each.
I want to create a dataset that is a replicate of x in terms of column names and row names but which contains the data values in y. If the data is not available then an NA would be used as the value for that coordinate.
Not all of the row names in x are present in y and vice versa. The same holds true for the column names.
For the example input data I've given below, the rownames in x corresponding to those in y are the rowname start and end at | (I want to retain everthing after the | for other mappings).
What is the most efficient way to do this?
DESIRED OUTPUT
z = structure(c(NA, 1, NA, NA, NA, NA, NA, NA, 0, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0, NA, NA, NA, NA, NA,
NA, 0, NA, NA, NA, 0, NA, NA, NA, NA, NA, NA, 0, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), .Dim = c(11L, 5L), .Dimnames = list(
c("AACSL|729522", "AACS|65985", "AADACL2|344752", "AADACL3|126767",
"AADACL4|343066", "AADAC|13", "AADAT|51166", "AAGAB|79719",
"AAK1|22848", "AAK12|14", "AANAT|15"), c("S18", "S20", "S45",
"S95", "S100")))
EXAMPLE INPUT
x = structure(c(0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0,
0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0), .Dim = c(11L,
5L), .Dimnames = list(c("AACSL|729522", "AACS|65985", "AADACL2|344752",
"AADACL3|126767", "AADACL4|343066", "AADAC|13", "AADAT|51166",
"AAGAB|79719", "AAK1|22848", "AAK12|14", "AANAT|15"), c("S18",
"S20", "S45", "S95", "S100")))
y = structure(c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0), .Dim = c(11L, 4L), .Dimnames = list(c("A1BG",
"A1CF", "A2ML1", "A4GALT", "AACS", "AAK1", "AARD", "AARS2", "AASDHPPT",
"AASS", "BAACS"), c("S18", "S10", "S45", "S95")))
I think there might be a slight problem with the example that you provided, i can not see how the z is coming from the x and y above.. see this code:
intersect(sapply(rownames(x), #I am just extracting the letter codes here
function(i){
return(
strsplit(x=i,split="|",fixed=TRUE)[[1]][[1]])
}),rownames(y))
#[1] "AACS" "AAK1"
weird, right? I mean, there is only 2 codes in y compared to x. However, I think the code below does what you are planning (with the exception of this inconsistency):
library(data.table)
library(reshape2)
library(dplyr)
x %>% as.data.frame %>% mutate(rownames=rownames(x)) %>%
mutate(nms=sapply(rownames(x),
function(i){
return(
strsplit(x=i,split="|",fixed=TRUE)[[1]][[1]])
})) %>%
melt(id.vars=c("nms","rownames")) %>%
merge(., y %>% as.data.frame %>% mutate(nms=rownames(y))%>% melt(id.vars="nms"), by=c("variable","nms"), all.x=TRUE) %>%
select(-nms, -value.x) %>% dcast(formula = rownames~variable, value.var="value.y") -> xy
#now put back the column names where they belong
rownames(xy)<-xy$rownames
#now the only thing left is to arrange the columns
xy[rownames(x),colnames(x)] -> xy
Or am I wrong in understanding some of your points?

Resources