-
Notifications
You must be signed in to change notification settings - Fork 3
/
easyodds.pl
95 lines (73 loc) · 3.01 KB
/
easyodds.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
:- module(easyodds, []).
:- use_module(library(http/html_write)).
:- use_module(session).
:- use_module(r).
:- use_module(rint).
:- use_module(mathml).
:- use_module(navbar).
navbar:page(easyodds, "OR (3)").
task(oratio).
:- discontiguous intermediate/2, expert/5, buggy/5, feedback/4, hint/4.
% Prettier symbols for mathematical rendering
math_hook(pi_A, subscript(pi, "A")).
math_hook(odds_A, subscript(odds, "A")).
math_hook(pi_B, subscript(pi, "B")).
math_hook(or, 'OR').
% R constants
rint:r_hook(odds_A).
rint:r_hook(pi_A).
rint:r_hook(pi_B).
rint:r_hook(or).
render
--> {start(item(Odds_A, Pi_B, OR)) },
html(
[ div(class(card), div(class('card-body'),
[ h1(class('card-title'), "Odds ratio"),
p(class('card-text'),
[ "The odds for succeding with treatment A are ",
\mmlm([r(Odds_A), ","]), " while treatment B has a success probability of ",
\mmlm([r(Pi_B), "."]), " The odds ratio between both treatments is ",
\mmlm([r(OR), "."])
])]))]).
task(oratio)
--> { start(item(_Odds_A, _Pi_B, _OR)),
session_data(resp(easyodds, oratio, Resp), resp(easyodds, oratio, '#.##'))
},
html(\htmlform(["What is the success probability for treatment A?"], oratio, Resp)).
% Odds ratio with two probabilities.
intermediate(oratio, item).
start(item(odds_A, pi_B, or)).
expert(oratio, stage(2), From, To, [step(expert, odd, [])]) :-
From = item(Odds_A, _Pi_B, _OR),
To = { '<-'(pi_A, dfrac(Odds_A, 1 + Odds_A))
}.
feedback(odd, [], _Col, FB) =>
FB = [ "Correctly calculated the success probability from ", \mmlm([odds_A, "."]) ].
hint(odd, [], _Col, FB) =>
FB = [ "This is an odds ratio."].
% 1) Tried conversion from odds to odds, as if starting with
% a probability.
buggy(oratio, stage(2), From, To, [step(buggy, subscript, [Odds_A])]) :-
From = 1 + Odds_A,
To = instead(subscript, 1 - Odds_A, 1 + Odds_A).
feedback(subscript, [Odds_A], Col, FB) =>
FB = [ "Please use the correct formula to convert ", \mmlm(Col, color(subscript, Odds_A)), " to ",
\mmlm(Col, [color(subscript, pi_A), "."]) ].
hint(subscript, [_Odds_A], _Col, FB) =>
FB = [ "Do not apply the formula to calculate the odds from the success probability." ].
% 2) Used pi_B rather than odds_A.
buggy(oratio, stage(1), From, To, [step(buggy, pi, [])]) :-
From = odds_A,
To = instead(pi, pi_B, odds_A).
feedback(pi, [], Col, FB) =>
FB = [ "Please use ", \mmlm(Col, color(pi, odds_A)), " instead of ", \mmlm(Col, [color(pi, pi_B), "."]) ].
hint(pi, [], Col, FB) =>
FB = [ "Do not use the success probability for therapy B ", \mmlm(Col, [color(pi, pi_B), "."]) ].
% 3) Used OR rather than odds_A.
buggy(oratio, stage(1), From, To, [step(buggy, ratio, [])]) :-
From = odds_A,
To = instead(ratio, or, odds_A).
feedback(ratio, [], Col, FB) =>
FB = [ "Please use ", \mmlm(Col, color(ratio, odds_A)), " instead of ", \mmlm(Col, [color(ratio, or), "."]) ].
hint(ratio, [], Col, FB) =>
FB = [ "Do not use the odds ratio ", \mmlm(Col, [color(ratio, or), "."]) ].