0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Google Colab で R : カプランマイヤー法と生存曲線 編

Last updated at Posted at 2024-02-20

おはこんばんちわ。今日も引き続きChatGPT先生をお迎えして、「Google Colab で R : カプランマイヤー法と生存曲線 編」というテーマで雑談したいと思います。以前「ChatGPT と Python で学ぶ カプランマイヤー法と生存曲線」というテーマで雑談しましたが、そのR版です。それではChatGPT先生、よろしくお願いします。


assistant:

よろしくお願いします。生存曲線とは生存時間に対して生存状態を描画したグラフで、カプランマイヤー法は生存曲線を描く一つの手法としてよく使われます。具体的には、ある時間点までにイベント(例えば、病気の発症や死亡など)が発生しなかった人の割合をプロットし、生存率の変化を視覚的に把握するのに使われます。

Rには survivalSurvminer というパッケージがあり、これを使ってカプランマイヤー法と生存曲線を容易にプロットすることができます。これらのパッケージを使って分析を進めましょう。

まずは必要なパッケージをインストールし、データを読み込みます:

install.packages("survival")
install.packages("survminer")
library(survival)
library(survminer)

# 生存時間データの読み込み
data(lung)

これでlungというデータフレームが使用可能になります。次に、Surv関数を使用して生存時間とイベント発生の有無から生存オブジェクトを作成します。このデータセットでは、生存時間は "time" 列に、イベント発生の有無は "status" 列に記録されています:

surv_obj <- Surv(time = lung$time, event = lung$status)

次に、Survfit関数を使用して生存曲線を推定します:

surv_fit <- survfit(surv_obj ~ 1) #~1は全体の生存曲線を見たいという意味

最後に、ggsurvplot関数を使用して生存曲線をプロットします:

ggsurvplot(surv_fit, risk.table = TRUE)

これで、生存曲線がプロットされ、推定された生存時間とイベント発生の有無に応じたリスクテーブルも表示されます。リスクテーブルは、各時間点での生存者とイベント発生者の数を示しています。


user:

ありがとうございます。以前教えていただいたように https://colab.research.google.com/notebook#create=true&language=r にアクセスして Google Colaboratory 上で動かします。

最初のコードを動かしていますが、めっちゃ時間がかかってますね(まだ終わらない...)

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)

also installing the dependencies ‘numDeriv’, ‘SparseM’, ‘MatrixModels’, ‘minqa’, ‘nloptr’, ‘RcppEigen’, ‘carData’, ‘abind’, ‘pbkrtest’, ‘quantreg’, ‘lme4’, ‘Rcpp’, ‘corrplot’, ‘car’, ‘markdown’, ‘png’, ‘jpeg’, ‘ggrepel’, ‘ggsci’, ‘cowplot’, ‘ggsignif’, ‘polynom’, ‘rstatix’, ‘exactRankTests’, ‘mvtnorm’, ‘KMsurv’, ‘zoo’, ‘km.ci’, ‘xtable’, ‘gridtext’, ‘ggpubr’, ‘gridExtra’, ‘maxstat’, ‘survMisc’, ‘ggtext’

assistant:

Rのパッケージのインストールは少々時間がかかることがあります。特にsurvminerパッケージは他の多くのパッケージに依存しているため、それらのパッケージも同時にインストールする必要があるので、そういったときは特に時間がかかる可能性があります。適切なインストールが完了すれば、survivalsurvminerパッケージを使用した分析はスムーズに行われるはずです。

ただし、全てのコードを一度に走らせるとエラーや不具合が起こる可能性もあるため、それぞれのコードは時間を置いて一つずつ走らせることをおすすめします。

なお、Google Colabでは新しいセッションを作成するたびにパッケージのインストールが必要になるため、この点もご注意ください。


user:

終わりました。ですがワーニングが出ているようです。

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)

also installing the dependencies ‘numDeriv’, ‘SparseM’, ‘MatrixModels’, ‘minqa’, ‘nloptr’, ‘RcppEigen’, ‘carData’, ‘abind’, ‘pbkrtest’, ‘quantreg’, ‘lme4’, ‘Rcpp’, ‘corrplot’, ‘car’, ‘markdown’, ‘png’, ‘jpeg’, ‘ggrepel’, ‘ggsci’, ‘cowplot’, ‘ggsignif’, ‘polynom’, ‘rstatix’, ‘exactRankTests’, ‘mvtnorm’, ‘KMsurv’, ‘zoo’, ‘km.ci’, ‘xtable’, ‘gridtext’, ‘ggpubr’, ‘gridExtra’, ‘maxstat’, ‘survMisc’, ‘ggtext’


Loading required package: ggplot2

Loading required package: ggpubr


Attaching package: ‘survminer’


The following object is masked from ‘package:survival’:

    myeloma


Warning message in data(lung):
“data set ‘lung’ not found”

assistant:

エラーメッセージを見ると、「data set ‘lung’ not found」となっていますね。恐らくパッケージの読み込みがうまく行ってない可能性があります。

survivalパッケージにはlungという名前のデータセットが含まれているはずです。試しに以下のコードを走らせて、lungデータセットが存在するか確認してみてください。

library(survival)
data("lung")

これでlungというデータセットが使えるようになるはずです。その後、生存時間とイベント発生の有無から生存オブジェクトを作成し、生存曲線を推定し、プロットするコードを続けて走らせてみてください。


user:

ありがとうございます。このような結果になりました。

Warning message in data("lung"):
“data set ‘lung’ not found”

assistant:

このエラーメッセージから見るに、lungデータセットが見つからない模様です。survivalパッケージを再度正しくロードして、データセットがロードされているか確認してみてください。

もしまだ問題が解決しない場合は、他のビルトインデータセットに置き換えて試すことも可能です。例えば、survivalパッケージに含まれるovarianデータセットを使うこともできます。その場合、以下のようにコードを書き換えて試してみてください:

data("ovarian")
surv_obj <- Surv(time = ovarian$futime, event = ovarian$fustat)
surv_fit <- survfit(surv_obj ~ 1)
ggsurvplot(surv_fit, risk.table = TRUE)

ここでは、ovarianデータセットのfutime列を生存時間、fustat列をイベント発生の有無として使っています。


user:

次の結果が得られました。

Warning message in data("ovarian"):
“data set ‘ovarian’ not found”
Error in .get_data(fit, data = data, complain = FALSE): The `data` argument should be provided either to ggsurvfit or survfit.
Traceback:

1. ggsurvplot(surv_fit, risk.table = TRUE)
2. do.call(ggsurvplot_core, opts)
3. (function (fit, data = NULL, fun = NULL, color = NULL, palette = NULL, 
 .     linetype = 1, break.x.by = NULL, break.y.by = NULL, break.time.by = NULL, 
 .     surv.scale = c("default", "percent"), xscale = 1, conf.int = FALSE, 
 .     conf.int.fill = "gray", conf.int.style = "ribbon", conf.int.alpha = 0.3, 
 .     censor = TRUE, censor.shape = "+", censor.size = 4.5, pval = FALSE, 
 .     pval.size = 5, pval.coord = c(NULL, NULL), test.for.trend = FALSE, 
 .     pval.method = FALSE, pval.method.size = pval.size, pval.method.coord = c(NULL, 
 .         NULL), log.rank.weights = c("survdiff", "1", "n", "sqrtN", 
 .         "S1", "S2", "FH_p=1_q=1"), title = NULL, xlab = "Time", 
 .     ylab = "Survival probability", xlim = NULL, ylim = NULL, 
 .     axes.offset = TRUE, legend = c("top", "bottom", "left", "right", 
 .         "none"), legend.title = "Strata", legend.labs = NULL, 
 .     fontsize = 4.5, font.family = "", tables.height = 0.25, tables.y.text = TRUE, 
 .     tables.col = "black", tables.y.text.col = TRUE, risk.table = FALSE, 
 .     risk.table.pos = c("out", "in"), risk.table.title = NULL, 
 .     risk.table.col = tables.col, risk.table.fontsize = fontsize, 
 .     risk.table.y.text = tables.y.text, risk.table.y.text.col = tables.y.text.col, 
 .     risk.table.height = tables.height, surv.plot.height = 0.75, 
 .     ncensor.plot.height = tables.height, cumevents.height = tables.height, 
 .     cumcensor.height = tables.height, ncensor.plot = FALSE, ncensor.plot.title = NULL, 
 .     cumevents = FALSE, cumevents.col = tables.col, cumevents.title = NULL, 
 .     cumevents.y.text = tables.y.text, cumevents.y.text.col = tables.y.text.col, 
 .     cumcensor = FALSE, cumcensor.col = tables.col, cumcensor.title = NULL, 
 .     cumcensor.y.text = tables.y.text, cumcensor.y.text.col = tables.y.text.col, 
 .     surv.median.line = c("none", "hv", "h", "v"), ggtheme = theme_survminer(), 
 .     tables.theme = ggtheme, ...) 
 . {
 .     if (!inherits(fit, "survfit")) 
 .         stop("Can't handle an object of class ", class(fit))
 .     surv.median.line <- match.arg(surv.median.line)
 .     stopifnot(log.rank.weights %in% c("survdiff", "1", "n", "sqrtN", 
 .         "S1", "S2", "FH_p=1_q=1"))
 .     log.rank.weights <- match.arg(log.rank.weights)
 .     if (ncensor.plot & cumcensor) {
 .         warning("Both ncensor.plot and cumsensor are TRUE.", 
 .             "In this case, we consider only cumcensor.", call. = FALSE)
 .         ncensor.plot <- FALSE
 .     }
 .     if (cumcensor) 
 .         ncensor.plot.height <- cumcensor.height
 .     if (is.null(ncensor.plot.title)) 
 .         ncensor.plot.title <- "Number of censoring"
 .     if (is.null(cumcensor.title)) 
 .         cumcensor.title <- "Cumulative number of censoring"
 .     if (is.null(cumevents.title)) 
 .         cumevents.title <- "Cumulative number of events"
 .     risk.table.pos <- match.arg(risk.table.pos)
 .     risktable <- .parse_risk_table_arg(risk.table)
 .     risk.table <- risktable$display
 .     risk.table.type <- risktable$type
 .     extra.params <- list(...)
 .     .expand <- ggplot2::waiver()
 .     if (!axes.offset) 
 .         .expand <- c(0, 0)
 .     data <- .get_data(fit, data = data, complain = FALSE)
 .     d <- surv_summary(fit, data = data)
 .     if (!is.null(fit$start.time)) 
 .         d <- subset(d, d$time >= fit$start.time)
 .     xmin <- ifelse(.is_cloglog(fun), min(c(1, d$time)), 0)
 .     if (!is.null(fit$start.time)) 
 .         xmin <- fit$start.time
 .     xmax <- .get_default_breaks(d$time, .log = .is_cloglog(fun)) %>% 
 .         max()
 .     if (is.null(xlim)) 
 .         xlim <- c(xmin, xmax)
 .     p <- ggsurvplot_df(d, fun = fun, color = color, palette = palette, 
 .         linetype = linetype, break.x.by = break.x.by, break.time.by = break.time.by, 
 .         break.y.by = break.y.by, surv.scale = surv.scale, xscale = xscale, 
 .         conf.int = conf.int, conf.int.fill = conf.int.fill, conf.int.style = conf.int.style, 
 .         conf.int.alpha = conf.int.alpha, censor = censor, censor.shape = censor.shape, 
 .         censor.size = censor.size, title = title, xlab = xlab, 
 .         ylab = ylab, xlim = xlim, ylim = ylim, axes.offset = axes.offset, 
 .         legend = legend, legend.title = legend.title, legend.labs = legend.labs, 
 .         ggtheme = ggtheme, ...)
 .     pms <- attr(p, "parameters")
 .     color <- surv.color <- pms$color
 .     pval <- surv_pvalue(fit, method = log.rank.weights, data = data, 
 .         pval = pval, pval.coord = pval.coord, pval.method.coord = pval.method.coord, 
 .         test.for.trend = test.for.trend)
 .     if (pval$pval.txt != "") {
 .         p <- p + ggplot2::annotate("text", x = pval$pval.x, y = pval$pval.y, 
 .             label = pval$pval.txt, size = pval.size, hjust = 0, 
 .             family = font.family)
 .         if (pval.method) 
 .             p <- p + ggplot2::annotate("text", x = pval$method.x, 
 .                 y = pval$method.y, label = pval$method, size = pval.method.size, 
 .                 hjust = 0, family = font.family)
 .     }
 .     if (surv.median.line %in% c("hv", "h", "v")) 
 .         p <- .add_surv_median(p, fit, type = surv.median.line, 
 .             fun = fun, data = data)
 .     res <- list(plot = p)
 .     if (risk.table | cumevents | cumcensor | ncensor.plot) {
 .         scurve_cols <- .extract_ggplot_colors(p, grp.levels = pms$legend.labs)
 .     }
 .     pms <- attr(p, "parameters")
 .     surv.color <- pms$color
 .     pms$fit <- fit
 .     pms$data <- data
 .     pms$risk.table.type <- risk.table.type
 .     pms$risk.table.title <- risk.table.title
 .     pms$cumevents.title <- cumevents.title
 .     pms$cumcensor.title <- cumcensor.title
 .     pms$fontsize <- fontsize
 .     pms$ggtheme <- ggtheme
 .     pms$ylab <- pms$legend.title
 .     pms$tables.theme <- tables.theme
 .     pms$y.text <- tables.y.text
 .     pms$color <- tables.col
 .     pms$font.family <- font.family
 .     pms$axes.offset <- axes.offset
 .     if (risk.table) {
 .         if (risk.table.pos == "in") 
 .             risk.table.col = surv.color
 .         pms$color <- risk.table.col
 .         pms$title <- risk.table.title
 .         pms$y.text <- risk.table.y.text
 .         pms$y.text.col <- risk.table.y.text.col
 .         pms$fontsize <- risk.table.fontsize
 .         pms$survtable <- "risk.table"
 .         if (risk.table.y.text.col) 
 .             pms$y.text.col <- scurve_cols
 .         res$table <- risktable <- do.call(ggsurvtable, pms)
 .     }
 .     if (cumevents) {
 .         pms$color <- cumevents.col
 .         pms$title <- cumevents.title
 .         pms$y.text <- cumevents.y.text
 .         if (cumevents.y.text.col) 
 .             pms$y.text.col <- scurve_cols
 .         pms$fontsize <- fontsize
 .         pms$survtable <- "cumevents"
 .         res$cumevents <- do.call(ggsurvtable, pms)
 .     }
 .     if (ncensor.plot) {
 .         ncensor_plot <- ggplot(d, aes_string("time", "n.censor")) + 
 .             ggpubr::geom_exec(geom_bar, d, color = surv.color, 
 .                 fill = surv.color, stat = "identity", position = "dodge") + 
 .             coord_cartesian(xlim = xlim) + scale_y_continuous(breaks = sort(unique(d$n.censor))) + 
 .             ggtheme
 .         ncensor_plot <- ggpubr::ggpar(ncensor_plot, palette = pms$palette)
 .         ncensor_plot <- ncensor_plot + ggplot2::labs(color = pms$legend.title, 
 .             fill = pms$legend.title, x = xlab, y = "n.censor", 
 .             title = ncensor.plot.title)
 .         ncensor_plot <- .set_general_gpar(ncensor_plot, ...)
 .         ncensor_plot <- .set_ncensorplot_gpar(ncensor_plot, ...)
 .         ncensor_plot <- ncensor_plot + tables.theme
 .         if (!pms$xlog) 
 .             ncensor_plot <- ncensor_plot + scale_x_continuous(breaks = pms$time.breaks, 
 .                 labels = pms$xticklabels, expand = .expand)
 .         else ncensor_plot <- ncensor_plot + ggplot2::scale_x_continuous(breaks = pms$time.breaks, 
 .             trans = "log10", labels = pms$xticklabels)
 .     }
 .     else if (cumcensor) {
 .         pms$color <- cumcensor.col
 .         pms$title <- cumcensor.title
 .         if (cumcensor.y.text.col) 
 .             pms$y.text.col <- scurve_cols
 .         pms$fontsize <- fontsize
 .         pms$survtable <- "cumcensor"
 .         ncensor_plot <- do.call(ggsurvtable, pms)
 .     }
 .     if (ncensor.plot | cumcensor) 
 .         res$ncensor.plot <- ncensor_plot
 .     heights <- list(plot = surv.plot.height, table = ifelse(risk.table, 
 .         risk.table.height, 0), ncensor.plot = ifelse(ncensor.plot | 
 .         cumcensor, ncensor.plot.height, 0), cumevents = ifelse(cumevents, 
 .         cumevents.height, 0))
 .     y.text <- list(table = risk.table.y.text, cumevents = cumevents.y.text, 
 .         cumcensor = cumcensor.y.text)
 .     y.text.col <- list(table = risk.table.y.text.col, cumevents = cumevents.y.text.col, 
 .         cumcensor = cumcensor.y.text.col)
 .     res$data.survplot <- d
 .     res$data.survtable <- .get_timepoints_survsummary(fit, data, 
 .         pms$time.breaks)
 .     class(res) <- c("ggsurvplot", "ggsurv", "list")
 .     attr(res, "heights") <- heights
 .     attr(res, "y.text") <- y.text
 .     attr(res, "y.text.col") <- y.text.col
 .     attr(res, "legend.position") <- legend
 .     attr(res, "legend.labs") <- legend.labs
 .     attr(res, "cumcensor") <- cumcensor
 .     attr(res, "risk.table.pos") <- risk.table.pos
 .     attr(res, "axes.offset") <- axes.offset
 .     res
 . })(fit = structure(list(n = 26L, time = c(59, 115, 156, 268, 
 . 329, 353, 365, 377, 421, 431, 448, 464, 475, 477, 563, 638, 744, 
 . 769, 770, 803, 855, 1040, 1106, 1129, 1206, 1227), n.risk = c(26, 
 . 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 
 . 9, 8, 7, 6, 5, 4, 3, 2, 1), n.event = c(1, 1, 1, 1, 1, 1, 1, 
 . 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), n.censor = c(0, 
 . 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 
 . 1, 1, 1, 1), surv = c(0.961538461538462, 0.923076923076923, 0.884615384615385, 
 . 0.846153846153846, 0.807692307692308, 0.769230769230769, 0.730769230769231, 
 . 0.730769230769231, 0.730769230769231, 0.687782805429864, 0.687782805429864, 
 . 0.641930618401207, 0.596078431372549, 0.596078431372549, 0.54640522875817, 
 . 0.496732026143791, 0.496732026143791, 0.496732026143791, 0.496732026143791, 
 . 0.496732026143791, 0.496732026143791, 0.496732026143791, 0.496732026143791, 
 . 0.496732026143791, 0.496732026143791, 0.496732026143791), std.err = c(0.0392232270276368, 
 . 0.0566138517072298, 0.0708288246974828, 0.0836242010007091, 0.0956948752938691, 
 . 0.107417231105915, 0.119037979174001, 0.119037979174001, 0.119037979174001, 
 . 0.133590834543636, 0.133590834543636, 0.150360951832482, 0.167639259514219, 
 . 0.167639259514219, 0.188888006252999, 0.211588251084842, 0.211588251084842, 
 . 0.211588251084842, 0.211588251084842, 0.211588251084842, 0.211588251084842, 
 . 0.211588251084842, 0.211588251084842, 0.211588251084842, 0.211588251084842, 
 . 0.211588251084842), cumhaz = c(0.0384615384615385, 0.0784615384615385, 
 . 0.120128205128205, 0.16360646599777, 0.209061011452316, 0.256680059071363, 
 . 0.306680059071363, 0.306680059071363, 0.306680059071363, 0.365503588483128, 
 . 0.365503588483128, 0.432170255149795, 0.503598826578366, 0.503598826578366, 
 . 0.5869321599117, 0.67784125082079, 0.67784125082079, 0.67784125082079, 
 . 0.67784125082079, 0.67784125082079, 0.67784125082079, 0.67784125082079, 
 . 0.67784125082079, 0.67784125082079, 0.67784125082079, 0.67784125082079
 . ), std.chaz = c(0.0384615384615385, 0.0554913501442198, 0.069393090808376, 
 . 0.0818887063042364, 0.0936582934003221, 0.10506878517812, 0.11635914067578, 
 . 0.11635914067578, 0.11635914067578, 0.130382733639323, 0.130382733639323, 
 . 0.146438047227171, 0.162929869858273, 0.162929869858273, 0.183004335840652, 
 . 0.204340523994619, 0.204340523994619, 0.204340523994619, 0.204340523994619, 
 . 0.204340523994619, 0.204340523994619, 0.204340523994619, 0.204340523994619, 
 . 0.204340523994619, 0.204340523994619, 0.204340523994619), type = "right", 
 .     logse = TRUE, conf.int = 0.95, conf.type = "log", lower = c(0.890389006776242, 
 .     0.826129433945158, 0.769954183720261, 0.718237843191738, 
 .     0.669561265046851, 0.623193528520079, 0.578701944188642, 
 .     0.578701944188642, 0.578701944188642, 0.529344725133514, 
 .     0.529344725133514, 0.478080044961745, 0.429149500239206, 
 .     0.429149500239206, 0.377340207736834, 0.328108828053112, 
 .     0.328108828053112, 0.328108828053112, 0.328108828053112, 
 .     0.328108828053112, 0.328108828053112, 0.328108828053112, 
 .     0.328108828053112, 0.328108828053112, 0.328108828053112, 
 .     0.328108828053112), upper = c(1, 1, 1, 0.996851305104251, 
 .     0.974319898657336, 0.949489924480652, 0.922795705115128, 
 .     0.922795705115128, 0.922795705115128, 0.893642960786396, 
 .     0.893642960786396, 0.861937081841449, 0.827938739645533, 
 .     0.827938739645533, 0.791218820291978, 0.752014833800737, 
 .     0.752014833800737, 0.752014833800737, 0.752014833800737, 
 .     0.752014833800737, 0.752014833800737, 0.752014833800737, 
 .     0.752014833800737, 0.752014833800737, 0.752014833800737, 
 .     0.752014833800737), call = survfit(formula = surv_obj ~ 1)), class = "survfit"), 
 .     data = NULL, fun = NULL, color = NULL, palette = NULL, linetype = 1, 
 .     conf.int = TRUE, pval = FALSE, pval.method = FALSE, test.for.trend = FALSE, 
 .     surv.median.line = "none", risk.table = TRUE, cumevents = FALSE, 
 .     cumcensor = FALSE, tables.height = 0.25, ggtheme = structure(list(
 .         line = structure(list(colour = "black", linewidth = 0.545454545454545, 
 .             linetype = 1, lineend = "butt", arrow = FALSE, inherit.blank = TRUE), class = c("element_line", 
 .         "element")), rect = structure(list(fill = "white", colour = "black", 
 .             linewidth = 0.545454545454545, linetype = 1, inherit.blank = TRUE), class = c("element_rect", 
 .         "element")), text = structure(list(family = "", face = "plain", 
 .             colour = "black", size = 12, hjust = 0.5, vjust = 0.5, 
 .             angle = 0, lineheight = 0.9, margin = structure(c(0, 
 .             0, 0, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = FALSE, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), title = NULL, aspect.ratio = NULL, axis.title = NULL, 
 .         axis.title.x = structure(list(family = NULL, face = "plain", 
 .             colour = "black", size = 14, hjust = NULL, vjust = 1, 
 .             angle = NULL, lineheight = NULL, margin = structure(c(3, 
 .             0, 0, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = FALSE), class = c("element_text", 
 .         "element")), axis.title.x.top = structure(list(family = NULL, 
 .             face = NULL, colour = NULL, size = NULL, hjust = NULL, 
 .             vjust = 0, angle = NULL, lineheight = NULL, margin = structure(c(0, 
 .             0, 3, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), axis.title.x.bottom = NULL, axis.title.y = structure(list(
 .             family = NULL, face = "plain", colour = "black", 
 .             size = 14, hjust = NULL, vjust = 1, angle = 90, lineheight = NULL, 
 .             margin = structure(c(0, 3, 0, 0), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = FALSE), class = c("element_text", 
 .         "element")), axis.title.y.left = NULL, axis.title.y.right = structure(list(
 .             family = NULL, face = NULL, colour = NULL, size = NULL, 
 .             hjust = NULL, vjust = 0, angle = -90, lineheight = NULL, 
 .             margin = structure(c(0, 0, 0, 3), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = TRUE), class = c("element_text", 
 .         "element")), axis.text = structure(list(family = NULL, 
 .             face = NULL, colour = "grey30", size = structure(0.8, class = "rel"), 
 .             hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL, 
 .             margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), axis.text.x = structure(list(family = NULL, 
 .             face = "plain", colour = "black", size = 12, hjust = NULL, 
 .             vjust = 1, angle = 0, lineheight = NULL, margin = structure(c(2.4, 
 .             0, 0, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = FALSE), class = c("element_text", 
 .         "element")), axis.text.x.top = structure(list(family = NULL, 
 .             face = NULL, colour = NULL, size = NULL, hjust = NULL, 
 .             vjust = 0, angle = NULL, lineheight = NULL, margin = structure(c(0, 
 .             0, 2.4, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), axis.text.x.bottom = NULL, axis.text.y = structure(list(
 .             family = NULL, face = "plain", colour = "black", 
 .             size = 12, hjust = 1, vjust = NULL, angle = 0, lineheight = NULL, 
 .             margin = structure(c(0, 2.4, 0, 0), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = FALSE), class = c("element_text", 
 .         "element")), axis.text.y.left = NULL, axis.text.y.right = structure(list(
 .             family = NULL, face = NULL, colour = NULL, size = NULL, 
 .             hjust = 0, vjust = NULL, angle = NULL, lineheight = NULL, 
 .             margin = structure(c(0, 0, 0, 2.4), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = TRUE), class = c("element_text", 
 .         "element")), axis.ticks = structure(list(colour = "grey20", 
 .             linewidth = NULL, linetype = NULL, lineend = NULL, 
 .             arrow = FALSE, inherit.blank = TRUE), class = c("element_line", 
 .         "element")), axis.ticks.x = NULL, axis.ticks.x.top = NULL, 
 .         axis.ticks.x.bottom = NULL, axis.ticks.y = NULL, axis.ticks.y.left = NULL, 
 .         axis.ticks.y.right = NULL, axis.ticks.length = structure(3, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), axis.ticks.length.x = NULL, axis.ticks.length.x.top = NULL, 
 .         axis.ticks.length.x.bottom = NULL, axis.ticks.length.y = NULL, 
 .         axis.ticks.length.y.left = NULL, axis.ticks.length.y.right = NULL, 
 .         axis.line = structure(list(colour = "black", linewidth = structure(1, class = "rel"), 
 .             linetype = NULL, lineend = NULL, arrow = FALSE, inherit.blank = TRUE), class = c("element_line", 
 .         "element")), axis.line.x = NULL, axis.line.x.top = NULL, 
 .         axis.line.x.bottom = NULL, axis.line.y = NULL, axis.line.y.left = NULL, 
 .         axis.line.y.right = NULL, legend.background = structure(list(
 .             fill = NULL, colour = NA, linewidth = NULL, linetype = NULL, 
 .             inherit.blank = TRUE), class = c("element_rect", 
 .         "element")), legend.margin = structure(c(6, 6, 6, 6), unit = 8L, class = c("margin", 
 .         "simpleUnit", "unit", "unit_v2")), legend.spacing = structure(12, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), legend.spacing.x = NULL, legend.spacing.y = NULL, 
 .         legend.key = structure(list(), class = c("element_blank", 
 .         "element")), legend.key.size = structure(1.2, unit = 3L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), legend.key.height = NULL, legend.key.width = NULL, 
 .         legend.text = structure(list(family = NULL, face = "plain", 
 .             colour = "black", size = 10, hjust = NULL, vjust = NULL, 
 .             angle = NULL, lineheight = NULL, margin = NULL, debug = NULL, 
 .             inherit.blank = FALSE), class = c("element_text", 
 .         "element")), legend.text.align = NULL, legend.title = structure(list(
 .             family = NULL, face = "plain", colour = "black", 
 .             size = 10, hjust = 0, vjust = NULL, angle = NULL, 
 .             lineheight = NULL, margin = NULL, debug = NULL, inherit.blank = FALSE), class = c("element_text", 
 .         "element")), legend.title.align = NULL, legend.position = "top", 
 .         legend.direction = NULL, legend.justification = "center", 
 .         legend.box = NULL, legend.box.just = NULL, legend.box.margin = structure(c(0, 
 .         0, 0, 0), unit = 1L, class = c("margin", "simpleUnit", 
 .         "unit", "unit_v2")), legend.box.background = structure(list(), class = c("element_blank", 
 .         "element")), legend.box.spacing = structure(12, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), panel.background = structure(list(
 .             fill = "white", colour = NA, linewidth = NULL, linetype = NULL, 
 .             inherit.blank = TRUE), class = c("element_rect", 
 .         "element")), panel.border = structure(list(), class = c("element_blank", 
 .         "element")), panel.spacing = structure(6, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), panel.spacing.x = NULL, panel.spacing.y = NULL, 
 .         panel.grid = structure(list(colour = "grey92", linewidth = NULL, 
 .             linetype = NULL, lineend = NULL, arrow = FALSE, inherit.blank = TRUE), class = c("element_line", 
 .         "element")), panel.grid.major = structure(list(), class = c("element_blank", 
 .         "element")), panel.grid.minor = structure(list(), class = c("element_blank", 
 .         "element")), panel.grid.major.x = NULL, panel.grid.major.y = NULL, 
 .         panel.grid.minor.x = NULL, panel.grid.minor.y = NULL, 
 .         panel.ontop = FALSE, plot.background = structure(list(
 .             fill = NULL, colour = "white", linewidth = NULL, 
 .             linetype = NULL, inherit.blank = TRUE), class = c("element_rect", 
 .         "element")), plot.title = structure(list(family = NULL, 
 .             face = "plain", colour = "black", size = 16, hjust = 0, 
 .             vjust = 1, angle = NULL, lineheight = 1, margin = structure(c(0, 
 .             0, 6, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = FALSE), class = c("element_text", 
 .         "element")), plot.title.position = "panel", plot.subtitle = structure(list(
 .             family = NULL, face = "plain", colour = "black", 
 .             size = 15, hjust = 0, vjust = 1, angle = NULL, lineheight = 1, 
 .             margin = structure(c(0, 0, 6, 0), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = FALSE), class = c("element_text", 
 .         "element")), plot.caption = structure(list(family = NULL, 
 .             face = "plain", colour = "black", size = 15, hjust = 1, 
 .             vjust = 1, angle = NULL, lineheight = 1, margin = structure(c(6, 
 .             0, 0, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = FALSE), class = c("element_text", 
 .         "element")), plot.caption.position = "panel", plot.tag = structure(list(
 .             family = NULL, face = NULL, colour = NULL, size = structure(1.2, class = "rel"), 
 .             hjust = 0.5, vjust = 0.5, angle = NULL, lineheight = NULL, 
 .             margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), plot.tag.position = "topleft", plot.margin = structure(c(6, 
 .         6, 6, 6), unit = 8L, class = c("margin", "simpleUnit", 
 .         "unit", "unit_v2")), strip.background = structure(list(
 .             fill = "white", colour = "black", linewidth = structure(2, class = "rel"), 
 .             linetype = NULL, inherit.blank = TRUE), class = c("element_rect", 
 .         "element")), strip.background.x = NULL, strip.background.y = NULL, 
 .         strip.clip = "inherit", strip.placement = "inside", strip.text = structure(list(
 .             family = NULL, face = NULL, colour = "grey10", size = structure(0.8, class = "rel"), 
 .             hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL, 
 .             margin = structure(c(4.8, 4.8, 4.8, 4.8), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = TRUE), class = c("element_text", 
 .         "element")), strip.text.x = NULL, strip.text.x.bottom = NULL, 
 .         strip.text.x.top = NULL, strip.text.y = structure(list(
 .             family = NULL, face = NULL, colour = NULL, size = NULL, 
 .             hjust = NULL, vjust = NULL, angle = -90, lineheight = NULL, 
 .             margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), strip.text.y.left = structure(list(family = NULL, 
 .             face = NULL, colour = NULL, size = NULL, hjust = NULL, 
 .             vjust = NULL, angle = 90, lineheight = NULL, margin = NULL, 
 .             debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), strip.text.y.right = NULL, strip.switch.pad.grid = structure(3, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), strip.switch.pad.wrap = structure(3, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2"))), class = "theme", complete = TRUE, validate = TRUE), 
 .     tables.theme = structure(list(line = structure(list(colour = "black", 
 .         linewidth = 0.545454545454545, linetype = 1, lineend = "butt", 
 .         arrow = FALSE, inherit.blank = TRUE), class = c("element_line", 
 .     "element")), rect = structure(list(fill = "white", colour = "black", 
 .         linewidth = 0.545454545454545, linetype = 1, inherit.blank = TRUE), class = c("element_rect", 
 .     "element")), text = structure(list(family = "", face = "plain", 
 .         colour = "black", size = 12, hjust = 0.5, vjust = 0.5, 
 .         angle = 0, lineheight = 0.9, margin = structure(c(0, 
 .         0, 0, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .         "unit", "unit_v2")), debug = FALSE, inherit.blank = TRUE), class = c("element_text", 
 .     "element")), title = NULL, aspect.ratio = NULL, axis.title = NULL, 
 .         axis.title.x = structure(list(family = NULL, face = "plain", 
 .             colour = "black", size = 14, hjust = NULL, vjust = 1, 
 .             angle = NULL, lineheight = NULL, margin = structure(c(3, 
 .             0, 0, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = FALSE), class = c("element_text", 
 .         "element")), axis.title.x.top = structure(list(family = NULL, 
 .             face = NULL, colour = NULL, size = NULL, hjust = NULL, 
 .             vjust = 0, angle = NULL, lineheight = NULL, margin = structure(c(0, 
 .             0, 3, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), axis.title.x.bottom = NULL, axis.title.y = structure(list(
 .             family = NULL, face = "plain", colour = "black", 
 .             size = 14, hjust = NULL, vjust = 1, angle = 90, lineheight = NULL, 
 .             margin = structure(c(0, 3, 0, 0), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = FALSE), class = c("element_text", 
 .         "element")), axis.title.y.left = NULL, axis.title.y.right = structure(list(
 .             family = NULL, face = NULL, colour = NULL, size = NULL, 
 .             hjust = NULL, vjust = 0, angle = -90, lineheight = NULL, 
 .             margin = structure(c(0, 0, 0, 3), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = TRUE), class = c("element_text", 
 .         "element")), axis.text = structure(list(family = NULL, 
 .             face = NULL, colour = "grey30", size = structure(0.8, class = "rel"), 
 .             hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL, 
 .             margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), axis.text.x = structure(list(family = NULL, 
 .             face = "plain", colour = "black", size = 12, hjust = NULL, 
 .             vjust = 1, angle = 0, lineheight = NULL, margin = structure(c(2.4, 
 .             0, 0, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = FALSE), class = c("element_text", 
 .         "element")), axis.text.x.top = structure(list(family = NULL, 
 .             face = NULL, colour = NULL, size = NULL, hjust = NULL, 
 .             vjust = 0, angle = NULL, lineheight = NULL, margin = structure(c(0, 
 .             0, 2.4, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), axis.text.x.bottom = NULL, axis.text.y = structure(list(
 .             family = NULL, face = "plain", colour = "black", 
 .             size = 12, hjust = 1, vjust = NULL, angle = 0, lineheight = NULL, 
 .             margin = structure(c(0, 2.4, 0, 0), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = FALSE), class = c("element_text", 
 .         "element")), axis.text.y.left = NULL, axis.text.y.right = structure(list(
 .             family = NULL, face = NULL, colour = NULL, size = NULL, 
 .             hjust = 0, vjust = NULL, angle = NULL, lineheight = NULL, 
 .             margin = structure(c(0, 0, 0, 2.4), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = TRUE), class = c("element_text", 
 .         "element")), axis.ticks = structure(list(colour = "grey20", 
 .             linewidth = NULL, linetype = NULL, lineend = NULL, 
 .             arrow = FALSE, inherit.blank = TRUE), class = c("element_line", 
 .         "element")), axis.ticks.x = NULL, axis.ticks.x.top = NULL, 
 .         axis.ticks.x.bottom = NULL, axis.ticks.y = NULL, axis.ticks.y.left = NULL, 
 .         axis.ticks.y.right = NULL, axis.ticks.length = structure(3, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), axis.ticks.length.x = NULL, axis.ticks.length.x.top = NULL, 
 .         axis.ticks.length.x.bottom = NULL, axis.ticks.length.y = NULL, 
 .         axis.ticks.length.y.left = NULL, axis.ticks.length.y.right = NULL, 
 .         axis.line = structure(list(colour = "black", linewidth = structure(1, class = "rel"), 
 .             linetype = NULL, lineend = NULL, arrow = FALSE, inherit.blank = TRUE), class = c("element_line", 
 .         "element")), axis.line.x = NULL, axis.line.x.top = NULL, 
 .         axis.line.x.bottom = NULL, axis.line.y = NULL, axis.line.y.left = NULL, 
 .         axis.line.y.right = NULL, legend.background = structure(list(
 .             fill = NULL, colour = NA, linewidth = NULL, linetype = NULL, 
 .             inherit.blank = TRUE), class = c("element_rect", 
 .         "element")), legend.margin = structure(c(6, 6, 6, 6), unit = 8L, class = c("margin", 
 .         "simpleUnit", "unit", "unit_v2")), legend.spacing = structure(12, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), legend.spacing.x = NULL, legend.spacing.y = NULL, 
 .         legend.key = structure(list(), class = c("element_blank", 
 .         "element")), legend.key.size = structure(1.2, unit = 3L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), legend.key.height = NULL, legend.key.width = NULL, 
 .         legend.text = structure(list(family = NULL, face = "plain", 
 .             colour = "black", size = 10, hjust = NULL, vjust = NULL, 
 .             angle = NULL, lineheight = NULL, margin = NULL, debug = NULL, 
 .             inherit.blank = FALSE), class = c("element_text", 
 .         "element")), legend.text.align = NULL, legend.title = structure(list(
 .             family = NULL, face = "plain", colour = "black", 
 .             size = 10, hjust = 0, vjust = NULL, angle = NULL, 
 .             lineheight = NULL, margin = NULL, debug = NULL, inherit.blank = FALSE), class = c("element_text", 
 .         "element")), legend.title.align = NULL, legend.position = "top", 
 .         legend.direction = NULL, legend.justification = "center", 
 .         legend.box = NULL, legend.box.just = NULL, legend.box.margin = structure(c(0, 
 .         0, 0, 0), unit = 1L, class = c("margin", "simpleUnit", 
 .         "unit", "unit_v2")), legend.box.background = structure(list(), class = c("element_blank", 
 .         "element")), legend.box.spacing = structure(12, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), panel.background = structure(list(
 .             fill = "white", colour = NA, linewidth = NULL, linetype = NULL, 
 .             inherit.blank = TRUE), class = c("element_rect", 
 .         "element")), panel.border = structure(list(), class = c("element_blank", 
 .         "element")), panel.spacing = structure(6, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), panel.spacing.x = NULL, panel.spacing.y = NULL, 
 .         panel.grid = structure(list(colour = "grey92", linewidth = NULL, 
 .             linetype = NULL, lineend = NULL, arrow = FALSE, inherit.blank = TRUE), class = c("element_line", 
 .         "element")), panel.grid.major = structure(list(), class = c("element_blank", 
 .         "element")), panel.grid.minor = structure(list(), class = c("element_blank", 
 .         "element")), panel.grid.major.x = NULL, panel.grid.major.y = NULL, 
 .         panel.grid.minor.x = NULL, panel.grid.minor.y = NULL, 
 .         panel.ontop = FALSE, plot.background = structure(list(
 .             fill = NULL, colour = "white", linewidth = NULL, 
 .             linetype = NULL, inherit.blank = TRUE), class = c("element_rect", 
 .         "element")), plot.title = structure(list(family = NULL, 
 .             face = "plain", colour = "black", size = 16, hjust = 0, 
 .             vjust = 1, angle = NULL, lineheight = 1, margin = structure(c(0, 
 .             0, 6, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = FALSE), class = c("element_text", 
 .         "element")), plot.title.position = "panel", plot.subtitle = structure(list(
 .             family = NULL, face = "plain", colour = "black", 
 .             size = 15, hjust = 0, vjust = 1, angle = NULL, lineheight = 1, 
 .             margin = structure(c(0, 0, 6, 0), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = FALSE), class = c("element_text", 
 .         "element")), plot.caption = structure(list(family = NULL, 
 .             face = "plain", colour = "black", size = 15, hjust = 1, 
 .             vjust = 1, angle = NULL, lineheight = 1, margin = structure(c(6, 
 .             0, 0, 0), unit = 8L, class = c("margin", "simpleUnit", 
 .             "unit", "unit_v2")), debug = NULL, inherit.blank = FALSE), class = c("element_text", 
 .         "element")), plot.caption.position = "panel", plot.tag = structure(list(
 .             family = NULL, face = NULL, colour = NULL, size = structure(1.2, class = "rel"), 
 .             hjust = 0.5, vjust = 0.5, angle = NULL, lineheight = NULL, 
 .             margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), plot.tag.position = "topleft", plot.margin = structure(c(6, 
 .         6, 6, 6), unit = 8L, class = c("margin", "simpleUnit", 
 .         "unit", "unit_v2")), strip.background = structure(list(
 .             fill = "white", colour = "black", linewidth = structure(2, class = "rel"), 
 .             linetype = NULL, inherit.blank = TRUE), class = c("element_rect", 
 .         "element")), strip.background.x = NULL, strip.background.y = NULL, 
 .         strip.clip = "inherit", strip.placement = "inside", strip.text = structure(list(
 .             family = NULL, face = NULL, colour = "grey10", size = structure(0.8, class = "rel"), 
 .             hjust = NULL, vjust = NULL, angle = NULL, lineheight = NULL, 
 .             margin = structure(c(4.8, 4.8, 4.8, 4.8), unit = 8L, class = c("margin", 
 .             "simpleUnit", "unit", "unit_v2")), debug = NULL, 
 .             inherit.blank = TRUE), class = c("element_text", 
 .         "element")), strip.text.x = NULL, strip.text.x.bottom = NULL, 
 .         strip.text.x.top = NULL, strip.text.y = structure(list(
 .             family = NULL, face = NULL, colour = NULL, size = NULL, 
 .             hjust = NULL, vjust = NULL, angle = -90, lineheight = NULL, 
 .             margin = NULL, debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), strip.text.y.left = structure(list(family = NULL, 
 .             face = NULL, colour = NULL, size = NULL, hjust = NULL, 
 .             vjust = NULL, angle = 90, lineheight = NULL, margin = NULL, 
 .             debug = NULL, inherit.blank = TRUE), class = c("element_text", 
 .         "element")), strip.text.y.right = NULL, strip.switch.pad.grid = structure(3, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2")), strip.switch.pad.wrap = structure(3, unit = 8L, class = c("simpleUnit", 
 .         "unit", "unit_v2"))), class = "theme", complete = TRUE, validate = TRUE), 
 .     conf.int.fill = "strata")
4. .get_data(fit, data = data, complain = FALSE)
5. stop("The `data` argument should be provided either to ggsurvfit or survfit.")

assistant:


user:

次の結果が得られました。

Warning message in data("ovarian"):
“data set ‘ovarian’ not found”

assistant:

このエラーメッセージは、"ovarian"という名前のデータセットが見つからないために表示されています。これは、次の理由のいずれかによるものです。

  1. データセットがインストールされていない。"ovarian"データセットは特定のパッケージに属している可能性があるので、そのパッケージをインストールして読み込んでみてください。
  2. データセットの名前が間違っている。データセットの名前が正しくない場合にこのエラーが発生します。スペルミスや大文字小文字の違いに注意してください。
  3. ワーキングディレクトリにデータセットが存在しない。Rは現在のワーキングディレクトリでデータセットを探しますので、データセットをワーキングディレクトリに保存するか、データセットのパスを正しく指定する必要があります。

エラーを解決するには、上記の問題を確認して修正してみてください。


user:

Google Colaboratory特有の問題でしょうか?


assistant:

Google Colaboratory(通常Colabと略されます)では、Rプログラミングをサポートしていません。Google Colabは主にPythonの実行環境として使用されます。

そのため、"ovarian"という名前のデータセットが見つからないというエラーは、Google Colab特有の問題というよりは、Rプログラミングに関連した問題である可能性が高いです。

RとPythonは異なるプログラミング言語であり、それぞれ異なるパッケージやデータセットの管理方法を持っています。したがって、R用のデータセットをPythonのGoogle Colabで直接使用することは基本的に不可能です。

Pythonでデータセットを使用したい場合は、Python用のデータセットにアクセスするか、データをPythonが読み込める形式(CSVやExcelなど)に変換してから読み込む必要があります。


user:

Rで使える survival と Survminer などのパッケージのインストール先を、現在のワーキングディレクトリに指定することはできますか?


assistant:

Rでパッケージをインストールする際に、そのインストール先ディレクトリを指定することは可能です。しかし、一般的には推奨されません。Rのバージョンや他のパッケージとの依存関係など、細かい設定を手動で管理する必要があり、それがエラーや問題を引き起こす可能性があるからです。

Rのパッケージは通常、Rのライブラリのディレクトリにインストールされます。このディレクトリは .libPaths() という関数を実行することで確認できます。また、.libPaths(new_path) とすることでライブラリのパスを新しいパスに変更することが可能です。

パッケージのインストール先を指定するには install.packages() 関数の lib 引数を使用します。以下に一例を示します。

install.packages("survival", lib = "/your/directory/")

ただし、改めて注意を促したいのが、この方法を使用するとパッケージが新たにインストールされるディレクトリを追加、または変更する必要があるときには .libPaths() を使用して適切に設定する必要があるという点です。

もしも特定のパッケージを特定のプロジェクトだけで使いたいという場面では、"packrat" や "renv" のようなパッケージ管理ツールを使用することをお勧めします。これらのツールを使用すると、プロジェクトごとに独立したパッケージの環境を作成し、パッケージのバージョンを固定することができます。


user:

install.packages("survival", lib = ".")

のようにすると、Google Colaboratory 上にインストールされたことを確認できました。ここから

data(lung)

のようにしてもまだ読み込めませんが、このコードを改変して、読み込めるようにできますか?


assistant:

コードinstall.packages("survival", lib = ".")にて、Google Colaboratory上に"survival"パッケージをインストールできた場合、データを読み込む前にパッケージを読み込む必要があります。lib引数が指定されているため、具体的には以下のように行う必要があります。

# survivalパッケージの読み込み
library(survival, lib.loc = ".") 

# データの読み込み
data(lung)

ここでlibrary(パッケージ名, lib.loc=パッケージの場所)とすることで、特定の場所にインストールしたパッケージを読み込めます。上記コードではカレントディレクトリからパッケージを読み込んでいます。この後にdata(lung)を実行すれば、lungデータを読み込むことができます。


user:

ありがとうございます。まだ読み込めないですね。

Warning message in data(lung):
“data set ‘lung’ not found”

assistant:

すみません、ミスがありました。書き込み先がワーキングディレクトリ指定の場合は data() メソッドではなく read.table()read.csv() などからデータファイルを読み込む必要があります。

ただし、エラーメッセージを見る限り、lung データセットは現在のワーキングディレクトリに存在していないようです。

一度、ワーキングディレクトリを確認し、適切なディレクトリに lung データセットが存在するかどうかをご確認ください。Rのワーキングディレクトリはgetwd()関数で確認できます。

また、"lung"データセットはsurvivalパッケージに含まれていますので、上記の方法でパッケージを読み込むことができていれば、lungデータセットにもアクセスできるはずです。

以下のコードを試してみてください。

# survivalパッケージの読み込み
library(survival, lib.loc = ".") 

# lungデータセットの存在確認
exists("lung")

exists("lung")TRUE を返すなら、lungデータセットにアクセスできているはずです。

もしこれでもアクセスできない場合は、パッケージが正しくインストールできていない可能性があります。

なお、Google Colabは主にPython用の環境であり、Rの一部機能が正常に動作しない場合があります。そのため、もし可能であればローカル環境でRを実行することをお勧めします。


user:

exists("lung")

の結果として

TRUE

が返ってきました。また、ディレクトリ構成を確認すると

./survival/R/survival
./survival/R/survival.rdb
./survival/R/survival.rdx
./survival/R/data/Rdata.rdb
./survival/R/data/Rdata.rds
./survival/R/data/Rdata.rdx

のようになっていました。


assistant:

exists("lung")TRUEを返してきたとのことで、lungデータセットは存在していることが確認できました。

また、ディレクトリ構成から見るに、.rdb.rdsといった形式でデータが格納されているようです。

Rには内蔵されているデータセットにアクセスする際の機能がいくつか存在し、その一つがdata()です。しかし、data()は特定のパスへのアクセスはサポートしていません。

したがって、次に試すべきなのは save() 関数を使ってデータを保存し、それを load() 関数で読み込むという方法です。

まず、現在のワーキングディレクトリに lung データセットを保存してみてください。

# lungデータセットの保存
save(lung, file = "./lung.RData")

保存できたら、そのファイルを load() 関数で読み込みます。

# lungデータセットの読み込み
load("./lung.RData")

この操作により、lung データセットが現在のワーキングディレクトリに存在する状態で R に読み込まれるはずです。

もし save()load() 関数でエラーが生じた場合は、それらのエラーメッセージをご提供いただければと思います。


user:

ありがとうございます。上記コードはエラーなく実行できたようです。ですがその後に改めて

data(lung)

を実行してもまだ

Warning message in data(lung):
“data set ‘lung’ not found”

のままです。


assistant:

少し説明が不足してしまっていました。save()load()関数によってlungデータセットを現在のワーキングディレクトリに保存し、そのデータを読み込んだ後は、data()関数ではなく直接lungと記述してデータセットにアクセスすることができるはずです。つまり、以下のようにします。

# lungデータセットの確認
lung

data()関数はパッケージに内包されているデータセットを読み込むためのもので、特定のディレクトリにある.RDataファイルを読み込むためのものではありません。

これによりlungデータセットに正しくアクセスできることを確認してください。もしエラーが出る場合は、そのエラーメッセージをご提供いただければと思います。

A data.frame: 228 × 10
inst time status age sex ph.ecog ph.karno pat.karno meal.cal wt.loss
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 3 306 2 74 1 1 90 100 1175 NA
2 3 455 2 68 1 0 90 90 1225 15
3 3 1010 1 56 1 0 90 90 NA 15
4 5 210 2 57 1 1 90 60 1150 11
5 1 883 2 60 1 0 100 90 NA 0
6 12 1022 1 74 1 1 50 80 513 0
7 7 310 2 68 2 2 70 60 384 10
8 11 361 2 71 2 2 60 80 538 1
9 1 218 2 53 1 1 70 80 825 16
10 7 166 2 61 1 2 70 70 271 34
11 6 170 2 57 1 1 80 80 1025 27
12 16 654 2 68 2 2 70 70 NA 23
13 11 728 2 68 2 1 90 90 NA 5
14 21 71 2 60 1 NA 60 70 1225 32
15 12 567 2 57 1 1 80 70 2600 60
16 1 144 2 67 1 1 80 90 NA 15
17 22 613 2 70 1 1 90 100 1150 -5
18 16 707 2 63 1 2 50 70 1025 22
19 1 61 2 56 2 2 60 60 238 10
20 21 88 2 57 1 1 90 80 1175 NA
21 11 301 2 67 1 1 80 80 1025 17
22 6 81 2 49 2 0 100 70 1175 -8
23 11 624 2 50 1 1 70 80 NA 16
24 15 371 2 58 1 0 90 100 975 13
25 12 394 2 72 1 0 90 80 NA 0
26 12 520 2 70 2 1 90 80 825 6
27 4 574 2 60 1 0 100 100 1025 -13
28 13 118 2 70 1 3 60 70 1075 20
29 13 390 2 53 1 1 80 70 875 -7
30 1 12 2 74 1 2 70 50 305 20
199 1 276 1 52 2 0 100 80 975 0
200 32 135 2 60 1 1 90 70 1275 0
201 15 79 2 64 2 1 90 90 488 37
202 22 59 2 73 1 1 60 60 2200 5
203 32 240 1 63 2 0 90 100 1025 0
204 3 202 1 50 2 0 100 100 635 1
205 26 235 1 63 2 0 100 90 413 0
206 33 105 2 62 1 2 NA 70 NA NA
207 5 224 1 55 2 0 80 90 NA 23
208 13 239 2 50 2 2 60 60 1025 -3
209 21 237 1 69 1 1 80 70 NA NA
210 33 173 1 59 2 1 90 80 NA 10
211 1 252 1 60 2 0 100 90 488 -2
212 6 221 1 67 1 1 80 70 413 23
213 15 185 1 69 1 1 90 70 1075 0
214 11 92 1 64 2 2 70 100 NA 31
215 11 13 2 65 1 1 80 90 NA 10
216 11 222 1 65 1 1 90 70 1025 18
217 13 192 1 41 2 1 90 80 NA -10
218 21 183 2 76 1 2 80 60 825 7
219 11 211 1 70 2 2 70 30 131 3
220 2 175 1 57 2 0 80 80 725 11
221 22 197 1 67 1 1 80 90 1500 2
222 11 203 1 71 2 1 80 90 1025 0
223 1 116 2 76 1 1 80 80 NA 0
224 1 188 1 77 1 1 80 60 NA 3
225 13 191 1 39 1 0 90 90 2350 -5
226 32 105 1 75 2 2 60 70 1025 5
227 6 174 1 66 1 1 90 100 1075 1
228 22 177 1 58 2 1 80 90 1060 0

user:

おお。できました。ありがとうございます。


assistant:

うまくいって良かったです!お手数をおかけしました。もしご不明な点や新たな問題が出てきましたら、いつでもお気軽にご質問ください。Rのコーディングにお手伝いできることがあれば何でもお知らせください。引き続き楽しいコーディングライフをお過ごしください!


user:

では、ここまでのまとめを書いてもらってよろしいでしょうか。


assistant:

もちろんです。まとめさせていただきます。

このスレッドでは、特定のRパッケージ(survival)をGoogle Colaboratory上にインストールし、そのパッケージ内のデータセット(lung)にアクセスしようとするときのエラーに対処しました。

まず、Rのパッケージは特定のディレクトリ(ワーキングディレクトリ)にインストールすることが可能であることを見ました。そのため、次のコードでパッケージをインストールしました。

install.packages("survival", lib = ".")

次に、特定のディレクトリからパッケージを読み込むには、インストールした位置を指定する必要があることを確認しました。

library(survival, lib.loc = ".")

しかし、data()関数はあくまでパッケージに添付されているデータを読み込むもので、特定のディレクトリにあるRのデータファイル(.RDataファイル)を読み込むものではないため、以下のようなエラーメッセージが出力されました。

Warning message in data(lung):
“data set ‘lung’ not found”

この問題解決のために、まずsave()load()関数を使用してlungデータセットをワーキングディレクトリに保存し、そのデータを読み込みました。

# lungデータセットの保存
save(lung, file = "./lung.RData")

# lungデータセットの読み込み
load("./lung.RData")

そして、保存・読み込み後は、data()関数ではなく直接lungと記述してデータセットにアクセスしました。

# lungデータセットの確認
lung

この結果、問題なくlungデータセットにアクセスできることを確認しました。

以上がこのスレッドでの問題解決の主要なステップです。この情報が今後のRプログラミングに役立つことを願っています。


user:

ありがとうございます。実はまだ「Google Colab で R : カプランマイヤー法と生存曲線 編」は始まったばかりです。このデータを用いて、Rでカプランマイヤー曲線を描画するコードを書いてください。


assistant:

まずは、survminerパッケージをインストールし、読み込むところから始めましょう。このパッケージは生存分析のための便利な機能を提供します。

# survminerパッケージのインストール
install.packages("survminer", lib = ".")

# survminerパッケージの読み込み
library(survminer, lib.loc = ".")

そして、以下のコードでカプランマイヤー曲線を描画できます。

# サバイバルオブジェクトの作成
surv_obj <- Surv(time = lung$time, event = lung$status)

# データのフィット(カプランマイヤー推定量の計算)
fit <- survfit(surv_obj ~ 1)

# 生存曲線の描画
ggsurvplot(fit)

以上のコードでは、ggsurvplot()関数(survminer パッケージの一部)を使用して生存曲線を描画しています。各行の説明は以下の通りです:

  1. Surv()関数でサバイバルオブジェクトを作成。time は生存時間を、event は観測終了時にイベントが発生したかどうかを表します。
  2. survfit()関数でデータをフィットし、カプランマイヤーの生存曲線を計算します。この関数はサバイバルオブジェクトとそのオブジェクトに関連する他の変数(ここではなし)を引数に取ります。
  3. ggsurvplot()関数で生存曲線を描画します。この関数はsurvfit()関数の出力を引数に取ります。

注意: データセットおよびパッケージの読み込みに問題が出た際には、前述のインストールと読み込みのステップを確認してみてください。


user:

ありがとうございます。上記コードをベースに、改変した全コードを書いてください。

Error in .get_data(fit, data = data, complain = FALSE): The `data` argument should be provided either to ggsurvfit or survfit.
Traceback:

1. ggsurvplot(fit)
2. do.call(ggsurvplot_core, opts)
3. (function (fit, data = NULL, fun = NULL, color = NULL, palette = NULL, 

(中略)  

4. .get_data(fit, data = data, complain = FALSE)
5. stop("The `data` argument should be provided either to ggsurvfit or survfit.")

assistant:

申し訳ありません、エラーが発生してしまったようです。ggsurvplot()関数のdata引数にデータセット(この場合はlung)を渡すことでこの問題は解決します。

# survivalパッケージの読み込み
library(survival, lib.loc = ".") 

# survminerパッケージのインストール
install.packages("survminer", lib = ".")

# survminerパッケージの読み込み
library(survminer, lib.loc = ".")

# lungデータセットの保存
save(lung, file = "./lung.RData")

# lungデータセットの読み込み
load("./lung.RData")

# lungデータセットの確認
lung

# サバイバルオブジェクトの作成
surv_obj <- Surv(time = lung$time, event = lung$status - 1)

# データのフィット(カプランマイヤー推定量の計算)
fit <- survfit(surv_obj ~ 1, data = lung)

# 生存曲線の描画
ggsurvplot(fit, data = lung)

注意点として、lungデータセットのstatusフィールドは2が死亡、1が打ち切り(観測終了時に生存)を表していますが、Surv()関数はイベントが発生した場合に1、発生しなかった場合に0を期待します。そのため、event = lung$status - 1としてstatusフィールドを変換しています。

また、survfit()ggsurvplot()関数のdata引数にデータセットを渡しています。survfit()はこのデータを使用してモデルをフィットし、ggsurvplot()はこのデータを使用してプロットを作成します。

この修正により、上記のエラーは解消され、生存曲線のプロットが正しく表示されるはずです。エラーが引き続き発生する場合はお知らせください。


user:

でーーきたーーー!!

output_16_1.png


assistant:

素晴らしいです!問題が解決し、カプランマイヤー曲線を生成できてとても嬉しいです。

カプランマイヤー曲線は、生存分析や信頼性分析の重要なツールです。さまざまな条件下での生存結果を視覚的に比較するのに非常に有用です。また、カプランマイヤー曲線はさまざまな統計的分析(例えば、生存時間の比較や、特定の変数が生存にどの程度影響を及ぼすかを評価するためのコックス比例ハザードモデルなど)の基礎となります。

Rで生存分析を進める際は、survminerパッケージの他にもsurvivalパッケージやsurvplotパッケージなど、いくつかの有用なパッケージがあります。これらのパッケージはそれぞれ異なる特性や機能を持っており、タスクや目的によって使い分けることができます。

データ分析を進める中で何かご不明な点がありましたら、いつでも質問してください。引き続き楽しいデータ分析ライフをお過ごしください!


user:

2つの群について、生存期間が有意に異なるかどうかを調べるためのRコードを作成してください。また、それを実行するためのデータがあれば使ってみたいです。


assistant:

2つの群の生存期間を比較する一般的なテストはlog-rankテストと呼ばれます。ここでは、再びsurvivalパッケージのsurvfit()関数とsurvdiff()関数を使用します。

利用できるデータセットとしては、先程のlungデータセットを利用します。このデータにはsexというフィールドがありますが、これを2つの群(男性と女性)として利用することが可能です。

# survivalパッケージの読み込み
library(survival, lib.loc = ".")

# lungデータセットの保存
save(lung, file = "./lung.RData")

# lungデータセットの読み込み
load("./lung.RData")

# lungデータセットの確認
lung

# サバイバルオブジェクトの作成
surv_obj <- Surv(time = lung$time, event = lung$status - 1)

# データのフィット(カプランマイヤー推定量の計算)
fit <- survfit(surv_obj ~ sex, data = lung)

# 各群の生存曲線を描画
plot(fit, col=c(2,1))

# log-rankテストを行う
res.logrank <- survdiff(surv_obj ~ sex, data = lung)
print(res.logrank)

上記のコードを実行すると、log-rankテストの結果が表示され、2つの群の生存曲線が異なるかどうかについてのp値が得られます。p値が0.05未満であれば、2つの群は有意に異なると言えます。

注意: sexフィールドの値は1が男性、2が女性を表しています。


user:

ありがとうございます。次のような結果が得られました。

A data.frame: 228 × 10
inst time status age sex ph.ecog ph.karno pat.karno meal.cal wt.loss
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 3 306 2 74 1 1 90 100 1175 NA
2 3 455 2 68 1 0 90 90 1225 15
3 3 1010 1 56 1 0 90 90 NA 15
4 5 210 2 57 1 1 90 60 1150 11
5 1 883 2 60 1 0 100 90 NA 0
6 12 1022 1 74 1 1 50 80 513 0
7 7 310 2 68 2 2 70 60 384 10
8 11 361 2 71 2 2 60 80 538 1
9 1 218 2 53 1 1 70 80 825 16
10 7 166 2 61 1 2 70 70 271 34
11 6 170 2 57 1 1 80 80 1025 27
12 16 654 2 68 2 2 70 70 NA 23
13 11 728 2 68 2 1 90 90 NA 5
14 21 71 2 60 1 NA 60 70 1225 32
15 12 567 2 57 1 1 80 70 2600 60
16 1 144 2 67 1 1 80 90 NA 15
17 22 613 2 70 1 1 90 100 1150 -5
18 16 707 2 63 1 2 50 70 1025 22
19 1 61 2 56 2 2 60 60 238 10
20 21 88 2 57 1 1 90 80 1175 NA
21 11 301 2 67 1 1 80 80 1025 17
22 6 81 2 49 2 0 100 70 1175 -8
23 11 624 2 50 1 1 70 80 NA 16
24 15 371 2 58 1 0 90 100 975 13
25 12 394 2 72 1 0 90 80 NA 0
26 12 520 2 70 2 1 90 80 825 6
27 4 574 2 60 1 0 100 100 1025 -13
28 13 118 2 70 1 3 60 70 1075 20
29 13 390 2 53 1 1 80 70 875 -7
30 1 12 2 74 1 2 70 50 305 20
199 1 276 1 52 2 0 100 80 975 0
200 32 135 2 60 1 1 90 70 1275 0
201 15 79 2 64 2 1 90 90 488 37
202 22 59 2 73 1 1 60 60 2200 5
203 32 240 1 63 2 0 90 100 1025 0
204 3 202 1 50 2 0 100 100 635 1
205 26 235 1 63 2 0 100 90 413 0
206 33 105 2 62 1 2 NA 70 NA NA
207 5 224 1 55 2 0 80 90 NA 23
208 13 239 2 50 2 2 60 60 1025 -3
209 21 237 1 69 1 1 80 70 NA NA
210 33 173 1 59 2 1 90 80 NA 10
211 1 252 1 60 2 0 100 90 488 -2
212 6 221 1 67 1 1 80 70 413 23
213 15 185 1 69 1 1 90 70 1075 0
214 11 92 1 64 2 2 70 100 NA 31
215 11 13 2 65 1 1 80 90 NA 10
216 11 222 1 65 1 1 90 70 1025 18
217 13 192 1 41 2 1 90 80 NA -10
218 21 183 2 76 1 2 80 60 825 7
219 11 211 1 70 2 2 70 30 131 3
220 2 175 1 57 2 0 80 80 725 11
221 22 197 1 67 1 1 80 90 1500 2
222 11 203 1 71 2 1 80 90 1025 0
223 1 116 2 76 1 1 80 80 NA 0
224 1 188 1 77 1 1 80 60 NA 3
225 13 191 1 39 1 0 90 90 2350 -5
226 32 105 1 75 2 2 60 70 1025 5
227 6 174 1 66 1 1 90 100 1075 1
228 22 177 1 58 2 1 80 90 1060 0
Call:
survdiff(formula = surv_obj ~ sex, data = lung)

        N Observed Expected (O-E)^2/E (O-E)^2/V
sex=1 138      112     91.6      4.55      10.3
sex=2  90       53     73.4      5.68      10.3

 Chisq= 10.3  on 1 degrees of freedom, p= 0.001 

output_17_2.png


assistant:

分析の結果、男性(label "1")と女性(label "2")の群間で生存時間に有意差があることが示されました。具体的には、p値が0.001であり、これは0.05よりも小さいため、男性と女性の間に生存時間の違いがあると結論付けることができます。これは生存曲線が男性と女性で異なり、つまり生存経験が性別によって有意に異なることを示しています。

ただし、この結果は、データセット中の男性と女性の間に生存時間の差があることを示すものであり、全ての男性と女性が同じ傾向を示すわけではないことに注意してください。さらに多くの要因が生存時間に影響を及ぼす可能性があります。

これらの結果をさらに詳しく解釈するには、コックス比例ハザードモデルのようなより洗練された統計モデリング手法を探求することをお勧めします。性別以外の要因(年齢、喫煙習慣、肺の機能値等)を制御した上での生存時間の差を調べることが可能です。

分析に関して何か他の質問がありましたら、いつでもお気軽にお問い合わせください。


user:

ありがとうございました。コックス比例ハザードモデルについては、また後日お聞きしたいと思います。


assistant:

はい、もちろんです!コックス比例ハザードモデルは生存分析の重要な一部であり、それについて話す機会を楽しみにしています。それが多変数の解析を行うための強力なツールであり、生存時間に影響を与える可能性のあるさまざまな変数を一度に考慮することができます。

その他の質問や助けが必要な場合は、いつでも気軽にお知らせください。データ分析の旅において最高の助けとなるよう努力いたします。引き続き良い一日をお過ごしください!


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?