Skip to content

Commit

Permalink
Fixed bug in detectSerieOut causing all slopes to be non-outliers
Browse files Browse the repository at this point in the history
  • Loading branch information
BartJanvanRossum committed Jul 30, 2021
1 parent 5d7c932 commit b0bebc2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions R/detectSerieOut.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,19 @@ detectSerieOut <- function(corrDat,
if (!is.null(dim(plantDat))) {
## if there are plants, estimate the slopes.
## Convert matrix to data.frame for lm.
plantDat <- as.data.frame(plantDat)
plantDatLm <- as.data.frame(plantDat)
## Construct empty matrix for storing results.
slopemat <- matrix(nrow = ncol(plantDat), ncol = ncol(plantDat),
dimnames = list(colnames(plantDat), colnames(plantDat)))
slopemat <- matrix(nrow = ncol(plantDatLm), ncol = ncol(plantDatLm),
dimnames = list(colnames(plantDatLm),
colnames(plantDatLm)))
## Compute slope per pair of plots.
slopemat[lower.tri(slopemat)] <-
combn(x = colnames(plantDat), m = 2, FUN = function(plants) {
combn(x = colnames(plantDatLm), m = 2, FUN = function(plants) {
## Wrap plants in ` to allow for irregular names in formula.
plants <- paste0("`", plants, "`")
## Fit linear model and extract slope.
modForm <- formula(paste(plants, collapse = "~"))
slope <- abs(coef(lm(modForm, data = plantDat))[2])
slope <- abs(coef(lm(modForm, data = plantDatLm))[2])
if (slope > 1) slope <- 1 / slope
return(slope)
}, simplify = TRUE)
Expand Down

0 comments on commit b0bebc2

Please sign in to comment.