循环lm和msmFit提取系数

时间:2018-09-14 14:07:07

标签: r loops lm

我有一个带有81个变量的xts对象。其中,我需要使用公共字符串提取其中的25个。对于此子集的每个元素,我需要进行以下估算,该估算适用于一个元素(PortAvilliq#)。首先是lm,然后是msmFit。

Port1 <- lm(PortAvilliq1 ~ 1, data = ger_ts) # The msm 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

我该怎么办?

0 个答案:

没有答案