2

I am trying to set my initial parameters in order to run a markov regime switching model but I always get the following error:

AttributeError: can't set attribute

My code is the following:

from statsmodels.tsa.regime_switching.markov_autoregression import MarkovAutoregression as mark_auto

mod = mark_auto(endog = data.dlgnp, k_regimes = 2, order=1, switching_variance= False, switching_exog= False, switching_trend= False)
mod.k_params
mod.param_names
regression.start_params = np.array([0.4,0.4,1,1])

The source code can be found here but the part specially concerning my problem is the following:

@property
def start_params(self):
    """
    (array) Starting parameters for maximum likelihood estimation.
    """
    # Inherited parameters
    params = markov_switching.MarkovSwitching.start_params.fget(self)

    # OLS for starting parameters
    endog = self.endog.copy()
    if self._k_exog > 0 and self.order > 0:
        exog = np.c_[self.exog, self.exog_ar]
    elif self._k_exog > 0:
        exog = self.exog
    elif self.order > 0:
        exog = self.exog_ar

    if self._k_exog > 0 or self.order > 0:
        beta = np.dot(np.linalg.pinv(exog), endog)
        variance = np.var(endog - np.dot(exog, beta))
    else:
        variance = np.var(endog)

I have also tried np.r_but it didn't help. I am running my code on python 2.7.15 and the strangest thing is that I remember having the code working last time I ran it. Any help would be extremely appreciated.

1 Answer 1

3

The start_params property just provides the default starting parameters used when calling the fit function - you don't have to set it yourself.

If you do want to set specific starting parameters, you would do that when calling fit, e.g.:

res = mod.fit(start_params=np.array([0.4,0.4,1,1]))

2
  • Oh perfect thank you very much ! I am actually taking your code found on github for this work :)
    – Joachim
    Apr 7, 2019 at 12:34
  • Glad to hear it's helpful!
    – cfulton
    Apr 7, 2019 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.