prais_winsten accepts a fitted panel model of class plm in place of its
arguments formula, data and index, which are taken from the model (#11).
Since the estimator obtains all its estimates by ordinary least squares, only
models that were estimated with model = "pooling" are supported, and the within
and the random effects model are rejected with a message that points at the dummy
variables of the formula, because their own transformation does not leave the
AR(1) structure of the errors intact. The data are obtained by evaluating the
data argument of the call of the model, so the object it refers to must still be
available. The model frame of the fitted model cannot be used instead, because its
columns are named after the terms of the formula, so that a term such as
factor(id) or log(x) could not be evaluated again. If the data are a
pdata.frame, the time variable is turned back into a number, since the index of
a pdata.frame is stored as factors, which order the periods but do not carry the
distances between them that the transformation of a gap requires. Thanks to Julian
Jäcker for the request.
Gaps in the time variable are taken into account by the Prais-Winsten transformation. Two observations of a panel that lie k periods apart are correlated by rho^k under an AR(1) process, so an observation whose predecessor lies k periods back is now differenced against that power and rescaled to keep the variance of the transformed errors constant. The estimates are those of generalised least squares evaluated at the periods that were observed, while previously the observations that surround a gap were treated as if they were consecutive. As a gap grows, the transformation approaches the one of the first observation of a panel, so that an observation after a long gap effectively starts a new spell. Equally spaced data are unaffected, and the warning that a gap used to raise is gone. The same applies to the gap that an observation dropped for missing values leaves behind (#12). Thanks to Sebastian Krantz for pointing out that the lags have to be taken from the time variable rather than from adjacent rows.
The distances between the periods are counted in steps of the greatest common
divisor of the differences of the time variable, so that quarterly, monthly or
biennial data are handled without further arguments and the estimates no longer
depend on the unit the periods are expressed in. Date and POSIXct variables
are supported, which the check of the time variable previously skipped, because
is.numeric is FALSE for them. If the periods are not multiples of a common
step, a warning is issued and the observations that surround a gap are treated as
if they were consecutive, as before.
The estimate of rho is still obtained from the residuals of an observation and its predecessor, whether or not a gap lies between them. Since the correlation across a gap is rho^k rather than rho, the estimate is attenuated towards zero if a large share of the observations follows a gap. This is now documented.
Added the component timeid to objects of class prais, which holds the
periods of the observations counted in whole steps from the first period of their
panel. summary.prais and the covariance matrices repeat the transformation on
the data of the model and need the same distances, and the time variable is not
part of the model frame of a time series.
Added a vignette that walks through the estimation of a time series model and
of a panel model. It covers how to read the output of summary, the comparison
with ordinary least squares, confidence intervals and predictions, panel specific
estimates of rho and their weighted average, panel-corrected standard errors,
gaps in the time variable and the interface to plm.
Added methods for the generics tidy, glance and augment of package
broom, which summarise the coefficients, the goodness of fit and the fitted
values of an estimated model in tidy data frames. glance also reports the AR(1)
coefficient and the Durbin-Watson statistics, which are NA if the model was
estimated with panelwise = TRUE, because there is one coefficient per panel in
that case. The generics are the interface through which packages for publishable
regression output, such as gtsummary and modelsummary, obtain the results of
a model (#13). The methods are registered when broom is loaded, so broom
remains a suggested package and the generics are not re-exported, unlike in the
version of the extension that was part of release 1.1.3. Since delayed registration requires
R (>= 3.6.0), the minimum version of R was raised accordingly.
predict.prais gained the arguments se.fit, interval and level, so that
the standard errors and the confidence interval of the predicted conditional mean
can be obtained (#10). They are based on the covariance matrix of vcov.prais and
the quantiles of the t distribution with the residual degrees of freedom of the
model, so they agree with the standard errors of summary.prais and the intervals
of confint.prais. Prediction intervals for an individual observation are not
available, because their variance would depend on the serial correlation of the
error of the predicted period, which the predictions do not use. The default
result is unchanged. Thanks to Angel Paternina for the request.
Added vcov.prais, which returns the covariance matrix of the coefficients
that the standard errors of summary.prais are based on. Functions that obtain
the covariance matrix from a model, such as lmtest::coeftest, previously
failed with "no applicable method for 'vcov'" and now work without passing the
matrix explicitly.
Added confint.prais. The intervals are based on the t distribution with the
residual degrees of freedom of the model, so they agree with the p-values of
summary.prais and with the intervals of tidy. Without the method they would
be obtained by confint.default, which uses the quantiles of the normal
distribution and is therefore too narrow in small samples.
The transformed model matrix and the transformed response are added to the
estimated object as the components x and y. The tests of package lmtest,
such as dwtest, bgtest and bptest, do not use the residuals of the model
they are given, but take those two components and re-estimate the model by
ordinary least squares. Without them both were taken from the model frame, which
holds the original data, so the tests described the untransformed model and
reported the same Durbin-Watson statistic as before the correction for serial
correlation (#16). They now refer to the estimated model. The components are not
added for panel data, because the tests difference the residuals over all
observations at once, which mixes the last observation of a panel with the first
observation of the next one. summary reports a Durbin-Watson statistic that
respects the panels instead.
The Prais-Winsten transformation is applied to all panels at once instead of one panel at a time, which allocated a copy of the involved rows for every panel. The results are unchanged.
Fixed summary.prais and the covariance matrices vcovHC.prais and
vcovPC.prais for panel models whose formula contains a transformed term, such
as log(x) or poly(x, 2), whose source column is not itself part of the model
frame. They failed with "object 'x' not found". The ID and time variables were
appended to the model frame with cbind, which returns a new data frame and
drops its terms attribute, so the frame was no longer recognised as a model
frame and model.matrix evaluated the variables of the formula against it again
instead of taking the columns it already holds. The variables are now assigned as
columns, which leaves the attributes of the frame intact. Single time series were
not affected, and neither were terms such as factor(id) that refer to a
variable of the index, because that column had just been appended.
The estimate of rho is bounded to the interval [-1, 1] in every case. The
bound was only applied to the panel-specific estimates of panelwise = TRUE,
while the estimate of the usual case was left as the regression of the residuals
on their lag returned it. A value outside the interval makes the scale of the
first observation of a panel, (1 - rho^2)^(1 / 2), complex, so that the
observation became NaN and was silently dropped from the estimation, although
the documentation stated that the estimates are bounded. Errors that follow an
explosive process are enough to reach that path.
vcovPC reduces the periods and the panels of the observations to the rows
that the transformation produced. The residuals were matched to the full set of
observations by position, so that a dropped row shifted them to the wrong panel
and period and the covariances were computed from mismatched residuals, which
only showed as a warning about a recycled vector.
Argument index of prais_winsten defaults to NULL, so that it can be
omitted for data whose observations are already in the order of the periods.
Passing NULL has always been supported, but leaving the argument out raised
the missing-argument error of R.
A model that contains no pair of consecutive observations is rejected with a
message. The AR(1) coefficient is obtained by regressing the residuals on the
residuals of the preceding period, which such a model cannot provide. It was
reached by a model without coefficients estimated from a single observation,
which keeps its residual degrees of freedom, and failed inside lm.fit with
"incompatible dimensions".
citation("prais") reports the DOI of the
archive.vcovPC.prais for panels that do not all begin in the same period. The
covariances of the panels were indexed by the order in which the panels first
appear, while the observations of a period follow the panel, so the covariances
were assigned to the wrong panels. The results now agree with package pcse.index after the
model frame was built. A subset that reorders the observations undid that order
and made the transformation use the wrong lags.summary.prais are considerably faster for data with many
panels, and the check of argument index and the alignment of the observations
no longer dominate the run time of larger samples. The positions of the observations were obtained by appending to a vector
once per panel, which copies the whole vector in every iteration.pcse, which prais depends on, is
licensed under GPL (>= 3), with which GPL-2 alone is not compatible.prais_winsten. Observations that were
dropped by lm are now also removed from the data that is used to construct the
panel and lag positions, which previously caused errors such as
"subscript out of bounds" or "NA/NaN/Inf in 'y'".prais_winsten now throws an informative error if the variables specified in
argument index contain NA values.newdata of predict.prais, which was positioned after ... and
was therefore ignored when it was not passed by name. predict(object, newdata)
silently returned the fitted values instead of the predictions.predict.prais now builds the model matrix of newdata from the model terms.
Transformed variables, factors and interactions are handled correctly, and the
variables in newdata no longer have to be named after the model coefficients.prais_winsten returns the new elements xlevels and contrasts.lm, the coefficients of such variables are set
to NA and omitted from the fitted values, the coefficient table of summary.prais,
the covariance matrices of vcovHC.prais and vcovPC.prais and from predict.prais.print.summary.prais reports the number of coefficients that are not defined
because of singularities.subset and weights are now passed on to lm correctly. They
could not be evaluated when they were passed through the dots, which also made the
check for weighted least squares unreachable.vcovPC.prais throws an informative error if it is used on a model that was not
estimated from panel data.vcovHC.prais and vcovPC.prais no longer build an n x n matrix, which required a
prohibitive amount of memory for larger samples. The results are unchanged.message instead of cat and can
be suppressed with suppressMessages.prais_winsten throws an error if the variables specified in argument index are
not contained in data or do not uniquely identify the observations, and warns if
the time variable is not equally spaced.summary.prais returns the residuals of the transformed model, so that they are on
the same scale as the reported residual standard error.rhoweight no longer fails with "object 'n_groups' not found" if rho is not
panel specific. The weights only combine panel-specific estimates and are ignored
otherwise.max_iter and tol are validated. max_iter = 0 was silently treated
as one iteration and made the estimation of panel-specific rho fail with
"subscript out of bounds".print.summary.prais states that the reported residuals belong to the
transformed model.vcovPC.prais reports panels that do not have a period in common instead of
returning a covariance matrix of NaN. Argument pairwise = TRUE can be used to
match the observations of two panels by period in that case.prais_winsten reports panels with less than two observations if panelwise is
TRUE, because a panel-specific rho cannot be obtained from a single observation.predict.prais has its own help page, the description of
argument ... of prais_winsten is no longer overwritten, the note on values of rho
above 1 reflects that rho is bounded, summary.prais documents the components it
actually returns, and several typos were corrected.predict.prais.summary.prais when only an intercept is estimated.barium example data set.index of prais_winsten.prais_winsten$indexvcovPC.praisvcovHC.prais documentationNEWS.md file to track changes to the package