Computes several features associated with a categorical time series
Computes several features associated with a categorical time series
calculate_features computes several features associated with a categorical time series or between a categorical and a real-valued time series
UTF-8
calculate_features(series, n_series =NULL, lag =1, type =NULL)
Arguments
series: An object of type tsibble (see R package tsibble), whose column named Value contains the values of the corresponding CTS. This column must be of class factor and its levels must be determined by the range of the CTS.
n_series: A real-valued time series.
lag: The considered lag (default is 1).
type: String indicating the feature one wishes to compute.
Returns
The corresponding feature.
Details
Assume we have a CTS of length T with range V={1,2,…,r}, Xt={X1,…,XT}, with pi
being the natural estimate of the marginal probability of the ith category, and pij(l) being the natural estimate of the joint probability for categories i and j at lag l, i,j=1,…,r. Assume also that we have a real-valued time series of length T, Zt={Z1,…,ZT}. The function computes the following quantities depending on the argument type:
If type=gini_index, the function computes the estimated gini index, g=r−1r(1−∑i=1rpi2).
If type=entropy, the function computes the estimated entropy, e=ln(r)−1∑i=1rpilnpi.
If type=chebycheff_dispersion, the function computes the estimated chebycheff dispersion, c=r−1r(1−maxipi).
If type=gk_tau, the function computes the estimated Goodman and Kruskal's tau, τ(l)=1−∑i=1rpi2∑i,j=1rpjpij(l)2−∑i=1rpi2.
If type=gk_lambda, the function computes the estimated Goodman and Kruskal's lambda, λ(l)=1−maxipi∑j=1rmaxipij(l)−maxipi.
If type=uncertainty_coefficient, the function computes the estimated uncertainty coefficient, u(l)=−∑i=1rpilnpi∑i,j=1rpij(l)ln(pipjpij(l)).
If type=pearson_measure, the function computes the estimated Pearson measure, XT2(l)=T∑i,j=1rpipj(pij(l)−pipj)2.
If type=phi2_measure, the function computes the estimated Phi2 measure, Φ2(l)=TXT2(l).
If type=sakoda_measure, the function computes the estimated Sakoda measure, p∗(l)=(r−1)(1+Φ2(l))rΦ2(l).
If type=cramers_vi, the function computes the estimated Cramer's vi, v(l)=r−11∑i,j=1rpipj(pij(l)−pipj)2.
If type=cohens_kappa, the function computes the estimated Cohen's kappa, κ(l)=1−∑i=1rpi2∑j=1r(pjj(l)−pj2).
If type=total_correlation, the function computes the the estimated sum Ψ(l)=r21∑i,j=1rψij(l)2, where ψij(l) is the estimated correlation Corr(Yt,i,Yt−l,j), i,j=1,…,r, being Yt={Y1,…,YT}, with Yk=(Yk,1,…,Yk,r)⊤, the binarized time series of Xt.
If type=spectral_envelope, the function computes the estimated spectral envelope.
If type=total_mixed_correlation_1, the function computes the estimated total mixed l-correlation given by
Ψ1(l)=r1i=1∑rψi(l)2,
where ψi(l)=Corr(Yt,i,Zt−l), being Yt={Y1,…,YT}, with Yk=(Yk,1,…,Yk,r)⊤, the binarized time series of Xt.
If type=total_mixed_correlation_2, the function computes the estimated total mixed q-correlation given by
Ψ2(l)=r1i=1∑r∫01ψiρ(l)2dρ,
where ψiρ(l)=Corr(Yt,i,I(Zt−l≤qZt(ρ))), being Yt={Y1,…,YT}, with Yk=(Yk,1,…,Yk,r)⊤, the binarized time series of Xt, ρ∈(0,1) a probability level, I(⋅) the indicator function and qZt the quantile function of the corresponding real-valued process.
Examples
sequence_1 <- GeneticSequences[which(GeneticSequences$Series==1),]uc <- calculate_features(series = sequence_1, type ='uncertainty_coefficient')# Computing the uncertainty coefficient# for the first series in dataset GeneticSequencesse <- calculate_features(series = sequence_1, type ='spectral_envelope')# Computing the spectral envelope# for the first series in dataset GeneticSequences