Dear all,
I have an xts object with 81 variables. Of these, I need to extract 25 of them with a common string. For each element of this subset I need to do the following estimation, which works for one element (PortAvilliq#). Firstly, a lm, then a msmFit.
Port1 <- lm(PortAvilliq1 ~ 1, data = ger_ts)
# The msmFit
summary(msmPort1 <- msmFit(Port1, 2, sw=rep(TRUE,2)))
# Two variables to determine the greater and smaller coefficients
Port1HighIll <- ifelse(msmPort1@Coef[1,]> msmPort1@Coef[2,],msmPort1@Coef[1,],
msmPort1@Coef[2,])
Port1LowIll <- ifelse(msmPort1@Coef[1,] < msmPort1@Coef[2,], msmPort1@Coef[1,],
msmPort1@Coef[2,])
# The associated probabilities
Port1ProbLow <- ifelse(msmPort1@Coef[1,] > msmPort1@Coef[2,], msmPort1@transMat[2,2],
msmPort1@transMat[1,1])
Port1ProbHigh <- ifelse(msmPort1@Coef[1,] > msmPort1@Coef[2,], msmPort1@transMat[1,1],
msmPort1@transMat[2,2])
# The main variable of interest
Port1EIll <- Port1LowIll * Port1ProbLow + (Port1HighIll-Port1LowIll) * Port1ProbHigh`
I could workout
myNames <- paste("PortAvilliq", 1:25, sep = "")
myNames <- subset(datager, select = myNames)
mycoefs <- lapply(myNames, function(myNames) mod <- lm(myNames ~ 1))
However, now I'm stuck as to run the msmFit for each model and then extract coefficients in an array
How can I do it?
Thanks for any help