0
$\begingroup$

I wonder if you can help.

# create the baseline (on which the for example a model is fitted form which one can sample and derive the uncertainity of the cycle)

    x <- "
Groups  5Y(average) 2016    2017    2018    2019    2020
1   26  21  23  26  28  31
2   21  20  21  22  22  22
3   26  28  28  27  26  24
4   17  19  18  16  15  15
5   7   9   8   7   6   5
6   2   2   2   1   1   1
7   1   0   1   0   1   1
8   1   1   1   0   0   0
"
  
data <- read.table(
    textConnection(object = x),
    header = TRUE,
    sep = "",
    stringsAsFactors = FALSE
)
data
    
ccf.list <- list()
for(i in 1:nrow(data)){
    ccf.res <- ccf(ts(data)[i,],ts(rev(data))[i,])
    ccf.list[[i]] <- data.frame(group=i, lag=ccf.res$lag, ccf=ccf.res$acf)
}

cycl <- do.call(rbind, ccf.list)
cycl

q.cycle <- do.call(data.frame, with(cycl[ ,c("lag","ccf")], aggregate(cycl[ ,c("lag","ccf")], list(lag), quantile)))
q.cycle
q.cycle.short <- q.cycle[ ,c(1,c(7:ncol(q.cycle)))] # pick up teh 75% percentile as the baseline as the curve seems to fit the best (full down and up cycle)

# to long format for plotting all percentiles
q.cycle.long <- data.frame(lag=matrix(as.matrix(q.cycle.short[1]), ncol=1), ccf=matrix(as.matrix(q.cycle.short[-1]), ncol=1))
q.cycle.long$year <- with(q.cycle.long, rep(1:11,nrow(q.cycle.long)/11))
tail(q.cycle.long)
   
plot(ccf.75. ~ 1, data=q.cycle.short, col="red", type="b", pch=19, lwd=3, ylim=c(-0.5,0.5))
lines(ccf ~ year, data=q.cycle.long, col="darkgray")
abline(h=0, col="blue", lwd=3, lty=3)

enter image description here

Here this would be possible if a parametric model would exist and just new.data=data.frame(years=1:10) would allow to extrapolate. But how to get there sensibly?

Below you find very simple attempt which based on first inspection seems to be plausible but there must be better (and correct) way to estimate it.

Sample data and the attempt (in r):

The data are percentages per group and represent the proportion of observations per group of the overall dataset per year (each column should sum to 100% or 1, but because of rounding some might be slightly over 100%). The below data contains 5Y of data and its collected once a year (end of year) and this sample (patients in given category) shifts across these groups. (due to health risk).

This current data represents currently lower cycle with lower health risk. The cyclicality is expected due to exogenous factors and have roughly (length of upper or down cycle between 5-10 years. Unfortunately there is limited data on this migration and its expected (assumed) that the current down cycle its just reverse to explain how the upper cycle looks like (just a mirror).

The graph below is derived form this code:

plot(ccf ~ lag, data=cycl[cycl$group==1, ], col=1, type="l", ylim=c(-1,1))
with(cycl, by(cycl, group, function(x) lines(ccf ~ lag, data=x, col=group)))

enter image description here

$\endgroup$
10
  • $\begingroup$ Please don't require us to read or run your code just to figure out your question. Explain what these plots represent. What "distribution" do you refer to? How does either plot illustrate a "shift"? How is that related to "cyclicality," which refers to some kind of regular pattern of repetition? How are the data related to either of the plots, neither of which appears to represent the data themselves? $\endgroup$
    – whuber
    Commented Mar 9, 2023 at 20:41
  • $\begingroup$ Apologies, you are correct. I have now added that information towards the data. $\endgroup$
    – Maximilian
    Commented Mar 9, 2023 at 22:05
  • 1
    $\begingroup$ I still cannot discern any kind of "distribution" in your first plot and, because it lacks labels, is incomprehensible. $\endgroup$
    – whuber
    Commented Mar 9, 2023 at 22:47
  • $\begingroup$ I have now deleted the first graph to narrowing the question and limit the possible confusion (failing to communicate this properly). The question has now only 2 points instead of 3. $\endgroup$
    – Maximilian
    Commented Mar 9, 2023 at 22:57
  • $\begingroup$ What, per your understanding, is "cyclicity"? In other words, is it the presence or lack thereof? The period of a cycle? The amplitude? The functional shape of the cycle? $\endgroup$
    – AdamO
    Commented Mar 9, 2023 at 23:45

1 Answer 1

0
$\begingroup$

In panel such as these, a regression model is often used. One may add a random effect, like a random intercept, to account for heterogeneity between clusters.

Since you already know the period of the cycle, we may assume WLOG that you can appropriately assign any timepoint to its relative location in the cycle. This is equivalent to having "season" as an effect in the model - you can parse dates and find whether they lie in Fall, Winter, etc.

Simply using fixed effects - i.e. dummy variables - for season gives you a robust and flexible estimate of the cycloid. You can subdivide these into any level of granularity you desire, up to month or even day, depending on the robustness (i.e. quantity) of data.

More than likely, this approach may become untenable. You can reduce model complexity by enforcing smoothness via splines. I have a post about this here: What are periodic version of splines?.

$\endgroup$
4
  • $\begingroup$ thanks, but this is rather very sparse answer, have you tried to fit this to the data? Can you elaborate please on the use of ccf() function and the approach of obtaining the derived cycle path? Do I fit the model as you referenced on that time series? Because on the raw data (object: data) it does not provide plausible result. $\endgroup$
    – Maximilian
    Commented Mar 10, 2023 at 8:57
  • $\begingroup$ @Maximilian what exactly is sparse per your understanding? The issue to me seems that you are asking a modeling question but lack a (statistical) modeling background. It should be obvious ccf has nothing to do with your question. $\endgroup$
    – AdamO
    Commented Mar 10, 2023 at 13:23
  • $\begingroup$ wouldn’t be year-to-year dependence, hence ccf(), a good basis to start to assess the rate of change and from this to arrive on the shape of cycle? (Amplitude) $\endgroup$
    – Maximilian
    Commented Mar 11, 2023 at 8:06
  • $\begingroup$ I will completely rephrase this question later today. $\endgroup$
    – Maximilian
    Commented Mar 11, 2023 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.