Hi, I'm looking for help with the commands to generate a graph to illustrate the effect of Variable X on the sensitivities at 95% specificity of Variable Y.
Attached is an example
Thanks!
Attached is an example
Thanks!
* Example generated by -dataex-. To install: ssc install dataex clear input byte case float(VarY VarX) 0 67.782104 0 0 66.60757 1.3376954 0 55.62016 1.1250879 0 62.93091 0 0 57.56018 0 1 52.43447 0 1 56.04311 1.6595508 1 52.87027 1.1951367 1 65.13115 0 1 55.72673 1.6695703 end
// GENERATE TOY DATA set more off clear set obs 10 set seed 1234 gen x = runiform() expand 50 gen y = rnormal(50, 5) gen p_case = invlogit(1 + 0.01*y - 0.004*x*y) summ p_case gen byte case = runiform() < p_case drop p_case // CALCULATE SENS & SPEC AT VALUES OF Y WITHIN X by x, sort: egen n_cases = total(case) by x, sort: egen n_non_cases = total(!case) by x (y), sort: gen specificity = sum(!case)/n_non_cases gsort x -y by x: gen sensitivity = sum(case)/n_cases // NOW FIND THE HIGHEST SENSITIVITY AT WHICH SPECIFICTY >= 95% by x: egen sens_at_spec_95 = max(cond(specificity >= 0.95, sensitivity, .)) egen flag = tag(x) graph twoway line sens_at_spec_95 x if flag
Comment