Skip to content

Commit

Permalink
will fix #73
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
sbalci committed Dec 10, 2023
1 parent 4fd2f6e commit ce9c3fb
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 39 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: ClinicoPath
Title: Analysis for Clinicopathological Research
Version: 0.0.2.12
Date: 2023-12-07
Version: 0.0.2.13
Date: 2023-12-10
Authors@R:
person(given = "Serdar",
family = "Balci",
Expand Down
73 changes: 41 additions & 32 deletions R/survival.b.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ survivalClass <- if (requireNamespace('jmvcore'))
"survivalClass",
inherit = survivalBase,
private = list(




.init = function() {


Expand All @@ -36,7 +36,7 @@ survivalClass <- if (requireNamespace('jmvcore'))
# }

}

,


Expand Down Expand Up @@ -66,7 +66,7 @@ survivalClass <- if (requireNamespace('jmvcore'))

all_labels <- labelled::var_label(mydata)


mytime <-
names(all_labels)[all_labels == self$options$elapsedtime]

Expand All @@ -79,9 +79,9 @@ survivalClass <- if (requireNamespace('jmvcore'))
myfudate <-
names(all_labels)[all_labels == self$options$fudate]

myexplanatory <-
myexplanatory <-
names(all_labels)[all_labels == self$options$explanatory]

return(list(
"mydata_labelled" = mydata
, "mytime_labelled" = mytime
Expand All @@ -90,14 +90,14 @@ survivalClass <- if (requireNamespace('jmvcore'))
, "myfudate_labelled" = myfudate
, "myexplanatory_labelled" = myexplanatory
))


}





# ,
# .todo = function() {
# if (
Expand All @@ -108,7 +108,7 @@ survivalClass <- if (requireNamespace('jmvcore'))
# is.null(self$options$dod) &&
# is.null(self$options$dooc) &&
# is.null(self$options$awd) && is.null(self$options$awod)

# )
# ) ||

Expand Down Expand Up @@ -184,7 +184,7 @@ survivalClass <- if (requireNamespace('jmvcore'))

mydata[["mytime"]] <-
jmvcore::toNumeric(mydata[[mytime_labelled]])


} else if (tint) {
# Time Interval ----
Expand Down Expand Up @@ -272,8 +272,8 @@ survivalClass <- if (requireNamespace('jmvcore'))
# Define Outcome ----
,
.definemyoutcome = function() {


labelled_data <- private$.getData()

mydata <- labelled_data$mydata_labelled
Expand All @@ -293,17 +293,17 @@ survivalClass <- if (requireNamespace('jmvcore'))
# myexplanatory_labelled = myexplanatory_labelled
# )
# )



# mydata <- mydata_labelled #self$data

contin <- c("integer", "numeric", "double")

outcomeLevel <- self$options$outcomeLevel
multievent <- self$options$multievent


# outcome1 <- self$options$outcome
# outcome1 <- self$data[[outcome1]]
outcome1 <- mydata[[myoutcome_labelled]]
Expand All @@ -325,7 +325,7 @@ survivalClass <- if (requireNamespace('jmvcore'))
}

mydata[["myoutcome"]] <- mydata[[myoutcome_labelled]]
# mydata[[self$options$outcome]]
# mydata[[self$options$outcome]]

} else if (inherits(outcome1, "factor")) {
mydata[["myoutcome"]] <-
Expand Down Expand Up @@ -425,8 +425,8 @@ survivalClass <- if (requireNamespace('jmvcore'))
# mydata <- self$data

# expl <- self$options$explanatory


labelled_data <- private$.getData()

mydata_labelled <- labelled_data$mydata_labelled
Expand Down Expand Up @@ -491,7 +491,7 @@ survivalClass <- if (requireNamespace('jmvcore'))



cleanData <- dplyr::left_join(time, outcome, by = "row_names") %>%
cleanData <- dplyr::left_join(time, outcome, by = "row_names") %>%
dplyr::left_join(factor, by = "row_names")
# %>%
# dplyr::select(-row_names)
Expand Down Expand Up @@ -556,8 +556,8 @@ survivalClass <- if (requireNamespace('jmvcore'))
!!name2outcome := myoutcome,
!!name3explanatory := myfactor
)



# names(cleanData) <-
# c(name1time, name2outcome, name3explanatory)
Expand Down Expand Up @@ -971,7 +971,7 @@ survivalClass <- if (requireNamespace('jmvcore'))
# Proportional Hazards Assumption ----

if (self$options$ph_cox) {

# self$results$mydataview$setContent(
# list(
# mydata = head(mydata),
Expand All @@ -994,7 +994,7 @@ survivalClass <- if (requireNamespace('jmvcore'))


mydata[[mytime]] <- jmvcore::toNumeric(mydata[[mytime]])


formula <-
paste('survival::Surv(',
Expand All @@ -1009,14 +1009,14 @@ survivalClass <- if (requireNamespace('jmvcore'))


cox_model <- survival::coxph(formula, data = mydata)

zph <- survival::cox.zph(cox_model)

self$results$cox_ph$setContent(print(zph))

image7 <- self$results$plot7
image7$setState(zph)

}

}
Expand Down Expand Up @@ -1264,6 +1264,9 @@ survivalClass <- if (requireNamespace('jmvcore'))
legend = 'none',
break.time.by = self$options$byplot,
xlim = c(0, self$options$endplot),
ylim = c(
self$options$ybegin_plot,
self$options$yend_plot),
title = paste0("Survival curves for ", title2),
subtitle = "Based on Kaplan-Meier estimates",
risk.table = self$options$risktable,
Expand Down Expand Up @@ -1332,6 +1335,9 @@ survivalClass <- if (requireNamespace('jmvcore'))
legend = 'none',
break.time.by = self$options$byplot,
xlim = c(0, self$options$endplot),
ylim = c(
self$options$ybegin_plot,
self$options$yend_plot),
title = paste0("Cumulative Events ", title2),
fun = "event",
risk.table = self$options$risktable,
Expand Down Expand Up @@ -1399,6 +1405,9 @@ survivalClass <- if (requireNamespace('jmvcore'))
legend = 'none',
break.time.by = self$options$byplot,
xlim = c(0, self$options$endplot),
ylim = c(
self$options$ybegin_plot,
self$options$yend_plot),
title = paste0("Cumulative Hazard ", title2),
fun = "cumhaz",
risk.table = self$options$risktable,
Expand Down Expand Up @@ -1483,7 +1492,7 @@ survivalClass <- if (requireNamespace('jmvcore'))
# cox.zph ----
,
.plot7 = function(image7, ggtheme, theme, ...) {

ph_cox <- self$options$ph_cox

if (!ph_cox)
Expand Down
30 changes: 30 additions & 0 deletions R/survival.h.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ survivalOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
ce = FALSE,
ch = FALSE,
endplot = 60,
ybegin_plot = 0,
yend_plot = 1,
byplot = 12,
multievent = FALSE,
ci95 = FALSE,
Expand Down Expand Up @@ -184,6 +186,14 @@ survivalOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"endplot",
endplot,
default=60)
private$..ybegin_plot <- jmvcore::OptionNumber$new(
"ybegin_plot",
ybegin_plot,
default=0)
private$..yend_plot <- jmvcore::OptionNumber$new(
"yend_plot",
yend_plot,
default=1)
private$..byplot <- jmvcore::OptionInteger$new(
"byplot",
byplot,
Expand Down Expand Up @@ -234,6 +244,8 @@ survivalOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
self$.addOption(private$..ce)
self$.addOption(private$..ch)
self$.addOption(private$..endplot)
self$.addOption(private$..ybegin_plot)
self$.addOption(private$..yend_plot)
self$.addOption(private$..byplot)
self$.addOption(private$..multievent)
self$.addOption(private$..ci95)
Expand Down Expand Up @@ -267,6 +279,8 @@ survivalOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
ce = function() private$..ce$value,
ch = function() private$..ch$value,
endplot = function() private$..endplot$value,
ybegin_plot = function() private$..ybegin_plot$value,
yend_plot = function() private$..yend_plot$value,
byplot = function() private$..byplot$value,
multievent = function() private$..multievent$value,
ci95 = function() private$..ci95$value,
Expand Down Expand Up @@ -299,6 +313,8 @@ survivalOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
..ce = NA,
..ch = NA,
..endplot = NA,
..ybegin_plot = NA,
..yend_plot = NA,
..byplot = NA,
..multievent = NA,
..ci95 = NA,
Expand Down Expand Up @@ -642,6 +658,8 @@ survivalResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"sc",
"endplot",
"byplot",
"ybegin_plot",
"yend_plot",
"ci95",
"risktable",
"censored",
Expand All @@ -667,6 +685,8 @@ survivalResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"ce",
"endplot",
"byplot",
"ybegin_plot",
"yend_plot",
"ci95",
"risktable",
"censored",
Expand All @@ -691,6 +711,8 @@ survivalResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"ch",
"endplot",
"byplot",
"ybegin_plot",
"yend_plot",
"ci95",
"risktable",
"censored",
Expand All @@ -715,6 +737,8 @@ survivalResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"kmunicate",
"endplot",
"byplot",
"ybegin_plot",
"yend_plot",
"explanatory",
"outcome",
"outcomeLevel",
Expand Down Expand Up @@ -781,6 +805,8 @@ survivalBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
#' @param ce .
#' @param ch .
#' @param endplot .
#' @param ybegin_plot .
#' @param yend_plot .
#' @param byplot .
#' @param multievent .
#' @param ci95 .
Expand Down Expand Up @@ -843,6 +869,8 @@ survival <- function(
ce = FALSE,
ch = FALSE,
endplot = 60,
ybegin_plot = 0,
yend_plot = 1,
byplot = 12,
multievent = FALSE,
ci95 = FALSE,
Expand Down Expand Up @@ -895,6 +923,8 @@ survival <- function(
ce = ce,
ch = ch,
endplot = endplot,
ybegin_plot = ybegin_plot,
yend_plot = yend_plot,
byplot = byplot,
multievent = multievent,
ci95 = ci95,
Expand Down
1 change: 0 additions & 1 deletion debug.log

This file was deleted.

4 changes: 2 additions & 2 deletions jamovi/0000.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: Common Analysis for Clinicopathological Research
name: ClinicoPath
version: 0.0.2.12
version: 0.0.2.13
jms: '1.0'
authors:
- Serdar Balci
maintainer: Serdar Balci <drserdarbalci@gmail.com>
date: '2023-12-07'
date: '2023-12-10'
type: R
description: >-
ClinicoPath help researchers to generate natural language summaries of their
Expand Down
11 changes: 10 additions & 1 deletion jamovi/survival.a.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ options:
default: holm



- name: ph_cox
title: Proportional Hazards Assumption
type: Bool
Expand Down Expand Up @@ -242,6 +241,16 @@ options:
type: Integer
default: 60

- name: ybegin_plot
title: Start y-axis
type: Number
default: 0.00

- name: yend_plot
title: End y-axis
type: Number
default: 1.00


- name: byplot
title: Time Interval
Expand Down
Loading

0 comments on commit ce9c3fb

Please sign in to comment.