Skip to content

Commit a221fbf

Browse files
committed
Merge branch 'basic-multitrait'
2 parents 06d4845 + 9082cec commit a221fbf

File tree

160 files changed

+4185
-2005
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+4185
-2005
lines changed

DESCRIPTION

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: breedR
22
Type: Package
33
Title: Statistical Methods for Forest Genetic Resources Analysts
4-
Version: 0.11-5
4+
Version: 0.12
55
Encoding: UTF-8
66
Authors@R: c(person("Facundo", "Muñoz",
77
role=c("aut", "cre"),
@@ -24,12 +24,16 @@ Depends:
2424
sp
2525
Imports:
2626
ggplot2,
27+
graphics,
28+
grDevices,
2729
Matrix (>= 1.2.0),
2830
methods,
2931
nlme,
3032
pedigree,
3133
pedigreemm,
32-
splines
34+
splines,
35+
stats,
36+
utils
3337
Suggests:
3438
doParallel,
3539
GGally,
@@ -52,4 +56,4 @@ URL: https://github.com/famuvie/breedR
5256
BugReports: https://github.com/famuvie/breedR/issues
5357
Additional_repositories: http://www.math.ntnu.no/inla/R/testing
5458
VignetteBuilder: knitr
55-
RoxygenNote: 5.0.1
59+
RoxygenNote: 6.0.1

NAMESPACE

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ S3method(all,equal.remlf90)
77
S3method(as.data.frame,metagene)
88
S3method(as.data.frame,pedigree)
99
S3method(coef,remlf90)
10-
S3method(effect_size,breedr_effect)
11-
S3method(effect_size,effect_group)
10+
S3method(dim,breedr_effect)
11+
S3method(dim,effect_group)
1212
S3method(effect_type,breedr_effect)
1313
S3method(effect_type,effect_group)
1414
S3method(extractAIC,remlf90)
@@ -38,8 +38,9 @@ S3method(nobs,remlf90)
3838
S3method(plot,metagene)
3939
S3method(plot,ranef.breedR)
4040
S3method(plot,remlf90)
41+
S3method(print,breedR.q)
4142
S3method(print,breedR.variogram)
42-
S3method(print,ranef.breedR)
43+
S3method(print,breedR_estimates)
4344
S3method(print,remlf90)
4445
S3method(print,summary.metagene)
4546
S3method(print,summary.remlf90)
@@ -59,6 +60,7 @@ S3method(renderpf90,permanent_environmental_competition)
5960
S3method(renderpf90,splines)
6061
S3method(residuals,remlf90)
6162
S3method(sim.spatial,metagene)
63+
S3method(summary,breedR.q)
6264
S3method(summary,metagene)
6365
S3method(summary,remlf90)
6466
S3method(vcov,random)
@@ -96,11 +98,34 @@ exportMethods("coordinates<-")
9698
exportMethods(coordinates)
9799
import(Matrix)
98100
import(ggplot2)
101+
import(sp)
102+
importFrom(grDevices,colorRampPalette)
103+
importFrom(graphics,par)
104+
importFrom(graphics,plot.new)
105+
importFrom(methods,as)
99106
importFrom(methods,setMethod)
100107
importFrom(methods,setOldClass)
101108
importFrom(nlme,fixef)
102109
importFrom(nlme,ranef)
110+
importFrom(stats,AIC)
111+
importFrom(stats,BIC)
112+
importFrom(stats,aggregate)
113+
importFrom(stats,dist)
114+
importFrom(stats,fitted)
115+
importFrom(stats,logLik)
116+
importFrom(stats,median)
103117
importFrom(stats,model.matrix)
118+
importFrom(stats,model.response)
104119
importFrom(stats,nobs)
120+
importFrom(stats,printCoefmat)
121+
importFrom(stats,quantile)
122+
importFrom(stats,residuals)
123+
importFrom(stats,runif)
124+
importFrom(stats,sd)
125+
importFrom(stats,terms)
126+
importFrom(stats,var)
105127
importFrom(stats,vcov)
128+
importFrom(stats,xtabs)
129+
importFrom(utils,read.table)
130+
importFrom(utils,str)
106131
importMethodsFrom(Matrix,coerce)

NEWS

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
* Interface for using **weights** for residual variance
1+
breedR 0.12
2+
===========
3+
4+
* Basic multitrait interface (#30)
5+
6+
* Default values for initial (co)variances are now a function of empirical
7+
(co)variances
8+
9+
* Interface for using **weights** for residual variance (#77)
210

311
* Vignette: Heterogeneous variances
412

R/AllGeneric.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ get_param <- function(x) UseMethod('get_param')
2323
#' @param x object to be \emph{translated} to progsf90
2424
effect_type <- function(x) UseMethod('effect_type')
2525

26-
#' Size of a (group of) effect(s)
27-
#'
28-
#' Returns 0 for a \code{fixed} effect, and the size of a \code{effect_group}
29-
#' @param x element of the breedr_modelframe
30-
effect_size <- function(x) UseMethod('effect_size')
31-
3226
#' Render a progsf90 effect
3327
#'
3428
#' Translates breedR effects into progsf90 parameters and data.

R/ar.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,6 @@ build.AR.rho.grid <- function(rho) {
115115
build.AR1d <- function(n, x) {
116116
temp <- diag(c(1, rep(1 + x^2, n-2), 1))
117117
subdiag <- rbind(0, cbind(diag(-x, n-1), 0))
118-
return(as(Matrix::Matrix(temp + subdiag + t(subdiag), sparse = TRUE), 'dgTMatrix'))
118+
ans <- Matrix::Matrix(temp + subdiag + t(subdiag), sparse = TRUE)
119+
return(methods::as(ans, 'dgTMatrix'))
119120
}

R/binaries.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ check_progsf90 <- function(path = breedR.getOption('breedR.bin'),
3030
if (!check && !quiet) {
3131
message('Binary dependencies missing.',
3232
'\nWould you like to install them?\t')
33-
if (menu(c("Yes", "No")) == 1) {
33+
if (utils::menu(c("Yes", "No")) == 1) {
3434
install_progsf90(dest = path, platform = platform)
3535
check <- check_progsf90(path, platform, quiet)
3636
}
@@ -100,7 +100,7 @@ retrieve_bin <- function(f, url, dest) {
100100

101101
} else {
102102
out <- tryCatch(
103-
download.file(
103+
utils::download.file(
104104
url = file.path(url, f),
105105
destfile = destf,
106106
mode = 'wb',
@@ -154,12 +154,15 @@ progsf90_files <- function(os = breedR.os.type(),
154154
}
155155

156156

157-
## Check whether there is internet connection
157+
# Check whether there is internet connection
158158
breedR_online <- function() {
159159
tf <- tempfile()
160160
!inherits(
161161
suppressWarnings(
162-
try(download.file('http://famuvie.github.io/breedR/', tf, quiet = TRUE))
162+
try(utils::download.file(
163+
'http://famuvie.github.io/breedR/', tf, quiet = TRUE
164+
),
165+
silent = TRUE)
163166
),
164167
'try-error'
165168
)

R/breedr_effect.R

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Constructor for a generic effect
1+
#' Constructor for a generic breedR effect
22
#'
33
#' The breedr_effect-class is virtual. No object should be directly created with
44
#' this constructor. This constructor is to be called from within non-virtual
@@ -24,6 +24,19 @@ breedr_effect <- function(incidence) {
2424
return(ans)
2525
}
2626

27+
28+
# @describeIn breedr_effect Dimension of a \code{breedr_effect}: 0 for a fixed
29+
# effect, 1 for a random effect
30+
#' @rdname breedr_effect
31+
#' @param x A \code{breedr_effect}.
32+
#' @export
33+
dim.breedr_effect <- function(x) {
34+
siz <- ifelse(inherits(x, 'random'), 1, 0)
35+
return(c(size = siz, ntraits = NA))
36+
}
37+
38+
39+
2740
#' Constructor for a group of effects
2841
#'
2942
#' Builds an \code{effect_group} from a list of \code{breer_effect} elements.
@@ -32,28 +45,28 @@ breedr_effect <- function(incidence) {
3245
#' object. In the future, the initial covariance matrix will be a matter of the
3346
#' inference engine, not inherent to the model.
3447
#'
48+
#' The `ntraits` is used to check the dimension of the initial variance matrix.
49+
#'
3550
#' @param x list of breedr_effect elements
3651
#' @param cov.ini initial covariance matrix for the estimation algorithm
52+
#' @param ntraits number of traits in the model
3753
#'
3854
#' @return A list of \code{breedr_effect} elements.
39-
effect_group <- function(x, cov.ini) {
55+
effect_group <- function(x, cov.ini, ntraits) {
4056

4157
## Checks ==========================================
4258
## x is a list and cov.ini a SPD matrix
4359
stopifnot(is.list(x))
4460
cov.ini <- as.matrix(cov.ini)
45-
stopifnot(is.numeric(cov.ini))
46-
stopifnot(isSymmetric.matrix(cov.ini, check.attributes = FALSE))
47-
ev <- eigen(cov.ini, symmetric = TRUE, only.values = TRUE)$values
48-
stopifnot(all(ev > 0))
61+
validate_variance(cov.ini)
4962

5063
## all elements are breedr_effects
5164
if (!all(sapply(x, inherits, 'breedr_effect')))
5265
stop('All of the effects must be of class breedr_effect.')
5366

5467
## cov.ini is square and of size equal to number of effects
5568
nx <- length(x)
56-
if (!all(dim(cov.ini) == nx))
69+
if (!all(dim(cov.ini) == nx*ntraits))
5770
stop('Dimension of the initial covariance matrix do not conform with
5871
number of effects in the group.')
5972

@@ -63,10 +76,12 @@ effect_group <- function(x, cov.ini) {
6376
return(ans)
6477
}
6578

66-
#' Size of a group of effects
67-
#'
68-
#' @param x object of class \code{effect_group}
69-
group_size <- function(x) {
70-
stopifnot(inherits(x, 'effect_group'))
71-
length(x$effects)
79+
# @describeIn effect_group Returns the dimension of an \code{effect_group}
80+
# factored by its size and number of traits
81+
#' @rdname effect_group
82+
#' @export
83+
dim.effect_group <- function(x) {
84+
siz <- length(x$effects)
85+
ntr <- dim(as.matrix(x$cov.ini))[1] / siz
86+
return(c(size = siz, ntraits = ntr))
7287
}

0 commit comments

Comments
 (0)