Displaying 20 results from an estimated 10000 matches similar to: "simultaneous estimation"
2012 Feb 20
2
stats on transitions from one state to another
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, -0.81, 0.39, -1.38,
0.06, 0.84, 0.51, -1, -1.29, 2.15, 0.39, 0.78, 0.85, 1.18, 1.66,
0.9, -0.94,
2011 Mar 31
3
choosing best 'match' for given factor
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
2010 Oct 12
1
graphics layout
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 |
|_________|_________|
| |____6____|
| 5 |____7____|
|_________|____8____|
Note that subscreens 1:5 are the same
2010 Sep 01
2
getting column names of row-by-row sorted matrix
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 1.2240818 1.7869131
[2,]
2010 Oct 18
1
questions on unstack()
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",
2008 Jul 02
5
multiplication question
folks,
is there a clever way to compute the sum of the product of two vectors such that the common indices are not multiplied together?
i.e. if i have vectors X, Y, how can i compute
Sum (X[i] * Y[j])
i != j
where i != j
also, what if i wanted
Sum (X[i] * Y[j] * R[i, j])
i != j
where R is a matrix?
thanks,
murali
2007 Mar 29
1
creating conditional list of elements
Sorry to plague the list, but I think I got the answer. The following
would do:
> signalList <- list(tradingRules$Signal[tradingRules$Enabled]) [[1]]
> length(signalList)
[1] 2
Now my problem is shifted: I have the Signal column in the original data
frame referring to actual
matrices previously created in R. That is, bar_signal and cif_signal are
extant matrices. What I
need is the
2007 Sep 19
3
Row-by-row regression on matrix
Folks,
I have a 3000 x 4 matrix (y), which I need to regress row-by-row against a
4-vector (x) to create a
matrix lm.y of intercepts and slopes. To illustrate:
y <- matrix(rnorm(12000), ncol = 4)
x <- c(1/12, 3/12, 6/12, 1)
system.time(lm.y <- t(apply(y, 1, function(z) lm(z ~ x)$coefficient)))
[1] 44.72 18.00 69.52 NA NA
Takes more than a minute to do (and I need to do many
2007 Feb 13
2
Computing stats on common parts of multiple dataframes
Folks,
I have three dataframes storing some information about
two currency pairs, as follows:
R> a
EUR-USD NOK-SEK
1.23 1.33
1.22 1.43
1.26 1.42
1.24 1.50
1.21 1.36
1.26 1.60
1.29 1.44
1.25 1.36
1.27 1.39
1.23 1.48
1.22 1.26
1.24 1.29
1.27 1.57
1.21 1.55
1.23 1.35
1.25 1.41
1.25 1.30
1.23 1.11
1.28 1.37
1.27 1.23
R> b
EUR-USD NOK-SEK
1.23 1.22
1.21 1.36
1.28 1.61
1.23 1.34
1.21 1.22
2009 Jun 18
3
Replace zeroes in vector with nearest non-zero value
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) {
y[i] <- y[i - 1]
}
}
> y
[1] 0 -1 -1 -1 -1 -1 1 -1 1 1
You can see the
2008 Nov 05
2
matrix indexing and update
Folks,
I have a matrix:
set.seed(123)
a <- matrix(rnorm(100), 10)
And a vector:
b <- rnorm(10)
Now, I want to switch the signs of those rows of a corresponding to
indices in b whose values exceed the 75 %-ile of b
which(b > quantile(b)[4])
[1] 2 6 10
so I want, in effect:
a[2, ] <- -a[2, ]
a[6, ] <- -a[6, ]
a[10, ] <- -a[10, ]
I thought I could do
a[which(b >
2009 Apr 27
2
series at low freq expanded into high freq
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)
names(mm)<-c("Nov 2008", "Dec 2008", "Jan 2009", "Feb
2007 Apr 27
2
Jarque-Bera and rnorm()
Folks,
I'm a bit puzzled by the fact that if I generate 100,000 standard normal
variates using rnorm() and perform the Jarque-Bera on the resulting vector,
I get p-values that vary drastically from run to run. Is this expected?
Surely the p-val should be close to 1 for each test?
Are 100,000 variates sufficient for this test?
Or is it that rnorm() is not a robust random number generator?
2017 Nov 02
0
repeat a function
Hi Eric
I did not see any answer and frankly speaking I cannot provide you with canned help.
AFAIK if a function is defined within another function (which is your case) it cannot be called directly so it is necessary to define it in global environment.
> fff <- function(x) {
+ myf <- function(a) a+2
+ myf(x)^2}
>
> fff(5)
[1] 49
> myf(5)
Error in myf(5) : could not find
2017 Nov 02
2
repeat a function
Hi Petr,
Many thanks for your response.
Basically I want to create a probability matrix to be used in a trinomial tree going forward. This is the reason why I thought to build the matrix around 0 would be much more efficient. I need to loop through because the probabilities will depend on my node and is not always the same per row (e.g. if N> jmax, jmax being defined in another function)
I
2009 Mar 27
2
adding matrices with common column names
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 increases, then i'm a bit stymied.
> a <- matrix(1:20,ncol=4); colnames(a) <-
2017 Nov 01
3
repeat a function
I want to populate the matrix prb through the function HWMProb <- function (a,j,dt) that encapsulates different functions (please see code below), using j= 0:2 for each j.
It only populates prb if I specify each function independently in the global environment and then run the loop with the iF statement, as per below.
for (j in 0:2) {
if (j==0) {
prb["0","1"] <-
2017 Nov 03
0
repeat a function
Hi
Well, I am not an expert in this field so I cannot comment your approach. I wanted only to point out that building matrix your way is like scratching your left ear with right hand, especially in R. What if you want increase size of your matrix?
E.g. you use function ProbUP once for row "0" and than for rows different from jmax (if I correctly understand your code). Use of any
2007 Mar 16
1
cumsum over varying column lengths
Folks,
I have a matrix of historicalReturns, where entry (i, j) is the daily return
corresponding to date i and equity j. I also have a matrix startOffset,
where entry (1, k) is the row offset in historicalReturns where I entered
into equity k.
So we have that NCOL(startOffset) = NCOL(historicalReturns).
Now I would like compute for each column in historicalReturns, the
cumulative return
2010 Jan 20
1
min and max operations on matrix
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,] 1 2 3
[2,] 5 3 4
[3,] 3 2 1
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.
So in the above case I want to end up as follows:
[,1] [,2] [,3]
[1,] -1 0