Michel Lutz
2011-Jul-29 07:37 UTC
[R] 'breackpoints' (package 'strucchange'): 2 blocking error messages when using for multiple regression model testing
Good morning to all, I am encountering a blocking issue when using the function 'breackpoints' from package 'strucchange'. *Context:* I use a data frame, 248 observations of 5 variables, no NA. I compute a linear model, as y~x1+...+x4 x4 is a dummy variable (0 or 1). I want to check this model for structural changes. *Process & issues:* *First, I used function Fstats.* It works perfectly. However, this test is not adapted because regression residuals are not independant. That is why *I used 'breackpoints', which works for depedant errors* (Bai, 1997). Syntax: struc.test <- breakpoints(y~x1+x2+x3+x3+x4, data=D) *I get an error message:* Erreur dans chol2inv(qr.R(fm$qr)) : l'élément (5, 5) est nul, donc l'inverse ne peut être calculé (sorry for the french version, I don't know how to get the message english translation in R). My first assumption was this has *something to do with the dummy variable, so I skipped it*: struc.test <- breakpoints(y~x1+x2+x3+x3, data=D) *New error message:* Erreur dans if (max(abs((betar - fm$coefficients)/fm$coefficients)) < tol) check <- FALSE : valeur manquante là où TRUE / FALSE est requis I really can't understand what is going wrong. What 'tol' stands for? Seems it is not a 'breackpoints' attributes. Any help would greatly appreciated. Many thanks in advance, Regards, Michel [[alternative HTML version deleted]]
Achim Zeileis
2011-Jul-29 08:58 UTC
[R] 'breackpoints' (package 'strucchange'): 2 blocking error messages when using for multiple regression model testing
Michel:> I am encountering a blocking issue when using the function 'breackpoints' > from package 'strucchange'. > > *Context:* > > I use a data frame, 248 observations of 5 variables, no NA. > I compute a linear model, as y~x1+...+x4 > x4 is a dummy variable (0 or 1). > > I want to check this model for structural changes.If you want to _test_ for structural changes, then you should use a test, i.e., apply sctest() to an Fstats(), efp(), or gefp(). If your errors are correlated, one standard approach is to employ a HAC (heteroskedasticity and autocorrelation consistent) covariance matrix. There is a worked example with Fstats() using a HC matrix in example("durab"). An example with gefp() using a HAC matrix is in example("gefp"). See also the vignette("sandwich", package = "sandwich"). The breakpoints() function is for _estimating_ (aka dating) structural changes, not for testing.> *Process & issues:* > > *First, I used function Fstats.* It works perfectly. However, this test is > not adapted because regression residuals are not independant. > > That is why *I used 'breackpoints', which works for depedant errors* (Bai, > 1997).Yes, as for coefficient estimates in a regression model, the breakpoint estimates are still consistent. But the tests need to be adjusted. Note also the in the presence of autocorrelation, the standard information criteria do not perform well (Bai & Perron 2003).> Syntax: > > struc.test <- breakpoints(y~x1+x2+x3+x3+x4, data=D) > > *I get an error message:* > Erreur dans chol2inv(qr.R(fm$qr)) : > l'?l?ment (5, 5) est nul, donc l'inverse ne peut ?tre calcul? > (sorry for the french version, I don't know how to get the message > english translation in R). > > My first assumption was this has *something to do with the dummy variable, > so I skipped it*: > struc.test <- breakpoints(y~x1+x2+x3+x3, data=D) > > *New error message:* > Erreur dans if (max(abs((betar - fm$coefficients)/fm$coefficients)) < tol) > check <- FALSE : > valeur manquante l? o? TRUE / FALSE est requis > > I really can't understand what is going wrong. What 'tol' stands for? Seems > it is not a 'breackpoints' attributes.The breakpoints() function needs to estimate the model on all possible subsets to determine the optimal breakpoints. This can be done via computation of recursive residuals and "tol" is an argument of the recresid() function. However, I recently enhanced the code trying to fix exactly this problem. Please try strucchange 1.4-5. Best, Z> Any help would greatly appreciated. > > Many thanks in advance, > > Regards, > > Michel > > [[alternative HTML version deleted]] > >
Michel Lutz
2011-Jul-29 13:21 UTC
[R] 'breackpoints' (package 'strucchange'): 2 blocking error messages when using for multiple regression model testing
Hi Hadley, Thanks for the idea, but this was a typo... My code is the following: D <- data.frame(CPU=pred.cor2$CPU, PREP=PREP, BRG=BIZ$JOBPREPLOTRULE_BRG, CLOG=res.WIP, WE=DUMMY) model.mes <- CPU~PREP+BRG+CLOG+WE stab.model <- Fstats(model.mes, data = D, from = 0.1, vcov = function(x, ...) vcovHC(x, type = "HC", ...)) plot(stab.model) bp.mes <- breakpoints(model.mes, data = D) Fstats works, by breakpoints tells me: Erreur dans chol2inv(qr.R(fm$qr)) : l'élément (5, 5) est nul, donc l'inverse ne peut être calculé I tried and tried again, no clue.... Thanks Michel On Fri, Jul 29, 2011 at 3:14 PM, Hadley Wickham <hadley@rice.edu> wrote:> >> struc.test <- breakpoints(y~x1+x2+x3+x3+x4, data=D) > >> > >> *I get an error message:* > >> Erreur dans chol2inv(qr.R(fm$qr)) : > >> l'?l?ment (5, 5) est nul, donc l'inverse ne peut ?tre calcul? > >> (sorry for the french version, I don't know how to get the message > >> english translation in R). > >> > >> My first assumption was this has *something to do with the dummy > variable, > >> so I skipped it*: > >> struc.test <- breakpoints(y~x1+x2+x3+x3, data=D) > >> > >> *New error message:* > >> Erreur dans if (max(abs((betar - fm$coefficients)/fm$coefficients)) < > tol) > >> check <- FALSE : > >> valeur manquante l? o? TRUE / FALSE est requis > >> > >> I really can't understand what is going wrong. What 'tol' stands for? > >> Seems > >> it is not a 'breackpoints' attributes. > > > > The breakpoints() function needs to estimate the model on all possible > > subsets to determine the optimal breakpoints. This can be done via > > computation of recursive residuals and "tol" is an argument of the > > recresid() function. However, I recently enhanced the code trying to fix > > exactly this problem. Please try strucchange 1.4-5. > > Or maybe trying removing the duplicate x3 from your model formula? > > Hadley > > -- > Assistant Professor / Dobelman Family Junior Chair > Department of Statistics / Rice University > http://had.co.nz/ >[[alternative HTML version deleted]]