Skip to content

Commit

Permalink
will fix sbalci/jsurvival#2 functions are being updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalci committed Dec 10, 2023
1 parent d7dfb72 commit 4fd2f6e
Show file tree
Hide file tree
Showing 15 changed files with 820 additions and 459 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.08
Date: 2023-12-03
Version: 0.0.2.12
Date: 2023-12-07
Authors@R:
person(given = "Serdar",
family = "Balci",
Expand Down
2 changes: 1 addition & 1 deletion R/jjhistostats.b.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ jjhistostatsClass <- if (requireNamespace('jmvcore'))
x = !!dep,

binwidth = binwidth,
# bar.measure = barmeasure, ----
# bar.measure = barmeasure,
# xlab = NULL,
# title = NULL,
# subtitle = NULL,
Expand Down
6 changes: 3 additions & 3 deletions R/jjhistostats.h.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jjhistostatsOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Clas
initialize = function(
dep = NULL,
grvar = NULL,
excl = TRUE,
excl = FALSE,
typestatistics = "parametric",
centralityparameter = "mean",
centralityline = TRUE,
Expand Down Expand Up @@ -55,7 +55,7 @@ jjhistostatsOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Clas
private$..excl <- jmvcore::OptionBool$new(
"excl",
excl,
default=TRUE)
default=FALSE)
private$..typestatistics <- jmvcore::OptionList$new(
"typestatistics",
typestatistics,
Expand Down Expand Up @@ -339,7 +339,7 @@ jjhistostats <- function(
data,
dep,
grvar,
excl = TRUE,
excl = FALSE,
typestatistics = "parametric",
centralityparameter = "mean",
centralityline = TRUE,
Expand Down
267 changes: 142 additions & 125 deletions R/multisurvival.b.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,62 @@ multisurvivalClass <- if (requireNamespace('jmvcore'))
inherit = multisurvivalBase,
private = list(

.todo = function() {
# If no variable selected Initial Message ----

if (

(is.null(self$options$outcome) && !(self$options$multievent)) ||

(self$options$multievent && (is.null(self$options$dod) && is.null(self$options$dooc) && is.null(self$options$awd) && is.null(self$options$awod))) ||

(is.null(self$options$elapsedtime) && !(self$options$tint)) ||

(self$options$tint && (is.null(self$options$dxdate) || is.null(self$options$fudate))) ||

is.null(self$options$explanatory)

# ||

# (!is.null(self$options$explanatory) && is.null(self$options$contexpl))


)
{
# TODO ----

todo <- glue::glue(
"
<br>Welcome to ClinicoPath
<br><br>
This tool will help you perform a multivariable survival analysis.
<br><br>
Explanatory variables can be categorical (ordinal or nominal) or continuous.
<br><br>
Select outcome level from Outcome variable.
<br><br>
Outcome Level: if patient is dead or event (recurrence) occured. You may also use advanced outcome options depending on your analysis type.
<br><br>
Survival time should be numeric, continuous, and in months. You may also use dates to calculate survival time in advanced elapsed time options.
<br><br>
This function uses finalfit, survival, survminer and ggstatsplot packages. Please cite jamovi and the packages as given below.
<br><br>
"
)
# https://finalfit.org/articles/all_tables_examples.html#cox-proportional-hazards-model-survival-time-to-event


html <- self$results$todo
html$setContent(todo)
return()

} else {
if (nrow(self$data) == 0)
stop('Data contains no (complete) rows')
}

}
,
# .todo = function() {
# # If no variable selected Initial Message ----
#
# if (
#
# (is.null(self$options$outcome) && !(self$options$multievent)) ||
#
# (self$options$multievent && (is.null(self$options$dod) && is.null(self$options$dooc) && is.null(self$options$awd) && is.null(self$options$awod))) ||
#
# (is.null(self$options$elapsedtime) && !(self$options$tint)) ||
#
# (self$options$tint && (is.null(self$options$dxdate) || is.null(self$options$fudate))) ||
#
# is.null(self$options$explanatory)
#
# # ||
#
# # (!is.null(self$options$explanatory) && is.null(self$options$contexpl))
#
#
# )
# {
# # TODO ----
#
# todo <- glue::glue(
# "
# <br>Welcome to ClinicoPath
# <br><br>
# This tool will help you perform a multivariable survival analysis.
# <br><br>
# Explanatory variables can be categorical (ordinal or nominal) or continuous.
# <br><br>
# Select outcome level from Outcome variable.
# <br><br>
# Outcome Level: if patient is dead or event (recurrence) occured. You may also use advanced outcome options depending on your analysis type.
# <br><br>
# Survival time should be numeric, continuous, and in months. You may also use dates to calculate survival time in advanced elapsed time options.
# <br><br>
# This function uses finalfit, survival, survminer and ggstatsplot packages. Please cite jamovi and the packages as given below.
# <br><br>
# "
# )
# # https://finalfit.org/articles/all_tables_examples.html#cox-proportional-hazards-model-survival-time-to-event
#
#
# html <- self$results$todo
# html$setContent(todo)
# # return()
#
# } else {
# if (nrow(self$data) == 0)
# stop('Data contains no (complete) rows')
# }
#
# }
# ,


.cleandata = function() {
Expand All @@ -81,6 +81,7 @@ multisurvivalClass <- if (requireNamespace('jmvcore'))
elapsedtime <- self$options$elapsedtime
outcome <- self$options$outcome
explanatory <- self$options$explanatory
contexpl <- self$options$contexpl
outcomeLevel <- self$options$outcomeLevel
tint <- self$options$tint

Expand Down Expand Up @@ -285,26 +286,35 @@ multisurvivalClass <- if (requireNamespace('jmvcore'))
myfactors <- c(myexplanatory, mycontexpl)


self$results$mydataview$setContent(
list(
head(mydata, n = 10),
myexplanatory = myexplanatory,
mycontexpl = mycontexpl,
myfactors = myfactors
)
)

# Add Redefined Outcome to Data ----

if (self$options$multievent) {
# Add Redefined Outcome to Data ----

if (self$options$outcomeredifened &&
self$results$outcomeredifened$isNotFilled()) {
self$results$outcomeredifened$setValues(mydata[["myoutcome"]])
}
}
# if (self$options$multievent) {
#
# if (self$options$outcomeredifened &&
# self$results$outcomeredifened$isNotFilled()) {
# self$results$outcomeredifened$setValues(mydata[["myoutcome"]])
# }
# }

# Add Calculated Time to Data ----

if (self$options$tint) {

if (self$options$calculatedtime &&
self$results$calculatedtime$isNotFilled()) {
self$results$calculatedtime$setValues(mydata[["mytime"]])
}
}
# if (self$options$tint) {
#
# if (self$options$calculatedtime &&
# self$results$calculatedtime$isNotFilled()) {
# self$results$calculatedtime$setValues(mydata[["mytime"]])
# }
# }



Expand Down Expand Up @@ -332,7 +342,11 @@ multisurvivalClass <- if (requireNamespace('jmvcore'))

mydata <- jmvcore::select(df = mydata, columnNames = c("mytime", "myoutcome", myfactors))


# self$results$mydataview$setContent(
# list(
# head(mydata, n = 30)
# )
# )


# naOmit ----
Expand All @@ -355,24 +369,24 @@ multisurvivalClass <- if (requireNamespace('jmvcore'))


# Errors ----
if (

(is.null(self$options$outcome) && !(self$options$multievent)) ||

(self$options$multievent && (is.null(self$options$dod) && is.null(self$options$dooc) && is.null(self$options$awd) && is.null(self$options$awod))) ||

(self$options$tint && (is.null(self$options$dxdate) || is.null(self$options$fudate))) ||

is.null(self$options$explanatory)

# ||
#
# (!is.null(self$options$explanatory) && is.null(self$options$contexpl))

) {
private$.todo()
return()
}
# if (
#
# (is.null(self$options$outcome) && !(self$options$multievent)) ||
#
# (self$options$multievent && (is.null(self$options$dod) && is.null(self$options$dooc) && is.null(self$options$awd) && is.null(self$options$awod))) ||
#
# (self$options$tint && (is.null(self$options$dxdate) || is.null(self$options$fudate))) ||
#
# is.null(self$options$explanatory)
#
# #
# #
# # (!is.null(self$options$explanatory) && is.null(self$options$contexpl))
#
# ) {
# private$.todo()
# # return()
# }

if (nrow(self$data) == 0)
stop('Data contains no (complete) rows')
Expand All @@ -384,6 +398,9 @@ multisurvivalClass <- if (requireNamespace('jmvcore'))
mydata <- cleaneddata$mydata





# Cox ----

private$.cox(mydata)
Expand All @@ -396,7 +413,7 @@ multisurvivalClass <- if (requireNamespace('jmvcore'))
# )


# # Prepare Data For Plots ----
# Prepare Data For Plots ----


image <- self$results$plot
Expand All @@ -406,8 +423,8 @@ multisurvivalClass <- if (requireNamespace('jmvcore'))
image3$setState(mydata)


image4 <- self$results$plot4
image4$setState(mydata)
# image4 <- self$results$plot4
# image4$setState(mydata)


# imageKM <- self$results$plotKM
Expand Down Expand Up @@ -827,39 +844,39 @@ multisurvivalClass <- if (requireNamespace('jmvcore'))



# coxzph plot ----
,
.plot4 = function(image4, ggtheme, theme, ...) {

plotData <- image4$state

formula2 <-
jmvcore::constructFormula(terms = c(self$options$explanatory, self$options$contexpl))

formula3 <-
paste("survival::Surv(mytime, myoutcome) ~ ", formula2)

formula3 <- as.formula(formula3)

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



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


# plot all variables
plot4 <- survminer::ggcoxzph(cox_zph_fit)


# print plot ----

print(plot4)
TRUE

}
# # coxzph plot ----
# ,
# .plot4 = function(image4, ggtheme, theme, ...) {
#
# plotData <- image4$state
#
# formula2 <-
# jmvcore::constructFormula(terms = c(self$options$explanatory, self$options$contexpl))
#
# formula3 <-
# paste("survival::Surv(mytime, myoutcome) ~ ", formula2)
#
# formula3 <- as.formula(formula3)
#
# cox_model <-
# survival::coxph(formula = formula3,
# data = plotData)
#
#
#
# cox_zph_fit <- survival::cox.zph(cox_model)
#
#
# # plot all variables
# plot4 <- survminer::ggcoxzph(cox_zph_fit)
#
#
# # print plot ----
#
# print(plot4)
# TRUE
#
# }



Expand Down
Loading

0 comments on commit 4fd2f6e

Please sign in to comment.