Displaying 20 results from an estimated 2000 matches similar to: "function odiag(): assigning values to off-diagonal"
2010 Feb 12
1
using mle2 for multinomial model optimization
Hi there
I'm trying to find the mle fo a multinomial model ->*L(N,h,S?x)*. There
is only *N* I want to estimate, which is used in the number of successes
for the last cell probability. These successes are given by:
p^(N-x1-x2-...xi)
All the other parameters (i.e. h and S) I know from somewhere else.
Here is what I've tried to do so far for a imaginary data set:
2011 Apr 04
1
Ordering every row of a matrix while ignoring off diagonal elements
Sorry if this is a stupid question but I've been stuck on how to code
so that I can order rows of a matrix without paying attention to the
diagonal elements.
Say, for example, I have a matrix d:
> d
[,1] [,2] [,3] [,4]
[1,] 0.000000 2.384158 2.0065682 2.2998856
[2,] 2.384158 0.000000 1.4599928 2.4333213
[3,] 2.006568 1.459993 0.0000000 0.9733285
[4,] 2.299886
2004 Oct 13
2
diagonal matrix construction
Hi,
I have worked long and hard and looked in the manuals and am having a hard time constructing a diagonal matrix. I can get the diagonals out of a matrix but can't construct the matrix with just the diagonals. I have been on the web site and manuals and I think that it says to use:
dsj <- diag (three = 1, nrow, ncol = 7) three is the name of my matrix and
2009 Aug 24
1
Filling matrix secondary diagonal
Hi,
how do i fill the secondary diagonals of a matrix?
Is there an funktion like the "diag" funktion in matlab, where i can specify
the diagonal i?d like to fill?
--
View this message in context: http://www.nabble.com/Filling-matrix-secondary-diagonal-tp25121745p25121745.html
Sent from the R help mailing list archive at Nabble.com.
2024 Dec 04
3
Undocumented behaviour of diag when replacing the diagonal of a matrix?
Dear list,
is anyone aware of the following behavious of diag when used to replace
diagonals (plural!) of a matrix?
Small example: The following is documented and clearly to be expected:
A <- matrix(0, nrow = 5, ncol = 5)
diag(A) <- 1; A
BUT, what about the following? When executing the code of `diag<-` line
by line, it throws errors. So why does it work?
diag(A[-1, ]) <- 2; A
2010 Apr 23
2
Matrix diagonal help
Hi
Suppose I have a matrix (cohort are rows and years are columns)
[2000] [2001] [2002] [2003]
[C1] 0.01 0.03 0.02 0.09
[C2] 0.06 0.05 0.07 0.11
[C3] 0.1 0.5 0.4 0.98
[C4] 0.7 0.6 0.2 0.77
I want to extracts the diagonals to get a matrix which looks like this (C1
becomes C2 in 2002, C2 becomes C3 in 2003
2007 Jul 26
0
Diagonal Submatrices Extraction
Yes you are right ... an example is mandatory.
So ... I have a matrix of 0 with just a single 1 per row and per column
I need to extract all maximal 'diagonal' submatrices
Let's say I have the following matrix
A B C D E
a 0 1 0 0 0
b 1 0 0 0 0
c 0 0 1 0 0
d 0 0 0 1 0
e 0 0 0 0 1
well I would like to get, for this example, the two following submatrices
A B C D E
2008 Aug 18
2
matrix row product and cumulative product
I spent a lot of time searching and came up empty handed on the
following query. Is there an equivalent to rowSums that does product or
cumulative product and avoids use of apply or looping? I found a rowProd
in a package but it was a convenience function for apply. As part of a
likelihood calculation called from optim, I?m computing products and
cumulative products of rows of matrices with
2012 Sep 27
3
problem with nls starting values
Hi
I would like to fit a non-linear regression to the follwoing data:
quantiles<-c(seq(.05,.95,0.05))
slopes<-c( 0.000000e+00, 1.622074e-04 , 3.103918e-03 , 2.169135e-03 ,
9.585523e-04
,1.412327e-03 , 4.288103e-05, -1.351171e-04 , 2.885810e-04 ,-4.574773e-04
, -2.368968e-03, -3.104634e-03, -5.833970e-03, -6.011945e-03, -7.737697e-03
, -8.203058e-03, -7.809603e-03, -6.623985e-03,
2007 Jun 20
1
How to extract diagonals
Hello,
I am using Mac OS X on a power book and R 2.5.0
I try to extract a diagonal from a dissimilarity matrix made with
dsvdis, with this code:
diag(DiTestRR)
But I get this error message:
Fehler in array(0, c(n, p)) : 'dim' spezifiziert ein zu großes Array
english:
Error in array(0, c(n, p)) : 'dim' specifies a too big array.
Is there a limit to extract diagonals?
I
2011 Nov 27
1
generating a vector of y_t = \sum_{i = 1}^t (alpha^i * x_{t - i + 1})
Dear R-help,
I have been trying really hard to generate the following vector given
the data (x) and parameter (alpha) efficiently.
Let y be the output list, the aim is to produce the the following
vector(y) with at least half the time used by the loop example below.
y[1] = alpha * x[1]
y[2] = alpha^2 * x[1] + alpha * x[2]
y[3] = alpha^3 * x[1] + alpha^2 * x[2] + alpha * x[3]
.....
below are
2013 Jan 23
2
setting off-diagonals to zero
The following 1460 x 1460 matrix can be throught of as 16 distinct 365 x 365
matrices. I'm trying to set off-diaganol terms in the 16 sub-matrices with
indices more than +/- 5 (days) from each other to zero using some for loops.
This works well for some, but not all, of the for loops. The R code I"m
using follows. For some reason the third loop below zero's-out everything
in the
2003 Mar 22
1
cumprod doesn't work with data frames (PR#2667)
Full_Name: J. Sisk
Version: 1.6.1
OS: Linux (RedHat 8)
Submission from: (NULL) (67.119.41.66)
Suppose you make a data-frame like so:
xxx <- data.frame(a=10,b=20,c=30,d=40)
Then
cumprod(xxx[1,])
returns
> cumprod(xxx[1,])
a b c d
1 10 20 30 40
The documentation for cumprod says that it should work on "numerical objects",
and this is a data-frame, but it
2001 May 19
2
calculations on diagonals of a matrix
Given an nxm matrix A I want to compute the nxm matrix B whose ij-th
element is the sum of the elements of A lying on the diagonal that ends
with element ij, i.e.,
b_ij = a_ij + a_(i-1)(j-1) + a_(i-2)(j-2) + ...
In APL (which I no longer use), I would use the 'rotate' operator to derive
an array whose columns are diagonals of the given array and then cumulate
down columns. Is
2007 Oct 10
3
as.dist with diagonal unequal zero
Hello and sorry that I still haven?t found a solution for my problem.
I need to extract the lower and upper triangle from a square matrix
including the diagonal. This diagonal is not zero in that special case.
I tried with as.dist
w<-as.dist(w, diag = TRUE)
> w
1 2 3 4 5
1 0
2 2 0
3 3 8 0
4 4 9 14 0
5 5 10 15 20 0
but found no way to keep the diagonal that is in the
2011 Jul 19
2
Taking all "complete" diagonals of a matrix
Hi R-Help!
I am trying to find a nicer way of extracting all the "complete" diagonals
of a matrix. I am working with very large matrices that have many more rows
than columns. I want to be able to extract each of the diagonals that are
as long as the number of columns in the matrix. I have written a rather
ugly function that presently does the job. It illustrates what I am trying
to
2009 Jul 31
1
what meaning missing value True /False needed
This is my code i don't understand the error message:
library(rgenoud)
rm(list=ls())
set.seed(666)
#########################################################
# As a first step, it is assumed that all input parameters are independent of ageing :
#########################################################
InputDim <-20
# Max number of ageings in the inputs
CPIRate <- rep(0.02 , InputDim )
#
2009 Sep 16
2
Generalized cumsum?
Is there anything like cumsum and cumprod but which allows you to
apply an arbitrary function instead of sum and product? In other words,
I want a function cumfunc(x, f) that returns a vector, so that for all n
up to the length of x
cumapply(x,f)[n] = f(x[1:n])
This would give cumsum and cumprod as special cases when f=sum or
f=prod.
I could write such a function, but I can't see
2011 Jan 27
1
How do I fix this ?
Just when I think I'm starting to learn ....
Statement z1 works, statement z doesn't. Why doesn't z work and what do I do
to fix it ? Clearly the problem is with the first NA, but I would think it's
handled through the loop vectorization.
y1 <- rnorm(20, 0, .013)
y1
[1] -0.0068630836 -0.0101106230 -0.0169663344 -0.0066314769 0.0075063818
[6] -0.0033548024 0.0015647863
2012 May 25
1
Filling NA with cumprod?
Hello,
I need to build certain interpolation logic using R. Unfortunately, I just
started using R, and I'm not familiar with lots of advanced or just
convenient features of the language to make this simpler. So I struggled
for few days and pretty much reduced the whole exercise to the following
problem, which I cannot resolve:
Assume we have a vector of some values with NA:
a <- c(1,