I've encountered the following error when re-using an estimator that was originally used to estimate without a domain, and then adding a domain. This doesn't occur if the estimator wasn't previously used, or if the code is ran the other way round. I think this is because the self.stderror dictionary isn't correctly reset to a dictionary, but I haven't dug into the logic to see where that occurs:
from samplics import TaylorEstimator
from samplics.datasets import load_nhanes2
from samplics.utils.types import PopParam
nhanes2 = load_nhanes2()["data"]
mean_est = TaylorEstimator(PopParam.mean)
mean_est.estimate(
y=nhanes2["highlead"],
psu=nhanes2["psuid"],
stratum=nhanes2["stratid"],
remove_nan=True,
)
mean_est.estimate(
y=nhanes2["highlead"],
psu=nhanes2["psuid"],
stratum=nhanes2["stratid"],
domain=nhanes2["race"],
remove_nan=True,
)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File c:\Users\Michael.Walshe.AMADEUS\source\katalyze-data\CAMIS\testing.py:1
----> 1 mean_est.estimate(
2 y=nhanes2["highlead"],
3 psu=nhanes2["psuid"],
4 stratum=nhanes2["stratid"],
5 domain = nhanes2["race"],
6 remove_nan=True,
7 )
9 print(mean_est)
File c:\Users\Michael.Walshe.AMADEUS\source\katalyze-data\CAMIS\renv\python\virtualenvs\renv-python-3.11\Lib\site-packages\samplics\estimation\expansion.py:838, in TaylorEstimator.estimate(self, y, samp_weight, x, stratum, psu, ssu, domain, by, fpc, deff, coef_var, single_psu, strata_comb, as_factor, remove_nan)
835 self.as_factor = as_factor
837 if _by.shape in ((), (0,)):
--> 838 self._estimate(
839 y=_y,
840 samp_weight=_samp_weight,
841 x=_x,
842 stratum=_stratum,
843 psu=_psu,
844 ssu=_ssu,
845 domain=_domain,
846 fpc=self.fpc,
847 deff=deff,
848 coef_var=coef_var,
849 skipped_strata=skipped_strata,
850 as_factor=as_factor,
851 remove_nan=remove_nan,
852 )
853 else:
854 for b in self.by:
File c:\Users\Michael.Walshe.AMADEUS\source\katalyze-data\CAMIS\renv\python\virtualenvs\renv-python-3.11\Lib\site-packages\samplics\estimation\expansion.py:684, in TaylorEstimator._estimate(self, y, samp_weight, x, stratum, psu, ssu, domain, fpc, deff, coef_var, skipped_strata, as_factor, remove_nan)
682 self.upper_ci[key] = upper_ci
683 elif isinstance(self.point_est, dict):
--> 684 self.stderror[key] = math.sqrt(self.variance[key])
685 self.lower_ci[key] = self.point_est[key] - t_quantile * self.stderror[key]
686 self.upper_ci[key] = self.point_est[key] + t_quantile * self.stderror[key]
TypeError: 'float' object does not support item assignment
Hi,
I've encountered the following error when re-using an estimator that was originally used to estimate without a domain, and then adding a domain. This doesn't occur if the estimator wasn't previously used, or if the code is ran the other way round. I think this is because the
self.stderrordictionary isn't correctly reset to a dictionary, but I haven't dug into the logic to see where that occurs: