Home > other >  For loop vary one parameter keeping the other constant
For loop vary one parameter keeping the other constant

Time:01-16

I have a for loop in which I only want to vary one parameter p while keeping the other q constant. p and q are "auto regression" and "moving average" orders in gls(). How to achieve that? Here is my code (not working):

cor.results <- NULL
for(p in 0:3) {
  cor.temp <- gls(di.posaf~di.index   factor(subject):day   factor(subject), data=PMBCall2, method='ML', correlation=corARMA(p=p, q=0, form = ~ day | subject)) #I want to vary p only and keep q constant
  cor.results <- rbind(cor.results, c(p, q, logLik(cor.temp), AIC(cor.temp))) 
}

CodePudding user response:

It turns out that corARMA() does not accept p=0 & q=0 at the same time and so I increased the starting value of p to 1

cor.results <- NULL
for(p in 1:3) {
  cor.temp <- gls(di.posaf~di.index   factor(subject):day   factor(subject), data=PMBCall2, method='ML', correlation=corARMA(p=p, q=0, form = ~ day | subject)) #p should start from 1
  cor.results <- rbind(cor.results, c(p, q, logLik(cor.temp), AIC(cor.temp))) 
}
  •  Tags:  
  • Related