Public
Edited
Oct 26, 2022
1 fork
Importers
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
plot1_3 = {
let xmin0 = pars1_3.mean0 - 5.2;
let xmax0 = pars1_3.mean0 + 5.2;
let xmin1 = pars1_3.mean1 - 5.2;
let xmax1 = pars1_3.mean1 + 5.2;
let xmin = d3.min([xmin0, xmin1]);
let xmax = d3.max([xmax0, xmax1]);
let w = 800;

let labels = [tex`H_0`, tex`H_1`, 'H0']

let alpha = pars1_3.sig;
let t0 = jstat.normal.inv(1-alpha, pars1_3.mean0, pars1_3.sd );
let t1 = jstat.normal.inv(1-alpha, pars1_3.mean1, pars1_3.sd );
let t2 = jstat.normal.inv(alpha, pars1_3.mean1, pars1_3.sd );

let p = plotter({
xDomain: [xmin, xmax],
yDomain: [0.5, -0.05],
grid: false,
width: w,
height: w / 2,
xLabel: '',
yLabel: '',
yTickCount: 5,
xTickCount: 5,
y: {
axis: null
}
});
let dx = 0.05;

let right0 = [{x: t0, y: 0}]
.concat(
d3.range(t0, xmax0, dx).map(x => ({x: x, y:jstat.normal.pdf(x, pars1_3.mean0, pars1_3.sd ) }))
);

let right1 = [{x: t0, y: 0}]
.concat(
d3.range(t0, xmax1, dx).map(x => ({x: x, y:jstat.normal.pdf(x, pars1_3.mean1, pars1_3.sd ) }))
);

let left1 = [{ x: xmin1, y: 0 }]
.concat(
d3.range(xmin1, t0, dx).map(x => ({ x: x, y: jstat.normal.pdf(x, pars1_3.mean1, pars1_3.sd ) }))
)
.concat([{ x: t0, y: jstat.normal.pdf(t0, pars1_3.mean1, pars1_3.sd) },{x: t0, y: 0}])

p.func(x => jstat.normal.pdf(x, pars1_3.mean0, pars1_3.sd ), {
stroke: 'grey',
width: 2,
opacity: 0.7,
dash: '2,2'
});
p.func(x => jstat.normal.pdf(x, pars1_3.mean1, pars1_3.sd ), {
stroke: 'grey',
width: 2,
opacity: 0.7,
})

p.polygon(right0, { fill: 'red', width: 0.2, opacity: 0.3 });
p.text('α', t0+0.2, 0.03, { stroke: 'red', weight: 600 });

p.polygon(right1, { fill: 'lightblue', width: 0.2, opacity: 0.5 });
p.text('1-β', t1, 0.03, { stroke: 'blue', weight: 600 });

p.polygon(left1, { fill: 'orange', width: 0.2, opacity: 0.5 });
p.text('β', t0-0.2, 0.03, { stroke: 'orange', weight: 600 });

p.text('H0', pars1_3.mean0, 0.4, { stroke: 'grey', weight: 600 });
p.text('H1', pars1_3.mean1, 0.4, { stroke: 'grey', weight: 600 });

p.line_segment(t0, -0.05, t0, 0.4, { stroke: 'grey', width: 1});
p.arrow(t0, -0.05, t0+1, -0.05, { stroke: 'grey'});
p.text(`Reject Null Hypothesis`, t0+2.5, -0.06, { stroke: 'grey' });
return p.node;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
plot6_1 = Plot.plot({
marginLeft: 60,
marginRight: 60,
height:400,
width:400,
style: {
background: '#fafafa',
},
y: {
label: null,
tickSize: 0,
margin: 10
},
x:{
label: 'Month →',
grid: true,
domain: [0,24],
ticks: 8,
// axis: 'top',
},
marks: [
Plot.ruleY(data2.plot1,
{x: "time", y: "id",
stroke: d=>d.time == month ? 'orange' : 'black'}
),
Plot.dot(data2.plot1,
{
x: "time", y: "id",
fill: d=> d.censor ? 'white': d.time == month ? 'orange' : 'black',
stroke: d=>d.time == month ? 'orange' : 'black',
r: 4}
),
// Plot.ruleY([]),
Plot.ruleX([0, 24]),
Plot.text(data2.plot1,
{x: "time", y: "id",
text: d=>d.event,
fill: d=>d.time == month ? 'orange' : 'black',
dy: -10,
dx: -3}
)
]
})
Insert cell
// viewof month = Inputs.range([0, 24], {step: 1, value: 0, label: 'Month'})
Insert cell
plot6_2 = Plot.plot({
marginLeft: 30,
marginRight: 50,
height:400,
width:700,
style: {
background: '#fafafa',
},
y: {
label: 'Estimated Event-free Survival',
// tickSize: 0,
margin: 10,
domain: [0,1.05],
},
x:{
label: 'Month →',
grid: true,
domain: [0,24],
ticks: 8,
// axis: 'top',
},
marks: [
// Plot.ruleY(data2.plot1, {x: "time", y: "id", fill: "black"}),
Plot.dot(data2.plot2.filter(d=>(d.change & d.time <= month)),
{x: "time", y: "s",
fill: d=>d.pos==1 ? 'white': 'black',
stroke:'black',
r: d=>d.time == 0 ? 0 : 4}
),
Plot.text(data2.plot2.filter(d=>d.change == false & d.time <= month), {x: "time", y: "s", text: d=>'|'}),
Plot.ruleY([0]),
Plot.ruleX([0]),
Plot.text(data2.plot2.filter(d=>d.time == month),
{
x: d=>d.time == 24 ? d.time -5 : d.time,
y: d=>d.pos == 1 ? d.s-0.02 : d.s+0.03,
text: d=>d.note,
fontSize: 12,
textAnchor: 'start',
// dy: d=>d.pos == 1 ? -10 : 10,
dx: 5
}
),
Plot.line(data2.plot2.filter(d=>d.time <= month), {x:'time', y:'s'})
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data3 = [
{i:1, event:22, b:-4.05, z:-2.02, p:0.0434},
{i:2, event:44, b:-2.86, z:-2.38, p:0.0174},
{i:3, event:66, b:-2.34, z:-2.92, p:0.0036},
{i:4, event:88, b:-2.04, z:null, p:null},
{i:5, event:88, b:2.04, z:null, p:null},
{i:6, event:66, b:2.34, z:null, p:null},
{i:7, event:44, b:2.86, z:null, p:null},
{i:8, event:22, b:4.05, z:null, p:null},
]
Insert cell
data2 = ({
plot1: [
{id:'Subject1', time:24, event:'Event free', censor:true},
{id:'Subject2', time:8, event:'Hospitalization', censor:false},
{id:'Subject3', time:3, event:'Death', censor:false},
{id:'Subject4', time:14, event:'Withdrawal', censor:true},
{id:'Subject5', time:16, event:'Hospitalization', censor:false}
],
plot2: [
{time:0, s:1, pos:1, note:'beginning of follow-up', change:true},
{time:3, s:1, pos:1, note:'Subject3: died at Month 3', change:true},
{time:3, s:0.8, pos:2, note:'S(3) = 1 x (5-1)/5 = 0.8', change:true},
{time:8, s:0.8, pos:1, note:'Subject3: Hospitalization at Month 8', change:true},
{time:8, s:0.6, pos:2, note:'S(8) = 0.8 x (4-1)/4 = 0.6', change:true},
{time:14, s:0.6, pos:1, note:'Subject4: Withdrawal at Month 14', change:false},
{time:14, s:0.6, pos:2, note:'S(t) does not change', change:false},
{time:16, s:0.6, pos:1, note:'Subject5: Hospitalization at Month 16', change:true},
{time:16, s:0.3, pos:2, note:'S(16) = 0.6 x (2-1)/2 = 0.3', change:true},
{time:24, s:0.3, pos:1, note:'Subject1: censored at Month 24', change:false},
{time:24, s:0.3, pos:2, note:'S(t) does not change', change:false},
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more