Statistics & probability

Longitudinal marginal structural model calculator from treatment history probabilities

Combine observed treatment-history probabilities into stabilized weights for a terminal-outcome marginal structural model.

Your numbers

Valid JSON. Each subject: treatment[], numerator[], denominator[], outcome. Probabilities are for OBSERVED treatment history entries.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

When earlier treatment affects later confounders, adjusting for those later variables in an ordinary outcome regression can block part of the treatment effect. A marginal structural model instead uses weights to reframe the observed treatment histories.

THE FORMULAFor each subject i and visit t supply probability of the observed treatment (not automatically probabilityA=1) in denominator d_it and stabilizing numerator n_it. Product weight w_i=exp(sum_t(log n_it-log d_it)). If user instead inputs P(A=1), transform each according to observedA. Fit a prespecified weighted marginal outcome model on exposure-history summary using WLS; continuous-outcome first mode. Report weights, ESS=(sumw)^2/sumw², weighted balance inputs ifprovided and truncation policy. A cluster/subj robust sandwich for repeated rows needs separate implementation; simpler one final outcome per subject. Distinguish supplied probabilities from an internally fitted propensity model.

A worked example

With the prefilled inputs, coefficients = [1.9603507766724562,2.99801072236934]. Each subject: treatment[], numerator[], denominator[], outcome. Probabilities are for OBSERVED treatment history entries.

Good to know

Terminal continuous outcome regressed on cumulative treatment count with stabilized history weights; HC1 independent-subject sandwich. This is one prespecified MSM, not nuisance fitting or guaranteed causal identification.

Why treatment history matters

When earlier treatment affects later confounders, adjusting for those later variables in an ordinary outcome regression can block part of the treatment effect. A marginal structural model instead uses weights to reframe the observed treatment histories.

The intended causal interpretation depends on sequential exchangeability, consistency and positivity. Supplying a sequence of probabilities does not establish those assumptions or repair an unmeasured time-varying confounder.

Longitudinal inverse-probability weightStabilized weight is a product over visitsVisit 10.5 / 0.5ratio = 1Visit 20.5 / 0.25ratio = 2×2w = (0.5/0.5) × (0.5/0.25) = 2Probabilities refer to the treatment actions actually observed.
Scroll across to see the full diagram.
The observed two-visit treatment history has denominator probabilities0.5 and0.25 and numerator probabilities0.5 and0.5, producing stabilized weight2.

Compare with the Inverse probability weighted treatment effect calculator from propensity scores. Construct cumulative stabilized weights for repeated treatment histories with time-varying confounding; existing IPW accepts one treatment per independent row.

Enter probabilities of observed actions

Each subject: treatment[], numerator[], denominator[], outcome. Probabilities are for OBSERVED treatment history entries.At every visit, the denominator must correspond to the treatment action that actually occurred under the stated history model. If the observed action is zero and the entered model gives P(A=1), use one minus that probability.

The stabilizing numerator has its own stated conditioning set. Mixing numerator and denominator conventions across visits changes the estimand and can produce weights that appear reasonable while answering a different question. Each subject supplies equal-length arrays of binary treatment decisions, numerator probabilities and denominator probabilities, followed by one terminal continuous outcome. The probabilities are for the treatment that was actually observed at each visit. They are not always the probability of treatment one: an observed zero needs the corresponding probability of zero. There are two to six visits, with thirty to three hundred independent subjects. The calculator does not estimate either probability model, construct histories from raw clinical records or infer which time-varying confounders should have been included in those models.

Multiply histories in logarithms

A subject's stabilized weight is the product of the numerator-to-denominator probability ratios over visits. Summing log ratios first avoids underflow when several small probabilities occur.

A near-zero denominator can create an enormous weight. That is evidence of limited practical positivity or an unstable probability model, not a reason to silently cap the value and conceal the affected subject.

Fit a prespecified marginal model

Choose the treatment-history summary and outcome model before looking for the strongest result. The simple continuous-outcome mode uses one final outcome per subject with weighted regression on that specified history design.

The calculation does not fit a propensity model unless it explicitly says so. Probabilities supplied from another analysis must be estimated using the correct temporal information and retained with the weight calculation.

A two-visit weight

Suppose the observed treatment path has denominator probabilities0.5 and0.25, and stabilizing probabilities0.5 and0.5. The visit ratios are one and two, making the subject's total weight two.

If numerator and denominator probabilities match at every visit, all weights are one. Under the same outcome design, the weighted least-squares fit then reduces to ordinary least squares, providing a useful consistency check.

Inspect effective sample size

The effective sample-size diagnostic is the square of the total weight divided by the sum of squared weights. A few influential histories can make this much smaller than the number of observed subjects.

This is a weight-concentration summary, not an exact replacement for all regression degrees of freedom. Balance, overlap and model diagnostics still need attention even when the effective count looks comfortable.

Disclose truncation and uncertainty

If a prespecified truncation rule is used, report its threshold and the number of affected subjects. Truncation trades some instability for a changed weighting analysis and should not be selected only to improve significance.

Final uncertainty must account for the supported outcome and dependence structure, and may need the probability-estimation stage as well. Repeated outcome rows or clustered subjects require covariance calculations beyond an independent final-outcome fit. History weights are computed in logarithms and rescaled by their largest log weight before the regression. Common rescaling leaves the weighted regression unchanged while avoiding needless overflow. The relative weights and the removed log scale are both reported, so the user can reconstruct the declared convention. The outcome design is specifically an intercept plus cumulative treatment count, not an arbitrary regimen model or a separate effect at every visit. HC1 uncertainty treats subjects as independent units. Effective sample size is a weight-concentration diagnostic; a large original sample cannot compensate automatically for near-positivity violations or incorrectly supplied nuisance probabilities. Terminal continuous outcome regressed on cumulative treatment count with stabilized history weights; HC1 independent-subject sandwich. This is one prespecified MSM, not nuisance fitting or guaranteed causal identification.

A few questions, answered

Should I enter P(A=1) at every visit?

Only if the interface explicitly converts it using the observed action; otherwise enter the probability of the action that occurred.

Why stabilize the weights?

The numerator can reduce variability while preserving the intended weighting target under its stated conditioning convention.

Does a weight of two mean two actual people?

No. It is a contribution multiplier in the weighted estimating procedure, not a new observation count.

Can this prove there is no time-varying confounding?

No. The identification assumptions concern the treatment and covariate process and cannot be verified from the weight product alone.

Find your calculator

Start typing to explore the library.