Package microsim.statistics.regression
Class LinearRegression
java.lang.Object
microsim.statistics.regression.LinearRegression
- All Implemented Interfaces:
LinReg
- Direct Known Subclasses:
LogitRegression
,ProbitRegression
-
Constructor Summary
ConstructorDescriptionLinearRegression
(@NonNull MultiKeyCoefficientMap map) Linear Regression object. -
Method Summary
Modifier and TypeMethodDescriptionstatic double
computeScore
(@NonNull MultiKeyCoefficientMap amap, @NonNull Map<String, Double> values) Warning - only use when LinearRegression object contains a MultiKeyCoefficientMap with only one key.computeScore
(@NonNull MultiKeyCoefficientMap coeffMultiMap, @NonNull DoubleSource iDblSrc, @NonNull Class<T> enumTypeDouble, @NonNull ObjectSource iObjSrc, @NonNull Class<U> enumTypeObject) Requires the implementation of the ObjectSource to ascertain whether any additional conditioning regression keys are used (e.g.static <T extends Enum<T>>
doublecomputeScore
(@NonNull MultiKeyCoefficientMap coeffMultiMap, @NonNull DoubleSource iDblSrc, Class<T> enumType) Uses reflection to obtain information from the iDblSrc object, so it is possibly slow.static <T extends Enum<T>>
doublecomputeScore
(@NonNull MultiKeyCoefficientMap coeffMultiMap, @NonNull DoubleSource iDblSrc, Class<T> enumType, boolean singleKeyCoefficients) Use this method when the underlying agent does not have any additional conditioning regression keys (such as the gender or civil status) to determine the appropriate regression co-efficients, i.e.static double
computeScore
(MultiKeyCoefficientMap coeffMultiMap, Object agent) To be used when the agent Object has member fields that correspond by name to all the regressors of the Regression's MultiKeyCoefficientMap map.double
To be used when the agent Object has member fields that correspond by name to all the regressors of the Regression's MultiKeyCoefficientMap map.double
Warning - only use when LinearRegression object contains a MultiKeyCoefficientMap with only one key.<T extends Enum<T>>
doublegetScore
(@NonNull DoubleSource iDblSrc, @NonNull Class<T> enumType) getScore
(@NonNull DoubleSource iDblSrc, @NonNull Class<T> enumTypeDouble, @NonNull ObjectSource iObjSrc, @NonNull Class<U> enumTypeObject) Requires the implementation of the ObjectSource to ascertain whether any additional conditioning regression keys are used (e.g.static double
multiplyCoeffsWithValues
(@NonNull Map<String, Double> regCoeffMap, @NonNull Map<String, Double> valueMap)
-
Constructor Details
-
LinearRegression
Linear Regression object.- Parameters:
map
- Needs to fulfil two criteria: 1) Map must have a key in the MultiKey that matches the name specified in the RegressionColumnNames enum called Regressor. 2) Map must have a value key that matches the name specified in the RegressionColumnNames enum called Coefficient. If loading from an .xls spreadsheet using theExcelAssistant.loadCoefficientMap(String, String, int, int, int, int)
, the Regressor column must be situated to the left of the Coefficient column.
-
-
Method Details
-
computeScore
public static double computeScore(@NonNull @NonNull MultiKeyCoefficientMap amap, @NonNull @NonNull Map<String, Double> values) Warning - only use when LinearRegression object contains a MultiKeyCoefficientMap with only one key. This method only looks at the first key of the MultiKeyCoefficientMap field of LinearRegression, so any other keys that are used to distinguish a unique multiKey (i.e. if the first key occurs more than once) will be ignored! If the first key of the multiKey appears more than once, the method would return an incorrect value, so will throw an exception.- Parameters:
amap
- A coefficient map.values
- Another map for regression values.- Returns:
- the score value.
-
computeScore
public static <T extends Enum<T>> double computeScore(@NonNull @NonNull MultiKeyCoefficientMap coeffMultiMap, @NonNull @NonNull DoubleSource iDblSrc, Class<T> enumType, boolean singleKeyCoefficients) Use this method when the underlying agent does not have any additional conditioning regression keys (such as the gender or civil status) to determine the appropriate regression co-efficients, i.e. the regression co-efficients do not depend on any properties of the underlying model. Requires that the MultiKeyCoefficientMap only has one entry in the multiKey - that of the name of the regressor variables.- Parameters:
coeffMultiMap
- is a MultiKeyCoefficientMap that has a MultiKey whose first Key is the name of the regressor variable.iDblSrc
- is an object that implements theDoubleSource
interface, and hence has a method getDoubleValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case-sensitive) name of the keys of coeffMultiMap's MultiKeyenumType
- specifies the enum type that is used in the getDoubleValue(Enum.valueOf(enumType, String)) method of the iDblSrc object. The String is the name of the enum case, used as a switch to determine the appropriate double value to return
-
computeScore
public static <T extends Enum<T>> double computeScore(@NonNull @NonNull MultiKeyCoefficientMap coeffMultiMap, @NonNull @NonNull DoubleSource iDblSrc, Class<T> enumType) Uses reflection to obtain information from the iDblSrc object, so it is possibly slow. For time critical cases, use the other computeScore method that requires passing in an object that implements the ObjectSource interface; this has signature:public static <T extends Enum<T>, U extends Enum<>> double computeScore(MultiKeyCoefficientMap coeffMultiMap, IDoubleSource iDblSrc, Class<T> enumTypeDouble, ObjectSource iObjSrc, Class<> enumTypeObject)
Requires the first column entry of the MultiKeyCoefficientMap (i.e. the first entry of coeffMultiMap's multiKey) to be the name of the regressor variables. The names of the other keys of the coeffMultiMap must match the (case-sensitive) name of the corresponding fields of the iDblSrc class.- Parameters:
coeffMultiMap
- is a MultiKeyCoefficientMap that has a MultiKey whose first Key is the name of the regressor variable. The names of the other keys of the coeffMultiMap must match the (case sensitive) name of the corresponding fields of the iDblSrc class.iDblSrc
- is an object that implements theDoubleSource
interface, and hence has a method getDoubleValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case sensitive) name of the keys of coeffMultiMap's MultiKeyenumType
- specifies the enum type that is used in the getDoubleValue(Enum.valueOf(enumType, String)) method of the iDblSrc object. The String is the name of the enum case, used as a switch to determine the appropriate double value to return
-
computeScore
To be used when the agent Object has member fields that correspond by name to all the regressors of the Regression's MultiKeyCoefficientMap map. The agent must also have fields that specify any additional conditioning keys e.g. gender or civil status, of the regression map's MultiKeys.- Parameters:
agent
- is the object whose fields must match by name, the regressors and additional conditioning keys of the Regression map's MultiKeys.
-
multiplyCoeffsWithValues
-
computeScore
public static <T extends Enum<T>,U extends Enum<U>> double computeScore(@NonNull @NonNull MultiKeyCoefficientMap coeffMultiMap, @NonNull @NonNull DoubleSource iDblSrc, @NonNull @NonNull Class<T> enumTypeDouble, @NonNull @NonNull ObjectSource iObjSrc, @NonNull @NonNull Class<U> enumTypeObject) Requires the implementation of the ObjectSource to ascertain whether any additional conditioning regression keys are used (e.g. whether the underlying agent is female, married etc., where the regression co-efficients are conditioned on additional keys of gender and civil status, for example). If the underlying agent does not implement ObjectSource but does have additional conditioning regression keys, use the computeScore method (that uses reflection, so is slower) with signature:public static <T extends Enum<T>> double computeScore(MultiKeyCoefficientMap coeffMultiMap, IDoubleSource iDblSrc, Class<T> enumType)
If the underlying agent does not have additional conditioning regression keys, use the computeScore method with signature:-Requires the MultiKeyCoefficientMap coeffMultiMap to have a key in its multiKey that corresponds to the name of the regressor variables. The names of the other keys of the coeffMultiMap must match the (case-sensitive) name of the corresponding fields of the iDblSrc class.
- Parameters:
coeffMultiMap
- is a MultiKeyCoefficientMap that has a MultiKey containing the name of the regressor variable. The names of the other keys of the coeffMultiMap must match the (case-sensitive) name of the corresponding fields of the iDblSrc class.iDblSrc
- is an object that implements theDoubleSource
interface (e.g. the underlying agent whose properties are the covariates), and hence has a method getDoubleValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case sensitive) name of the first key entry of the coeffMultiMap's MultiKeyenumTypeDouble
- specifies the enum type that is used in the getDoubleValue(Enum.valueOf(enumType, String)) method of the iDblSrc object. The String is the name of the enum case, used as a switch to determine the appropriate double value to returniObjSrc
- is an object that implements the ObjectSource interface (e.g. the underlying agent whose properties are the covariates), and hence has a method getObjectValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case-sensitive) name of the conditioning regression key entries of coeffMultiMap's MultiKey (not the first key entry, which is reserved for the regressor name)enumTypeObject
- specifies the enum type that is used in the getObjectValue(Enum.valueOf(enumType, String)) method of the iObjSrc object. The String is the name of the enum case, used as a switch to determine the appropriate object value to return
-
getScore
Warning - only use when LinearRegression object contains a MultiKeyCoefficientMap with only one key. This method only looks at the first key of the MultiKeyCoefficientMap field of LinearRegression, so any other keys that are used to distinguish a unique multiKey (i.e. if the first key occurs more than once) will be ignored! If the first key of the multiKey appears more than once, the method would return an incorrect value, so will throw an exception. -
getScore
public <T extends Enum<T>> double getScore(@NonNull @NonNull DoubleSource iDblSrc, @NonNull @NonNull Class<T> enumType) -
getScore
To be used when the agent Object has member fields that correspond by name to all the regressors of the Regression's MultiKeyCoefficientMap map. The agent must also have fields that specify any additional conditioning keys e.g. gender or civil status, of the regression map's MultiKeys. -
getScore
public <T extends Enum<T>,U extends Enum<U>> double getScore(@NonNull @NonNull DoubleSource iDblSrc, @NonNull @NonNull Class<T> enumTypeDouble, @NonNull @NonNull ObjectSource iObjSrc, @NonNull @NonNull Class<U> enumTypeObject) Requires the implementation of the ObjectSource to ascertain whether any additional conditioning regression keys are used (e.g. whether the underlying agent is female, married etc., where the regression co-efficients are conditioned on additional keys of gender and civil status, for example). If the underlying agent does not implement ObjectSource but does have additional conditioning regression keys, use the computeScore method (that uses reflection, so is slower) with signature:public static <T extends Enum<T>> double getScore(IDoubleSource iDblSrc, Class<T> enumType)
If the underlying agent does not have additional conditioning regression keys, use the computeScore method with signature:-- Specified by:
getScore
in interfaceLinReg
- Parameters:
iDblSrc
- is an object that implements theDoubleSource
interface (e.g. the underlying agent whose properties are the covariates), and hence has a method getDoubleValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case-sensitive) name of the first key entry of the coeffMultiMap's MultiKeyenumTypeDouble
- specifies the enum type that is used in the getDoubleValue(Enum.valueOf(enumType, String)) method of the iDblSrc object. The String is the name of the enum case, used as a switch to determine the appropriate double value to returniObjSrc
- is an object that implements the ObjectSource interface (e.g. the underlying agent whose properties are the covariates), and hence has a method getObjectValue(enum), where the enum determines the appropriate double value to return. It must have some fields that match the (case-sensitive) name of the conditioning regression key entries of coeffMultiMap's MultiKey (not the first key entry, which is reserved for the regressor name)enumTypeObject
- specifies the enum type that is used in the getObjectValue(Enum.valueOf(enumType, String)) method of the iObjSrc object. The String is the name of the enum case, used as a switch to determine the appropriate object value to return
-