pedigreemm
pedigreemm
pedigreemm
R topics documented:
Dmat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
editPed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
getA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
getAInv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
inbreeding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
mastitis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
milk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
pedCows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
pedCowsR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
pedigree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
pedigree-class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
pedigreemm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
pedigreemm-class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
pedSires . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
relfactor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1
2 editPed
Index 16
Dmat 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)
Description
This function helps to prepare a pedigree to generate a pedigree object
Usage
editPed(sire, dam, label, verbose)
editPed 3
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))
4 getAInv
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
Description
Inverse of the Relationship matrix from a pedigree
Usage
getAInv(ped)
Arguments
ped a pedigree that includes the individuals who occur in labs
inbreeding 5
Details
Determine the inverse of the relationship matrix from a pedigree ped.
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
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
6 mastitis
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)
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.
Details
The pedigree of the sires is given in the companion pedSires data set.
milk 7
Source
Vazquez, A.I. 2007. Analysis of number of episodes of clinical mastitis in Norwegian Red and Hol-
stein 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, pedigree
Examples
str(mastitis)
summary(mastitis, maxsum = 10)
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
8 pedCows
Source
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)
Description
A pedigree object giving (part of) the pedigree of the cows in the 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
Examples
str(pedCows)
pedCowsR 9
pedCowsR Pedigree of the cows in milk with 0.70 of the information in pedCows
Description
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.
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
Examples
str(pedCowsR)
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.
10 pedigree-class
Value
an object of formal class "pedigree".
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 class.
Examples
example("pedigree-class") ## 'p1' pedigree object `the hard way'
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.
Slots
sire: integer vector (with some NA entries), denoting a previous entry in the pedigree correspond-
ing 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.
pedigreemm 11
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 Publish-
ing, 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, 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)
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, ...)
12 pedigreemm
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 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.
Value
a pedigreemm 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, pedigree, relfactor.
pedigreemm-class 13
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')
Description
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.
Slots
relfac: A list of relationship matrix factors. All other slots are inherited from class "merMod".
Extends
Class "merMod", 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)" object.
residuals signature(object = "pedigreemm"): also a non-method for the same reason as fitted
14 pedSires
See Also
pedigreemm
Examples
showClass("pedigreemm")
Description
A pedigree object giving (part of) the pedigree of the sires from the 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
Examples
str(pedSires)
relfactor 15
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 re-
stricted 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
Dmat, 2
editPed, 2
fitted,pedigreemm-method
(pedigreemm-class), 13
getA, 4
getAInv, 4
glmer, 12
16