Skip to content

Commit

Permalink
updated test-coverage yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
abigailkeller committed Apr 16, 2024
1 parent 4e7a6a4 commit 2c40443
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 102 deletions.
202 changes: 101 additions & 101 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,104 +1,3 @@
)
# constants
nsite <- 20
nobs_count <- 100
nobs_pcr <- 8
# params
mu <- rlnorm(nsite,meanlog=log(1),sdlog=1)
alpha <- c(0.5, 0.1, -0.4)
log_p10 <- -4.5
phi <- 1.2
# count
count <- matrix(NA,nrow=nsite,ncol=nobs_count)
for(i in 1:nsite){
count[i,] <- rnbinom(n=nobs_count,mu=mu[i],size=phi)
}
# site-level covariates
mat_site <- matrix(NA,nrow=nsite,ncol=length(alpha))
mat_site[,1] <- 1 # intercept
for(i in 2:length(alpha)){
mat_site[,i] <- rnorm(nsite,0,1)
}
colnames(mat_site) <- c('int','var_a','var_b')
# p11 (probability of true positive eDNA detection) and p (probability
# of eDNA detection)
p11 <- rep(NA,nsite)
p <- rep(NA,nsite)
for (i in 1:nsite){
p11[i] <- mu[i] / (mu[i] + exp(sum(mat_site[i,]*alpha)))
p[i] <- min(p11[i] + exp(log_p10),1)
}
# qPCR.N (# qPCR observations)
qPCR.N <- matrix(NA,nrow=nsite,ncol=nobs_pcr)
for(i in 1:nsite){
qPCR.N[i,] <- rep(3,nobs_pcr)
}
# qPCR.K (# positive qPCR detections)
qPCR.K <- matrix(NA,nrow=nsite,ncol=nobs_pcr)
for (i in 1:nsite){
qPCR.K[i,] <- rbinom(nobs_pcr, qPCR.N[i,], rep(p[i],nobs_pcr))
}
# collect data
data <- list(
qPCR.N = qPCR.N,
qPCR.K = qPCR.K,
count = count,
site.cov = mat_site
)
# initial values
inits <- list()
inits[[1]] <- list(
mu = mu,
p10 = log_p10,
alpha = alpha,
phi = phi
)
names(inits[[1]]) <- c('mu','p10','alpha',
'phi')
# run model
fit <- jointModel(data=data, family = 'negbin',
cov=c('var_a','var_b'),
n.chain=1, multicore=FALSE, seed = 10,
initial_values=inits)
# constants
nsite <- 20
nobs_count <- 100
nobs_pcr <- 8
# params
mu <- rlnorm(nsite,meanlog=log(1),sdlog=1)
alpha <- c(0.5, 0.1, -0.4)
log_p10 <- -4.5
phi <- 10
# count
count <- matrix(NA,nrow=nsite,ncol=nobs_count)
for(i in 1:nsite){
count[i,] <- rnbinom(n=nobs_count,mu=mu[i],size=phi)
}
# site-level covariates
mat_site <- matrix(NA,nrow=nsite,ncol=length(alpha))
mat_site[,1] <- 1 # intercept
for(i in 2:length(alpha)){
mat_site[,i] <- rnorm(nsite,0,1)
}
colnames(mat_site) <- c('int','var_a','var_b')
# p11 (probability of true positive eDNA detection) and p (probability
# of eDNA detection)
p11 <- rep(NA,nsite)
p <- rep(NA,nsite)
for (i in 1:nsite){
p11[i] <- mu[i] / (mu[i] + exp(sum(mat_site[i,]*alpha)))
p[i] <- min(p11[i] + exp(log_p10),1)
}
# qPCR.N (# qPCR observations)
qPCR.N <- matrix(NA,nrow=nsite,ncol=nobs_pcr)
for(i in 1:nsite){
qPCR.N[i,] <- rep(3,nobs_pcr)
}
# qPCR.K (# positive qPCR detections)
qPCR.K <- matrix(NA,nrow=nsite,ncol=nobs_pcr)
for (i in 1:nsite){
qPCR.K[i,] <- rbinom(nobs_pcr, qPCR.N[i,], rep(p[i],nobs_pcr))
}
# collect data
data <- list(
qPCR.N = qPCR.N,
Expand Down Expand Up @@ -510,3 +409,104 @@ initial_values=inits)
output_params <- rownames(as.data.frame(jointSummarize(fit$model)))
# test expectation
expect_true(all(!c('p10','q','phi') %in% output_params))
roxygen2::roxygenise()
library(covr)
package_coverage()
getwd()
cov <- package_coverage("/home/abby/eDNAjoint")
posterior <- read.csv('../eDNA_presentation/Joint_posterior.csv')
library(tidyverse)
ggplot()+
geom_density(aes(x=posterior$p10))
ggplot()+
geom_density(aes(x=exp(posterior$p10)))
rounded <- round(posterior$p10,7)
head(roudned)
head(rounded)
table(rounded)
rounded <- round(posterior$p10,3)
table(rounded)
names(table(rounded))
names <- as.numeric(names(table(rounded)))
names
values <- as.vector(tables(rounded))
values <- as.vector(table(rounded))
ggplot()+
geom_line(aes(x=names,y=values))
ggplot()+
geom_line(aes(x=names,y=exp(values)))
rounded <- round(posterior$p10,7)
names <- as.numeric(names(table(rounded)))
values <- as.vector(table(rounded))
ggplot()+
geom_line(aes(x=names,y=exp(values)))
ggplot()+
geom_line(aes(x=exp(names),y=values))
rounded <- round(posterior$p10,3)
names <- as.numeric(names(table(rounded)))
values <- as.vector(table(rounded))
ggplot()+
geom_line(aes(x=exp(names),y=values))
ggplot()+
geom_smooth(aes(x=exp(names),y=values))
ggplot()+
geom_density(aes(x=exp(posterior$p10)))
ggplot()+
geom_density(aes(x=exp(posterior$p10)))+
labs(x='probability of false positive eDNA detection',
y='density')+
theme_minimal()
ggplot()+
geom_density(aes(x=exp(posterior$p10)),linewidth=1)+
labs(x='probability of false positive eDNA detection',
y='density')+
theme_minimal()
ggplot()+
geom_density(aes(x=exp(posterior$p10)),linewidth=1)+
labs(x='probability of false positive eDNA detection',
y='density')+
theme_minimal()+
theme(text=element_text(size=12))
p10_plot <- ggplot()+
geom_density(aes(x=exp(posterior$p10)),linewidth=1)+
labs(x='probability of false positive eDNA detection',
y='density')+
theme_minimal()+
theme(text=element_text(size=12))
ggsave('../eDNA_presentation/p10_plot.png',p10_plot,dpi=400)
raa_plot <- ggplot()+
geom_density(aes(x=posterior$mu_crab.15),linewidth=1)+
labs(x='EGC density (crabs/trap)',
y='density')+
theme_minimal()+
theme(text=element_text(size=12))
raa_plot
raa_plot <- ggplot()+
geom_density(aes(x=posterior$mu.15),linewidth=1)+
labs(x='EGC density (crabs/trap)',
y='density')+
theme_minimal()+
theme(text=element_text(size=12))
raa_plot
raa_plot <- ggplot()+
geom_density(aes(x=posterior$mu.15),linewidth=1)+
scale_x_continuous(limits=c(0,1.5))+
labs(x='EGC density (crabs/trap)',
y='density')+
theme_minimal()+
theme(text=element_text(size=12))
raa_plot
ggsave('../eDNA_presentation/raa_plot.png',p10_plot,dpi=400)
ggsave('../eDNA_presentation/raa_plot.png',raa_plot,dpi=400)
cov <- package_coverage("/home/abby/eDNAjoint")
cov$`detectionCalculate.R:429:7:429:70:7:70:431:431`
dim(cov)
str(cov)
cov$`detectionCalculate.R:429:7:429:70:7:70:431:431`
length(cov)
test <- as.data.frame(cov)
View(test)
table(test$value)
zero_coverage(cov)
getwd()
saveRDS(test,'../eDNAjoint_coverage.rds')
4 changes: 3 additions & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

steps:
- uses: actions/checkout@v4
Expand All @@ -28,11 +29,12 @@ jobs:

- name: Test coverage
run: |
token <- Sys.getenv("CODECOV_TOKEN", "")
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package"),
paths = c("src/", "R/")
token = if (token != "") token
)
shell: Rscript {0}

Expand Down

0 comments on commit 2c40443

Please sign in to comment.