[R] ggplot2 - specific y axis scale for each time series in facet grind

2016-01-21 Thread Maxim Fomin
Dear R users,

I have a (melted) data frame of several metal prices from 1980. I want to
make a time series plot for each metal price. By default ggplot constructs
single plot for all prices. Adding +facet_grid(variable~.) makes for each
metal price a plot, but now there is another problem - scale of y axis.
Some metals have price $1000 and some $2. Because ggplot makes same y scale
for each metal, some metal prices printed as straight horizontal line. What
is the command to make for each plot specific y axis scale?

Currently I am trying command:

ggplot(data=melted2, aes(x=date, y=value, group=variable,
color=variable))+geom_line()+facet_grid(variable~.)


Best regards,
Maxim

P.S dput

structure(list(date = structure(c(3652, 3683, 3712, 3743, 3773,
3804, 3834, 3865, 3896, 3926, 3957, 3987, 4018, 4049, 4077, 4108,
4138, 4169, 4199, 4230, 4261, 4291, 4322, 4352, 4383, 4414, 4442,
4473, 4503, 4534, 4564, 4595, 4626, 4656, 4687, 4717, 4748, 4779,
4807, 4838, 4868, 4899, 4929, 4960, 4991, 5021, 5052, 5082, 5113,
5144, 5173, 5204, 5234, 5265, 5295, 5326, 5357, 5387, 5418, 5448,
5479, 5510, 5538, 5569, 5599, 5630, 5660, 5691, 5722, 5752, 5783,
5813, 5844, 5875, 5903, 5934, 5964, 5995, 6025, 6056, 6087, 6117,
6148, 6178, 6209, 6240, 6268, 6299, 6329, 6360, 6390, 6421, 6452,
6482, 6513, 6543, 6574, 6605, 6634, 6665, 6695, 6726, 6756, 6787,
6818, 6848, 6879, 6909, 6940, 6971, 6999, 7030, 7060, 7091, 7121,
7152, 7183, 7213, 7244, 7274, 7305, 7336, 7364, 7395, 7425, 7456,
7486, 7517, 7548, 7578, 7609, 7639, 7670, 7701, 7729, 7760, 7790,
7821, 7851, 7882, 7913, 7943, 7974, 8004, 8035, 8066, 8095, 8126,
8156, 8187, 8217, 8248, 8279, 8309, 8340, 8370, 8401, 8432, 8460,
8491, 8521, 8552, 8582, 8613, 8644, 8674, 8705, 8735, 8766, 8797,
8825, 8856, 8886, 8917, 8947, 8978, 9009, 9039, 9070, 9100, 9131,
9162, 9190, 9221, 9251, 9282, 9312, 9343, 9374, 9404, 9435, 9465,
9496, 9527, 9556, 9587, 9617, 9648, 9678, 9709, 9740, 9770, 9801,
9831, 9862, 9893, 9921, 9952, 9982, 10013, 10043, 10074, 10105,
10135, 10166, 10196, 10227, 10258, 10286, 10317, 10347, 10378,
10408, 10439, 10470, 10500, 10531, 10561, 10592, 10623, 10651,
10682, 10712, 10743, 10773, 10804, 10835, 10865, 10896, 10926,
10957, 10988, 11017, 11048, 11078, 11109, 11139, 11170, 11201,
11231, 11262, 11292, 11323, 11354, 11382, 11413, 11443, 11474,
11504, 11535, 11566, 11596, 11627, 11657, 11688, 11719, 11747,
11778, 11808, 11839, 11869, 11900, 11931, 11961, 11992, 12022,
12053, 12084, 12112, 12143, 12173, 12204, 12234, 12265, 12296,
12326, 12357, 12387, 12418, 12449, 12478, 12509, 12539, 12570,
12600, 12631, 12662, 12692, 12723, 12753, 12784, 12815, 12843,
12874, 12904, 12935, 12965, 12996, 13027, 13057, 13088, 13118,
13149, 13180, 13208, 13239, 13269, 13300, 13330, 13361, 13392,
13422, 13453, 13483, 13514, 13545, 13573, 13604, 13634, 13665,
13695, 13726, 13757, 13787, 13818, 13848, 13879, 13910, 13939,
13970, 14000, 14031, 14061, 14092, 14123, 14153, 14184, 14214,
14245, 14276, 14304, 14335, 14365, 14396, 14426, 14457, 14488,
14518, 14549, 14579, 14610, 14641, 14669, 14700, 14730, 14761,
14791, 14822, 14853, 14883, 14914, 14944, 14975, 15006, 15034,
15065, 15095, 15126, 15156, 15187, 15218, 15248, 15279, 15309,
15340, 15371, 15400, 15431, 15461, 15492, 15522, 15553, 15584,
15614, 15645, 15675, 15706, 15737, 15765, 15796, 15826, 15857,
15887, 15918, 15949, 15979, 16010, 16040, 16071, 16102, 16130,
16161, 16191, 16222, 16252, 16283, 16314, 16344, 16375, 16405,
16436, 16467, 16495, 16526, 16556, 16587, 16617, 16648, 16679,
16709, 16740, 3652, 3683, 3712, 3743, 3773, 3804, 3834, 3865,
3896, 3926, 3957, 3987, 4018, 4049, 4077, 4108, 4138, 4169, 4199,
4230, 4261, 4291, 4322, 4352, 4383, 4414, 4442, 4473, 4503, 4534,
4564, 4595, 4626, 4656, 4687, 4717, 4748, 4779, 4807, 4838, 4868,
4899, 4929, 4960, 4991, 5021, 5052, 5082, 5113, 5144, 5173, 5204,
5234, 5265, 5295, 5326, 5357, 5387, 5418, 5448, 5479, 5510, 5538,
5569, 5599, 5630, 5660, 5691, 5722, 5752, 5783, 5813, 5844, 5875,
5903, 5934, 5964, 5995, 6025, 6056, 6087, 6117, 6148, 6178, 6209,
6240, 6268, 6299, 6329, 6360, 6390, 6421, 6452, 6482, 6513, 6543,
6574, 6605, 6634, 6665, 6695, 6726, 6756, 6787, 6818, 6848, 6879,
6909, 6940, 6971, 6999, 7030, 7060, 7091, 7121, 7152, 7183, 7213,
7244, 7274, 7305, 7336, 7364, 7395, 7425, 7456, 7486, 7517, 7548,
7578, 7609, 7639, 7670, 7701, 7729, 7760, 7790, 7821, 7851, 7882,
7913, 7943, 7974, 8004, 8035, 8066, 8095, 8126, 8156, 8187, 8217,
8248, 8279, 8309, 8340, 8370, 8401, 8432, 8460, 8491, 8521, 8552,
8582, 8613, 8644, 8674, 8705, 8735, 8766, 8797, 8825, 8856, 8886,
8917, 8947, 8978, 9009, 9039, 9070, 9100, 9131, 9162, 9190, 9221,
9251, 9282, 9312, 9343, 9374, 9404, 9435, 9465, 9496, 9527, 9556,
9587, 9617, 9648, 9678, 9709, 9740, 9770, 9801, 9831, 9862, 9893,
9921, 9952, 9982, 10013, 10043, 10074, 10105, 10135, 10166, 10196,
10227, 10258, 10286, 10317, 10347, 10378, 10408, 10439, 10470,
10500, 10531, 10561, 10592, 10623, 10651, 10682, 10712, 10743,
10773, 10804, 10835, 10865, 10

Re: [R] ggplot2 - specific y axis scale for each time series in facet grind

2016-01-21 Thread Maxim Fomin
Thanks, that worked.

Best regards,
Maxim

2016-01-21 22:29 GMT+03:00 Ulrik Stervbo :
>
> You can try facet_grid(variable~., scales = "free_y")
>
> On Thu, 21 Jan 2016 at 19:29 Maxim Fomin  wrote:
>>
>> Dear R users,
>>
>> I have a (melted) data frame of several metal prices from 1980. I want to
>> make a time series plot for each metal price. By default ggplot constructs
>> single plot for all prices. Adding +facet_grid(variable~.) makes for each
>> metal price a plot, but now there is another problem - scale of y axis.
>> Some metals have price $1000 and some $2. Because ggplot makes same y scale
>> for each metal, some metal prices printed as straight horizontal line. What
>> is the command to make for each plot specific y axis scale?
>>
>> Currently I am trying command:
>>
>> ggplot(data=melted2, aes(x=date, y=value, group=variable,
>> color=variable))+geom_line()+facet_grid(variable~.)
>>
>>
>> Best regards,
>> Maxim
>>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Doing time series markov regime switching in R

2015-09-09 Thread Maxim Fomin
Dear all,

I am doing business cycle research on industry data. One of methods to identify
cycle is Markov regime switching. As I see, there is a MSwM package
for the purposes which is pretty straightforward to use. However, some
questions for me remain:

1) Are there any packages? This is relevant because I could not couple
with 2-3-4.
2) The MSwM package provides example for regression analysis (one of
the steps is to provide regression model to msmFit). In my case I have
time series. Googling issue shows that regressing on intercept is
sufficient (i.e. 'time_data ~ 1') but I am not sure.
3) The package provides some diagnostic tools, mainly plotDiag (shows
pooled residuals, QQ plot, residual acf). However, it does not provide
tools to test a) that intercepts are same b) state variables are
independent. Accepting respective null hypotheses is evidence against
the model. How this can be done in R?
4) The package allows AR terms to be affected by unobservable state
's' through 'p' parameter. However, it is unclear when specification
should include switching in coefficients (ok, it depends on use case,
but what is general theory?).

Thanks in advance,
Best regards.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] MSwM R package: model and state probability significance (p00+p11=1)

2015-10-07 Thread Maxim Fomin
 Dear  R community,

It seems that MSwM package provides three model diagnostic tools:
pooled residuals plot, QQ plot and ACFs plot (via plotDiag). However, I cannot
find any statistic to test the whole model significance (and even for
each reported regime only multiple R^2 is provided).

After searching for the answer I found one paper (Lec-Markov_note.pdf
in web) which states  that there are two tests for MRSM model. The
first has long description and essentially links to Hansen (1992)
paper -  it tests whether switching parameters are nuisance. The
second test is H0: p00+p11=1 and can be tested with Wald test.

So, my question is follows. How the first test can be performed in R
and where to get variance of state probabilities to perform Wald test
of second hypothesis (I couldn't find relevant data in MSM.lm object)?

Thanks in advance,
Best regards,
Maxim Fomin

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.