Skip to content

Commit

Permalink
Merge branch 'next' into 332-rm-old-bmds
Browse files Browse the repository at this point in the history
  • Loading branch information
shapiromatron committed Feb 12, 2024
2 parents fcb7d56 + 71786b7 commit 1ad2696
Show file tree
Hide file tree
Showing 38 changed files with 517 additions and 224 deletions.
17 changes: 0 additions & 17 deletions frontend/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,4 @@ export const simulateClick = function(el) {
},
getLabel = function(value, mapping) {
return _.find(mapping, d => d.value == value).label;
},
parseErrors = errorText => {
let errors = [],
textErrors = [];
try {
errors = JSON.parse(errorText);
} catch {
console.error("Cannot parse error response");
return {errors, textErrors};
}
textErrors = errors.map(error => {
if (error.loc && error.msg) {
return `${error.loc[0]}: ${error.msg}`;
}
return JSON.stringify(error);
});
return {errors, textErrors};
};
6 changes: 5 additions & 1 deletion frontend/src/components/IndividualModel/CDFTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ class CDFTable extends Component {
const {bmd_dist} = this.props;
return (
<table className="table table-sm table-bordered text-right">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead>
<tr className="bg-custom text-left">
<th colSpan="2">CDF</th>
</tr>
<tr>
<th>Percentile</th>
<th>Cumulative Probability</th>
<th>BMD</th>
</tr>
</thead>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/IndividualModel/ContinuousDeviance.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class ContinuousDeviance extends Component {
</colgroup>
<thead>
<tr className="bg-custom">
<th colSpan="9">Likelihoods of Interest</th>
<th colSpan="9">Likelihoods</th>
</tr>
<tr>
<th>Model</th>
<th>Log Likelihood</th>
<th>-2* Log(Likelihood Ratio)</th>
<th># of Parameters</th>
<th>AIC</th>
</tr>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/IndividualModel/ContinuousSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ContinuousSummary extends Component {
</colgroup>
<thead>
<tr className="bg-custom">
<th colSpan="2">Summary</th>
<th colSpan="2">Modeling Summary</th>
</tr>
</thead>
<tbody>
Expand All @@ -40,7 +40,7 @@ class ContinuousSummary extends Component {
<td>{ff(results.fit.aic)}</td>
</tr>
<tr>
<td>Log Likelihood</td>
<td>-2* Log(Likelihood Ratio)</td>
<td>{ff(results.fit.loglikelihood)}</td>
</tr>
<tr>
Expand All @@ -50,7 +50,7 @@ class ContinuousSummary extends Component {
<td>{fractionalFormatter(p_value)}</td>
</tr>
<tr>
<td>Model DOF</td>
<td>Model d.f.</td>
<td>{ff(results.tests.dfs[3])}</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class ContinuousTestOfInterest extends Component {
</colgroup>
<thead>
<tr className="bg-custom text-left">
<th colSpan="4">Test of Interest</th>
<th colSpan="4">Tests of Mean and Variance Fits</th>
</tr>
<tr>
<th>Test</th>
<th>
LLR
<HelpTextPopover title="LLR" content="2 * Log(Likelihood Ratio)" />
</th>
<th>Test DOF</th>
<th>Test d.f.</th>
<th>
<i>P</i>-Value
</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class DichotomousDeviance extends Component {
</tr>
<tr>
<th>Model</th>
<th>Log Likelihood</th>
<th>-2* Log(Likelihood Ratio)</th>
<th># Parameters</th>
<th>Deviance</th>
<th>Test DOF</th>
<th>Test d.f.</th>
<th>
<i>P</i>-Value
</th>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/IndividualModel/DichotomousSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DichotomousSummary extends Component {
</colgroup>
<thead>
<tr className="bg-custom">
<th colSpan="2">Summary</th>
<th colSpan="2">Modeling Summary</th>
</tr>
</thead>
<tbody>
Expand All @@ -39,7 +39,7 @@ class DichotomousSummary extends Component {
<td>{ff(results.fit.aic)}</td>
</tr>
<tr>
<td>Log Likelihood</td>
<td>-2* Log(Likelihood Ratio)</td>
<td>{ff(results.fit.loglikelihood)}</td>
</tr>
<tr>
Expand All @@ -49,7 +49,7 @@ class DichotomousSummary extends Component {
<td>{fourDecimalFormatter(results.gof.p_value)}</td>
</tr>
<tr>
<td>Overall DOF</td>
<td>Overall d.f.</td>
<td>{ff(results.gof.df)}</td>
</tr>
<tr>
Expand Down
172 changes: 113 additions & 59 deletions frontend/src/components/IndividualModel/GoodnessFit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,141 @@ import {Dtype} from "@/constants/dataConstants";
import {isLognormal} from "@/constants/modelConstants";
import {ff} from "@/utils/formatters";

/* eslint-disable */
const hdr_c_normal = [
"Dose", "Size", "Observed Mean", "Calculated Mean", "Estimated Mean",
"Observed SD", "Calculated SD", "Estimated SD", "Scaled Residual",
],
hdr_c_lognormal = [
"Dose", "Size", "Observed Mean", "Calculated Median", "Estimated Median",
"Observed SD", "Calculated GSD", "Estimated GSD", "Scaled Residual",
],
hdr_d = [ "Dose", "Size", "Observed", "Expected", "Estimated Probability", "Scaled Residual"];
/* eslint-enable */

@observer
class GoodnessFit extends Component {
getHeaders(dtype, settings) {
if (dtype == Dtype.CONTINUOUS || dtype == Dtype.CONTINUOUS_INDIVIDUAL) {
const headers = isLognormal(settings.disttype) ? hdr_c_lognormal : hdr_c_normal;
return [headers, [10, 10, 10, 12, 12, 12, 10, 12, 12]];
}
if (dtype == Dtype.DICHOTOMOUS) {
return [hdr_d, [17, 16, 16, 17, 17, 17]];
}
throw Error("Unknown dtype");
getDichotomousData() {
const {store} = this.props,
gof = store.modalModel.results.gof,
dataset = store.selectedDataset;
return {
headers: [
"Dose",
"N",
"Observed",
"Expected",
"Estimated Probability",
"Scaled Residual",
],
colwidths: [17, 16, 16, 17, 17, 17],
data: dataset.doses.map((dose, i) => {
return [
dose,
dataset.ns[i],
dataset.incidences[i],
ff(gof.expected[i]),
ff(gof.expected[i] / dataset.ns[i]),
ff(gof.residual[i]),
];
}),
};
}

getContinuousNormalData(dtype) {
const {store} = this.props,
gof = store.modalModel.results.gof,
dataset = store.selectedDataset,
useFF = dtype === Dtype.CONTINUOUS_INDIVIDUAL;
return {
headers: [
"Dose",
"N",
"Sample Mean",
"Model Fitted Mean",
"Sample SD",
"Model Fitted SD",
"Scaled Residual",
],
colwidths: [1, 1, 1, 1, 1, 1, 1],
data: dataset.doses.map((dose, i) => {
return [
dose,
dataset.ns[i],
useFF ? ff(gof.obs_mean[i]) : gof.obs_mean[i],
ff(gof.est_mean[i]),
useFF ? ff(gof.obs_sd[i]) : gof.obs_sd[i],
ff(gof.est_sd[i]),
ff(gof.residual[i]),
];
}),
};
}

getContinuousLognormalData(dtype) {
const {store} = this.props,
gof = store.modalModel.results.gof,
dataset = store.selectedDataset,
useFF = dtype === Dtype.CONTINUOUS_INDIVIDUAL;
return {
headers: [
"Dose",
"N",
"Sample Mean",
"Approximate Sample Median",
"Model Fitted Median",
"Sample SD",
"Approximate Sample GSD",
"Model Fitted GSD",
"Scaled Residual",
],
colwidths: [10, 10, 10, 12, 12, 12, 10, 12, 12],
data: dataset.doses.map((dose, i) => {
return [
dose,
dataset.ns[i],
useFF ? ff(gof.obs_mean[i]) : gof.obs_mean[i],
ff(gof.calc_mean[i]),
ff(gof.est_mean[i]),
useFF ? ff(gof.obs_sd[i]) : gof.obs_sd[i],
ff(gof.calc_mean[i]),
ff(gof.est_sd[i]),
ff(gof.residual[i]),
];
}),
};
}
render() {
const {store} = this.props,
settings = store.modalModel.settings,
gof = store.modalModel.results.gof,
dataset = store.selectedDataset,
{dtype} = dataset,
headers = this.getHeaders(dtype, settings);
{dtype} = dataset;

let data;
if (dtype == Dtype.DICHOTOMOUS) {
data = this.getDichotomousData();
} else {
if (isLognormal(settings.disttype)) {
data = this.getContinuousLognormalData(dtype);
} else {
data = this.getContinuousNormalData(dtype);
}
}
return (
<table className="table table-sm table-bordered text-right">
<colgroup>
{headers[1].map((d, i) => (
{data.colwidths.map((d, i) => (
<col key={i} width={`${d}%`} />
))}
</colgroup>
<thead>
<tr className="bg-custom text-left">
<th colSpan={headers[0].length}>Goodness of Fit</th>
<th colSpan={data.headers.length}>Goodness of Fit</th>
</tr>
<tr>
{headers[0].map((d, i) => (
{data.headers.map((d, i) => (
<th key={i}>{d}</th>
))}
</tr>
</thead>
<tbody>
{dtype == Dtype.CONTINUOUS || dtype == Dtype.CONTINUOUS_INDIVIDUAL
? gof.dose.map((item, i) => {
const useFF = dtype === Dtype.CONTINUOUS_INDIVIDUAL;
return (
<tr key={i}>
<td>{item}</td>
<td>{gof.size[i]}</td>
<td>{useFF ? ff(gof.obs_mean[i]) : gof.obs_mean[i]}</td>
<td>{ff(gof.calc_mean[i])}</td>
<td>{ff(gof.est_mean[i])}</td>
<td>{useFF ? ff(gof.obs_sd[i]) : gof.obs_sd[i]}</td>
<td>{ff(gof.calc_sd[i])}</td>
<td>{ff(gof.est_sd[i])}</td>
<td>{ff(gof.residual[i])}</td>
</tr>
);
})
: null}
{dtype == Dtype.DICHOTOMOUS
? dataset.doses.map((dose, i) => {
return (
<tr key={i}>
<td>{dose}</td>
<td>{dataset.ns[i]}</td>
<td>{dataset.incidences[i]}</td>
<td>{ff(gof.expected[i])}</td>
<td>{ff(gof.expected[i] / dataset.ns[i])}</td>
<td>{ff(gof.residual[i])}</td>
</tr>
);
})
: null}
{data.data.map((row, i) => {
return (
<tr key={i}>
{row.map((cell, j) => (
<td key={j}>{cell}</td>
))}
</tr>
);
})}
</tbody>
</table>
);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/IndividualModel/ModelDetailModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ModelBody extends Component {
</Col>
</Row>
<Row>
<Col xl={isDichotomous ? 8 : 10}>
<Col xl={isDichotomous ? 8 : 12}>
<GoodnessFit store={outputStore} />
</Col>
</Row>
Expand All @@ -82,7 +82,7 @@ class ModelBody extends Component {
) : null}
{isContinuous ? (
<Row>
<Col xl={6}>
<Col xl={8}>
<ContinuousDeviance store={outputStore} />
<ContinuousTestOfInterest store={outputStore} />
</Col>
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/components/IndividualModel/ModelOptionsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {getLabel} from "@/common";
import TwoColumnTable from "@/components/common/TwoColumnTable";
import {Dtype} from "@/constants/dataConstants";
import {hasDegrees} from "@/constants/modelConstants";
import {isHybridBmr} from "@/constants/optionsConstants";
import {
continuousBmrOptions,
dichotomousBmrOptions,
Expand Down Expand Up @@ -39,7 +40,7 @@ class ModelOptionsTable extends Component {
data = [
["BMR Type", getLabel(model.settings.bmr_type, dichotomousBmrOptions)],
["BMR", ff(model.settings.bmr)],
["Confidence Level", ff(1 - model.settings.alpha)],
["Confidence Level (one sided)", ff(1 - model.settings.alpha)],
hasDegrees.has(model.model_class.verbose)
? ["Degree", ff(model.settings.degree)]
: null,
Expand All @@ -53,8 +54,10 @@ class ModelOptionsTable extends Component {
["BMRF", ff(model.settings.bmr)],
["Distribution Type", getLabel(model.settings.disttype, distTypeOptions)],
["Direction", model.settings.is_increasing ? "Up" : "Down"],
["Confidence Level", 1 - ff(model.settings.alpha)],
["Tail Probability", ff(model.settings.tail_prob)],
["Confidence Level (one sided)", 1 - ff(model.settings.alpha)],
isHybridBmr(model.settings.bmr_type)
? ["Tail Probability", ff(model.settings.tail_prob)]
: null,
hasDegrees.has(model.model_class.verbose)
? ["Degree", ff(model.settings.degree)]
: null,
Expand All @@ -66,7 +69,7 @@ class ModelOptionsTable extends Component {
data = [
["BMR Type", getLabel(model.settings.bmr_type, dichotomousBmrOptions)],
["BMR", ff(model.settings.bmr)],
["Confidence Level", ff(1 - model.settings.alpha)],
["Confidence Level (one sided)", ff(1 - model.settings.alpha)],
["Bootstrap Seed", model.settings.bootstrap_seed],
["Bootstrap Iterations", model.settings.bootstrap_iterations],
[
Expand Down
Loading

0 comments on commit 1ad2696

Please sign in to comment.