Title: | Partition/Decomposition of Breeding Values by Paths of Information |
---|---|
Description: | A software that implements a method for partitioning genetic trends to quantify the sources of genetic gain in breeding programmes. The partitioning method is described in Garcia-Cortes et al. (2008) <doi:10.1017/S175173110800205X>. The package includes the main function AlphaPart for partitioning breeding values and auxiliary functions for manipulating data and summarizing, visualizing, and saving results. |
Authors: | Gregor Gorjanc [aut, cre] , Jana Obsteter [aut] , Thiago de Paula Oliveira [aut] |
Maintainer: | Gregor Gorjanc <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.9.8 |
Built: | 2024-11-19 06:46:12 UTC |
Source: | CRAN |
A function to partition breeding values by a path variable. The partition method is described in García-Cortés et al., 2008: Partition of the genetic trend to validate multiple selection decisions. Animal : an international journal of animal bioscience. DOI: doi:10.1017/S175173110800205X
AlphaPart(x, pathNA, recode, unknown, sort, verbose, profile, printProfile, pedType, colId, colFid, colMid, colPath, colBV, colBy, center, scaleEBV)
AlphaPart(x, pathNA, recode, unknown, sort, verbose, profile, printProfile, pedType, colId, colFid, colMid, colPath, colBV, colBy, center, scaleEBV)
x |
data.frame , with (at least) the following columns:
individual, father, and mother identif ication, and year of birth;
see arguments |
pathNA |
Logical, set dummy path (to "XXX") where path information is unknown (missing). |
recode |
Logical, internally recode individual, father and,
mother identification to |
unknown |
Value(s) used for representing unknown (missing)
parent in |
sort |
Logical, initially sort |
verbose |
Numeric, print additional information: |
profile |
Logical, collect timings and size of objects. |
printProfile |
Character, print profile info on the fly
( |
pedType |
Character, pedigree type: the most common form is
|
colId |
Numeric or character, position or name of a column holding individual identif ication. |
colFid |
Numeric or character, position or name of a column holding father identif ication. |
colMid |
Numeric or character, position or name of a column
holding mother identif ication or maternal grandparent identif
ication if |
colPath |
Numeric or character, position or name of a column holding path information. |
colBV |
Numeric or character, position(s) or name(s) of column(s) holding breeding Values. |
colBy |
Numeric or character, position or name of a column holding group information (see details). |
center |
Logical, if |
scaleEBV |
a list with two arguments defining whether is
appropriate to center and/or scale the
|
Pedigree in x
must be valid in a sense that there
are:
no directed loops (the simplest example is that the individual identification is equal to the identification of a father or mother)
no bisexuality, e.g., fathers most not appear as mothers
father and/or mother can be unknown (missing) - defined with any "code" that is different from existing identifications
Unknown (missing) values for breeding values are propagated down the
pedigree to provide all available values from genetic
evaluation. Another option is to cut pedigree links - set parents to
unknown and remove them from pedigree prior to using this function -
see pedSetBase
function. Warning is issued
in the case of unknown (missing) values.
In animal breeding/genetics literature the model with the underlying
pedigree type "IPP"
is often called animal model, while the
model for pedigree type "IPG"
is often called sire - maternal
grandsire model. With a combination of colFid
and
colMid
mother - paternal grandsire model can be accomodated as
well.
Argument colBy
can be used to directly perform a summary
analysis by group, i.e., summary(AlphaPart(...),
by="group")
. See summary.AlphaPart
for
more. This can save some CPU time by skipping intermediate
steps. However, only means can be obtained, while summary
method gives more flexibility.
An object of class AlphaPart
, which can be used in
further analyses - there is a handy summary method
(summary.AlphaPart
works on objects of
AlphaPart
class) and a plot method for its output
(plot.summaryAlphaPart
works on objects of
summaryAlphaPart
class). Class AlphaPart
is a
list. The first length(colBV)
components (one for each trait
and named with trait label, say trt) are data frames. Each
data.frame contains:
x
columns from initial data x
trt_pa
parent average
trt_w
Mendelian sampling term
trt_path1, trt_path2, ...
breeding value partitions
The last component of returned object is also a list named
info
with the following components holding meta information
about the analysis:
path
column name holding path information
nP
number of paths
lP
path labels
nT
number of traits
lT
trait labels
warn
potential warning messages associated with this object
If colBy!=NULL
the resulting object is of a class
summaryAlphaPart
, see
summary.AlphaPart
for details.
If profile=TRUE
, profiling info is printed on screen to spot
any computational bottlenecks.
Garcia-Cortes, L. A. et al. (2008) Partition of the genetic trend to validate multiple selection decisions. Animal, 2(6):821-824. doi:10.1017/S175173110800205X
summary.AlphaPart
for summary
method that works on output of AlphaPart
,
pedSetBase
for setting base population,
pedFixBirthYear
for imputing unknown
(missing) birth years, orderPed
in
pedigree package for sorting pedigree
## Small pedigree with additive genetic (=breeding) values ped <- data.frame( id=c( 1, 2, 3, 4, 5, 6), fid=c( 0, 0, 2, 0, 4, 0), mid=c( 0, 0, 1, 0, 3, 3), loc=c("A", "B", "A", "B", "A", "A"), gen=c( 1, 1, 2, 2, 3, 3), trt1=c(100, 120, 115, 130, 125, 125), trt2=c(100, 110, 105, 100, 85, 110)) ## Partition additive genetic values tmp <- AlphaPart(x=ped, colBV=c("trt1", "trt2")) print(tmp) ## Summarize by generation (genetic mean) summary(tmp, by="gen") ## Summarize by generation (genetic variance) summary(tmp, by="gen", FUN = var) ## There are also two demos demo(topic="AlphaPart_deterministic", package="AlphaPart", ask=interactive()) demo(topic="AlphaPart_stochastic", package="AlphaPart", ask=interactive())
## Small pedigree with additive genetic (=breeding) values ped <- data.frame( id=c( 1, 2, 3, 4, 5, 6), fid=c( 0, 0, 2, 0, 4, 0), mid=c( 0, 0, 1, 0, 3, 3), loc=c("A", "B", "A", "B", "A", "A"), gen=c( 1, 1, 2, 2, 3, 3), trt1=c(100, 120, 115, 130, 125, 125), trt2=c(100, 110, 105, 100, 85, 110)) ## Partition additive genetic values tmp <- AlphaPart(x=ped, colBV=c("trt1", "trt2")) print(tmp) ## Summarize by generation (genetic mean) summary(tmp, by="gen") ## Summarize by generation (genetic variance) summary(tmp, by="gen", FUN = var) ## There are also two demos demo(topic="AlphaPart_deterministic", package="AlphaPart", ask=interactive()) demo(topic="AlphaPart_stochastic", package="AlphaPart", ask=interactive())
A dataset containing pedigree information and breeding values for six individuals.
AlphaPart.ped
AlphaPart.ped
A data frame with 6 rows and 8 variables:
individual's ID
Father's ID
Mother's ID
Generation
Country
Individual's sex
Breeding value for trait 1
Breeding value for trait 1
Simulation.
A function to choose the partition paths to keep.
AlphaPartSubset(x, paths = NULL)
AlphaPartSubset(x, paths = NULL)
x |
AlphaPart or summaryAlphaPart, object from the |
paths |
Character, names of paths to be kept. |
Displaying results of partitions for many paths is often confusing.
This function helps in selecting only paths of interest.
Unspecified paths are removed from the input object x
.
Meta information is modified accordingly. Default setting does nothing.
An object of class AlphaPart
or summaryAlphaPart
with only some paths.
Meta information in slot "info" is modified as well.
AlphaPart
for the main method,
summary.AlphaPart
for summary method that works on output of AlphaPart
,
AlphaPartSum
for sum method.
## Small pedigree with additive genetic (=breeding) values ped <- data.frame( id=c( 1, 2, 3, 4, 5, 6), fid=c( 0, 0, 2, 0, 4, 0), mid=c( 0, 0, 1, 0, 3, 3), loc=c("A", "B", "A", "B", "A", "A"), gen=c( 1, 1, 2, 2, 3, 3), trt1=c(100, 120, 115, 130, 125, 125), trt2=c(100, 110, 105, 100, 85, 110)) ## Partition additive genetic values (tmp <- AlphaPart(x=ped, colBV=c("trt1", "trt2"))) ## Keep some partitions (working on object of class AlphaPart) (tmp2 <- AlphaPartSubset(x=tmp, paths="A")) ## Summarize by generation (tmpS <- summary(tmp, by="gen")) ## Keep some partitions (working on object of class summaryAlphaPart) (tmpS2 <- AlphaPartSubset(x=tmpS, paths="A")) ## ... must be equal to (tmpS3 <- summary(tmp2, by="gen"))
## Small pedigree with additive genetic (=breeding) values ped <- data.frame( id=c( 1, 2, 3, 4, 5, 6), fid=c( 0, 0, 2, 0, 4, 0), mid=c( 0, 0, 1, 0, 3, 3), loc=c("A", "B", "A", "B", "A", "A"), gen=c( 1, 1, 2, 2, 3, 3), trt1=c(100, 120, 115, 130, 125, 125), trt2=c(100, 110, 105, 100, 85, 110)) ## Partition additive genetic values (tmp <- AlphaPart(x=ped, colBV=c("trt1", "trt2"))) ## Keep some partitions (working on object of class AlphaPart) (tmp2 <- AlphaPartSubset(x=tmp, paths="A")) ## Summarize by generation (tmpS <- summary(tmp, by="gen")) ## Keep some partitions (working on object of class summaryAlphaPart) (tmpS2 <- AlphaPartSubset(x=tmpS, paths="A")) ## ... must be equal to (tmpS3 <- summary(tmp2, by="gen"))
A function to sum partitions of several paths.
AlphaPartSum( x, map = NULL, remove = TRUE, zeroPath = TRUE, call = "AlphaPartSum" )
AlphaPartSum( x, map = NULL, remove = TRUE, zeroPath = TRUE, call = "AlphaPartSum" )
x |
summaryAlphaPart, object from the |
map |
List, a map of summing paths; see details and examples. |
remove |
Logical, remove original paths or not. |
zeroPath |
Logical, set called path to zero if it does not exist. |
call |
character, for internal use with |
Sometimes partitions of particular paths are very small or we want to sum
paths that have some similarity. These actions are easy to achive manually
but this functions provides a way to do this consistently with the given
object x
.
Arguments map
must be a list of vectors of length at least
two. Vectors of length one are skipped. The idea is that the first element
is the new or existing path into which we add up all the remaining specified
paths, say list(c("A", "B"), c("X", "X", "Y"), c("Z", "X"))
would
imply A = B, X = X + Y, and Z = X = X + Y. Note that once X is changed its
changed value is used in further calculations. Specify different (new) names
for new targets if you want to avoid this.
Be carefull with remove=TRUE
, which is the default setting, as all
partitions defined after the first (target/new) partition in vector in list
will be removed, for example with list(c("A", "B"), c("X", "X", "Y"),
c("Z", "X"))
partitions B and Y will be removed, while X will not be removed
as it is defined as a target/new partition.
An object of class AlphaPart
or summaryAlphaPart
with modified partitions.
Meta information in slot "info" is modified as well.
AlphaPart
for the main method,
summary.AlphaPart
for summary method that works on output of AlphaPart
,
AlphaPartSubset
for subset/keep method
## Small pedigree with additive genetic (=breeding) values ped <- data.frame( id=c( 1, 2, 3, 4, 5, 6), fid=c( 0, 0, 2, 0, 4, 0), mid=c( 0, 0, 1, 0, 3, 3), loc=c("A", "B", "A", "B", "A", "A"), gen=c( 1, 1, 2, 2, 3, 3), trt1=c(100, 120, 115, 130, 125, 125), trt2=c(100, 110, 105, 140, 85, 110)) ## Partition additive genetic values (tmp <- AlphaPart(x=ped, colBV=c("trt1", "trt2"))) ## Sum some partitions (working on object of class AlphaPart) (tmp2 <- AlphaPartSum(x=tmp, map=list(c("X", "A", "B"), c("A", "B")))) ## Summarize by generation (tmpS <- summary(tmp, by="gen")) ## Sum some partitions (working on object of class summaryAlphaPart) (tmpS2 <- AlphaPartSum(x=tmpS, map=list(c("X", "A", "B"), c("A", "B")))) ## ... must be equal to (tmpS3 <- summary(tmp2, by="gen"))
## Small pedigree with additive genetic (=breeding) values ped <- data.frame( id=c( 1, 2, 3, 4, 5, 6), fid=c( 0, 0, 2, 0, 4, 0), mid=c( 0, 0, 1, 0, 3, 3), loc=c("A", "B", "A", "B", "A", "A"), gen=c( 1, 1, 2, 2, 3, 3), trt1=c(100, 120, 115, 130, 125, 125), trt2=c(100, 110, 105, 140, 85, 110)) ## Partition additive genetic values (tmp <- AlphaPart(x=ped, colBV=c("trt1", "trt2"))) ## Sum some partitions (working on object of class AlphaPart) (tmp2 <- AlphaPartSum(x=tmp, map=list(c("X", "A", "B"), c("A", "B")))) ## Summarize by generation (tmpS <- summary(tmp, by="gen")) ## Sum some partitions (working on object of class summaryAlphaPart) (tmpS2 <- AlphaPartSum(x=tmpS, map=list(c("X", "A", "B"), c("A", "B")))) ## ... must be equal to (tmpS3 <- summary(tmp2, by="gen"))
A function to fix (impute) missing birth years in pedigree.
pedFixBirthYear( x, interval, down = FALSE, na.rm = TRUE, sort = TRUE, direct = TRUE, report = TRUE, colId = 1, colFid = 2, colMid = 3, colBY = 4 )
pedFixBirthYear( x, interval, down = FALSE, na.rm = TRUE, sort = TRUE, direct = TRUE, report = TRUE, colId = 1, colFid = 2, colMid = 3, colBY = 4 )
x |
data.frame , with (at least) the following columns: individual, father, and mother identification,
and year of birth; see arguments |
interval |
Numeric, a value for generation interval in years. |
down |
Logical, the default is to impute birth years based on the birth year of children
starting from the youngest to the oldest individuals, while with |
na.rm |
Logical, remove |
sort |
Logical, initially sort |
direct |
Logical, insert inferred birth years immediately so they can be used for successive individuals within the loop. |
report |
Logical, report success. |
colId |
Numeric or character, position or name of a column holding individual identification. |
colFid |
Numeric or character, position or name of a column holding father identification. |
colMid |
Numeric or character, position or name of a column holding mother identification. |
colBY |
Numeric or character, position or name of a column holding birth year. |
Warnings are issued when there is no information to use to impute birth years or missing
values (NA
) are propagated.
Arguments down
and na.rm
allow for repeated use of this function, i.e., with
down=FALSE
and with down=TRUE
(both in combination with na.rm=TRUE
) in order to
propagate information over the pedigree until "convergence".
This function can be very slow on large pedigrees with extensive missingness of birth years.
Object x
with imputed birth years based on the birth year of children or parents.
If report=TRUE
success is printed on the screen as the number of initially, fixed,
and left unknown birth years is printed.
orderPed
in pedigree package
## Example pedigree with missing (unknown) birth year for some individuals ped0 <- data.frame( id=c( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), fid=c( 0, 0, 0, 1, 1, 1, 3, 3, 3, 5, 4, 0, 0, 12), mid=c( 0, 0, 0, 2, 0, 2, 2, 2, 5, 0, 0, 0, 0, 13), birth_dt=c(NA, 0, 1, NA, 3, 3, 3, 3, 4, 4, 5, NA, 6, 6) + 2000) ## First run - using information from children ped1 <- pedFixBirthYear(x=ped0, interval=1) ## Second run - using information from parents ped2 <- pedFixBirthYear(x=ped1, interval=1, down=TRUE) ## Third run - using information from children, but with no success ped3 <- pedFixBirthYear(x=ped2, interval=1)
## Example pedigree with missing (unknown) birth year for some individuals ped0 <- data.frame( id=c( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), fid=c( 0, 0, 0, 1, 1, 1, 3, 3, 3, 5, 4, 0, 0, 12), mid=c( 0, 0, 0, 2, 0, 2, 2, 2, 5, 0, 0, 0, 0, 13), birth_dt=c(NA, 0, 1, NA, 3, 3, 3, 3, 4, 4, 5, NA, 6, 6) + 2000) ## First run - using information from children ped1 <- pedFixBirthYear(x=ped0, interval=1) ## Second run - using information from parents ped2 <- pedFixBirthYear(x=ped1, interval=1, down=TRUE) ## Third run - using information from children, but with no success ped3 <- pedFixBirthYear(x=ped2, interval=1)
A function to set the base population in the pedigree.
pedSetBase( x, keep = NULL, unknown = NA, report = TRUE, colId = 1, colFid = 2, colMid = 3 )
pedSetBase( x, keep = NULL, unknown = NA, report = TRUE, colId = 1, colFid = 2, colMid = 3 )
x |
data.frame , with (at least) the following columns: individual, father, and mother identification,
and year of birth; see arguments |
keep |
Logical, indicator that defines which individuals should stay in the the pedigree; see details. |
unknown |
Value used to represent unknown/missing identification |
report |
Logical, report success. |
colId |
Numeric or character, position or name of a column holding individual identification. |
colFid |
Numeric or character, position or name of a column holding father identification. |
colMid |
Numeric or character, position or name of a column holding mother identification. |
Base population in the pedigree is set by removing rows for some individuals, while their presence as parents is also removed.
Arguments down
and na.rm
allow for repeated use of this function, i.e., with
down=FALSE
and with down=TRUE
(both in combination with na.rm=TRUE
) in order to
propagate information over the pedigree until "convergence".
This function can be very slow on large pedigrees with extensive missingness of birth years.
Object x
with removed rows for some individuals and their presence as parents.
If report=TRUE
progress is printed on the screen.
orderPed
in pedigree package
## Example pedigree ped <- data.frame( id=1:10, fid=c(0, 0, 0, 1, 1, 1, 3, 3, 3, 5), mid=c(0, 0, 0, 2, 0, 2, 2, 2, 5, 0), birth_dt=c(0, 0, 1, 2, 3, 3, 3, 4, 4, 5) + 2000) ## Set base population as those individuals that were born after year 2002 pedSetBase(x=ped, keep=ped$birth_dt > 2002, unknown=0)
## Example pedigree ped <- data.frame( id=1:10, fid=c(0, 0, 0, 1, 1, 1, 3, 3, 3, 5), mid=c(0, 0, 0, 2, 0, 2, 2, 2, 5, 0), birth_dt=c(0, 0, 1, 2, 3, 3, 3, 4, 4, 5) + 2000) ## Set base population as those individuals that were born after year 2002 pedSetBase(x=ped, keep=ped$birth_dt > 2002, unknown=0)
A function to plot summary of partitioned breeding values.
## S3 method for class 'summaryAlphaPart' plot(x, by, sortValue, sortValueFUN, sortValueDec, addSum, paths, xlab, ylab, xlim, ylim, color, lineSize, lineType, lineTypeList, useDirectLabels, method, labelPath, ...)
## S3 method for class 'summaryAlphaPart' plot(x, by, sortValue, sortValueFUN, sortValueDec, addSum, paths, xlab, ylab, xlim, ylim, color, lineSize, lineType, lineTypeList, useDirectLabels, method, labelPath, ...)
x |
summaryAlphaPart, object from the |
by |
Character, the name of a column by which summary function
FUN should be applied; if |
sortValue |
Logical, affect legend attributes via sort of paths
according to |
sortValueFUN |
Function, that produces single value for one
vector, say |
sortValueDec |
Logical, sort decreasing. |
addSum |
Logical, plot the overall trend. |
paths |
Character or list or characters, name of paths to plot;
if |
xlab |
Character, x-axis label. |
ylab |
Character, y-axis label; can be a vector of several
labels if there are more traits in |
xlim |
Numeric, a vector of two values with x-axis limits; use a list of vectors for more traits. |
ylim |
Numeric, a vector of two values with y-axis limits; use a list of vectors for more traits. |
color |
Character, color names; by default a set of 54 colors is predefined from the RColorBrewer package; in addition a black colour is attached at the begining for the overall trend; if there are more paths than colors then recycling occours. |
lineSize |
Numeric, line width. |
lineType |
Numeric, line type (recycled); can be used only if lineTypeList=NULL. |
lineTypeList |
List, named list of numeric values that help to
point out a set of paths (distinguished with line type) within
upper level of paths (distinguished by, color), e.g.,
lineTypeList=list("-1"=1, "-2"=2, def=1) will lead to use of line
2, for paths having "-2" at the end of path name, while line type 1
(default) will, be used for other paths; specification of this
argument also causes recycling of colors for the upper level of
paths; if NULL all lines have a standard line type, otherwise
|
useDirectLabels |
Logical, use directlabels package for legend. |
method |
List, method for direct.label. |
labelPath |
Character, legend title; used only if
|
... |
Arguments passed to other functions (not used at the moment). |
Information in summaries of partitions of breeding values can be overhelming due to a large volume of numbers. Plot method can be used to visualise this data in eye pleasing way using ggplot2 graphics.
A list of ggplot objects that can be further modified or
displayed. For each trait in x
there is one plot
visualising summarized values.
## Partition additive genetic values by country (res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2"))) ## Summarize population by generation (=trend) (ret <- summary(res, by="gen")) ## Plot the partitions p <- plot(ret, ylab=c("bv for trait 1", "bv for trait 2"), xlab="Generation") print(p[[1]]$abs) print(p[[2]]$abs) print(p) ## Partition additive genetic values by country and sex AlphaPart.ped$country.gender <- with(AlphaPart.ped, paste(country, gender, sep="-")) (res <- AlphaPart(x=AlphaPart.ped, colPath="country.gender", colBV=c("bv1", "bv2"))) ## Summarize population by generation (=trend) (ret <- summary(res, by="gen")) ## Plot the partitions p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation") print(p) p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation", lineTypeList=list("-1"=1, "-2"=2, def=3)) print(p) p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation", lineTypeList=list("-1"=1, "-2"=2, def=3), useGgplot2=FALSE, useDirectLabels = FALSE) print(p) ## Plot control (color and type of lines + limits) p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation", useGgplot2=TRUE, color=c("green", "gray"), lineType=c(2, 3), sortValue=FALSE, lineSize=4, xlim=c(-1, 7)) print(p)
## Partition additive genetic values by country (res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2"))) ## Summarize population by generation (=trend) (ret <- summary(res, by="gen")) ## Plot the partitions p <- plot(ret, ylab=c("bv for trait 1", "bv for trait 2"), xlab="Generation") print(p[[1]]$abs) print(p[[2]]$abs) print(p) ## Partition additive genetic values by country and sex AlphaPart.ped$country.gender <- with(AlphaPart.ped, paste(country, gender, sep="-")) (res <- AlphaPart(x=AlphaPart.ped, colPath="country.gender", colBV=c("bv1", "bv2"))) ## Summarize population by generation (=trend) (ret <- summary(res, by="gen")) ## Plot the partitions p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation") print(p) p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation", lineTypeList=list("-1"=1, "-2"=2, def=3)) print(p) p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation", lineTypeList=list("-1"=1, "-2"=2, def=3), useGgplot2=FALSE, useDirectLabels = FALSE) print(p) ## Plot control (color and type of lines + limits) p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation", useGgplot2=TRUE, color=c("green", "gray"), lineType=c(2, 3), sortValue=FALSE, lineSize=4, xlim=c(-1, 7)) print(p)
Partitioning of breeding values if often performed on
quite large datasets, which quickly fills in the whole
screen. Print method therefore prints out paths, number of
individuals and the first and the last few lines for each trait to
quickly see what kind of data is in x
.
## S3 method for class 'AlphaPart' print(x, n, ...)
## S3 method for class 'AlphaPart' print(x, n, ...)
x |
AlphaPart, output object from
|
n |
Integer, number of the first and last rows in |
... |
Arguments passed to |
## Small pedigree with additive genetic (=breeding) values ped <- data.frame( id=c( 1, 2, 3, 4, 5, 6), fid=c( 0, 0, 2, 0, 4, 0), mid=c( 0, 0, 1, 0, 3, 3), loc=c("A", "B", "A", "B", "A", "A"), gen=c( 1, 1, 2, 2, 3, 3), trt1=c(100, 120, 115, 130, 125, 125), trt2=c(100, 110, 105, 100, 85, 110)) ## Partition additive genetic values tmp <- AlphaPart(x=ped, colBV=c("trt1", "trt2")) print(tmp) ## Summarize by generation (genetic mean) summary(tmp, by="gen") ## Summarize by generation (genetic variance) summary(tmp, by="gen", FUN = var) ## There are also two demos demo(topic="AlphaPart_deterministic", package="AlphaPart", ask=interactive()) demo(topic="AlphaPart_stochastic", package="AlphaPart", ask=interactive())
## Small pedigree with additive genetic (=breeding) values ped <- data.frame( id=c( 1, 2, 3, 4, 5, 6), fid=c( 0, 0, 2, 0, 4, 0), mid=c( 0, 0, 1, 0, 3, 3), loc=c("A", "B", "A", "B", "A", "A"), gen=c( 1, 1, 2, 2, 3, 3), trt1=c(100, 120, 115, 130, 125, 125), trt2=c(100, 110, 105, 100, 85, 110)) ## Partition additive genetic values tmp <- AlphaPart(x=ped, colBV=c("trt1", "trt2")) print(tmp) ## Summarize by generation (genetic mean) summary(tmp, by="gen") ## Summarize by generation (genetic variance) summary(tmp, by="gen", FUN = var) ## There are also two demos demo(topic="AlphaPart_deterministic", package="AlphaPart", ask=interactive()) demo(topic="AlphaPart_stochastic", package="AlphaPart", ask=interactive())
plotSummaryAlphaPart
Plot output object from
plot.summaryAlphaPart
.
## S3 method for class 'plotSummaryAlphaPart' print(x, ask, ...)
## S3 method for class 'plotSummaryAlphaPart' print(x, ask, ...)
x |
plotSummaryAlphaPart, output object from
|
ask |
Logical, ask before printing another plot? |
... |
Arguments passed to other functions (not used at the moment). |
## Partition additive genetic values (res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2"))) ## Summarize population by generation (=trend) (ret <- summary(res, by="gen")) ## Plot the partitions p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation") print(p[[1]]) print(p[[2]]) #print(p)
## Partition additive genetic values (res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2"))) ## Summarize population by generation (=trend) (ret <- summary(res, by="gen")) ## Plot the partitions p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation") print(p[[1]]) print(p[[2]]) #print(p)
Print method for objects of the class
summaryAlphaPart
(result of summary(AlphaPart(...))
).
## S3 method for class 'summaryAlphaPart' print(x, ...)
## S3 method for class 'summaryAlphaPart' print(x, ...)
x |
summaryAlphaPart, output object from
|
... |
Arguments passed to other functions (not used at the moment). |
## --- Partition additive genetic values by loc --- res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2")) ## Summarize whole population ret <- summary(res) ## Summarize population by generation (=trend) ret <- summary(res, by="gen") ## Summarize population by generation (=trend) but only for domestic location ret <- summary(res, by="gen", subset=res[[1]]$country == "domestic") ## --- Partition additive genetic values by loc and gender --- AlphaPart.ped$country.gender <- with(AlphaPart.ped, paste(country, gender, sep="-")) res <- AlphaPart(x=AlphaPart.ped, colPath="country.gender", colBV=c("bv1", "bv2")) ## Summarize population by generation (=trend) ret <- summary(res, by="gen") ## Summarize population by generation (=trend) but only for domestic location ret <- summary(res, by="gen", subset=res[[1]]$country == "domestic")
## --- Partition additive genetic values by loc --- res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2")) ## Summarize whole population ret <- summary(res) ## Summarize population by generation (=trend) ret <- summary(res, by="gen") ## Summarize population by generation (=trend) but only for domestic location ret <- summary(res, by="gen", subset=res[[1]]$country == "domestic") ## --- Partition additive genetic values by loc and gender --- AlphaPart.ped$country.gender <- with(AlphaPart.ped, paste(country, gender, sep="-")) res <- AlphaPart(x=AlphaPart.ped, colPath="country.gender", colBV=c("bv1", "bv2")) ## Summarize population by generation (=trend) ret <- summary(res, by="gen") ## Summarize population by generation (=trend) but only for domestic location ret <- summary(res, by="gen", subset=res[[1]]$country == "domestic")
AlphaPart
Save plot method for AlphaPart
savePlot(...)
savePlot(...)
... |
Arguments passed to |
Beside the side effect of saving plots to disk, filenames are printed on screen during the process and at the end invisibly returned.
savePlot
from the grDevices package
works for current page on graphical device. This is an attempt to
make this function generic so that one can define savePlot
methods for particular needs.Save plot objects of class
plotSummaryAlphaPart
on the disk for permanent storage.
## S3 method for class 'plotSummaryAlphaPart' savePlot(x, filename, type, device, pre.hook, traitsAsDir, ...) ## Default S3 method: savePlot(...)
## S3 method for class 'plotSummaryAlphaPart' savePlot(x, filename, type, device, pre.hook, traitsAsDir, ...) ## Default S3 method: savePlot(...)
x |
Object on which to chose savePLot method. |
filename |
Character, filename to save to. |
type |
Character, file/device type. |
device |
Device, the device to save from. |
pre.hook |
Function, call some code before calling print method for plots (see examples). |
traitsAsDir |
Logical, should plots be saved within trait folders; the construction is
|
... |
Arguments passed to |
Beside the side effect of saving plots to disk, filenames are printed on screen during the process and at the end invisibly returned.
savePlot
help page on the default savePlot
method in the grDevices package; savePlot.plotSummaryAlphaPart
help page on the method for the objects of plotSummaryAlphaPart
class; and
plot.summaryAlphaPart
for ploting results of summaryAlphaPart object.
## Partition additive genetic values res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2")) ## Summarize population by generation (=trend) ret <- summary(res, by="gen") ## Plot the partitions p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation") ## Save the plots tmp <- savePlot(x = p, filename="test", type="png") ## Remove the files unlink(tmp)
## Partition additive genetic values res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2")) ## Summarize population by generation (=trend) ret <- summary(res, by="gen") ## Plot the partitions p <- plot(ret, ylab=c("BV for trait 1", "BV for trait 2"), xlab="Generation") ## Save the plots tmp <- savePlot(x = p, filename="test", type="png") ## Remove the files unlink(tmp)
Breedng values of individuals are often summarized,
either by year of birth or some other classification. Function
summary.AlphaPart
provides a way to ease the computation of
such summaries on partitions of breeding values.
## S3 method for class 'AlphaPart' summary(object, by, FUN, labelSum, subset, sums, cov, ...)
## S3 method for class 'AlphaPart' summary(object, by, FUN, labelSum, subset, sums, cov, ...)
object |
AlphaPart, output object from
|
by |
Character, the name of a column by which summary function
FUN should be applied; if |
FUN |
Function, which function should be used in summary; function should return single value per each level of by. |
labelSum |
Character, label used for the overall breeding value. |
subset |
Logical, perform summary only on a subset of
|
sums |
Logical, link between |
cov |
Logical, if FALSE returns |
... |
Arguments passed to other functions (not used at the moment). |
An object of class summaryAlphaPart
, which is a list
of data frames with summary statistics on breeding value
partitions. For each trait there a dataframe holds summary for the
"whole/original" breeding value and its partitions. In addition
another list is added (named info
) with the following
components holdinfg meta info:
path
column name holding path information
nP
number of paths
lP
path labels
nT
number of traits
lT
trait labels
by
column name of variable by which summary was performed
warn
potential warning messages associated with this object
labelSum
column name of summary for "whole/original" breeding values
There is a handy plot method (plot.summaryAlphaPart
) for output.
AlphaPart
for partitioning breeding
values, plot.summaryAlphaPart
for plotting
output of summary method
## --- Partition additive genetic values by loc --- res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2")) ## Summarize whole population ret <- summary(res) ## Summarize population by generation (=trend) ret <- summary(res, by="gen") ## Summarize population by generation (=trend) but only for domestic location ret <- summary(res, by="gen", subset=res[[1]]$country == "domestic") ## --- Partition additive genetic values by loc and gender --- AlphaPart.ped$country.gender <- with(AlphaPart.ped, paste(country, gender, sep="-")) res <- AlphaPart(x=AlphaPart.ped, colPath="country.gender", colBV=c("bv1", "bv2")) ## Summarize population by generation (=trend) ret <- summary(res, by="gen") ## Summarize population by generation (=trend) but only for domestic location ret <- summary(res, by="gen", subset=res[[1]]$country == "domestic")
## --- Partition additive genetic values by loc --- res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2")) ## Summarize whole population ret <- summary(res) ## Summarize population by generation (=trend) ret <- summary(res, by="gen") ## Summarize population by generation (=trend) but only for domestic location ret <- summary(res, by="gen", subset=res[[1]]$country == "domestic") ## --- Partition additive genetic values by loc and gender --- AlphaPart.ped$country.gender <- with(AlphaPart.ped, paste(country, gender, sep="-")) res <- AlphaPart(x=AlphaPart.ped, colPath="country.gender", colBV=c("bv1", "bv2")) ## Summarize population by generation (=trend) ret <- summary(res, by="gen") ## Summarize population by generation (=trend) but only for domestic location ret <- summary(res, by="gen", subset=res[[1]]$country == "domestic")
Save summaries of partitioned breeding values to CSV files on disk for further analyses of processing with other software or just for saving (backing up) results.
write.csv(...) ## Default S3 method: write.csv(...) ## S3 method for class 'AlphaPart' write.csv(x, file, traitsAsDir = FALSE, csv2 = TRUE, row.names = FALSE, ...) ## S3 method for class 'summaryAlphaPart' write.csv(x, file, traitsAsDir = FALSE, csv2 = TRUE, row.names = FALSE, ...)
write.csv(...) ## Default S3 method: write.csv(...) ## S3 method for class 'AlphaPart' write.csv(x, file, traitsAsDir = FALSE, csv2 = TRUE, row.names = FALSE, ...) ## S3 method for class 'summaryAlphaPart' write.csv(x, file, traitsAsDir = FALSE, csv2 = TRUE, row.names = FALSE, ...)
... |
Other options passed to |
x |
AlphaPart, object returned from |
file |
Character, file name with or without .csv extension, e.g., both "file" and "file.csv" are valid. |
traitsAsDir |
Logical, should results be saved within trait folders;
the construction is |
csv2 |
Logical, export using |
row.names |
Logical, export row names as well? |
Function write.csv
from the utils package works
when exported object is a data.frame
or a
matrix
. This is an attempt to make this function generic
so that one can define write.csv
methods for other objects.
It contains:
write.csv
- see write.csv
for details.
write.csv.AlphaPart
- for each trait (list component in x
) a file
is saved on disk with name "AlphaPart_trait.csv", where the file will hold
original data and breeding value partitions. With traitsAsDir=TRUE
files are saved as "trait/file_trait.csv". File names are printed on screen
during the process of export and at the end invisibly returned.
write.csv.summaryAlphaPart
- for each trait (list component in x
)
a file partitions named "file_trait.csv" is saved on disk. With
traitsAsDir=TRUE
files are saved as "trait/file_trait_*.csv". File
names are printed on screen during the process of export and at the end
invisibly returned.
default
: Default write.csv
method.
AlphaPart
: Save partitioned breeding values to CSV files on disk on disk for further
analyses or processing with other software or just for saving (backing up)
results.
summaryAlphaPart
: Save summaries of partitioned breeding values to CSV files on disk for further
analyses of processing with other software or just for saving (backing up)
results.
write.csv
help page on the default write.csv
and write.csv2
methods in the utils package;
summary.AlphaPart
and AlphaPart
help pages on the objects of summaryAlphaPart
and AlphaPart
classes.
## Partition additive genetic values res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2")) ## Write summary on the disk and collect saved file names fileName <- file.path(tempdir(), "AlphaPart") ret <- write.csv(x=res, file=fileName) print(ret) file.show(ret[1]) ## Clean up files <- dir(path=tempdir(), pattern="AlphaPart*") unlink(x=files)
## Partition additive genetic values res <- AlphaPart(x=AlphaPart.ped, colPath="country", colBV=c("bv1", "bv2")) ## Write summary on the disk and collect saved file names fileName <- file.path(tempdir(), "AlphaPart") ret <- write.csv(x=res, file=fileName) print(ret) file.show(ret[1]) ## Clean up files <- dir(path=tempdir(), pattern="AlphaPart*") unlink(x=files)