Help for package pedigreemm (original) (raw)
| Version: | 0.3-5 |
|---|---|
| Date: | 2024-10-10 |
| Title: | Pedigree-Based Mixed-Effects Models |
| Author: | Douglas Bates [aut], Ana Ines Vazquez [aut, cre], Paulino Perez Rodriguez [ctb] |
| Maintainer: | Ana Ines Vazquez avazquez@msu.edu |
| Description: | Fit pedigree-based mixed-effects models. |
| Depends: | R(≥ 3.0.0), lme4 (≥ 1.0), Matrix (≥ 1.0), methods |
| LazyLoad: | yes |
| LazyData: | yes |
| License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
| URL: | https://github.com/anainesvs/pedigreemm/ |
| NeedsCompilation: | yes |
| Packaged: | 2024-10-11 21:02:39 UTC; pperez |
| Repository: | CRAN |
| Date/Publication: | 2024-10-14 14:40:02 UTC |
vector of the diagonal for the D matrix from the decomposition A= TDT'
Description
numeric vector that should be the diagonal elements of the diagonal matrix D
Usage
Dmat(ped)Arguments
| ped | an object that inherits from class pedigree |
|---|
Details
Determine the diagonal factor in the decomposition of the relationship matrix from a pedigree equal to TDT'. Where T is unit lower triangular and D is a diagonal matrix. This function returns a numeric vector with the entries of D
Value
a numeric vector
Examples
ped <- pedigree(sire = c(NA,NA,1, 1,4,5),
dam = c(NA,NA,2,NA,3,2), label= 1:6)
Dmat(ped)
Complete and Order a Pedigree
Description
This function helps to prepare a pedigree to generate a pedigree object
Usage
editPed(sire, dam, label, verbose)Arguments
| sire | a vector (with some NA entries) with the father IDs |
|---|---|
| dam | similarly as sire for the “mother” of each entry. The vector must be of the same length than the one for the sire |
| label | a vector with the subjects id. Giving a unique ID for the corresponding entry. The length as sire and dam should be the same |
| verbose | logical entry inquiring whether to print line that the program is evaluating. The default is FALSE. |
Details
The function takes a vector of sires, another for dams and a final one for subjects all of the same length, convert them to character. If there are dams or sires not declared as subjects the function generates them. Finally, it orders the pedigree. The output can be used to build a pedigree object ped
Value
A data frame with strings as characters. All subjects are in the label column, and all subjects will appear in this column before appering as sires or dams.
Examples
#(1)
pede<-data.frame(sire=as.character(c(NA,NA,NA,NA,NA,1,3,5,6,4,8,1,10,8)),
dam= as.character(c(NA,NA,NA,NA,NA,2,2,NA,7,7,NA,9,9,13)),
label=as.character(1:14))
#scrambled original pedigree:
(pede<- pede[sample(replace=FALSE, 1:14),] )
(pede<- editPed(sire=pede$sire, dam= pede$dam, label=pede$label))
ped<- with(pede, pedigree(label=label, sire=sire, dam=dam))
#################################################################################################
#(2) With missing labels
pede<-data.frame(sire=as.character(c(NA,1,3,5,6,4,8,1,10,8)),
dam= as.character(c(NA,2,2,NA,7,7,NA,9,9,13)),
label=as.character(5:14))
#scrambled original pedigree:
(pede<- pede[sample(replace=FALSE, 1:10),] )
(pede<- editPed(sire=pede$sire, dam= pede$dam, label=pede$label))
ped<- with(pede, pedigree(label=label, sire=sire, dam=dam))
#################################################################################################
#(2) A larger pedigree
#Useing pedCows pedigree
# str(pedCows)
# pede<-data.frame(id=pedCows@label, sire=pedCows@sire, dam=pedCows@dam)
# pede<-pede[sample(1:nrow(pede),replace=FALSE),]
# pede<- editPed(sire=pede$sire, dam=pede$dam, label=pede$id)
# ped<- with(pede, pedigree(label=label, sire=sire, dam=dam))
Additive Relationship Matrix
Description
Additive relationship matrix from a pedigree
Usage
getA(ped)Arguments
| ped | a pedigree that includes the individuals who occur in labs |
|---|
Details
Returns the additive relationship matrix for the pedigree ped .
Value
Sparse matrix
Examples
## Example from chapter 2 of Mrode (2005)
ped <- pedigree(sire = c(NA,NA,1, 1,4,5),
dam = c(NA,NA,2,NA,3,2), label= 1:6)
(getA(ped))
Inverse of the relationship matrix
Description
Inverse of the Relationship matrix from a pedigree
Usage
getAInv(ped)Arguments
| ped | a pedigree that includes the individuals who occur in labs |
|---|
Details
Determine the inverse of the relationship matrix from a pedigreeped.
Value
sparse matrix, inverse of the relationship matrix
References
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
Examples
## Example from chapter 2 of Mrode (2005)
ped <- pedigree(sire = c(NA,NA,1, 1,4,5),
dam = c(NA,NA,2,NA,3,2), label= 1:6)
getAInv(ped)
Inbreeding coefficients from a pedigree...
Description
Inbreeding coefficients from a pedigree
Usage
inbreeding(ped)Arguments
| ped | an object that inherits from class pedigree |
|---|
Details
Determine the inbreeding coefficients for all the individuals of a pedigree. This function a numeric vector.
Value
a numeric vector
Source
Sargolzaei, M. and H. Iwaisaki, 2005. Comparison of four direct algorithms for computing the inbreeding coefficients. J. Anim. Sci, 76: 401-406.
References
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
Examples
ped <- pedigree(sire = c(NA,NA,1, 1,4,5),
dam = c(NA,NA,2,NA,3,2), label= 1:6)
inbreeding(ped)
Mastitis cases in dairy cattle
Description
Records of the number of cases of clinical mastitis during the first lactation of 1,675 cows, primarily Holsteins. Cows belonged to 41 herds and were daughters of 38 sires. There were 1,491 healthy cows, 134 had only one case of mastitis, 36 had 2 cases, and 14 had between 4 and cases. Overall, mastitis incidence was 0.11. Calving years for these records were from 2000 through 2005. The sire, herd and days in milk are also recorded for each cow.
Format
A data frame with 1675 observations on the following 8 variables.
id
Identifier of the animal.
sire
Identifier of the animal's sire.
birth
year of birth of the animal (as a factor).
herd
herd id number (as a factor).
calvingYear
year of calving for this lactation.
DIM
total number of days in milk for the lactation.
mastitis
a factor indicating if the cow had any incidents of clinical mastitis during the lactation.
NCM
An ordered factor giving the number of clinical mastitis cases for the cow during this lactation.
Details
The pedigree of the sires is given in the companion[pedSires](#topic+pedSires) data set.
Source
Vazquez, A.I. 2007. Analysis of number of episodes of clinical mastitis in Norwegian Red and Holstein cows with Poisson and categorical data mixed models. Master of Science Thesis. University of Wisconsin - Madison. 162 pp.
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
References
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
See Also
[pedSires](#topic+pedSires), [pedigree](#topic+pedigree)
Examples
str(mastitis)
summary(mastitis, maxsum = 10)
Milk production
Description
Records of the milk production of 3397 lactations from first through fifty parity Holsteins. These were 1,359 cows, daughters of 38 sires in 57 herds. The data was downloaded from the USDA internet site. All lactation records represent cows with at least 100 days in milk, with an average of 347 days. Milk yield ranged from 4,065 to 19,345 kg estimated for 305 days, averaging 11,636 kg. There were 1,314, 1,006, 640, 334 and 103 records were from first thorough fifth lactation animals.
Format
A data frame with 3397 observations on the following 9 variables.
id
numeric identifier of cow
lact
number of lactation for which production is measured
herd
a factor indicating the herd
sire
a factor indicating the sire
dim
number of days in milk for that lactation
milk
milk production estimated at 305 days
fat
fat production estimated at 305 days
prot
protein production estimated at 305 days
scs
the somatic cell score
Source
USDA web site. http://www.aipl.arsusda.gov/
References
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
Examples
str(milk)
Pedigree of the cows in milk
Description
A [pedigree](#topic+pedigree-class) object giving (part of) the pedigree of the cows in the [milk](#topic+milk) data frame.
Format
The format is: Formal class 'pedigree' [package "pedigreemm"] with 3 slots ..@ sire : int [1:6547] NA NA NA NA NA NA NA NA NA NA ... ..@ dam : int [1:6547] NA NA NA NA NA NA NA NA NA NA ... ..@ label: chr [1:6547] "1" "2" "3" "4" ...
References
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
See Also
[milk](#topic+milk)
Examples
str(pedCows)
Pedigree of the cows in milk with 0.70 of the information in pedCows
Description
A [pedigree](#topic+pedigree-class) object giving (part of) the pedigree of the cows in the [milk](#topic+milk) data frame. This pedigree allows the example with 'milk' to run faster.
Format
The format is: Formal class 'pedigree' [package "pedigreemm"] with 3 slots ..@ sire : int [1:6547] NA NA NA NA NA NA NA NA NA NA ... ..@ dam : int [1:6547] NA NA NA NA NA NA NA NA NA NA ... ..@ label: chr [1:6547] "1" "2" "3" "4" ...
References
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
See Also
[milk](#topic+milk)
Examples
str(pedCowsR)
Pedigree of the sires from mastitis
Description
A [pedigree](#topic+pedigree-class) object giving (part of) the pedigree of the sires from the [mastitis](#topic+mastitis) data frame. The pedigree is traced back on sires only.
Format
The format is: Formal class 'pedigree' [package "pedigreemm"] with 3 slots ..@ sire : int [1:352] NA NA NA NA NA NA NA NA NA NA ... ..@ dam : int [1:352] NA NA NA NA NA NA NA NA NA NA ... ..@ label: chr [1:352] "1" "2" "3" "4" ...
References
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
See Also
[mastitis](#topic+mastitis)
Examples
str(pedSires)
Pedigree Constructor
Description
Construct an object of class "pedigree", more conveniently than by new("pedigree", ....).
Usage
pedigree(sire, dam, label)
Arguments
| sire | numeric vector (with some NA entries) of integer IDs, denoting a previous entry in the pedigree corresponding to the current entry's “father”. |
|---|---|
| dam | similarly as sire for the “mother” of each entry. |
| label | a vector coercable to "character" of the same length as sire and dam giving a unique ID for the corresponding entry. |
Value
an object of formal class "[pedigree](#topic+pedigree-class)".
References
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
See Also
the [pedigree](#topic+pedigree-class) class.
Examples
example("pedigree-class") ## 'p1' pedigree object `the hard way'
ped <- pedigree(sire = c(NA,NA,1, 1,4,5),
dam = c(NA,NA,2,NA,3,2), label= 1:6)
## note that 'label' is coerced to character automatically
ped
stopifnot(identical(ped, p1))
Class "pedigree"
Description
Objects of class "pedigree" represent a set of individuals that can have two parents including their parent-child relations. The terminology has been taken from cattle breeding. The "pedinbred" class is an extension of the pedigree class with an additional slot of the inbreeding coefficients.
Objects from the Class
Objects in the "pedigree" class can be created by calls of the form new("pedigree", ...), or more conveniently,[pedigree](#topic+pedigree)(sire= ., dam = ., label =.).
Objects of the "pedinbred" class are created by coercing a pedigree to class "pedinbred".
Slots
sire:
integer vector (with some NA entries), denoting a previous entry in the pedigree corresponding to the current entry's “father”.
dam:
similarly as sire for the “mother” of each entry.
label:
a "character" vector of the same length as sire and dam giving a unique ID for the corresponding entry.
F:
(class "pedinbred" only) a numeric vector of inbreeding coefficients.
Methods
coerce
signature(from = "pedigree", to = "sparseMatrix"): returns a sparse, unit lower-triangular matrix which is the inverse of the "L" part of the "LDL'" form of the Cholesky factorization of the relationship matrix. All non-zero elements below the diagonal are -0.5.
coerce
signature(from = "pedigree", to = "data.frame"): ...
head
signature(x = "pedigree"): ...
show
signature(object = "pedigree"): ...
tail
signature(x = "pedigree"): ...
References
R. A. Mrode, Linear Models for the Prediction of Animal Breeding Values, 2nd ed, CABI Publishing, 2005.
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
See Also
[pedigree](#topic+pedigree), [inbreeding](#topic+inbreeding)
Examples
## Rather use, pedigree()! The following is "raw code":
## Example from chapter 2 of Mrode (2005)
p1 <- new("pedigree",
sire = as.integer(c(NA,NA,1, 1,4,5)),
dam = as.integer(c(NA,NA,2,NA,3,2)),
label = as.character(1:6))
p1
(dtc <- as(p1, "sparseMatrix")) # T-inverse in Mrode's notation
solve(dtc)
inbreeding(p1)
Fit mixed-effects models incorporating pedigrees
Description
Fit linear or generalized linear mixed models incorporating the effects of a pedigree.
Usage
pedigreemm(formula, data, family = NULL, REML = TRUE,
pedigree = list(), control = list(),
start = NULL, verbose = FALSE, subset, weights,
na.action, offset, contrasts = NULL, model = TRUE,
x = TRUE, ...)
Arguments
| pedigree | a named list of pedigree objects. The names must correspond to the names of grouping factors for random-effects terms in the formula argument. |
|---|---|
| formula | as in lmer |
| data | as in lmer |
| family | as in glmer |
| REML | as in lmer |
| control | as in lmer |
| start | as in lmer |
| verbose | as in lmer |
| subset | as in lmer |
| weights | as in lmer |
| na.action | as in lmer |
| offset | as in lmer |
| contrasts | as in lmer |
| model | as in lmer |
| x | as in lmer |
| ... | as in lmer |
Details
All arguments to this function are the same as those to the function[lmer](../../lme4/refman/lme4.html#topic+lmer) except pedigree which must be a named list of[pedigree](#topic+pedigree-class) objects. Each name (frequently there is only one) must correspond to the name of a grouping factor in a random-effects term in the formula. The observed levels of that factor must be contained in the pedigree. For each pedigree the (left) Cholesky factor of the relationship matrix restricted to the observed levels is calculated using [relfactor](#topic+relfactor) and applied to the model matrix for that term.
Value
a [pedigreemm](#topic+pedigreemm-class) object.
References
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
See Also
[pedigreemm](#topic+pedigreemm-class), [pedigree](#topic+pedigree-class),[relfactor](#topic+relfactor).
Examples
p1 <- new("pedigree",
sire = as.integer(c(NA,NA,1, 1,4,5)),
dam = as.integer(c(NA,NA,2,NA,3,2)),
label = as.character(1:6))
A<-getA(p1)
cholA<-chol(A)
varU<-0.4; varE<-0.6; rep<-20
n<-rep*6
set.seed(108)
bStar<- rnorm(6, sd=sqrt(varU))
b<-crossprod(as.matrix(cholA),bStar)
ID <- rep(1:6, each=rep)
e0<-rnorm(n, sd=sqrt(varE))
y<-b[ID]+e0
fm1 <- pedigreemm(y ~ (1|ID) , pedigree = list(ID = p1))
table(y01<-ifelse(y<1.3,0,1))
fm2 <- pedigreemm(y01 ~ (1|ID) , pedigree = list(ID = p1), family = 'binomial')
Pedigree-based mixed-effects model fits
Description
A mixed-effects model fit by [pedigreemm](#topic+pedigreemm). This class extends class "[merMod](../../lme4/refman/lme4.html#topic+merMod-class)" class and includes one additional slot, relfac, which is a list of (left) Cholesky factors of the relationship matrices derived from "[pedigree](#topic+pedigree-class)" objects.
Objects from the Class
Objects are created by calls to the[pedigreemm](#topic+pedigreemm) function.
Slots
relfac:
A list of relationship matrix factors. All other slots are inherited from class "[merMod](../../lme4/refman/lme4.html#topic+merMod-class)".
Extends
Class "[merMod](../../lme4/refman/lme4.html#topic+merMod-class)", directly.
Methods
fitted
signature(object = "pedigreemm"): actually a non-method in that fitted doesn't apply to such objects because of the pre-whitening.
ranef
signature(object = "pedigreemm"): incorporates the pedigree into the random effects as returned for the object viewed as a "[merMod](../../lme4/refman/lme4.html#topic+merMod-class))" object.
residuals
signature(object = "pedigreemm"): also a non-method for the same reason as fitted
See Also
[pedigreemm](#topic+pedigreemm)
Examples
showClass("pedigreemm")
Relationship factor from a pedigree...
Description
Relationship factor from a pedigree
Usage
relfactor(ped, labs)Arguments
| ped | a pedigree that includes the individuals who occur in labs |
|---|---|
| labs | a character vector or a factor giving the labels to which to restrict the relationship matrix. If labs is a factor then the levels of the factor are used as the labels. Default is the complete set of labels in the pedigree. |
Details
Determine the right Cholesky factor of the relationship matrix for the pedigree ped, possibly restricted to the specific labels that occur in labs.
Value
an upper triangular, sparse (right) Cholesky factor of the relationship matrix
References
2010. A.I. Vazquez, D.M. Bates, G.J.M. Rosa, D. Gianola and K.A. Weigel. Technical Note: An R package for fitting generalized linear mixed models in animal breeding. Journal of Animal Science, 88:497-504.
Examples
## Example from chapter 2 of Mrode (2005)
ped <- pedigree(sire = c(NA,NA,1, 1,4,5),
dam = c(NA,NA,2,NA,3,2), label= 1:6)
(fac <- relfactor(ped))
crossprod(fac) # the relationship matrix
getA(ped) # the relationship matrix