An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20050820/bbc5c458/attachment.pl
diagonal matrices
4 messages · Afshartous, David, Gabor Grothendieck, Brian Ripley +1 more
Have a look at adiag in the magic package.
On 8/20/05, Afshartous, David <afshart at exchange.sba.miami.edu> wrote:
Hello all,
I have matrices V.i of dimension n.i x n.i, where i = 1, ..., J, and the sum of n.i equals N. (and n.i ! = n.j)
goal: create one large matrix V, where V has matrices V.i on diagonal.
I create each matrix V.i in a for loop (1 to J), so each time I'd like to augment V with the
most recently calculated V.i, such that I'll have V after the final iteration of the for loop.
question: how to initialize V and do the augmentation. any advice much appreciated.
cheers,
dave
ps - please respond directly to afshar at miami.edu, thanks!
[[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On Sat, 20 Aug 2005, Afshartous, David wrote:
I have matrices V.i of dimension n.i x n.i, where i = 1, ..., J, and the sum of n.i equals N. (and n.i ! = n.j) goal: create one large matrix V, where V has matrices V.i on diagonal. I create each matrix V.i in a for loop (1 to J), so each time I'd like to augment V with the most recently calculated V.i, such that I'll have V after the final iteration of the for loop. question: how to initialize V and do the augmentation. any advice much appreciated.
It is probably best to pre-create a matrix and fill in the blocks. As in
V <- matrix(0, N, N)
# let n be a vector of what you called n.i
n0 <- c(0, cumsum(n))
for(i in 1:J) {
ind <- (n0[i]+1):n0[i+1]
V[ind, ind] <- V.i
}
cheers, dave ps - please respond directly to afshar at miami.edu, thanks!
Please set that as your reply address to ease the lot of your helpers.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
1 day later
Hello, I have posted this mail a few days ago without any answer:
I have the following doubts related with lm.ridge, from MASS package. To
show the problem using the Longley example, I have the following doubts:
First: I think coefficients from lm(Employed~.,data=longley) should be
equal coefficients from lm.ridge(Employed~.,data=longley, lambda=0) why
it does not happen?
Second: if I have for example
Ridge<-lm.ridge(Employed~., data=longley, lambda = seq(0,0.1,0.001)), I
suppose intercept coefficient is defined implicit, why it does not
appear in Ridge$coef?
Third: I suppose that if I define
1) y<-longley$Employed
2) X<-as.matrix(cbind(1,Longley[,1:6])
3) I as the identity
the following should be true:
Coef=(X'X+kI)^(-1) X'y
and if a take k=Ridge$kHKV, the coefficients should be approx equal to
Ridge$Coef[near value of kHKV] and it does not seem to happen, why?
Values:
Ridge$kHKB
[1] 0.004275357
Using the calculation above (third question, third point):
Coef=
[,1]
1 -0.095492310
GNP.deflator -0.052759002
GNP 0.070993540
Unemployed -0.004244391
Armed.Forces -0.005725582
Population -0.413341544
Year 0.048420107
And if I take from Ridge&coef:
Ridge$coef[0.004]
GNP.deflator -0.03098507
GNP -1.32553151
Unemployed -1.53237769
Armed.Forces -0.63334911
Population -0.88690241
Year 6.82105049
Any help, suggestion or orientation?
Thanks in advance
Daniel Rozengardt