document.pdf (213.7 KB)
response.pdf (176.7 KB)
Hello, thank you for answering so fast. Because this is actually working within a plumber API it's hard to remove the tmp file, if you desire to see the code, as I cannot attach it I'll copy the full text below. Problem is not with the Rmd as it can be well rendered, just not from console. Attached there are 2 pdfs where show the difference in the render. A priori changing the path on input didn't work. Please let me know about any other information that you would need
---
title: "`r params$title`"
output: pdf_document
params:
author: "1451396591419719682"
title: "Draft Report task1"
date: NA
taskId: "0c2aff86c1022205fdd901b44d9ec087"
alpha: .1
author: "`r params$author`"
date: "`r params$date`"
always_allow_html: yes
---
```{r setup, include=FALSE}
source("/home/hadoop/BiologyAPP/BiologyAPI/BiologicalDataAPI/config/config.R")
library("kableExtra")
library("gtsummary")
library("mongolite")
library("yaml")
library("properties")
library("PKI")
library("httr")
library("jsonlite")
library("ggplot2")
knitr::opts_chunk$set(echo = TRUE)
options(warn = -1)
mongoConfig = loadNacos()
url = paste0("mongodb://",mongoConfig$host,":",mongoConfig$port)
breedingCollection = mongo(db = "servini-aigs",collection = "breedingValues", url = url)
if(params$taskId=="NA"){
data = breedingCollection$find(paste0('{"userId": "',params$author,'"}'))
}else{
data = breedingCollection$find(paste0('{"userId": "',params$author,'"',
', "taskId": "',params$taskId,'"}'))
}
notNull = function(x){
!is.null(x)
}
alpha = as.numeric(params$alpha)
```
# Cross validation
Lorem ipsum dolor sit amet, consecteturadipiscing elit. Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.
```{r cs, echo=FALSE, results="asis", message=FALSE}
i = 1
for(i in 1:NROW(data)){
model = data$model[i]
variables = names(data$crossValidation$random)
for(variable in variables){
if(!is.null(data$crossValidation$random[[variable]][[i]])){
tmp = data$crossValidation$random[[variable]][[i]]
tmp$R2_Train = round(tmp$R2_Train, 4)
tmp$r_Train = round(tmp$r_Train, 4)
tmp$RMSE_Train = round(tmp$RMSE_Train, 4)
tmp$R2_Test = round(tmp$R2_Test, 4)
tmp$r_Test = round(tmp$r_Test, 4)
tmp$RMSE_Test = round(tmp$RMSE_Test, 4)
tmp$n_train = round(tmp$n_train)
tmp$n_test = round(tmp$n_test)
tmp$ignored = round(tmp$ignored)
tmp2 = as.data.frame(sapply(tmp, function(x) c( "Stand dev" = sd(x,na.rm=TRUE),
"Mean"= mean(x,na.rm=TRUE))))
tmp$n_train = formatC(tmp$n_train,format="d")
tmp$n_test = formatC(tmp$n_test,format="d")
tmp$ignored = formatC(tmp$ignored,format="d")
tmp2$n_train = formatC(tmp2$n_train, format="f", digits=2)
tmp2$n_test = formatC(tmp2$n_test, format="f", digits=2)
tmp2$ignored = formatC(tmp2$ignored, format="f", digits=2)
tmp = rbind(tmp, tmp2)
print(kable(tmp,
col.names = c("R2",
"r",
"RMSE",
"R2",
"r",
"RMSE",
"train",
"test",
"unused"), caption = paste0(model,
": random effect=",
variable,
", masking=random"),
digits = 4, booktabs = T, linesep = "", longtable = T) %>%
kable_styling(position = "float_right") %>%
add_header_above(c("", "Train" = 3, "Test" = 3,
"Sample Size" = 3))%>%
column_spec(1, italic = T) %>%
row_spec((NROW(tmp)-1):NROW(tmp), bold = T))
}
}
variables = names(data$crossValidation$cohort)
for(variable in variables){
if(!is.null(data$crossValidation$cohort[[variable]][[i]])){
tmp = data$crossValidation$cohort[[variable]][[i]]
tmp$R2_Train = round(tmp$R2_Train, 4)
tmp$r_Train = round(tmp$r_Train, 4)
tmp$RMSE_Train = round(tmp$RMSE_Train, 4)
tmp$R2_Test = round(tmp$R2_Test, 4)
tmp$r_Test = round(tmp$r_Test, 4)
tmp$RMSE_Test = round(tmp$RMSE_Test, 4)
tmp$n_train = round(tmp$n_train)
tmp$n_test = round(tmp$n_test)
tmp$ignored = round(tmp$ignored)
tmp2 = as.data.frame(sapply(tmp, function(x) c( "Stand dev" = sd(x,na.rm=TRUE),
"Mean"= mean(x,na.rm=TRUE))))
tmp$n_train = formatC(tmp$n_train,format="d")
tmp$n_test = formatC(tmp$n_test,format="d")
tmp$ignored = formatC(tmp$ignored,format="d")
tmp2$n_train = formatC(tmp2$n_train, format="f", digits=2)
tmp2$n_test = formatC(tmp2$n_test, format="f", digits=2)
tmp2$ignored = formatC(tmp2$ignored, format="f", digits=2)
tmp = rbind(tmp, tmp2)
print(kable(tmp,
col.names = c("R2",
"r",
"RMSE",
"R2",
"r",
"RMSE",
"train",
"test",
"unused"), caption = paste0(model,
": random effect=",
variable,
", masking=cohort"),
digits = 4, booktabs = T, linesep = "", longtable = T) %>%
kable_styling(position = "float_right") %>%
add_header_above(c("", "Train" = 3, "Test" = 3,
"Sample Size" = 3))%>%
column_spec(1, italic = T) %>%
row_spec((NROW(tmp)-1):NROW(tmp), bold = T))
}
}
}
```
Lorem ipsum dolor sit amet, consecteturadipiscing elit. Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.
Lorem ipsum dolor sit amet, consecteturadipiscing elit. Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.
# Model Summarys
## Bayesian
### Statistics
Lorem ipsum dolor sit amet, consecteturadipiscing elit. Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.
```{r bsum, echo=FALSE, results="asis", message=FALSE}
variables =names(data$GEVs$bayes)
n = 0
for(variable in variables){
n = n+sum(unlist(lapply(data$GEVs$bayes[[variable]], notNull)))
}
summaryTable = matrix(data = NA, nrow = n, ncol = 8)
colnames(summaryTable) = c("model", "randomEffect", "min", "Q1", "median", "mean",
"Q3", "max")
n=1
for(variable in variables){
for (i in 1:length(data$GEVs$bayes[[variable]])){
if(!is.null(data$GEVs$bayes[[variable]][[i]])){
summaryTable[n,1] = data$model[[i]]
summaryTable[n,2] = variable
summaryTable[n,3:8] = round(summary(data$GEVs$bayes[[variable]][[i]][["BV"]]),2)
n=n+1
}
}
}
kable(summaryTable,
col.names = c("Model",
"Breeding Variable",
"Minimum",
"1st Quantil",
"Median",
"Mean",
"3rd Quantil",
"Max"),
caption = paste0("Bayesian models summary table"),
digits = 2, booktabs = T, linesep = "", longtable = T) %>%
kable_styling(position = "float_right") %>%
column_spec(1:2, italic = T)
```
### Plots
Lorem ipsum dolor sit amet, consecteturadipiscing elit. Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.
```{r bplot, echo=FALSE, results="asis", message=FALSE}
variables =names(data$GEVs$bayes)
n=1
z = qnorm(1-alpha/2)
for(variable in variables){
for (i in 1:length(data$GEVs$bayes[[variable]])){
if(!is.null(data$GEVs$bayes[[variable]][[i]])){
temp = data$GEVs$bayes[[variable]][[i]]
colnames(temp)[1] = "id"
temp = temp[order(-temp$BV),]
temp = head(data$GEVs$bayes[[variable]][[i]], n=10L)
colnames(temp)[1] = "id"
temp$order = NROW(temp):1
temp$l = temp$BV-z*sqrt(temp$var)
temp$u = temp$BV+z*sqrt(temp$var)
p <- ggplot(temp, aes(x=BV, y=factor(order, labels = id), xmin=l,
xmax=u)) +
geom_pointrange() +
geom_vline(xintercept = 0, linetype=2) +
xlab('Breeding Value') +
ylab('ID') +
ggtitle(paste0("Effects of ", variable, " according model ",
data$model[i]))
print(p)
an=n+1
}
}
}
```
## GAME
Lorem ipsum dolor sit amet, consecteturadipiscing elit. Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.
### Statistics
Lorem ipsum dolor sit amet, consecteturadipiscing elit. Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.
```{r gsum, echo=FALSE, results="asis", message=FALSE}
variables =names(data$GEVs$blups)
n = 1
for(variable in variables){
n = n+sum(unlist(lapply(data$GEVs$bayes[[variable]], notNull)))
}
summaryTable = matrix(data = NA, nrow = n, ncol = 8)
colnames(summaryTable) = c("model", "randomEffect", "min", "Q1", "median", "mean",
"Q3", "max")
n=1
for(variable in variables){
for (i in 1:length(data$GEVs$blups[[variable]])){
if(!is.null(data$GEVs$blups[[variable]][[i]])){
summaryTable[n,1] = data$model[[i]]
summaryTable[n,2] = variable
summaryTable[n,3:8] = round(summary(data$GEVs$blups[[variable]][[i]][["value"]]),2)
n=n+1
}
}
}
kable(summaryTable,
col.names = c("Model",
"Breeding Variable",
"Minimum",
"1st Quantil",
"Median",
"Mean",
"3rd Quantil",
"Max"),
caption = paste0("Blups models summary table"),
digits = 2, booktabs = T, linesep = "", longtable = T) %>%
kable_styling(position = "float_right") %>%
column_spec(1:2, italic = T)
```
### Plots
Lorem ipsum dolor sit amet, consecteturadipiscing elit. Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.
```{r gameplot, echo=FALSE, results="asis", message=FALSE}
variables =names(data$GEVs$blups)
n=1
z = qnorm(1-alpha/2)
for(variable in variables){
for (i in 1:length(data$GEVs$blups[[variable]])){
if(!is.null(data$GEVs$blups[[variable]][[i]])){
temp = data$GEVs$blups[[variable]][[i]]
colnames(temp)[1] = "id"
temp = temp[order(-temp$value),]
temp = head(data$GEVs$blups[[variable]][[i]], n=10L)
temp$order = NROW(temp):1
temp$l = temp$value-z*sqrt(temp$var)
temp$u = temp$value+z*sqrt(temp$var)
p <- ggplot(temp, aes(x=value, y=factor(order, labels = id), xmin=l,
xmax=u)) +
geom_pointrange() +
geom_vline(xintercept = 0, linetype=2) +
xlab('Breeding Value') +
ylab('ID') +
ggtitle(paste0("Effects of ", variable, " according model ",
data$model[i]))
print(p)
n=n+1
}
}
}
```