From pperry at stern.nyu.edu  Thu May 28 05:19:09 2015
From: pperry at stern.nyu.edu (Patrick Perry)
Date: Wed, 27 May 2015 23:19:09 -0400
Subject: [Rd] Fix for bug in arima function
In-Reply-To: <57DB0FCD-7D29-4299-8923-37600E233508@gmail.com>
References: <25B343E47D08442686D0BB09924080F2@stern.nyu.edu>
	<C12E9FD6-C398-407E-92B7-87C18FB922FD@gmail.com>
	<CABAt4HdvK6U+YHUN=fG=Z-fS50VCq4ivuc4MnEpnsHGMq+6NdA@mail.gmail.com>
	<21853.39130.479116.797885@stat.math.ethz.ch>
	<D75099B3-0574-4DE8-83E7-DE867E6A352F@gmail.com>
	<21853.47141.218962.268511@stat.math.ethz.ch>
	<57DB0FCD-7D29-4299-8923-37600E233508@gmail.com>
Message-ID: <C0E2E32FA34F43BF9DC62D00BA80C4D9@stern.nyu.edu>


> I suspect that what we really need is  
>  
> fitI <- lm(x ~ xreg - 1, na.action = na.omit)
> fit <- if(length(dx) > ncol(dxreg))
> lm(dx ~ dxreg - 1, na.action = na.omit)
> else list(rank = 0L)
> if(fit$rank == 0L) {
> ## Degenerate model. Proceed anyway so as not to break old code
> fit <- fitI
> }
> n.used <- sum(!is.na(resid(fitI))) - length(Delta)
> init0 <- c(init0, coef(fit))
>  
> At least that would be the conservative change to get n.used indentical to what it was in 3.0.1

Along the same lines, here?s a solution that avoids the extra call to lm:

fit <- if(length(dx) > ncol(dxreg))
lm(dx ~ dxreg - 1, na.action = na.omit)
else list(rank = 0L)
if(fit$rank == 0L) {
## Degenerate model. Proceed anyway so as not to break old code
fit <- lm(x ~ xreg - 1, na.action = na.omit)
}
isna <- apply(is.na(xreg), 1, any) | is.na(x)
n.used <- sum(!isna) - length(Delta)
init0 <- c(init0, coef(fit))



[Rd] Fix for bug in arima function
Patrick Perry