psacf.Rd
psacf
, pspacf
and psccf
compute (and by default plot) estimates of the auto-, partial auto- and cross- correlation or covariance functions for panel-vectors and plm::pseries
. They are analogues to acf
, pacf
and ccf
.
psacf(x, ...) pspacf(x, ...) psccf(x, y, ...) # S3 method for default psacf(x, g, t = NULL, lag.max = NULL, type = c("correlation", "covariance","partial"), plot = TRUE, gscale = TRUE, ...) # S3 method for default pspacf(x, g, t = NULL, lag.max = NULL, plot = TRUE, gscale = TRUE, ...) # S3 method for default psccf(x, y, g, t = NULL, lag.max = NULL, type = c("correlation", "covariance"), plot = TRUE, gscale = TRUE, ...) # S3 method for pseries psacf(x, lag.max = NULL, type = c("correlation", "covariance","partial"), plot = TRUE, gscale = TRUE, ...) # S3 method for pseries pspacf(x, lag.max = NULL, plot = TRUE, gscale = TRUE, ...) # S3 method for pseries psccf(x, y, lag.max = NULL, type = c("correlation", "covariance"), plot = TRUE, gscale = TRUE, ...) # S3 method for data.frame psacf(x, by, t = NULL, cols = is.numeric, lag.max = NULL, type = c("correlation", "covariance","partial"), plot = TRUE, gscale = TRUE, ...) # S3 method for data.frame pspacf(x, by, t = NULL, cols = is.numeric, lag.max = NULL, plot = TRUE, gscale = TRUE, ...) # S3 method for pdata.frame psacf(x, cols = is.numeric, lag.max = NULL, type = c("correlation", "covariance","partial"), plot = TRUE, gscale = TRUE, ...) # S3 method for pdata.frame pspacf(x, cols = is.numeric, lag.max = NULL, plot = TRUE, gscale = TRUE, ...)
x, y | a numeric vector, panel series ( |
---|---|
g | a factor, |
by | data.frame method: Same input as |
t | same input as g, to indicate the time-variable(s). For secure computations on unordered panel-vectors. Data frame method also allows one-sided formula i.e. |
cols | data.frame method: Select columns using a function, column names, indices or a logical vector. Note: |
lag.max | integer. Maximum lag at which to calculate the acf. Default is |
type | character. String giving the type of acf to be computed. Allowed values are "correlation" (the default), "covariance" or "partial". |
plot | logical. If |
gscale | logical. Do a groupwise scaling / standardization of |
... | further arguments to be passed to |
If gscale = TRUE
data are standardized within each group (using fscale
) such that the group-mean is 0 and the group-standard deviation is 1. This is strongly recommended for most panels to get rid of individual-specific heterogeneity which would corrupt the ACF computations.
After scaling, psacf
, pspacf
and psccf
compute the ACF/CCF by creating a matrix of panel-lags of the series using flag
and then correlating this matrix with the series (x, y
) using cor
and pairwise-complete observations. This may require a lot of memory on large data, but is done because passing a sequence of lags to flag
and thus calling flag
and cor
one time is much faster than calling them lag.max
times. The partial ACF is computed from the ACF using a Yule-Walker decomposition, in the same way as in pacf
.
An object of class 'acf', see acf
. The result is returned invisibly if plot = TRUE
.
For plm::pseries
and plm::pdata.frame
, the first index variable is assumed to be the group-id and the second the time variable. If more than 2 index variables are attached to plm::pseries
, the last one is taken as the time variable and the others are taken as group-id's and interacted.
The pdata.frame
method only works for properly subsetted objects of class 'pdata.frame'. A list of 'pseries' will not work.
#> country iso3c date year decade region income OECD PCGDP #> 1 Afghanistan AFG 1961-01-01 1960 1960 South Asia Low income FALSE NA #> 2 Afghanistan AFG 1962-01-01 1961 1960 South Asia Low income FALSE NA #> 3 Afghanistan AFG 1963-01-01 1962 1960 South Asia Low income FALSE NA #> 4 Afghanistan AFG 1964-01-01 1963 1960 South Asia Low income FALSE NA #> 5 Afghanistan AFG 1965-01-01 1964 1960 South Asia Low income FALSE NA #> 6 Afghanistan AFG 1966-01-01 1965 1960 South Asia Low income FALSE NA #> LIFEEX GINI ODA #> 1 32.292 NA 114440000 #> 2 32.742 NA 233350000 #> 3 33.185 NA 114880000 #> 4 33.624 NA 236450000 #> 5 34.060 NA 302480000 #> 6 34.495 NA 370250000psacf(wlddev$PCGDP, wlddev$country, wlddev$year) # ACF of GDP per Capitapsacf(wlddev, PCGDP ~ country, ~year) # Same using data.frame methodpsacf(wlddev$PCGDP, wlddev$country) # The Data is sorted, can omit t#>pspacf(wlddev$PCGDP, wlddev$country) # Partial ACF#>psccf(wlddev$PCGDP, wlddev$LIFEEX, wlddev$country) # CCF with Life-Expectancy at Birth#>psacf(wlddev, PCGDP + LIFEEX + ODA ~ country, ~year) # ACF and CCF of GDP, LIFEEX and ODA## Using plm: pwlddev <- plm::pdata.frame(wlddev, index = c("country","year"))# Creating a Panel Data Frame PCGDP <- pwlddev$PCGDP # Panel Series of GDP per Capita LIFEEX <- pwlddev$LIFEEX # Panel Series of Life Expectancy psacf(PCGDP) # Same as above, more parsimoniouspspacf(PCGDP)psccf(PCGDP, LIFEEX)