Answer
Provide your answer below. When working in R Markdown, you can include code chunks to run your R code and display the results directly in the document. For example:
#load dataset
load("Coursework0525_Data.Rdata")
# Check which objects were loaded
ls()
## [1] "patient_data" "Y"
#object: Y
head(Y, 5) # see first 5 rows of data
## Sample001 Sample002 Sample003 Sample004 Sample005 Sample006
## ENSG00000157106 1555 29378 0 18618 62411 99033
## ENSG00000122565 3831 12505 0 15067 5170 23181
## ENSG00000124275 739 1643 0 2754 243 21602
## ENSG00000092036 583 784 0 505 0 1658
## ENSG00000160392 48 203 0 303 392 3527
## Sample007 Sample008 Sample009 Sample010 Sample011 Sample012
## ENSG00000157106 6605 69717 7174 119884 40832 17033
## ENSG00000122565 17583 13217 10208 73716 10901 15817
## ENSG00000124275 1413 14545 355 6099 11534 597
## ENSG00000092036 198 3513 50 5395 0 349
## ENSG00000160392 98 1140 19 674 681 0
## Sample013 Sample014 Sample015 Sample016 Sample017 Sample018
## ENSG00000157106 12519 18978 0 620483 22644 16391
## ENSG00000122565 26740 52647 34957 17486 1839 2815
## ENSG00000124275 905 524 4301 2 38044 7060
## ENSG00000092036 317 32 1203 268 181 44
## ENSG00000160392 289 0 0 416 815 230
## Sample019 Sample020 Sample021 Sample022 Sample023 Sample024
## ENSG00000157106 32627 35763 4542 138034 7703 13399
## ENSG00000122565 2676 1623 1350 896 599 1385
## ENSG00000124275 0 23599 4518 22728 2465 4968
## ENSG00000092036 145 88 41 14 20 53
## ENSG00000160392 1425 1391 442 705 523 269
## Sample025 Sample026 Sample027 Sample028 Sample029 Sample030
## ENSG00000157106 22736 22946 7874 77667 4893 4334
## ENSG00000122565 2032 5905 2227 2018 2245 1536
## ENSG00000124275 7694 21317 7347 6716 18238 2664
## ENSG00000092036 19 275 50 152 44 41
## ENSG00000160392 406 0 647 327 262 1
dim(Y) # column names Sample001:030 with rows 1:4568 gene expression counts
## [1] 4568 30
class(Y) # matrix array 30 across and 4568 down.
## [1] "matrix" "array"
#object: patient_data
head(patient_data, 5) # see first 5 rows of data
## tissue patient_id sample_id
## 1 Tumour Patient.1 Sample001
## 2 Tumour Patient.2 Sample002
## 3 Tumour Patient.3 Sample003
## 4 Tumour Patient.4 Sample004
## 5 Tumour Patient.5 Sample005
dim(patient_data) # 3 column named tissue, patient_id and sample_id with rows 30 patient data
## [1] 30 3
class(patient_data) # matrix array 3 across and 30 down.
## [1] "data.frame"
# Check unique values in key columns
unique(patient_data$tissue_type)
## NULL
unique(patient_data$patient_ID)
## NULL
You can run a code chunk by clicking the green “Run” button above it. This will execute the code and show the output in your R Markdown file. When you knit the document to HTML, the code chunks are run, and the output is included in the final HTML file.
# Calculate library sizes (sum of counts per sample)
lib_sizes <- colSums(Y)
# Normalize counts by library size and scale to 1 million (CPM)
Y_cpm <- sweep(Y, 2, lib_sizes, FUN = "/") * 1e6
Answer
Answer
library_size, propose a simple statistical
test and explain why it is appropriate. (4 marks)Answer
library(tidyverse)
library(MASS)
load("~/Coursework0125_Data.Rdata")
idx <- 20
c_cl <- setdiff(1:30, c(3, 18))
x <- patient_data$tissue[c_cl]
z <- patient_data$patient[c_cl]
tmp <- data.frame(y = Y[idx, c_cl], x = x, z = z, lib_size = colSums(Y[, c_cl]))
out <- glm.nb(y ~ x + lib_size, data = tmp)
p_val <- summary(out)$coefficients[2, 4]
summary(out)
Answer
Answer
Answer
Answer
Answer