ModelMultinomialLogit
andModelBinaryChoice
now have S3predict
andsummary
methods. Note thatModelMultinomialLogit
requiresnewdata
to be in the same format that is required bymlogit
.
- Move
matchingR
to Suggests. - Replace
lest::case_when()
withdata.table::case_when()
(#57). - Add a
name
argument toModel
's constructor function and expose it as an R6 active field. World$add()
can now be used to add a namedModel
without providing thename
argument.World$add()
gained areplace
argument withTRUE
as its default value.
- introduced
ModelCustom
a model class that let users specify its parameters andpredict
function. We also addModelMultinomialLogit
,ModelBinaryChoice
andModelLinear
which are implementations ofModelCustom
. - add
makeModel
to create a light weight Model object that can be used in the transition functions and classes. This basically creates an appropriate Model class from the given model object. - add helper functions
which_min_n
andwhich_max_n
. - renamed
unnest_datatable
tounnest_dt
which can take names of the list columns as a character vector.
- Added
sim()
for compiling and executing a microsimulation pipeline. - Added
targets
as an active field. - Fixed
get_transition
didn't use the preprocessing function when themodel
argument is ofModel
class. get_transition
now removes the dot prefix of variables in entity data. Those variables are considered as derived variables which will not be checked against when new entity data are geting added.- Added
dsample
for sampling from a discrete distribution, an extension ofbase:sample
. - Added
remove_entity
for removing entities from an [Entity] object. Entity$get_ids
can get the ids of removed entities using newly added theinclude_removed
argument.Entity
gains aprimary_id
field.Entity$add
did not check for potential duplicate ids in the removed data.World$set_time
returns self. The$start_iter
method may be removed in the near future as it is not quite intuitive.- Fixed the unexpected behaviour when a non
Target
object is passed into target arg ofTransition
. Prior to this fix, the object that got passed into the target argument was used to create a Target object. Hence, this created an expected behaviour, when the Target's get method was called it returned a scaled down value of the target. This may not be the desire default effect by users.
transition()
gainsvalues
field, it expects a named vector where its values will be used to replace the outcomes of the model and update the variable inattr
. See the example section to learnsmore.transition()
now supports a namedlist
model, e.g: list(yes = 0.1, no = 0.9).- Introduced
add_log()
,get_log()
,mutate_entity()
, andadd_entity()
. These functions are supposed to make constructing a microsimulation pipeline simpler. See their documentation for details. - Made
$colnames()
into an active field forDataBackendDataFrame
. - Added
omit_derived_varnames()
for internal use. Individual
now has ahid_col
active field which returns its household id column name.Entity$add()
now givesnewdata
new unique ids by default.- Deprecated
assign_reference()
,Container$get()
should be used instead.
Generic$log()
now usesNA_character_
as the default in itstag
argument.
- Added
transition()
, this is a function for simulating state transition inside a microsimulation pipeline. It also comes withget_transition()
which returns state transition outcomes. See its documentation,?dymiumCore::transition
, for more detail. - [Model] gains
preprocessing_fn
field, this is for storing a preprocessing function which will be used to evaluate the entity data in [Transition] prior to simulating the transition. A situation where this is useful could be when you want to limit the use of a [Model] object to the specific group of agents (e.g: age betweenx
andy
) that was used to estimate the model. - [Trans] supports [Model]'s
preprocessing_fn()
. - Minor fix to error msg in [TransitionClassification].
- [add_models] gains a as_r6model for returning models as [Model] objects.
- Classification models fitted using the
mlr
package is now supported bytransition
. - Added
simulate_choice
, a function for simulating choice selection from the predicted probability obtained from a model object, currently only supports most of the classification models fitted withcaret
andmlr
, andglm
of the binomial family.
- Renamed
Transition
toTrans
to make way fortranstion()
.
- Added
Population$household_type
method for classifying household types of household agents. There are four types: 'non_family_hh', 'couple_hh', 'couple_hh_with_children' and 'lone_parent_hh'. See its documentation for detail. - Added a
model
active field toModel
, this returns the original model object stored inside the object. Model
gained a S3 summary method.
Household$update_hhsize()
now returns NULL invinsibly instead of its attribute data.World
now acceptsModel
objects inadd
.
- Added
add(.data, ...)
method to Entity. This allows new entities to be added to the attribute database of existing entities. Note that,add_data(.data)
is for adding new databases andadd(.data, ...)
is for adding new records to the attribute database (Entity$database$attrs
) which are not the same. - Added
check_subset2
which basically the same check ascheckmate::check_subset
but it returns a short error message. The error message it returns only include those missing elements inx
fromchoices
. Seecheckmate::check_subset
for more details. DataBackendDataTable
again on option to use key(s) for row indexing.- Added
Entity$get_data2(ids)
which uses key(s) for subsetting of ids. This suppose to be a faster implementation ofget_data()
which is likely to supersede the original implementation in the next version. add_population(ind_data, hh_data)
now also assigns new ids to all the records of new entities ofind_data
andhh_data
to make sure no duplications of ids exist.DataBackend
has new active fields which aredata
amdremoved_data
these functions return a copy of the data and not a reference to the data (only applicable inDataBackendDataTable
andDataBackendSpatialFeature
).extract_data
returns all the data objects in the DataBackend objects that each Entity possess as a named list of data.table. This is useful for saving simulation data for furthur analysis. It works on World too!World
saves session info on its creation instead of just the R version it was created on.- Added
dymium.simulation_scale
global option that can be set withWorld$set_scale(x)
and access withWorld$scale
or getOption("dymium.simulation_scale"). This simulation scale will be used by allTarget
objects created when they are called by theirget
method.
- Ignore checking of attributes in all
data.table::all.equal(...)
calls. - Fixed
Target
's constructor method which failed to convert data.frame to data.table when storing the target data.
- Removed
Entity$initialise_data()
, the attribute data of Entity must be provided in its constructor method. This change affected many of the testthat tests. - Removed
household_formation()
to encourage more explicit approaches (e.g. usePopulation$leave_household()
andPopulation$join_household()
).
- Added a
plot_relationship
method toHousehold
. This usesvisNetwork
for plotting (added to Suggests). See #48 for its implementation detail. inspect
now has a verbose option.Transition
no longer removes theNA
reponses when target is used.- Added a
replace
method toWorld
which basicallyremove
andadd
in one call. - Moved
$subset_ids()
fromAgent
toEntity
. download_module()
andset_active_scenario()
now have a.basedir
argument which sets the base directory where their files will be created at. By default this is the root folder of the currently active R project (if you are using RStudio) which is determined byhere::here()
.- Renamed
use_scenario
tocreate_scenario
andactive_scenario
toget_active_scenario
. TransitionClassification
's target argument now accepts a dynamic target, see issue [#52] #52.- Added a
Target
R6 class which acts as a wrapper for different types of target and make them work consistently in theTransition
classes.
- Fixed World's remove method in commit c0df66d.
- Removed the
preprocess
method inTransition
. Whether the mutate step or the filter step should be run first is now determine by themutate_fisrt
public field which hasFALSE
as default. create_scenario
did not pass.basedir
toset_active_scenario
so when creating a new scenario that isn't within a RStudio project will raise an incorrect directory error.
- Unexported
Firm
as it has not been fully implemented and tested yet. - Removed deprecated Population's methods:
get_sum_hhsize
andcount_all
.
TransitionClassification
now treatsprobs
as probability weights and not exact probability values that should add up to 1.
- Removed the
target
argument fromTransitionRegression
as alignment is only applicable for classficaition model.
This version contains all the basic building blocks for dynamic microsimulation.