This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This example demonstrates that fitting a weighted linear mixed-effects model using lmer(weights = …) | |
is algebraically equivalent to pre-multiplying the outcome and all predictors (including intercepts) | |
by the square root of the weights and fitting an unweighted model on the transformed data. | |
The test validates that this "pre-weight and refit" strategy yields identical fitted values and | |
is especially useful when packages like clubSandwich prohibit prior weights in robust variance estimation. | |
Includes realistic longitudinal synthetic data with fixed and random effects, dropout, and continuous covariates. | |
""" | |
from typing import List |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
import cvxpy as cp | |
from typing import Sequence, Union | |
def entropy_balance_ipaw( | |
df: pd.DataFrame, | |
*, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Optional | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import warnings | |
import statsmodels.formula.api as smf | |
from statsmodels.tools.sm_exceptions import ( | |
ConvergenceWarning, |
OlderNewer