causalanalysis caEffect

Manufacturing Quality Control with Categorical Outcome (TMLE)

Scénario de test & Cas d'usage

Business Context

A factory wants to determine if a 'HighSpeed' machine setting causes more defects compared to 'Normal'. The outcome is binary (Defect: Yes/No). They use Targeted Maximum Likelihood Estimation (TMLE) for precise bias reduction on this critical binary metric.
About the Set : causalanalysis

Causal inference analysis and effect estimation.

Discover all actions of causalanalysis
Data Preparation

Small dataset with a Binary Outcome (Defect 1/0) and a categorical treatment.

Copied!
1 
2DATA mycas.factory_qc;
3call streaminit(777);
4DO batch = 1 to 200;
5temp = rand('NORMAL', 100, 5);
6humidity = rand('UNIFORM', 30, 60);
7IF rand('UNIFORM') > 0.5 THEN setting = 'HighSpeed';
8ELSE setting = 'Normal';
9logit_defect = -5 + 0.05*temp + 2*(setting='HighSpeed');
10prob_defect = 1 / (1 + exp(-logit_defect));
11IF rand('UNIFORM') < prob_defect THEN defect_flag = 1;
12ELSE defect_flag = 0;
13OUTPUT;
14END;
15 
16RUN;
17 

Étapes de réalisation

1
Fitting a Gradient Boosting model to predict the binary defect (simulating a complex outcome model).
Copied!
1 
2PROC CAS;
3decisionTree.gbtreeTrain TABLE={name='factory_qc'}, target='defect_flag', inputs={'setting', 'temp', 'humidity'}, casout={name='gb_model', replace=true};
4decisionTree.gbtreeScore TABLE={name='factory_qc'}, modelTable={name='gb_model'}, casout={name='qc_scored', replace=true}, copyVars='ALL', encodename=true;
5 
6RUN;
7 
2
Execution of caEffect using TMLE for a CATEGORICAL outcome.
Copied!
1 
2PROC CAS;
3causalanalysis.caEffect TABLE={name='qc_scored'}, method='TMLE', treatVar={name='setting'}, outcomeVar={name='defect_flag', type='CATEGORICAL', event='1'}, outcomeModel={predName='P_defect_flag1'}, pom={{trtLev='HighSpeed'}, {trtLev='Normal'}}, difference={{evtLev='HighSpeed', refLev='Normal'}}, inference=true;
4 
5RUN;
6 

Expected Result


The action correctly handles the 'CATEGORICAL' outcome type. It estimates the probability of Defect (event='1') for both machine settings using TMLE and reports the risk difference (causal effect) with valid confidence intervals.