plspm.config module¶
-
class
plspm.config.
Config
(path: pandas.core.frame.DataFrame, scaled: bool = True, default_scale: plspm.scale.Scale = None)¶ Bases:
object
Specify the model you want to calculate with
Plspm
Create an instance of this class in order to specify the model you want to use
Plspm
to calculate.-
__init__
(path: pandas.core.frame.DataFrame, scaled: bool = True, default_scale: plspm.scale.Scale = None)¶ Specify the model you want to calculate with
Plspm
:Once you have created an instance of this class, add the relevant latent and manifest variables with
add_lv()
oradd_lv_with_columns_named()
Parameters: - path – A square lower triangular matrix which specifies the paths between the latent variables (the inner model). The index and columns of this matrix must be the same, and must consist of the names of the latent variables. Cells should contain 1 if the variable in the column affects the variable in the row, 0 otherwise.
- scaled – Whether manifest variables should be standardized. When
True
, data is scaled to standardized values (mean 0 and variance 1). Only used whendefault_scale
is set toNone
. - default_scale – If your data is nonmetric, specify a default measurement type. Takes a value from the enum
Scale
, orNone
(the default) if the data is metric and does not require scaling.
-
add_lv
(lv_name: str, mode: plspm.mode.Mode, *mvs)¶ Add a latent variable and associated manifest variables to the model.
Parameters: - lv_name – The name of the latent variable to add. Must match the name used in the columns / index of the Path matrix passed into the constructor.
- mode – Whether the latent variable is reflective (mode A) or formative (mode B) with respect to its manifest variables. Takes a value from the enum
Mode
- *mvs – A list of manifest variables that make up the latent variable. These must be instances of
MV
-
add_lv_with_columns_named
(lv_name: str, mode: plspm.mode.Mode, data: pandas.core.frame.DataFrame, col_name_starts_with: str, default_scale: plspm.scale.Scale = None)¶ Add a latent variable and associated manifest variables to the model.
This is a convenience method that can be used if the names of the columns in the dataset corresponding to the manifest variables all share a common prefix, and are all the same
Scale
(if nonmetric).Parameters: - lv_name – The name of the latent variable to add. Must match the name used in the columns / index of the Path matrix passed into the constructor.
- mode – Whether the latent variable is reflective (mode A) or formative (mode B) with respect to its manifest variables. Takes a value from the enum
Mode
- data – The dataset that will be passed into
Plspm
- col_name_starts_with – The prefix for the column names in the dataset corresponding to the manifest variables. For example, if the columns are named
var1
,var2
,var3
, usevar
- default_scale – If the data is nonmetric, the measurement type of the manifest variables. Note that you can only use this method if all the manifest variables are the same type of measurement, otherwise use
add_lv()
. Takes a value from the enumScale
.None
(the default) if the data is metric.
-
dummies
(mv: str)¶ Internal method that returns a dummy matrix which is used for handling ordinal or nominal data
-
filter
(data: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame¶ Internal method that removes columns from the dataset that are not specified in the model, and rows where all MVs for an LV are unknown.
Parameters: data – The dataset to filter Returns: The dataset with columns not specified in the columns removed. Raises: ValueError – if the dataset is missing any columns with names that were specified as manifest variables in the model, or if there are any non-numeric values in the dataset.
-
lvs
()¶ Internal method that returns a list of the latent variables in the model.
-
metric
()¶ Internal method that returns whether we are using metric or nonmetric data.
-
mode
(lv: str)¶ Internal method that returns the mode of a given latent variable.
-
mv_index
(lv, mv)¶ Internal method that returns the index of a manifest variable for a given latent variable.
-
mvs
(lv)¶ Internal method that returns the manifest variables belonging to a given latent variable.
-
odm
()¶ Internal method that returns the outer design matrix showing which manifest variables belong to which latent variables in the model.
-
path
()¶ Internal method that returns the matrix of paths provided in the constructor.
-
scale
(mv: str)¶ Internal method that returns the scale for a given manifest variable.
-
scaled
()¶ Internal method that returns whether the user asked for the data to be scaled.
-
treat
(data: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame¶ Internal method that treats the data (including scaling, normalizing, standardizing and rankifying, where appropriate)
Parameters: data – The dataset to treat. Returns: The treated dataset. Raises: TypeError – if you have specified a scale for some but not all manifest variables. Specifying a scale for any MV tells Plspm that you are using nonmetric data, which means you must specify a scale for all MVs (or specify a default scale in the constructor).
-
-
class
plspm.config.
MV
(name: str, scale: plspm.scale.Scale = None)¶ Bases:
object
Specify a manifest variable to use in the model.
You must create an instance of this class for every manifest variable when using
add_lv()
to add latent variables to the model.-
__init__
(name: str, scale: plspm.scale.Scale = None)¶ Specify a manifest variable to use in the model.
Parameters: - name – The name of the manifest variable (must match the column name corresponding to this manifest variable in the dataset).
- scale – If using nonmetric data, the measurement type of the variable (otherwise
None
). Takes a value from the enumScale
. Note that if you specify a scale for one variable, you must specify a scale for all variables (or specify a default scale to use in the constructor).
-
name
()¶ Internal method that returns the name of the manifest variable
-
scale
()¶ Internal method that returns the scale of the manifest variable (if specified)
-
-
class
plspm.config.
Structure
¶ Bases:
object
Specify relationships betweeen constructs
Use this class to specify the relationships between constructs. It will generate a path matrix suitable for using in
Config
.-
__init__
()¶ Initialize self. See help(type(self)) for accurate signature.
-
addPath
(source: list, target: list)¶ Specify a relationship between two sets of constructs.
Parameters: - source – A list of antecedent constructs
- target – A list of outcome constructs
-
path
()¶ Get a path matrix for use in
Config
.
-