Re: [R] stats on transitions from one state to another

2012-02-21 Thread Murali.Menon
David: Brilliant! Thanks very much. As Berend pointed out, I was not precise in the query, sorry. Please note in the example that we have a run of three state 2 after 0, and later another run of two state 2 after 0. 0 2 2 2 0 0 2 2 Whenever the state moves from 0 to 2, I want to compute

[R] stats on transitions from one state to another

2012-02-20 Thread Murali.Menon
Folks, I'm trying to get stats from a matrix for each transition from one state to another. I have a matrix x as below. structure(c(0, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 2, 2, 1, 1, 1, 0, 0, 2, 2, 0.21, -0.57, -0.59, 0.16, -1.62, 0.18, -0.81, -0.19, -0.76, 0.74, -1.51, 2.79, 0.41, 1.63, -0.86,

Re: [R] choosing best 'match' for given factor

2011-04-01 Thread Murali.Menon
Interesting variety of solutions! Thanks very much. Murali -Original Message- From: Henrique Dallazuanna [mailto:www...@gmail.com] Sent: 31 March 2011 18:26 To: Menon Murali Cc: r-help@r-project.org Subject: Re: [R] choosing best 'match' for given factor Try this: bestMatch -

[R] choosing best 'match' for given factor

2011-03-31 Thread Murali.Menon
Folks, I have a 'matching' matrix between variables A, X, L, O: a - structure(c(1, 0.41, 0.58, 0.75, 0.41, 1, 0.6, 0.86, 0.58, 0.6, 1, 0.83, 0.75, 0.86, 0.83, 1), .Dim = c(4L, 4L), .Dimnames = list( c(A, X, L, O), c(A, X, L, O))) a A X L O A 1.00 0.41 0.58 0.75 X

[R] questions on unstack()

2010-10-18 Thread Murali.Menon
Folks, I have the following dataframe: x - structure(list(name = c(EU B, EU B, EU B, EU B, EU B, EU B, AU A, AU A, AU A, AU A, AU A, AU A), date = c(2010-10-11, 2010-10-12, 2010-10-13, 2010-10-14, 2010-10-15, 2010-10-18, 2010-10-11, 2010-10-12, 2010-10-13, 2010-10-14, 2010-10-15,

[R] graphics layout

2010-10-12 Thread Murali.Menon
Folks, I'm battling the layout() functionality in graphics, and getting a bit mixed up. I'd like to create subscreens like so: _ _ | | | |1|2| |_| | | | | |3|4| |_|_| |

Re: [R] graphics layout

2010-10-12 Thread Murali.Menon
Hiya, Thanks for this. It's the height parameters that baffle me. Why are they 1, 1, 1/3, 1/3, 1/3? Which subscreens do these heights correspond to? I did it like this: nf - layout(cbind(c(1,1,1,3,3,3,5,5,5),c(2,2,2,4,4,4,6,7,8))) mainly because I'm not clear about how the heights work.

[R] getting column names of row-by-row sorted matrix

2010-09-01 Thread Murali.Menon
Hi folks, I want to sort a matrix row-by-row and create a new matrix that contains the corresponding colnames of the original matrix. E.g. set.seed(123) a - matrix(rnorm(20), ncol=4); colnames(a) - c(A,B,C,D) a A B C D [1,] -0.56047565 1.7150650

[R] simultaneous estimation

2010-08-31 Thread Murali.Menon
Hi folks, Not sure what this sort of estimation is called. I have a 2-column time-series x(i,t) [with (i=1,2; t=1,...T)], and I want to do the following 'simultaneous' regressions: x(1,t) = (d - 1)(x(1, t-1) - mu(1)) x(2,t) = (d - 1)(x(2, t-1) - mu(2)) And I want to determine the coefficients

Re: [R] simultaneous estimation

2010-08-31 Thread Murali.Menon
Hi Duncan, Thanks for your response. Indeed, independent normal errors were what I had in mind. As for variances, if I assume they are the same, would a 'pooled model' apply in this case? Is that equivalent to your suggestion of concatenating x(1,t) and x(2,t)? Cheers, Murali -Original

Re: [R] simultaneous estimation

2010-08-31 Thread Murali.Menon
Bert, I expect you are correct, burrito notwithstanding (wasn't Taco Bell, was it? :-) The full model adds differences and lags, and incorporates non-zero covariances in the innovations. I only simplified to get an idea of how to implement in R. For anyone interested, I'm looking at the

[R] semiparametric fractional autoregressive model

2010-08-17 Thread Murali.Menon
folks, does anyone know if the SEMIFAR model has been implemented in R? i see that there's a S-FinMetrics function SEMIFAR() that does the job, but I have no access to that software. essentially, this semiparametric fractional autoregressive model introduces a deterministic trend to the

[R] converting a time to nearest half-hour

2010-07-23 Thread Murali.Menon
Hi folks, I've got a POSIXct datum as follows: Sys.time() [1] 2010-07-23 11:29:59 BST I want to convert this to the nearest half-hour, i.e., to 2010-07-23 11:30:00 BST (If the time were 11:59:ss, I want to convert to 12:00:00). How to achieve this? Thanks, Murali

Re: [R] converting a time to nearest half-hour

2010-07-23 Thread Murali.Menon
David, Stephen, You're right - it's the time zone conventions that threw me as well. I tried those round() operations earlier, but inevitably ended up being either an hour behind. Even when I specified my time zone, it didn't make any difference. So there's something else that I'm missing. I'll

[R] min and max operations on matrix

2010-01-20 Thread Murali.MENON
Folks, I've got a matrix x as follows: x - matrix(c(1,2,3,5,3,4,3,2,1), ncol = 3, byrow = TRUE) x [,1] [,2] [,3] [1,]123 [2,]534 [3,]321 In each row of x, I want to replace the minimum value by -1, the maximum value by +1 and all other values by 0.

[R] differing behaviour between xts (0.6-7) and zoo (1.5-8)

2009-09-25 Thread Murali.MENON
Folks, I have some weekly dataseries that I convert to monthly xts (with yearmon indices), and obtain the two following extracts: str(sig) An 'xts' object from Apr 1998 to Sep 1998 containing: Data: num [1:6, 1] 0.0083 0.2799 -0.2524 -0.0119 0.18 ... - attr(*, dimnames)=List of 2 ..$ :

[R] convert xts vector into matrix

2009-07-02 Thread Murali.MENON
hi folks, if i have an xts object as follows: library(xts) dd - as.POSIXct(strptime(c(2009-06-01 08:00:00, 2009-06-01 08:30:00,2009-06-01 09:00:00,2009-06-02 08:00:00, 2009-06-03 08:00:00, 2009-06-03 08:30:00),%Y-%m-%d %H:%M:%S)) a - xts(1:6,dd) a [[alternative HTML version

Re: [R] Replace zeroes in vector with nearest non-zero value

2009-06-19 Thread Murali.MENON
Jim, Gabor, William, Thanks very much. Works a treat. Cheers, Murali -Original Message- From: William Dunlap [mailto:wdun...@tibco.com] Sent: 18 June 2009 18:27 To: MENON Murali; r-help@r-project.org Subject: RE: [R] Replace zeroes in vector with nearest non-zero value approx() almost

[R] Replace zeroes in vector with nearest non-zero value

2009-06-18 Thread Murali.MENON
Folks, If I have a vector such as the following: x - c(0, -1, -1, -1, 0, 0, 1, -1, 1, 0) and I want to replace the zeroes by the nearest non-zero number to the left, is there a more elegant way to do this than the following loop? y - x for (i in 2 : length(x)) { if (y[i] == 0) {

[R] series at low freq expanded into high freq

2009-04-27 Thread Murali.MENON
Folks, If I have a series mm of, say, monthly observations, and a series dd of daily dates, what's a good way of expanding mm such that corresponding to each day in dd within the corresponding month in mm, the values of mm are repeated? So e.g., if I have mm: mm - c(15, 10, 12, 13, 11)

Re: [R] series at low freq expanded into high freq

2009-04-27 Thread Murali.MENON
Hmm, silly of me. I have the solution, after some mucking about with coercion and so on: xx - zoo(mm[as.character(as.yearmon(dd))], order.by = dd) xx 2008-11-03 2008-11-05 2009-01-04 2009-02-02 2009-02-17 2009-03-13 2009-03-14 2009-03-18 2009-03-26 15 15 12 13

Re: [R] adding matrices with common column names

2009-03-30 Thread Murali.MENON
Benjamin, Dimitris, Thanks very much. Neat work! Murali -Original Message- From: Nutter, Benjamin [mailto:nutt...@ccf.org] Sent: 27 March 2009 13:52 To: MENON Murali; r-help@r-project.org Subject: RE: [R] adding matrices with common column names Shucks, Dimitris beat me to it. And his

[R] adding matrices with common column names

2009-03-27 Thread Murali.MENON
folks, if i have three matrices, a, b, cc with some colnames in common, and i want to create a matrix which consists of the common columns added up, and the other columns tacked on, what's a good way to do it? i've got the following roundabout code for two matrices, but if the number of matrices

[R] Goldbach partitions code

2009-03-02 Thread Murali.MENON
Folks, I put up a brief note describing my naive attempts to compute Goldbach partitions, starting with a brute-force approach and refining progressively. http://jostamon.blogspot.com/2009/02/goldbachs-comet.html I'd welcome your suggestions on improvements, alternatives, other