Title: | Pedigree-Based Mixed-Effects Models |
---|---|
Description: | Fit pedigree-based mixed-effects models. |
Authors: | Douglas Bates, Paulino Perez Rodriguez and Ana Ines Vazquez, |
Maintainer: | Ana Ines Vazquez <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.3-4 |
Built: | 2024-11-21 03:49:34 UTC |
Source: | https://github.com/anainesvs/pedigreemm |
numeric vector that should be the diagonal elements of the diagonal matrix D
Dmat(ped)
Dmat(ped)
ped |
an object that inherits from class pedigree |
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
a numeric vector
ped <- pedigree(sire = c(NA,NA,1, 1,4,5), dam = c(NA,NA,2,NA,3,2), label= 1:6) Dmat(ped)
ped <- pedigree(sire = c(NA,NA,1, 1,4,5), dam = c(NA,NA,2,NA,3,2), label= 1:6) Dmat(ped)
This function helps to prepare a pedigree to generate a pedigree object
editPed(sire, dam, label, verbose)
editPed(sire, dam, label, verbose)
sire |
a vector (with some |
dam |
similarly as |
label |
a vector with the subjects id. Giving a unique ID for the corresponding
entry. The length as |
verbose |
logical entry inquiring whether to print line that the program is evaluating. The default is FALSE. |
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
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.
#(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))
#(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 from a pedigree
getA(ped)
getA(ped)
ped |
a pedigree that includes the individuals who occur in |
Returns the additive relationship matrix for the pedigree ped
.
Sparse matrix
## 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))
## 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 from a pedigree
getAInv(ped)
getAInv(ped)
ped |
a pedigree that includes the individuals who occur in |
Determine the inverse of the relationship matrix from a pedigree
ped
.
sparse matrix, inverse of the relationship matrix
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.
## 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)
## 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
inbreeding(ped)
inbreeding(ped)
ped |
an object that inherits from class pedigree |
Determine the inbreeding coefficients for all the individuals of a pedigree. This function a numeric vector.
a numeric vector
Sargolzaei, M. and H. Iwaisaki, 2005. Comparison of four direct algorithms for computing the inbreeding coefficients. J. Anim. Sci, 76: 401-406.
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.
ped <- pedigree(sire = c(NA,NA,1, 1,4,5), dam = c(NA,NA,2,NA,3,2), label= 1:6) inbreeding(ped)
ped <- pedigree(sire = c(NA,NA,1, 1,4,5), dam = c(NA,NA,2,NA,3,2), label= 1:6) inbreeding(ped)
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.
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.
The pedigree of the sires is given in the companion
pedSires
data set.
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.
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.
str(mastitis) summary(mastitis, maxsum = 10)
str(mastitis) summary(mastitis, maxsum = 10)
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.
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
USDA web site. http://www.aipl.arsusda.gov/
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.
str(milk)
str(milk)
A pedigree
object giving (part of) the pedigree
of the cows in the milk
data frame.
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" ...
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.
str(pedCows)
str(pedCows)
A pedigree
object giving (part of) the pedigree
of the cows in the milk
data frame.
This pedigree allows the example with 'milk' to run faster.
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" ...
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.
str(pedCowsR)
str(pedCowsR)
Construct an object of class "pedigree"
, more
conveniently than by new("pedigree", ....)
.
pedigree(sire, dam, label)
pedigree(sire, dam, label)
sire |
numeric vector (with some |
dam |
similarly as |
label |
a vector coercable to |
an object of formal class "pedigree"
.
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.
the pedigree
class.
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))
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))
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 in the "pedigree"
class can be created by calls of the
form new("pedigree", ...)
, or more conveniently,
pedigree(sire= ., dam = ., label =.)
.
Objects of the "pedinbred"
class are created by coercing a
pedigree to class "pedinbred"
.
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.
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.
signature(from = "pedigree", to = "data.frame")
: ...
signature(x = "pedigree")
: ...
signature(object = "pedigree")
: ...
signature(x = "pedigree")
: ...
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.
## 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)
## 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 linear or generalized linear mixed models incorporating the effects of a pedigree.
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, ...)
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, ...)
pedigree |
a named list of |
formula |
as in |
data |
as in |
family |
as in |
REML |
as in |
control |
as in |
start |
as in |
verbose |
as in |
subset |
as in |
weights |
as in |
na.action |
as in |
offset |
as in |
contrasts |
as in |
model |
as in |
x |
as in |
... |
as in |
All arguments to this function are the same as those to the function
lmer
except pedigree
which must be a named list of
pedigree
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
and applied to the model matrix for that
term.
a pedigreemm
object.
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.
pedigreemm
, pedigree
,
relfactor
.
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')
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')
A mixed-effects model fit by pedigreemm
.
This class extends class "merMod"
class and includes one
additional slot, relfac
, which is a list of (left) Cholesky
factors of the relationship matrices derived from
"pedigree"
objects.
Objects are created by calls to the
pedigreemm
function.
relfac
:A list of relationship matrix factors. All
other slots are inherited from class "merMod"
.
Class "merMod"
, directly.
signature(object = "pedigreemm")
: actually a
non-method in that fitted
doesn't apply to such objects
because of the pre-whitening.
signature(object = "pedigreemm")
: incorporates
the pedigree into the random effects as returned for the object
viewed as a "merMod)"
object.
signature(object = "pedigreemm")
: also a
non-method for the same reason as fitted
showClass("pedigreemm")
showClass("pedigreemm")
A pedigree
object giving (part of) the pedigree
of the sires from the mastitis
data frame. The
pedigree is traced back on sires only.
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" ...
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.
str(pedSires)
str(pedSires)
Relationship factor from a pedigree
relfactor(ped, labs)
relfactor(ped, labs)
ped |
a pedigree that includes the individuals who occur in |
labs |
a character vector or a factor giving the labels to
which to restrict the relationship matrix. If |
Determine the right Cholesky factor of the relationship matrix for the
pedigree ped
, possibly restricted to the specific labels that
occur in labs
.
an upper triangular, sparse (right) Cholesky factor of the relationship matrix
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.
## 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
## 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