@sjcrh/proteinpaint-server 2.88.0 → 2.88.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/routes/termdb.singlecellSamples.js +7 -3
- package/src/app.js +38 -29
- package/utils/regression.utils.R +32 -25
package/utils/regression.utils.R
CHANGED
|
@@ -515,20 +515,22 @@ plot_spline <- function(splineVariable, dat, outcome, res, regtype, formulatype,
|
|
|
515
515
|
preddat_ci_adj <- preddat_ci + sum(apply(newdat2, 1, prod), na.rm = T)
|
|
516
516
|
|
|
517
517
|
# plot data
|
|
518
|
-
plotfile <- paste0(cachedir, "splinePlot_", ifelse(is.null(formulatype), "", paste0(formulatype, "_")), createRandString(), ".
|
|
519
|
-
|
|
520
|
-
par(mar = c(
|
|
518
|
+
plotfile <- paste0(cachedir, "splinePlot_", ifelse(is.null(formulatype), "", paste0(formulatype, "_")), createRandString(), ".svg")
|
|
519
|
+
svg(filename = plotfile, width = 6.7, height = ifelse(is.null(formulatype),5.25,5.35), pointsize = 20)
|
|
520
|
+
par(mar = c(2, 2, ifelse(is.null(formulatype),0.7,1), 5) + 0.1, mgp = c(1, 1, 0))
|
|
521
521
|
if (regtype == "linear" | regtype == "logistic") {
|
|
522
522
|
if (regtype == "linear") {
|
|
523
523
|
# for linear, plot predicted values
|
|
524
524
|
pointtype <- 16
|
|
525
525
|
pointsize <- 0.3
|
|
526
|
+
pointalpha <- 0.8
|
|
526
527
|
ylab <- outcome$name
|
|
527
528
|
} else {
|
|
528
529
|
# for logistic, plot predicted probabilities
|
|
529
530
|
preddat_ci_adj <- 1/(1+exp(-preddat_ci_adj))
|
|
530
531
|
pointtype <- 124
|
|
531
532
|
pointsize <- 0.7
|
|
533
|
+
pointalpha <- 0.5
|
|
532
534
|
ylab <- paste0("Pr(", outcome$name, " ", outcome$categories$nonref, ")")
|
|
533
535
|
}
|
|
534
536
|
# use only finite predicted data
|
|
@@ -539,14 +541,16 @@ plot_spline <- function(splineVariable, dat, outcome, res, regtype, formulatype,
|
|
|
539
541
|
# predicted data will be overlayed later
|
|
540
542
|
plot(dat[,splineVariable$id],
|
|
541
543
|
dat[,outcome$id],
|
|
542
|
-
cex.axis = 0.5,
|
|
543
544
|
ann = F,
|
|
545
|
+
xaxt = "n",
|
|
546
|
+
yaxt = "n",
|
|
544
547
|
type = "n"
|
|
545
548
|
)
|
|
546
549
|
points(dat[,splineVariable$id],
|
|
547
550
|
dat[,outcome$id],
|
|
548
551
|
pch = pointtype,
|
|
549
|
-
cex = pointsize
|
|
552
|
+
cex = pointsize,
|
|
553
|
+
col = adjustcolor("#ce768e", alpha.f = pointalpha)
|
|
550
554
|
)
|
|
551
555
|
} else if (regtype == "cox") {
|
|
552
556
|
# for cox, plot hazard ratios
|
|
@@ -555,39 +559,40 @@ plot_spline <- function(splineVariable, dat, outcome, res, regtype, formulatype,
|
|
|
555
559
|
toKeep <- rowSums(!is.finite(preddat_ci_adj)) == 0
|
|
556
560
|
preddat_ci_adj <- preddat_ci_adj[toKeep,]
|
|
557
561
|
newdat <- newdat[toKeep,,drop = F]
|
|
558
|
-
pointtype <- 16
|
|
559
|
-
pointsize <- 0.3
|
|
560
562
|
ylab <- "Hazard Ratio"
|
|
561
563
|
# plot only predicted data
|
|
562
564
|
# do not also plot actual data (like for linear/logistic) because cox outcome data is time-to-event and will not be comparable to the predicted hazard ratios
|
|
563
565
|
plot(newdat[,splineVariable$id],
|
|
564
566
|
preddat_ci_adj[,"fit"],
|
|
565
567
|
ylim = c(min(preddat_ci_adj[,"lwr"]), max(preddat_ci_adj[,"upr"])),
|
|
566
|
-
cex.axis = 0.5,
|
|
567
568
|
ann = F,
|
|
569
|
+
xaxt = "n",
|
|
570
|
+
yaxt = "n",
|
|
568
571
|
type = "n"
|
|
569
572
|
)
|
|
570
573
|
} else {
|
|
571
574
|
stop("unrecognized regression type")
|
|
572
575
|
}
|
|
573
576
|
|
|
577
|
+
# axes
|
|
578
|
+
axis(1, cex.axis = 0.5, mgp = c(0, 0.2, 0))
|
|
579
|
+
axis(2, cex.axis = 0.5, mgp = c(0, 0.5, 0))
|
|
580
|
+
|
|
574
581
|
# titles
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
cex.lab = 0.5
|
|
584
|
-
)
|
|
582
|
+
title(xlab = splineVariable$name, line = 1, cex.lab = 0.5)
|
|
583
|
+
title(ylab = ylab, line = 1.5, cex.lab = 0.5)
|
|
584
|
+
if (!is.null(formulatype)) {
|
|
585
|
+
if (formulatype == "univariate") plotTitle <- "Univariate"
|
|
586
|
+
else if (formulatype == "multivariate") plotTitle <- "Multivariable-adjusted"
|
|
587
|
+
else stop("unexpected formula type")
|
|
588
|
+
title(main = plotTitle, cex.main = 0.5, line = 0.45)
|
|
589
|
+
}
|
|
585
590
|
|
|
586
591
|
# knots
|
|
587
592
|
abline(v = splineVariable$spline$knots[[1]],
|
|
588
593
|
col = "grey60",
|
|
589
594
|
lty = 2,
|
|
590
|
-
lwd =
|
|
595
|
+
lwd = 1,
|
|
591
596
|
xpd = F
|
|
592
597
|
)
|
|
593
598
|
|
|
@@ -601,29 +606,31 @@ plot_spline <- function(splineVariable, dat, outcome, res, regtype, formulatype,
|
|
|
601
606
|
# regression line
|
|
602
607
|
lines(newdat[,splineVariable$id],
|
|
603
608
|
preddat_ci_adj[,"fit"],
|
|
604
|
-
col = "
|
|
605
|
-
lwd =
|
|
609
|
+
col = "blue",
|
|
610
|
+
lwd = 1.7
|
|
606
611
|
)
|
|
607
612
|
|
|
608
613
|
# legend for lines
|
|
609
614
|
legend("topright",
|
|
615
|
+
inset = c(-0.39, 0),
|
|
610
616
|
cex = 0.5,
|
|
611
|
-
inset = c(-0.3, 0.1),
|
|
612
617
|
legend = c("knots", "cubic spline fit", "95% CI"),
|
|
613
618
|
text.col = "white",
|
|
614
619
|
lty = c(2, 1, NA),
|
|
615
|
-
col = c("grey60", "
|
|
620
|
+
col = c("grey60", "blue", NA),
|
|
621
|
+
xpd = TRUE
|
|
616
622
|
)
|
|
617
623
|
|
|
618
624
|
# legend for ci
|
|
619
625
|
legend("topright",
|
|
626
|
+
inset = c(-0.39, 0),
|
|
620
627
|
cex = 0.5,
|
|
621
|
-
inset = c(-0.3, 0.1),
|
|
622
628
|
legend = c("knots", "cubic spline fit", "95% CI"),
|
|
623
629
|
text.col = "black",
|
|
624
630
|
bty = "n",
|
|
625
631
|
fill = c(NA, NA, adjustcolor("grey", alpha.f = 0.8)),
|
|
626
|
-
border = c(NA, NA, NA)
|
|
632
|
+
border = c(NA, NA, NA),
|
|
633
|
+
xpd = TRUE
|
|
627
634
|
)
|
|
628
635
|
dev.off()
|
|
629
636
|
return(plotfile)
|