def test_get_df(self, df): d = Data( df=df, col_t='time', col_obs='ln_death_rate', col_covs=['covariate_1'], col_group='group', obs_space=ln_gaussian_pdf, ) pd.testing.assert_frame_equal(d.df, d._get_df()) pd.testing.assert_frame_equal(d.df[0:3], d._get_df(group='group1'))
def test_get_translated_observations(self, df): d = Data( df=df, col_t='time', col_obs='ln_death_rate', col_covs=['covariate_1'], col_group='group', obs_space=ln_gaussian_pdf, ) np.testing.assert_equal( np.exp(d.df[d.col_obs])[0:3], d._get_translated_observations(group='group1', space=gaussian_pdf))
def test_data(self, df): d = Data(df=df, col_t='time', col_obs='ln_death_rate', col_covs=['covariate_1'], col_group='group', obs_space=ln_gaussian_pdf, obs_se_func=lambda x: x**(-2.)) assert len(d.df == 6) np.testing.assert_equal(d.df.time, np.array([1, 4, 5, 1, 6, 7])) np.testing.assert_equal(d.df.group, np.repeat(['group1', 'group2'], repeats=3)) np.testing.assert_equal(d.df.obs_se, np.array([1, 4, 5, 1, 6, 7])**(-2.))
'independent_var': independent_var, 'measurement_value': measurement_value, 'measurement_std': measurement_std, 'cov_one': cov_one, 'social_distance': social_distance, 'data_group': data_group, } data_frame = pandas.DataFrame(data_dict) # ------------------------------------------------------------------------ # curve_model data = Data(df=data_frame, col_t='independent_var', col_obs='measurement_value', col_covs=['cov_one', 'social_distance'], col_group='data_group', obs_space=gaussian_cdf, col_obs_se='measurement_std') a_intercept = Variable(covariate='cov_one', var_link_fun=identity_fun, fe_init=a_true / 3, re_init=0.0, fe_bounds=[-numpy.inf, numpy.inf], re_bounds=[0.0, 0.0]) b_intercept = Variable(covariate='cov_one', var_link_fun=identity_fun, fe_init=b_true / 3, re_init=0.0,
'group_name': group_names[i], 'obs': group_sim, 'time': time })) group_data = pd.concat(groups) group_data['intercept'] = 1 return group_data df = simulate_data() # Use the `Data` object to store information about what the columns represent data = Data(df=df, col_t='time', col_obs='obs', col_covs=['intercept'], obs_space=ln_gaussian_pdf, col_group='group_name', obs_se_func=lambda x: 1) """ ``` ### Create a Parameter Set We need to define variables, parameters that use those variables (in this case there are only intercepts -- and one covariate per parameter -- so the variables are effectively the same as the parameters), and a parameter set that collects all of that information into one object. ```python """ alpha_fe = Variable(covariate='intercept', var_link_fun=lambda x: x, fe_init=fe_mean[0], re_init=0.,
data_dict = { 'independent_var': independent_var, 'measurement_value': measurement_value, 'measurement_std': measurement_std, 'constant_one': constant_one, 'data_group': data_group, } data_frame = pandas.DataFrame(data_dict) # ------------------------------------------------------------------------ # curve_model data = Data(df=data_frame, col_t='independent_var', col_obs='measurement_value', col_covs=num_params * ['constant_one'], col_group='data_group', obs_space=expit, col_obs_se='measurement_std') a_intercept = Variable(covariate='constant_one', var_link_fun=lambda x: x, fe_init=a_true[0] / 3.0, re_init=0.0, re_zero_sum_std=abs(a_true[0]) / 100.0, fe_gprior=[a_true[0], abs(a_true[0]) / 100.0], fe_bounds=[0.0, numpy.inf], re_bounds=[-2.0, 2.0]) b_intercept = Variable(covariate='constant_one', var_link_fun=lambda x: x,