Robel Tech πŸš€

Representing Parametric Survival Model in Counting Process form in JAGS

February 20, 2025

Representing Parametric Survival Model in Counting Process form in JAGS

Endurance investigation, a cornerstone of statistical modeling, performs a important function successful knowing clip-to-case information. Representing parametric endurance fashions, specified arsenic the Weibull oregon exponential fashions, inside a Bayesian model provides important advantages, permitting for the incorporation of anterior cognition and offering a afloat posterior organisation of exemplary parameters. JAGS (Conscionable Different Gibbs Sampler), a almighty Markov Concatenation Monte Carlo (MCMC) motor, is peculiarly fine-suited for this project, particularly once using the counting procedure formulation. This attack not lone simplifies the implementation however besides enhances the flexibility of the exemplary, accommodating clip-various covariates and analyzable censoring patterns.

Knowing the Counting Procedure

The counting procedure gives a dynamic cooperation of case occurrences complete clip. It basically tracks the figure of occasions that person occurred ahead to a circumstantial component. This model is peculiarly utile successful endurance investigation arsenic it permits america to exemplary the instantaneous hazard of an case, identified arsenic the hazard charge. By framing endurance information inside a counting procedure, we tin leverage the powerfulness of JAGS to estimation exemplary parameters and quantify uncertainty.

The counting procedure cooperation includes 2 cardinal elements: the case indicator and the astatine-hazard indicator. The case indicator signifies whether or not an case occurred astatine a peculiar clip component, piece the astatine-hazard indicator signifies whether or not an idiosyncratic is inactive nether reflection and vulnerable to the case astatine that clip. This permits for a much granular investigation of endurance information.

For illustration, ideate monitoring the clip till nonaccomplishment of physics parts. The counting procedure would evidence all nonaccomplishment and bespeak which parts are inactive functioning astatine all reflection clip. This attack facilitates dealing with conditions wherever parts participate the survey astatine antithetic instances oregon are censored owed to assorted causes.

Implementing Parametric Endurance Fashions successful JAGS

JAGS gives a versatile level for implementing a assortment of parametric endurance fashions inside the counting procedure model. Whether or not utilizing a Weibull, exponential, oregon log-logistic organisation, the cardinal is to specify the hazard relation appropriately. This includes specifying the organisation’s parameters and linking them to the covariates of involvement.

Inside the JAGS exemplary, the probability relation is constructed primarily based connected the counting procedure cooperation. This includes defining the likelihood of an case occurring astatine a fixed clip, conditional connected the idiosyncratic being astatine hazard and the values of the covariates. Priors are past specified for the exemplary parameters, reflecting current cognition oregon assumptions astir the underlying procedure.

Fto’s see an illustration wherever we are modeling the clip till relapse successful crab sufferers. We mightiness usage a Weibull organisation to seizure the altering hazard charge complete clip. Covariates specified arsenic care kind and property tin beryllium integrated into the exemplary to analyze their contact connected relapse hazard. JAGS permits america to estimation the posterior distributions of these parameters, offering a blanket knowing of their results.

Advantages of the Counting Procedure Attack

The counting procedure formulation provides respective advantages once implementing endurance fashions successful JAGS. Firstly, it simplifies the dealing with of analyzable censoring patterns, together with correct censoring, near censoring, and interval censoring. This is important successful existent-planet eventualities wherever absolute reflection of each occasions is frequently not imaginable. Secondly, it permits for the inclusion of clip-various covariates, which tin seizure dynamic adjustments successful idiosyncratic traits complete clip.

Moreover, the counting procedure model gives a earthy manner to exemplary recurrent occasions, wherever people tin education aggregate occasions complete the reflection play. This is peculiarly applicable successful areas specified arsenic healthcare, wherever sufferers whitethorn education aggregate episodes of a illness. The counting procedure permits america to path the incidence of all case and exemplary the idiosyncratic’s underlying case charge.

For case, successful a survey connected infirmary readmissions, the counting procedure attack permits researchers to analyse the elements contributing to aggregate readmissions inside a circumstantial timeframe, offering invaluable insights for bettering diligent attention and assets allocation.

Deciphering JAGS Output and Diagnostics

Erstwhile the JAGS exemplary has tally, it’s indispensable to cautiously construe the output and execute diagnostic checks. The capital output of involvement is the posterior organisation of the exemplary parameters. This organisation gives an estimation of the uncertainty related with all parameter, permitting for much strong inferences in contrast to conventional frequentist strategies. Convergence diagnostics, specified arsenic hint plots and Gelman-Rubin statistic, are important to guarantee that the MCMC chains person converged to the stationary organisation.

Moreover, it’s crucial to measure the exemplary’s goodness-of-acceptable utilizing methods specified arsenic posterior predictive checks. These affect evaluating noticed information to information simulated from the posterior organisation, permitting for an valuation of the exemplary’s quality to seizure the cardinal options of the noticed information. Appropriate exemplary validation ensures that the inferences drawn from the investigation are dependable and tin communicate determination-making.

For illustration, by analyzing the posterior organisation of the hazard ratio related with a peculiar care, we tin find the chance that the care reduces the hazard of the case and quantify the magnitude of this simplification. This accusation is invaluable for clinicians and policymakers successful evaluating the effectiveness of antithetic interventions.

  • Make the most of the counting procedure for simpler implementation and flexibility.
  • Leverage JAGS for a blanket Bayesian investigation of endurance information.
  1. Specify the hazard relation primarily based connected the chosen parametric exemplary.
  2. Concept the chance relation utilizing the counting procedure cooperation.
  3. Specify priors for the exemplary parameters.
  4. Tally the JAGS exemplary and construe the posterior distributions.

Infographic Placeholder: Ocular cooperation of the counting procedure and its exertion successful endurance investigation.

“Bayesian strategies supply a earthy model for incorporating anterior cognition and quantifying uncertainty successful endurance investigation.” - Andrew Gelman, Bayesian Information Investigation

Seat much accusation from: WinBUGS, JAGS and R2jags.

By adopting the counting procedure formulation and leveraging the powerfulness of JAGS, researchers tin addition a deeper knowing of clip-to-case information and brand much knowledgeable selections. This attack is peculiarly invaluable successful fields similar medication, engineering, and economics, wherever endurance investigation performs a captious function.

FAQ

Q: What are the communal parametric fashions utilized successful endurance investigation?

A: Communal parametric fashions see exponential, Weibull, log-average, log-logistic, and gamma distributions.

This attack to endurance investigation permits for much nuanced insights than conventional strategies, offering a almighty implement for researchers. Research additional by researching associated matters specified arsenic clip-various covariates, recurrent case modeling, and Bayesian exemplary examination. See implementing these methods successful your ain investigation to unlock the afloat possible of your endurance information. And don’t hesitate to dive deeper into JAGS and its capabilities for analyzable statistical modeling.

Question & Answer :
I’m making an attempt to physique a endurance exemplary successful JAGS that permits for clip-various covariates. I’d similar it to beryllium a parametric exemplary β€” for illustration, assuming endurance follows the Weibull organisation (however I’d similar to let the hazard to change, truthful exponential is excessively elemental). Truthful, this is basically a Bayesian interpretation of what tin beryllium accomplished successful the flexsurv bundle, which permits for clip-various covariates successful parametric fashions.

So, I privation to beryllium capable to participate the information successful a ‘counting-procedure’ signifier, wherever all taxable has aggregate rows, all corresponding to a clip interval successful which their covariates remained changeless (arsenic described successful this pdf oregon present. This is the (commencement, halt] formulation that the endurance oregon flexurv packages let.

Unluckily, all mentation of however to execute endurance investigation successful JAGS appears to presume 1 line per taxable.

I tried to return this easier attack and widen it to the counting procedure format, however the exemplary does not accurately estimation the organisation.

A Failed Effort:

Present’s an illustration. Archetypal we make any information:

room('dplyr') room('endurance') ## Brand the Information: ----- fit.fruit(three) n_sub <- one thousand current_date <- 365*2 true_shape <- 2 true_scale <- 365 dat <- data_frame(individual = 1:n_sub, true_duration = rweibull(n = n_sub, form = true_shape, standard = true_scale), person_start_time = runif(n_sub, min= zero, max= true_scale*2), person_censored = (person_start_time + true_duration) > current_date, person_duration = ifelse(person_censored, current_date - person_start_time, true_duration) ) individual person_start_time person_censored person_duration (int) (dbl) (lgl) (dbl) 1 1 eleven.81416 Mendacious 487.4553 2 2 114.20900 Mendacious 168.7674 three three seventy five.34220 Mendacious 356.6298 four four 339.98225 Mendacious 385.5119 5 5 389.23357 Mendacious 259.9791 6 6 253.71067 Mendacious 259.0032 7 7 419.52305 Actual 310.4770 

Past we divided the information into 2 observations per taxable. I’m conscionable splitting all taxable astatine clip = 300 (except they didn’t brand it to clip=300, successful which they acquire conscionable 1 reflection).

## Divided into aggregate observations per individual: -------- cens_point <- 300 # <----- attempt altering to zero for nary divided; if truthful, exemplary appropriately estimates dat_split <- dat %>% group_by(individual) %>% bash(data_frame( divided = ifelse(.$person_duration > cens_point, cens_point, .$person_duration), Commencement = c(zero, divided[1]), Extremity = c(divided[1], .$person_duration), TINTERVAL = c(divided[1], .$person_duration - divided[1]), CENS = c(ifelse(.$person_duration > cens_point, 1, .$person_censored), .$person_censored), # <β€” edited first station present owed to bug; however job inactive immediate once fixing bug TINTERVAL_CENS = ifelse(CENS, NA, TINTERVAL), END_CENS = ifelse(CENS, NA, Extremity) )) %>% filter(TINTERVAL != zero) individual divided Commencement Extremity TINTERVAL CENS TINTERVAL_CENS (int) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) 1 1 300.0000 zero 300.0000 300.00000 1 NA 2 1 300.0000 300 487.4553 187.45530 zero 187.45530 three 2 168.7674 zero 168.7674 168.76738 1 NA four three 300.0000 zero 300.0000 300.00000 1 NA 5 three 300.0000 300 356.6298 fifty six.62979 zero fifty six.62979 6 four 300.0000 zero 300.0000 300.00000 1 NA 

Present we tin fit ahead the JAGS exemplary.

## Fit-Ahead JAGS Exemplary ------- dat_jags <- arsenic.database(dat_split) dat_jags$N <- dimension(dat_jags$TINTERVAL) inits <- replicate(n = 2, simplify = Mendacious, expr = { database(TINTERVAL_CENS = with(dat_jags, ifelse(CENS, TINTERVAL + 1, NA)), END_CENS = with(dat_jags, ifelse(CENS, Extremity + 1, NA)) ) }) model_string <- " exemplary { # fit priors connected reparameterized interpretation, arsenic prompt # present: https://sourceforge.nett/p/mcmc-jags/treatment/610036/thread/d5249e71/?bounds=25#8c3b log_a ~ dnorm(zero, .001) log(a) <- log_a log_b ~ dnorm(zero, .001) log(b) <- log_b nu <- a lambda <- (1/b)^a for (i successful 1:N) { # Estimation Taxable-Durations: CENS[i] ~ dinterval(TINTERVAL_CENS[i], TINTERVAL[i]) TINTERVAL_CENS[i] ~ dweibull( nu, lambda ) } } " room('runjags') param_monitors <- c('a', 'b', 'nu', 'lambda') fit_jags <- tally.jags(exemplary = model_string, burnin = one thousand, example = a thousand, display = param_monitors, n.chains = 2, information = dat_jags, inits = inits) # estimates: fit_jags # existent: c(a=true_shape, b=true_scale) 

Relying connected wherever the divided component is, the exemplary estimates precise antithetic parameters for the underlying organisation. It lone will get the parameters correct if the information isn’t divided into the counting procedure signifier. It appears similar this is not the manner to format the information for this benignant of job.

If I americium lacking an presumption and my job is little associated to JAGS and much associated to however I’m formulating the job, recommendations are precise invited. I mightiness beryllium despairing that clip-various covariates tin’t beryllium utilized successful parametric endurance fashions (and tin lone beryllium utilized successful fashions similar the Cox exemplary, which assumes changeless hazards and which doesn’t really estimation the underlying organisation)β€” nevertheless, arsenic I talked about supra, the flexsurvreg bundle successful R does accommodate the (commencement, halt] formulation successful parametric fashions.

If anybody is aware of however to physique a exemplary similar this successful different communication (e.g. STAN alternatively of JAGS) that would beryllium appreciated excessively.

Edit:

Chris Jackson offers any adjuvant proposal through electronic mail:

I deliberation the T() concept for truncation successful JAGS is wanted present. Basically for all play (t[i], t[i+1]) wherever a individual is live however the covariate is changeless, the endurance clip is near-truncated astatine the commencement of the play, and perchance besides correct-censored astatine the extremity. Truthful you’d compose thing similar y[i] ~ dweib(form, standard[i])T(t[i], )

I tried implementing this proposition arsenic follows:

exemplary { # aforesaid arsenic earlier log_a ~ dnorm(zero, .01) log(a) <- log_a log_b ~ dnorm(zero, .01) log(b) <- log_b nu <- a lambda <- (1/b)^a for (i successful 1:N) { # modified to see near-truncation CENS[i] ~ dinterval(END_CENS[i], Extremity[i]) END_CENS[i] ~ dweibull( nu, lambda )T(Commencement[i],) } } 

Unluckily this doesn’t rather bash the device. With the aged codification, the exemplary was largely getting the standard parameter correct, however doing a precise atrocious occupation connected the form parameter. With this fresh codification, it will get precise adjacent to the accurate form parameter, however constantly complete-estimates the standard parameter. I person observed that the grade of complete-estimation is correlated with however advanced the divided component comes. If the divided-component is aboriginal (cens_point = 50), location’s not truly immoderate complete-estimation; if it’s advanced (cens_point = 350), location is a batch.

I idea possibly the job might beryllium associated to ’treble-counting’ the observations: if we seat a censored reflection astatine t=300, past from that aforesaid individual, an uncensored reflection astatine t=four hundred, it appears intuitive to maine that this individual is contributing 2 information-factors to our inference astir the Weibull parameters once truly they ought to conscionable beryllium contributing 1 component. I, so, tried incorporating a random-consequence for all individual; nevertheless, this wholly failed, with immense estimates (successful the 50-ninety scope) for the nu parameter. I’m not certain wherefore that is, however possibly that’s a motion for a abstracted station. Since I’m not whether or not the issues are associated, you tin discovery the codification for this entire station, together with the JAGS codification for that exemplary, present.

You tin usage rstanarm bundle, which is a wrapper about STAN. It permits to usage modular R expression notation to depict endurance fashions. stan_surv relation accepts arguments successful a “counting procedure” signifier. Antithetic basal hazard features together with Weibull tin beryllium utilized to acceptable the exemplary.

The endurance portion of rstanarm - stan_surv relation is inactive not disposable astatine CRAN truthful you ought to instal the bundle straight from mc-stan.org.

instal.packages("rstanarm", repos = c("https://mc-stan.org/r-packages/", getOption("repos"))) 

Delight seat the codification beneath:

room(dplyr) room(endurance) room(rstanarm) ## Brand the Information: ----- fit.fruit(three) n_sub <- a thousand current_date <- 365*2 true_shape <- 2 true_scale <- 365 dat <- data_frame(individual = 1:n_sub, true_duration = rweibull(n = n_sub, form = true_shape, standard = true_scale), person_start_time = runif(n_sub, min= zero, max= true_scale*2), person_censored = (person_start_time + true_duration) > current_date, person_duration = ifelse(person_censored, current_date - person_start_time, true_duration) ) ## Divided into aggregate observations per individual: -------- cens_point <- 300 # <----- attempt altering to zero for nary divided; if truthful, exemplary accurately estimates dat_split <- dat %>% group_by(individual) %>% bash(data_frame( divided = ifelse(.$person_duration > cens_point, cens_point, .$person_duration), Commencement = c(zero, divided[1]), Extremity = c(divided[1], .$person_duration), TINTERVAL = c(divided[1], .$person_duration - divided[1]), CENS = c(ifelse(.$person_duration > cens_point, 1, .$person_censored), .$person_censored), # <β€” edited first station present owed to bug; however job inactive immediate once fixing bug TINTERVAL_CENS = ifelse(CENS, NA, TINTERVAL), END_CENS = ifelse(CENS, NA, Extremity) )) %>% filter(TINTERVAL != zero) dat_split$CENS <- arsenic.integer(!(dat_split$CENS)) # Acceptable STAN endurance exemplary mod_tvc <- stan_surv( expression = Surv(Commencement, Extremity, CENS) ~ 1, information = dat_split, iter = a thousand, chains = 2, basehaz = "weibull-aft") # Mark acceptable coefficients mod_tvc$coefficients[2] unname(exp(mod_tvc$coefficients[1])) 

Output, which is accordant with actual values (true_shape <- 2; true_scale <- 365):

> mod_tvc$coefficients[2] weibull-form 1.943157 > unname(exp(mod_tvc$coefficients[1])) [1] 360.6058 

You tin besides expression astatine STAN origin utilizing rstan::get_stanmodel(mod_tvc$stanfit) to comparison STAN codification with the makes an attempt you made successful JAGS.