LinearGenomicModel#
- class pybrops.model.gmod.LinearGenomicModel.LinearGenomicModel[source]#
Bases:
GenomicModel
,PandasDictInputOutput
,CSVDictInputOutput
The LinearGenomicModel class represents a Multivariate Multiple Linear Regression model.
A Multivariate Multiple Linear Regression model is defined as:
\[Y = X \Beta + ZU + e\]Where:
\(Y\) is a matrix of response variables of shape
(n,t)
.\(X\) is a matrix of fixed effect predictors of shape
(n,q)
.\(\Beta\) is a matrix of fixed effect regression coefficients of shape
(q,t)
.\(Z\) is a matrix of random effect predictors of shape
(n,p)
.\(U\) is a matrix of random effect regression coefficients of shape
(p,t)
.\(e\) is a matrix of error terms of shape
(n,t)
.
Shape definitions:
n
is the number of individualsq
is the number of fixed effect predictors (e.g. environments)p
is the number of random effect predictors (e.g. genomic markers)t
is the number of traits
Methods
Calculate the Bulmer effect.
Calculate the Bulmer effect.
Make a shallow copy of the GenomicModel.
Determine whether a deleterious allele is available in the present taxa.
Calculate the deleterious allele count across all taxa.
Determine whether a deleterious allele is fixed across all taxa.
Calculate the deleterious allele frequency across all taxa.
Determine whether a deleterious allele is polymorphic across all taxa.
Make a deep copy of the GenomicModel.
Determine whether a favorable allele is polymorphic or fixed across all taxa.
Calculate the favorable allele count across all taxa.
Determine whether a favorable allele is fixed across all taxa.
Calculate the favorable allele frequency across all taxa.
Determine whether a favorable allele is polymorphic across all taxa.
Fit the model.
Fit the model.
Read an object from a set of CSV files specified by values in a
dict
.Read an object from an HDF5 file.
Read an object from a
dict
ofpandas.DataFrame
.Calculate genomic estimated breeding values.
Calculate genomic estimated breeding values.
Calculate genomic estimated genotypic values.
Calculate genomic estimated genotypic values.
Calculate the lower selection limit for a population.
Calculate the lower selection limit for a population.
Determine whether a neutral allele is fixed across all taxa.
Determine whether a neutral allele is polymorphic across all taxa.
Predict breeding values.
Predict breeding values.
Return the coefficient of determination R**2 of the prediction.
Return the coefficient of determination R**2 of the prediction.
Write an object to a set of CSV files specified by values in a
dict
.Write an object to an HDF5 file.
Export an object to a
dict
ofpandas.DataFrame
.Calculate the upper selection limit for a population.
Calculate the upper selection limit for a population.
Calculate the population additive genetic variance
Calculate the population additive genetic variance
Calculate the population genetic variance.
Calculate the population genetic variance.
Calculate the population additive genic variance
Calculate the population additive genic variance
Attributes
Fixed effect regression coefficients.
Model parameters.
Name of the model.
Number of explanatory variables required by the model.
Number of fixed effect explanatory variables required by the model.
Number of random effect explanatory variables required by the model.
Number of model parameters.
Number of fixed effect parameters.
Number of random effect parameters.
Number of traits predicted by the model.
Names of the traits predicted by the model.
Random effect regression coefficients.
- abstract property beta: object#
Fixed effect regression coefficients.
- abstract bulmer(gtobj, ploidy, **kwargs)#
Calculate the Bulmer effect.
- Parameters:
gtobj (GenotypeMatrix) – An object containing genotype data. Must be a matrix of genotype values.
ploidy (int) – Ploidy of the species.
kwargs (dict) – Additional keyword arguments.
- Returns:
out – Array of shape
(t,)
contianing Bulmer effects for each trait. In the event that additive genic variance is zero, NaN’s are produced.- Return type:
numpy.ndarray
- abstract bulmer_numpy(Z, p, ploidy, **kwargs)#
Calculate the Bulmer effect.
- Parameters:
Z (numpy.ndarray) – A matrix of genotypes.
p (numpy.ndarray) – A vector of genotype allele frequencies of shape (p,).
ploidy (int) – Ploidy of the species.
kwargs (dict) – Additional keyword arguments.
- Returns:
out – Array of shape
(t,)
contianing Bulmer effects for each trait. In the event that additive genic variance is zero, NaN’s are produced.- Return type:
numpy.ndarray
- abstract copy()#
Make a shallow copy of the GenomicModel.
- Returns:
out – A shallow copy of the original GenomicModel
- Return type:
- abstract daavail(gmat, dtype=None, **kwargs)#
Determine whether a deleterious allele is available in the present taxa.
An allele is considered deleterious if its effect is less than zero. Alleles with zero effect are not considered deleterious; they are considered neutral.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to determine deleterious allele frequencies.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native boolean type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A
numpy.ndarray
of shape(p,t)
containing whether a deleterious allele is available.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract dacount(gmat, dtype, **kwargs)#
Calculate the deleterious allele count across all taxa.
An allele is considered deleterious if its effect is less than zero. Alleles with zero effect are not considered deleterious; they are considered neutral.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to count deleterious alleles.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A numpy.ndarray of shape
(p,t)
containing allele counts of the deleterious allele.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract dafixed(gmat, dtype, **kwargs)#
Determine whether a deleterious allele is fixed across all taxa.
An allele is considered deleterious if its effect is less than zero. Alleles with zero effect are not considered deleterious; they are considered neutral.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to determine deleterious allele frequencies.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A
numpy.ndarray
of shape(p,t)
containing whether a deleterious allele is fixed.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract dafreq(gmat, dtype, **kwargs)#
Calculate the deleterious allele frequency across all taxa.
An allele is considered deleterious if its effect is less than zero. Alleles with zero effect are not considered deleterious; they are considered neutral.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to determine deleterious allele frequencies.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A
numpy.ndarray
of shape(p,t)
containing allele frequencies of the deleterious allele.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract dapoly(gmat, dtype, **kwargs)#
Determine whether a deleterious allele is polymorphic across all taxa.
An allele is considered deleterious if its effect is less than zero. Alleles with zero effect are not considered deleterious; they are considered neutral.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to determine deleterious allele frequencies.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A
numpy.ndarray
of shape(p,t)
containing whether a deleterious allele is polymorphic.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract deepcopy(memo)#
Make a deep copy of the GenomicModel.
- Parameters:
memo (dict) – Dictionary of memo metadata.
- Returns:
out – A deep copy of the original GenomicModel
- Return type:
- abstract faavail(gmat, dtype=None, **kwargs)#
Determine whether a favorable allele is polymorphic or fixed across all taxa.
An allele is considered favorable if its effect is greater than zero. Alleles with zero effect are not considered favorable; they are considered neutral.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to determine favorable allele frequencies.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A numpy.ndarray of shape
(p,t)
containing whether a favorable allele is available.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract facount(gmat, dtype, **kwargs)#
Calculate the favorable allele count across all taxa.
An allele is considered favorable if its effect is greater than zero. Alleles with zero effect are not considered favorable; they are considered neutral.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to count favorable alleles.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A numpy.ndarray of shape
(p,t)
containing allele counts of the favorable allele.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract fafixed(gmat, dtype, **kwargs)#
Determine whether a favorable allele is fixed across all taxa.
An allele is considered favorable if its effect is greater than zero. Alleles with zero effect are not considered favorable; they are considered neutral.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to determine favorable allele frequencies.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A numpy.ndarray of shape
(p,t)
containing whether a favorable allele is fixed.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract fafreq(gmat, dtype, **kwargs)#
Calculate the favorable allele frequency across all taxa.
An allele is considered favorable if its effect is greater than zero. Alleles with zero effect are not considered favorable; they are considered neutral.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to determine favorable allele frequencies.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A numpy.ndarray of shape
(p,t)
containing allele frequencies of the favorable allele.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract fapoly(gmat, dtype, **kwargs)#
Determine whether a favorable allele is polymorphic across all taxa.
An allele is considered favorable if its effect is greater than zero. Alleles with zero effect are not considered favorable; they are considered neutral.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to determine favorable allele frequencies.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A numpy.ndarray of shape
(p,t)
containing whether a favorable allele is polymorphic.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract classmethod fit(ptobj, cvobj, gtobj, **kwargs)#
Fit the model.
- Parameters:
ptobj (BreedingValueMatrix, pandas.DataFrame, numpy.ndarray) – An object containing phenotype data. Must be a matrix of breeding values or a phenotype data frame.
cvobj (numpy.ndarray) – An object containing covariate data.
gtobj (GenotypeMatrix, numpy.ndarray) – An object containing genotype data. Must be a matrix of genotype values.
kwargs (dict) – Additional keyword arguments.
- Return type:
None
- abstract classmethod fit_numpy(Y, X, Z, **kwargs)#
Fit the model.
- Parameters:
Y (numpy.ndarray) – A phenotype matrix of shape (n,t).
X (numpy.ndarray) – A covariate matrix of shape (n,q).
Z (numpy.ndarray) – A genotypes matrix of shape (n,p).
kwargs (dict) – Additional keyword arguments.
- Return type:
None
- abstract classmethod from_csv_dict(filenames, **kwargs)#
Read an object from a set of CSV files specified by values in a
dict
.- Parameters:
filenames (str) – Dictionary of CSV file names from which to read.
kwargs (dict) – Additional keyword arguments to use for dictating importing from a CSV.
- Returns:
out – An object read from a set of CSV files.
- Return type:
- abstract classmethod from_hdf5(filename, groupname)#
Read an object from an HDF5 file.
- Parameters:
filename (str, Path, h5py.File) – If
str
, an HDF5 file name from which to read. IfPath
, an HDF5 file name from which to read. Ifh5py.File
, an opened HDF5 file from which to read.groupname (str, None) – If
str
, an HDF5 group name under which object data is stored. IfNone
, object is read from base HDF5 group.
- Returns:
out – An object read from an HDF5 file.
- Return type:
- abstract classmethod from_pandas_dict(dic, **kwargs)#
Read an object from a
dict
ofpandas.DataFrame
.- Parameters:
dic (dict) – Python dictionary containing
pandas.DataFrame
from which to read.kwargs (dict) – Additional keyword arguments to use for dictating importing from a
dict
ofpandas.DataFrame
.
- Returns:
out – An object read from a
dict
ofpandas.DataFrame
.- Return type:
- abstract gebv(gtobj, **kwargs)#
Calculate genomic estimated breeding values.
Remark: The difference between ‘predict’ and ‘gebv’ is that ‘predict’ can incorporate other factors (e.g., fixed effects) to provide prediction estimates.
- Parameters:
gtobj (GenotypeMatrix) – An object containing genotype data. Must be a matrix of genotype values.
kwargs (dict) – Additional keyword arguments.
- Returns:
gebvmat_hat – Genomic estimated breeding values.
- Return type:
- abstract gebv_numpy(Z, **kwargs)#
Calculate genomic estimated breeding values.
Remark: The difference between ‘predict_numpy’ and ‘gebv_numpy’ is that ‘predict_numpy’ can incorporate other factors (e.g., fixed effects) to provide prediction estimates.
- Parameters:
Z (numpy.ndarray) – A matrix of genotype values.
kwargs (dict) – Additional keyword arguments.
- Returns:
gebv_hat – A matrix of genomic estimated breeding values.
- Return type:
numpy.ndarray
- abstract gegv(gtobj, **kwargs)#
Calculate genomic estimated genotypic values.
- Parameters:
Z (numpy.ndarray) – A matrix of genotypic markers.
kwargs (dict) – Additional keyword arguments.
- Returns:
out – A matrix of genomic estimated genotypic values.
- Return type:
numpy.ndarray
- abstract gegv_numpy(Z, **kwargs)#
Calculate genomic estimated genotypic values.
- Parameters:
Z (numpy.ndarray) – A matrix of genotypic markers.
kwargs (dict) – Additional keyword arguments.
- Returns:
out – A matrix of genomic estimated genotypic values.
- Return type:
numpy.ndarray
- abstract property hyperparams: dict#
Model parameters.
- abstract lsl(gtobj, ploidy, unscale, **kwargs)#
Calculate the lower selection limit for a population.
- Parameters:
gtobj (GenotypeMatrix) – An object containing genotype data. Must be a matrix of genotype values.
ploidy (int) – Ploidy of the species.
unscale (bool) – If
True
, then apply the mean of the fixed effects to the output.kwargs (dict) – Additional keyword arguments.
- Returns:
out – An array of shape (t,) containing lower selection limits for each of
t
traits.- Return type:
numpy.ndarray
- abstract lsl_numpy(p, ploidy, unscale, **kwargs)#
Calculate the lower selection limit for a population.
- Parameters:
p (numpy.ndarray) – A vector of genotype allele frequencies of shape (p,).
ploidy (int) – Ploidy of the species.
unscale (bool) – If
True
, then apply the mean of the fixed effects to the output.kwargs (dict) – Additional keyword arguments.
- Returns:
out – An array of shape (t,) containing lower selection limits for each of
t
traits.- Return type:
numpy.ndarray
- abstract property model_name: str#
Name of the model.
- abstract nafixed(gmat, dtype, **kwargs)#
Determine whether a neutral allele is fixed across all taxa.
An allele is considered neutral if its effect is equal to zero.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to determine neutral allele frequencies.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A numpy.ndarray of shape
(p,t)
containing whether a neutral allele is fixed.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract napoly(gmat, dtype, **kwargs)#
Determine whether a neutral allele is polymorphic across all taxa.
An allele is considered neutral if its effect is equal to zero.
- Parameters:
gmat (GenotypeMatrix) – Genotype matrix for which to determine neutral allele frequencies.
dtype (numpy.dtype, None) – Datatype of the returned array. If
None
, use the native type.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A numpy.ndarray of shape
(p,t)
containing whether a neutral allele is polymorphic.Where:
p
is the number of alleles.t
is the number of traits.
- Return type:
numpy.ndarray
- abstract property nexplan: Integral#
Number of explanatory variables required by the model.
- abstract property nexplan_beta: Integral#
Number of fixed effect explanatory variables required by the model.
- abstract property nexplan_u: Integral#
Number of random effect explanatory variables required by the model.
- abstract property nparam: Integral#
Number of model parameters.
- abstract property nparam_beta: Integral#
Number of fixed effect parameters.
- abstract property nparam_u: Integral#
Number of random effect parameters.
- abstract property ntrait: int#
Number of traits predicted by the model.
- abstract predict(cvobj, gtobj, **kwargs)#
Predict breeding values.
Remark: The difference between ‘predict’ and ‘gebv’ is that ‘predict’ can incorporate other factors (e.g., fixed effects) to provide prediction estimates.
- Parameters:
cvobj (numpy.ndarray) – An object containing covariate data.
gtobj (GenotypeMatrix) – An object containing genotype data. Must be a matrix of genotype values.
kwargs (dict) – Additional keyword arguments.
- Returns:
bvmat_hat – Estimated breeding values.
- Return type:
- abstract predict_numpy(X, Z, **kwargs)#
Predict breeding values.
Remark: The difference between ‘predict_numpy’ and ‘gebv_numpy’ is that ‘predict_numpy’ can incorporate other factors (e.g., fixed effects) to provide prediction estimates.
- Parameters:
X (numpy.ndarray) – A matrix of covariates.
Z (numpy.ndarray) – A matrix of genotype values.
kwargs (dict) – Additional keyword arguments.
- Returns:
Y_hat – A matrix of predicted breeding values.
- Return type:
numpy.ndarray
- abstract score(ptobj, cvobj, gtobj, **kwargs)#
Return the coefficient of determination R**2 of the prediction.
- Parameters:
ptobj (BreedingValueMatrix or pandas.DataFrame) – An object containing phenotype data. Must be a matrix of breeding values or a phenotype data frame.
cvobj (object) – An object containing covariate data.
gtobj (GenotypeMatrix) – An object containing genotype data. Must be a matrix of genotype values.
kwargs (dict) – Additional keyword arguments.
- Returns:
Rsq – A coefficient of determination array of shape
(t,)
.Where:
t
is the number of traits.
- Return type:
numpy.ndarray
- abstract score_numpy(Y, X, Z, **kwargs)#
Return the coefficient of determination R**2 of the prediction.
- Parameters:
Y (numpy.ndarray) – A matrix of phenotypes.
X (numpy.ndarray) – A matrix of covariates.
Z (numpy.ndarray) – A matrix of genotypes.
kwargs (dict) – Additional keyword arguments.
- Returns:
Rsq – A coefficient of determination array of shape
(t,)
.Where:
t
is the number of traits.
- Return type:
numpy.ndarray
- abstract to_csv_dict(filenames, **kwargs)#
Write an object to a set of CSV files specified by values in a
dict
.- Parameters:
filenames (dict) – Dictionary of CSV file names to which to write.
kwargs (dict) – Additional keyword arguments to use for dictating export to a CSV.
- Return type:
None
- abstract to_hdf5(filename, groupname, overwrite)#
Write an object to an HDF5 file.
- Parameters:
filename (str, Path, h5py.File) – If
str
, an HDF5 file name to which to write. IfPath
, an HDF5 file path to which to write. Ifh5py.File
, an opened HDF5 file to which to write.groupname (str, None) – If
str
, an HDF5 group name under which object data is stored. IfNone
, object is written to the base HDF5 group.overwrite (bool) – Whether to overwrite values in an HDF5 file if a field already exists.
- Return type:
None
- abstract to_pandas_dict(**kwargs)#
Export an object to a
dict
ofpandas.DataFrame
.- Parameters:
kwargs (dict) – Additional keyword arguments to use for dictating export to a
dict
ofpandas.DataFrame
.- Returns:
out – An output dataframe.
- Return type:
dict
- abstract property trait: ndarray#
Names of the traits predicted by the model.
- abstract property u: object#
Random effect regression coefficients.
- abstract usl(gtobj, ploidy, unscale, **kwargs)#
Calculate the upper selection limit for a population.
- Parameters:
gtobj (GenotypeMatrix) – An object containing genotype data. Must be a matrix of genotype values.
ploidy (int) – Ploidy of the species.
unscale (bool) – If
True
, then apply the mean of the fixed effects to the output.kwargs (dict) – Additional keyword arguments.
- Returns:
out – An array of shape (t,) containing upper selection limits for each of
t
traits.- Return type:
numpy.ndarray
- abstract usl_numpy(p, ploidy, unscale, **kwargs)#
Calculate the upper selection limit for a population.
- Parameters:
p (numpy.ndarray) – A vector of genotype allele frequencies of shape (p,).
ploidy (int) – Ploidy of the species.
unscale (bool) – If
True
, then apply the mean of the fixed effects to the output.kwargs (dict) – Additional keyword arguments.
- Returns:
out – An array of shape (t,) containing upper selection limits for each of
t
traits.- Return type:
numpy.ndarray
- abstract var_A(gtobj, **kwargs)#
Calculate the population additive genetic variance
- Parameters:
gtobj (GenotypeMatrix) – An object containing genotype data. Must be a matrix of genotype values.
kwargs (dict) – Additional keyword arguments.
- Returns:
out – Array of shape
(t,)
contianing additive genetic variances for each trait.- Return type:
numpy.ndarray
- abstract var_A_numpy(Z, **kwargs)#
Calculate the population additive genetic variance
- Parameters:
Z (numpy.ndarray) – A matrix of genotypes.
kwargs (dict) – Additional keyword arguments.
- Returns:
out – Array of shape
(t,)
contianing additive genetic variances for each trait.- Return type:
numpy.ndarray
- abstract var_G(gtobj, **kwargs)#
Calculate the population genetic variance.
- Parameters:
gtobj (GenotypeMatrix) – An object containing genotype data. Must be a matrix of genotype values.
kwargs (dict) – Additional keyword arguments.
- Returns:
out – Array of shape
(t,)
contianing genetic variances for each trait.- Return type:
numpy.ndarray
- abstract var_G_numpy(Z, **kwargs)#
Calculate the population genetic variance.
- Parameters:
Z (numpy.ndarray) – A matrix of genotypes.
kwargs (dict) – Additional keyword arguments.
- Returns:
out – Array of shape
(t,)
contianing genetic variances for each trait.- Return type:
numpy.ndarray
- abstract var_a(gtobj, ploidy, **kwargs)#
Calculate the population additive genic variance
- Parameters:
gtobj (GenotypeMatrix, numpy.ndarray) – An object containing genotype data. Must be a matrix of genotype values.
ploidy (int) – Ploidy of the species.
kwargs (dict) – Additional keyword arguments.
- Returns:
out – Array of shape
(t,)
contianing additive genic variances for each trait.- Return type:
numpy.ndarray
- abstract var_a_numpy(p, ploidy, **kwargs)#
Calculate the population additive genic variance
- Parameters:
p (numpy.ndarray) – A vector of genotype allele frequencies of shape (p,).
ploidy (int) – Ploidy of the species.
kwargs (dict) – Additional keyword arguments.
- Returns:
out – Array of shape
(t,)
contianing additive genic variances for each trait.- Return type:
numpy.ndarray