[R] user defined covariance structure
Jonathan Smith
jon3smith at hotmail.com
Mon Jul 31 16:08:22 CEST 2006
I am writing as I am still having trouble trying to define my own covariance
matrix. My code is displayed below. I am defining the covariance matrix in
the form of an AR1 process so it can be easily checked if working correctly.
Another question I have is if it is possible to define the matrix without
giving p a specific value and leaving it in as a coefficient. For the
reason that it can be estimated when model is run. I figure that is the way
AR1 works in GLS.
Thank you
Jon Smith
I would appreciate any help s I am stuck here and need to figure this out
prior to continuing my research.
function ()
{
library(nlme)
tim<-c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)
peep<-c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4)
y<-c(11.78,9.53,11.03,9.89,10.80,8.74,10.25,10.69,5.60,7.27,6.81,4.56,7.01,5.64,6.30,8.31)
#This y data was created from and AR1 model with correlation coefficient
equaling 0.7.
timMat<-matrix(c(tim),ncol=1,nrow=16)
peepMat<-matrix(c(peep),ncol=1,nrow=16)
yMat<-matrix(c(y),ncol=1,nrow=16)
dataframe<-data.frame(yMat,timMat,peepMat)
p=0.7
g=1
tester2<-corSymm(value = c(p^(1),p^(2),p^(3),p^(1),p^(2),p^(1)),form = ~
timMat|peepMat)
tester2<-Initialize(tester2, data = dataframe)
testMat2<-corMatrix(tester2)
print(testMat2)
# this appears to be working correctly
#smanGls<-gls(yMat~timMat,data = dataframe, corr = corAR1(form =
~timMat|peepMat))
# works perfectly
smanGls<-gls(yMat~timMat,data = dataframe, corr = corSymm(tester2))
arsum<-summary(smanGls)
print(arsum)
#this is what message I get when I try to use the covarince matrix I
defined.
#Error in gls(yMat ~ timMat, data = dataframe, corr = corSymm(tester2)) :
# false convergence (8)
}
More information about the R-help
mailing list