Published on :
Statistical CREATION_INTERNE

Normal Regression with Interval Censoring

This code is also available in: Deutsch Español Français
Awaiting validation
The script analyzes a dataset simulating potentially interval-censored event times (tl and tr). It presents two approaches to model interval censoring with PROC MCMC: a manual approach defining a custom likelihood function (llike) based on logpdf, logsdf, and logcdf functions, and a more concise approach using the MODEL statement with CLOWER and CUPPER options to directly specify the limits of the censoring interval. Both approaches estimate the same parameters mu and sigma.
Data Analysis

Type : CREATION_INTERNE


The 'cosmetic' dataset is created internally via a DATALINES statement. It contains 'tl' (lower event time) and 'tr' (upper event time) variables that define the censoring intervals. A dot ('.') indicates a missing value for left or right censoring. The 't' variable is initialized as missing.

1 Code Block
DATA STEP Data
Explanation :
This DATA block creates the 'cosmetic' dataset from the provided data lines (DATALINES). The 'tl' (lower time) and 'tr' (upper time) variables are read. The 't' variable is initialized as missing. Labels are defined for 'tl'. Note that the part ' @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json' of the INPUT statement is syntactically incorrect in this context and does not participate in reading the data, which comes exclusively from DATALINES.
Copied!
1title 'Normal Regression with Interval Censoring';
2DATA cosmetic;
3 t = .;
4 label tl = 'Time to Event (Months)';
5 INPUT tl tr @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
6 DATALINES;
745 . 6 10 . 7 46 . 46 . 7 16 17 . 7 14
837 44 . 8 4 11 15 . 11 15 22 . 46 . 46 .
925 37 46 . 26 40 46 . 27 34 36 44 46 . 36 48
1037 . 40 . 17 25 46 . 11 18 38 . 5 12 37 .
11 . 5 18 . 24 . 36 . 5 11 19 35 17 25 24 .
1232 . 33 . 19 26 37 . 34 . 36 .
13;
14 
2 Code Block
PROC MCMC
Explanation :
This first PROC MCMC block performs Bayesian inference for a normal regression model with interval censoring. It uses a custom likelihood function ('llike') to handle different types of censoring (left, right, interval censoring, and uncensored observations). The 'mu' and 'sigma' parameters are defined with non-informative priors. The MISSING=AC option handles missing values for chain analysis. The ODS SELECT PostSumInt statement selects the output table containing summaries and credibility intervals of the parameters.
Copied!
1PROC MCMC DATA=cosmetic outpost=postout seed=1 nmc=20000 missing=AC;
2 ods select PostSumInt;
3 parms mu 60 sigma 50;
4 
5 prior mu ~ normal(0, sd=1000);
6 prior sigma ~ gamma(shape=0.001,iscale=0.001);
7 
8 IF (tl^=. and tr^=. and tl=tr) THEN
9 llike = logpdf('normal',tr,mu,sigma);
10 ELSE IF (tl^=. and tr=.) THEN
11 llike = logsdf('normal',tl,mu,sigma);
12 ELSE IF (tl=. and tr^=.) THEN
13 llike = logcdf('normal',tr,mu,sigma);
14 ELSE
15 llike = log(sdf('normal',tl,mu,sigma) -
16 sdf('normal',tr,mu,sigma));
17 
18 model general(llike);
19RUN;
3 Code Block
PROC MCMC
Explanation :
This second PROC MCMC block performs the same Bayesian inference but in a more simplified way by using the CLOWER and CUPPER options of the MODEL statement. These options allow direct specification of the lower and upper limits of the censoring interval for the 't' variable, thus simplifying the likelihood implementation compared to the manual approach of the previous block. The MISSING=ACMODELY option is used for missing values in the model. ODS SELECT NONE suppresses all output from this procedure.
Copied!
1PROC MCMC DATA=cosmetic outpost=postout seed=117207154
2 nmc=20000 missing=ACMODELY;
3 ods select none;
4 parms mu 60 sigma 50;
5 
6 prior mu ~ normal(0, sd=1000);
7 prior sigma ~ gamma(shape=0.001,iscale=0.001);
8 
9 model t ~ normal(mu, sd=sigma, clower=tl, cupper=tr);
10RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : SAS Sample Library