-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatistic_prj10.Rmd
65 lines (50 loc) · 1.93 KB
/
Statistic_prj10.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
title: "wk10 assynment"
author: "Xiaoyan Wen"
date: "11/8/2020"
output: word_document
---
```{r}
# according to data description,
# column 1 - unit number; 2 - time(in cycle)
# there are three operational settings may have a substantial effect on engine performance - column 3-5
# in the training dataset, the degradation grows till a threshold beyond usage; in the test set, the time series ends prior to complete degradation
```
```{r setup}
library(survival)
library(survminer)
library(readr)
library(dplyr)
```
```{r read dataset}
# read data set from Challenge data
test <- read_table2("~/R_project/biostatistics2/test.txt", col_names = FALSE)
train <- read_table2("~/R_project/biostatistics2/train.txt", col_names = FALSE)
summary(test);summary(train)
```
```{r extract data}
# obtain summarized time data for both "dead" and "censored" event
test[,1:5] %>% group_by(test$X1) %>% summarise(time = max(X2),
op_setting1 = median(X3),
op_setting2 = median(X4),
op_setting3 = median(X5),
event = 0
) -> cesor_set
train[,1:5] %>% group_by(train$X1) %>% summarise(time = max(X2),
op_setting1 = median(X3),
op_setting2 = median(X4),
op_setting3 = median(X5),
event = 1
) -> event_set
# combine to dat
rm(dat)
dat <- cbind(id = c(1:436), rbind(cesor_set[,2:6], event_set[,2:6]))
summary(dat)
```
```{r, fit cox model}
# fit to cox hazard model
surv_object <- Surv(dat$time, dat$event )
cx <- coxph(surv_object ~ op_setting1 + op_setting2 + op_setting3, data = dat)
cx
ggforest(cx)
```