0

I have the following observations in a matrix M: 30 observations (row) in each of 1 to 5 groups (columns)

Reproducible code:

Simulate_phase_correction_isochronous<-function(N, nseq, alpha, st, sm)
{
  As<-matrix(NA, nrow=N, ncol=nseq)
  for(o in 1:nseq)
  {
    M=rnorm(N+2)
    T=rnorm(N+2)

    Z=st*T[1:(N+1)]-sm*M[2:(N+2)]+sm*M[1:(N+1)]
    AA=rep(0,N+2)
    for(I in 1:(N+1))
    {
      AA[I+1]<-(1-alpha)*AA[I]+Z[I]
    }
    As[,o]<-AA[3:(N+2)]
  }
  As
}

set.seed(1)
M<-Simulate_phase_correction_isochronous(N=30, nseq=5,  a=0.5, st=10, sm=5)

y=M[2:dim(M)[1],]
x=M[1:(dim(M)[1]-1),]

#wide to long 
data<-reshape2::melt(y); 
names(data)<-c("n", "group", "y")
data$x<-melt(x)$value 

Goal: I want to estimate the parameters of the variance and the covariance at lag -+1.

This can be done by employing a Moving Average Model from the gls {name} function:

MA1.gls<-gls(y~x, data=data,corr=corARMA(q=1, form=~1|group), method="ML" )

My Question: How can I set constraints/limits in the gls function so that particular conditions are met? for instance:

2*covariance < variance

dom
  • 29
  • 1
  • 4

1 Answers1

0

This can be achieved by optimizing a profiled likelihood function, see Pinheiro and Bates, 2000, p.202. Click here for my R implementation.

dom
  • 29
  • 1
  • 4
  • Welcome to SO. Link as answers are best for comments not answers. I suggest editing the above answer to add the main parts from the link so its in one place if/when the above links die. – Syfer Feb 07 '18 at 01:00