Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed remaining Notes in PEcAn.MA #2973

Merged
merged 13 commits into from
Aug 1, 2022
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ We are slowly change the license from NCSA opensource to BSD-3 to help with publ
- rstudio was not working behind traefik.
- plots now work in docker containers
- when specifying diferent rstudio user, dev setup would mount pecan folder in wrong path.
- Code cleanup in PEcAn.MA to protect against global namespace pollution (#2965, #2973; @nanu1605)
- Fixed vignettes and cleaned up internal warnings in PEcAn.DB (#2966, #2971; @nanu1605).

### Changed

Expand Down
1 change: 0 additions & 1 deletion modules/meta.analysis/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Description: The Predictive Ecosystem Carbon Analyzer (PEcAn) is a scientific
the functions used in the Bayesian meta-analysis of trait data.
Imports:
coda (>= 0.18),
XML,
lattice,
PEcAn.utils,
PEcAn.DB,
Expand Down
26 changes: 12 additions & 14 deletions modules/meta.analysis/R/jagify.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
##' @title Prepare trait data for JAGS meta-analysis
##' @param result input trait data
##' @param use_ghs (Logical) If `FALSE`, exclude all greenhouse data. If `TRUE`, use all data, including greenhouse data.
##' @export
##' @return result transformed to meet requirements of PEcAn meta-analysis model
##' @export
##' @author David LeBauer
jagify <- function(result, use_ghs = TRUE) {


## Create new column "trt_id" from column 'name'. Remove NAs. Assign treatments.
## Finally, summarize the results by calculating summary statistics from experimental replicates
r <- result[!is.na(result$mean), ]
Expand All @@ -33,18 +33,16 @@ jagify <- function(result, use_ghs = TRUE) {

r <- PEcAn.DB::assign.treatments(r)
r <- PEcAn.utils::summarize.result(r)
r <- subset(transform(r,
stat = as.numeric(stat),
n = as.numeric(n),
site_id = as.integer(factor(site_id, unique(site_id))),
greenhouse = as.integer(factor(greenhouse, unique(greenhouse))),
mean = mean,
citation_id = citation_id,
ghs = greenhouse,
site = site_id,
trt_name = name),
select = c("stat", "n", "site_id", "trt_id", "mean", "citation_id", "greenhouse",
"ghs", "treatment_id", "site", "trt_name")) # original versions of greenhouse, treatment_id, site_id, and name
r$stat <- as.numeric(r$stat)
r$n <- as.numeric(r$n)
r$site_id <- as.integer(factor(r$site_id, unique(r$site_id)))
r$greenhouse <- as.integer(factor(r$greenhouse, unique(r$greenhouse)))
r$ghs <- r$greenhouse
r$site <- r$site_id
r$trt_name <- r$name

r <- r[, c("stat", "n", "site_id", "trt_id", "mean", "citation_id", "greenhouse",
"ghs", "treatment_id", "site", "trt_name")]

#order by site_id and trt_id, but make sure "control" is the first trt of each site
uniq <- setdiff(unique(r$trt_id), "control")
Expand Down