Commit 4d571ba5 authored by mk11g11's avatar mk11g11
Browse files

add chapter one, figures and references

parent d2dbc0ac
This diff is collapsed.
book_filename: "thesis-dissertaion" # Change this to the actual title book_filename: "thesis-dissertaion" # Change this to the actual title
delete_merged_file: true delete_merged_file: true
rmd_files: ["index.Rmd","00-preface.Rmd", "01-intro.Rmd","02-methods.Rmd", "03-results-01.Rmd", "04-results-02.Rmd","05-discussion.Rmd", "20-appendix.Rmd","21-appendix-a.Rmd","22-appendix-b.Rmd", "99-references.Rmd"] rmd_files: ["index.Rmd","00-preface.Rmd", "01-general_intro_new_3.Rmd","02-methods.Rmd", "03-results-01.Rmd", "04-results-02.Rmd","05-discussion.Rmd", "20-appendix.Rmd","21-appendix-a.Rmd","22-appendix-b.Rmd", "99-references.Rmd"]
#rmd_files: ["index.Rmd","00-preface.Rmd", "01-intro.Rmd","02-methods.Rmd", "03-results-01.Rmd", "04-results-02.Rmd","05-discussion.Rmd", "20-appendix.Rmd","21-appendix-a.Rmd","22-appendix-b.Rmd", "99-references.Rmd"]
language: language:
ui: ui:
chapter_name: "Chapter " chapter_name: "Chapter "
\ No newline at end of file
This diff is collapsed.
...@@ -24,13 +24,6 @@ ...@@ -24,13 +24,6 @@
title = {rmarkdown: Dynamic Documents for R}, title = {rmarkdown: Dynamic Documents for R},
author = {JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and Winston Chang}, author = {JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and Winston Chang},
year = {2018}, year = {2018},
note = {R package version 1.10}, note = {R package version 1.9},
url = {https://CRAN.R-project.org/package=rmarkdown}, url = {https://CRAN.R-project.org/package=rmarkdown},
} }
@Manual{R-PepTools,
title = {PepTools - An R-package for making immunoinformatics accessible},
author = {Leon Eyrich Jessen},
year = {2018},
note = {R package version 0.1.0},
url = {https://github.com/leonjessen/PepTools},
}
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
# Dose response curve
# A.Bailey 12th June 2018
library(tidyverse)
library(drc)
library(janitor)
# Read data from thrashing analysis - at 60 min time point
dat <- read_csv("Learning/N2_DR_thrashing.csv") %>% clean_names()
dat1 <- read_csv("Learning/bus17_DR_thrashing.csv") %>%
clean_names()
# Drop dose and convert to matrix
dat_m <- dat %>% dplyr::select(-dose) %>% as.matrix()
dat_m1 <- dat1 %>% dplyr::select(-dose) %>% as.matrix()
# Find NAs
k <- which(is.na(dat_m), arr.ind=TRUE)
k1 <- which(is.na(dat_m1), arr.ind=TRUE)
# Copied the matrix
m <- dat_m
m1 <- dat_m1
# Fill missing values with row mean, mean for that dose
m[k] <- rowMeans(dat_m, na.rm=TRUE)[k[,1]]
m1[k1] <- rowMeans(dat_m, na.rm=TRUE)[k1[,1]]
# Convert back to tibble
d_m <- as.tibble(m)
d_m1 <- as.tibble(m1)
# Re-bind the dose column to complete data
dat_clean <- bind_cols(dose = dat$dose,d_m)
dat_clean1 <- bind_cols(dose = dat$dose,d_m1)
#combine data - look into this here
dat_comb <- bind_rows(dat_clean, dat_clean1)
# Gather according to dose
dat_melt <- dat_clean %>% gather(key = vars,value = response, -dose) #%>% dplyr::select(-vars)
dat_melt2 <- dat %>% gather(key = vars,value = response,-dose) %>% dplyr::select(-vars)
# Mutate log transformation
dat_melt <- dat_melt %>% mutate(log_dose = log(dose))
# Fit model with imputed data
model <- drc::drm(data = dat_melt, response ~ dose, fct = L.3())
# Fit original data
model2 <- drc::drm(data = dat_melt2, response ~ dose, fct = L.3(), na.action = na.omit)
summary(model2)
plot(model2)
plot(model)
preds <- as.tibble(model$predres) %>% clean_names()
dat_all <- dat_melt %>% mutate(predict = preds$predicted_values)
dat_spread <- dat_all %>%
dplyr::select(-log_dose) %>%
group_by(dose) %>%
mutate(mean_response = mean(response),
std_dev = sd(response),
se = std_dev/sqrt(length(response))) %>%
dplyr::select(dose,mean_response,vars,se,predict) %>%
spread(vars,mean_response) %>%
dplyr::select(dose, se, mean_response = x10, predict) %>%
ungroup() %>%
mutate(norm_rep = (mean_response - min(mean_response)) /
(max(mean_response) - min(mean_response)),
norm_pred = (predict - min(predict)) / (max(predict) - min(predict)),
norm_se = se/(mean_response))
dat_spread %>%
ggplot(aes(dose,norm_rep)) +
geom_point() +
geom_errorbar(aes(ymin = norm_rep - norm_se,ymax = norm_rep + norm_se)) +
geom_line(aes(dose,norm_pred)) +
#geom_smooth(aes(dose,norm_pred)) +
scale_x_log10()
```
# Monika Kudelska
#01/06/2018
#This script is the analysis of coffee consumtion and burger eating
# Monika Kudelska
#01/06/2018
#This script is the analysis of coffee consumtion and burger eating
#Reset R's brain
rm(list=ls())
#getwd tells you where R is currently looking
getwd
#setwd tells R where to look
setwd("//soton.ac.uk/ude/PersonalFiles/Users/mk11g11/mydocuments/PhD/R_analysis/Learning/Getting_started_with_R/datasets.zip")
#use getwd to confirm that R is now looking here
getwd()
#read csv file
comp.dat <- read.csv("compensation.csv")
#list objects
ls()
#check data
names(comp.dat) #Returns the names of columns
head(comp.dat) #Returns the names of headings
dim(comp.dat) #Returns the number of rows and columns
str(comp.dat) # A powerful compilations of the above
summary(comp.dat) # Summary of data
# Isolating, finding and grabbing data
comp.dat[,1] #Retun all rows of column 1
comp.dat[1,] # Retur all first rows
comp.dat[, 1:3] # Retun all observations from columns 1-3
comp.dat [1:3,] # Return three rows from all columns
comp.dat [1:3, 1:3] # Retun three rows from three columns
comp.dat [c(1:30), c(1:3)] # Use concatamate function if you want to select specific columns and rows. Select rows 1-30 and columns 1-3
comp.dat [c(1, 20, 21:30), c(1)] # Select column 1, rows 20 21-30
comp.dat [c(1, 20, 21:30), -c(2,3)] # Select all columns except column 1 and return rows 1, 20, 21-30
#Using names to grab data
comp.dat[,"Fruit"] # all observations from Fruit header (variable)
comp.dat[c("Fruit", "Grazing")] # all observation for Fruit and Grazing variables. Use concatamate to select mutliple variables
comp.dat$Grazing # Use dolar sign to select one variable.
subset(comp.dat, Grazing == "Grazed") #Return subset of the data (all 3 columns) with rows representing only "Grazed".
subset(comp.dat, Fruit == 35.53)
subset(comp.dat, Fruit > 35.53 & Root > 2)
subset(comp.dat, Fruit > 38, select = c(Fruit, Root)) #select only Fruit and Root vaiables and rows containing fruit size larger than 38
subset(comp.dat, c(Grazing == "Grazed", Fruit >30), select = c(-Root)) #Select all variables except Root, and show observations with fruit size over 30 and Grazed
# Aggregate - returns
mean.fruit <- aggregate(comp.dat$Fruit, list(comp.dat$Grazing), mean) #take the Fruit column from the object, divide it by the Grazing level system and calculate the mean in the grazing system
#tapply produces what aggregate does, but returns it as matrix and not data frame
tapply (comp.dat$Fruit, list(comp.dat$Grazing), mean)
Root,Fruit,Grazing
6.225,59.77,Ungrazed
6.487,60.98,Ungrazed
4.919,14.73,Ungrazed
5.13,19.28,Ungrazed
5.417,34.25,Ungrazed
5.359,35.53,Ungrazed
7.614,87.73,Ungrazed
6.352,63.21,Ungrazed
4.975,24.25,Ungrazed
6.93,64.34,Ungrazed
6.248,52.92,Ungrazed
5.451,32.35,Ungrazed
6.013,53.61,Ungrazed
5.928,54.86,Ungrazed
6.264,64.81,Ungrazed
7.181,73.24,Ungrazed
7.001,80.64,Ungrazed
4.426,18.89,Ungrazed
7.302,75.49,Ungrazed
5.836,46.73,Ungrazed
10.253,116.05,Grazed
6.958,38.94,Grazed
8.001,60.77,Grazed
9.039,84.37,Grazed
8.91,70.11,Grazed
6.106,14.95,Grazed
7.691,70.7,Grazed
8.988,80.31,Grazed
8.975,82.35,Grazed
9.844,105.07,Grazed
8.508,73.79,Grazed
7.354,50.08,Grazed
8.643,78.28,Grazed
7.916,41.48,Grazed
9.351,98.47,Grazed
7.066,40.15,Grazed
8.158,52.26,Grazed
7.382,46.64,Grazed
8.515,71.01,Grazed
8.53,83.03,Grazed
Dose,,,,,,,,,,,,,,,,,,
0.000001,49,48,36,48,45,52,41,37,48,51,54,44,45,44,42,52,40,
0.001,47,42,46,22,40,51,43,49,23,46,40,13,37,42,42,52,48,42
0.01,57,56,48,51,4,0,46,28,43,47,21,44,49,31,,,,
0.025,35,52,38,43,44,44,0,29,47,43,0,0,38,35,33,43,0,0
0.05,12,44,0,0,0,37,38,0,0,0,43,42,0,0,0,0,,
0.1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Dose,,,,,,,,,,,,,,,,,,,,,,,,
0.000001,44,40,34,43,38,41,44,45,50,39,47,43,39,37,46,,,,,,,,,
0.0001,39,35,32,36,40,48,45,41,34,24,35,47,50,35,43,45,38,,,,,,,
0.001,39,0,37,32,37,35,36,45,40,43,0,0,41,0,51,44,54,49,51,51,40,48,46,40
0.01,18,5,0,0,0,22,32,35,0,0,40,2,13,34,0,0,,,,,,,,
0.025,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,,,,,
0.05,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,,,,
# Dose response training
# Monika Kudelska
# 12/06/2018
# Clear R
#rm(list=ls())
# Load packages
library(drc)
#library(drm)
library(reshape2)
library(tidyverse)
#setwd("//soton.ac.uk/ude/PersonalFiles/Users/mk11g11/mydocuments/PhD/R_analysis")
data1 <- read_csv ("Learning/N2_DR_thrashing.csv")
data1t <- data1 %>%
gather (key = thrashing, value = response, -Dose) %>%
drop_na() %>%
select(Dose, response)
data2t <- data1t %>%
group_by(Dose) %>%
summarise(mean_resp = mean(response),
sd=sd(response),
se = sd/sqrt(length(response)))
#use drm function
model <- drc::drm(data = data1t, response ~ Dose,
fct = L.4(),
na.action = na.omit)
-------------------------------------------------------------------------------
model <- glm(mean_resp ~ log2(Dose), data = data2t)
data2t %>%
mutate(predict = model$fitted.values,
log_dose = log2(Dose)) %>%
ggplot(aes(x = log_dose, y = mean_resp)) +
geom_point() +
geom_line(aes(log_dose,predict))
# Dose response curve
# A.Bailey 12th June 2018
library(tidyverse)
library(drc)
library(janitor)
# Read data from thrashing analysis - at 60 min time point
dat <- read_csv("Learning/N2_DR_thrashing.csv") %>% clean_names()
dat1 <- read_csv("Learning/bus17_DR_thrashing.csv") %>%
clean_names()
# Drop dose and convert to matrix
dat_m <- dat %>% dplyr::select(-dose) %>% as.matrix()
dat_m1 <- dat1 %>% dplyr::select(-dose) %>% as.matrix()
# Find NAs
k <- which(is.na(dat_m), arr.ind=TRUE)
k1 <- which(is.na(dat_m1), arr.ind=TRUE)
# Copied the matrix
m <- dat_m
m1 <- dat_m1
# Fill missing values with row mean, mean for that dose
m[k] <- rowMeans(dat_m, na.rm=TRUE)[k[,1]]
m1[k1] <- rowMeans(dat_m, na.rm=TRUE)[k1[,1]]
# Convert back to tibble
d_m <- as.tibble(m)
d_m1 <- as.tibble(m1)
# Re-bind the dose column to complete data
dat_clean <- bind_cols(dose = dat$dose,d_m)
dat_clean1 <- bind_cols(dose = dat$dose,d_m1)
#combine data - look into this here
dat_comb <- bind_rows(dat_clean, dat_clean1)
# Gather according to dose
dat_melt <- dat_clean %>% gather(key = vars,value = response, -dose) #%>% dplyr::select(-vars)
dat_melt2 <- dat %>% gather(key = vars,value = response,-dose) %>% dplyr::select(-vars)
# Mutate log transformation
dat_melt <- dat_melt %>% mutate(log_dose = log(dose))
# Fit model with imputed data
model <- drc::drm(data = dat_melt, response ~ dose, fct = L.3())
# Fit original data
model2 <- drc::drm(data = dat_melt2, response ~ dose, fct = L.3(), na.action = na.omit)
summary(model2)
plot(model2)
plot(model)
preds <- as.tibble(model$predres) %>% clean_names()
dat_all <- dat_melt %>% mutate(predict = preds$predicted_values)
dat_spread <- dat_all %>%
dplyr::select(-log_dose) %>%
group_by(dose) %>%
mutate(mean_response = mean(response),
std_dev = sd(response),
se = std_dev/sqrt(length(response))) %>%
dplyr::select(dose,mean_response,vars,se,predict) %>%
spread(vars,mean_response) %>%
dplyr::select(dose, se, mean_response = x10, predict) %>%
ungroup() %>%
mutate(norm_rep = (mean_response - min(mean_response)) /
(max(mean_response) - min(mean_response)),
norm_pred = (predict - min(predict)) / (max(predict) - min(predict)),
norm_se = se/(mean_response))
dat_spread %>%
ggplot(aes(dose,norm_rep)) +
geom_point() +
geom_errorbar(aes(ymin = norm_rep - norm_se,ymax = norm_rep + norm_se)) +
geom_line(aes(dose,norm_pred)) +
#geom_smooth(aes(dose,norm_pred)) +
scale_x_log10()
dat_sprea
# dat <- read_csv("Analysis/Data/Exported/EPG/5-HT DR_peak.csv")
# dat1 <- dat[, 1:7]
# Read data from thrashing analysis - at 60 min time point
dat <- read_csv("Analysis/Data/Exported/EPG/5-HT DR_peak.csv") %>% clean_names()
library(tidyverse)
library(drc)
library(janitor)
library(drc)
library(reshape2)
library(ggplot2)
# Read data from thrashing analysis - at 60 min time point
dat <- read_csv("Analysis/Data/Exported/EPG/5-HT DR_peak.csv") %>% clean_names()
dat1 <- read_csv("Learning/bus17_DR_thrashing.csv") %>%
clean_names()
# Drop dose and convert to matrix
dat_m <- dat %>% dplyr::select(-dose) %>% as.matrix()
dat_m1 <- dat1 %>% dplyr::select(-dose) %>% as.matrix()
# Find NAs
k <- which(is.na(dat_m), arr.ind=TRUE)
k1 <- which(is.na(dat_m1), arr.ind=TRUE)
# Copied the matrix
m <- dat_m
m1 <- dat_m1
# Fill missing values with row mean, mean for that dose
m[k] <- rowMeans(dat_m, na.rm=TRUE)[k[,1]]
m1[k1] <- rowMeans(dat_m, na.rm=TRUE)[k1[,1]]
# Convert back to tibble
d_m <- as.tibble(m)
d_m1 <- as.tibble(m1)
# Re-bind the dose column to complete data
dat_clean <- bind_cols(dose = dat$dose,d_m)
dat_clean1 <- bind_cols(dose = dat$dose,d_m1)
#combine data - look into this here
dat_comb <- bind_rows(dat_clean, dat_clean1)
# Gather according to dose
dat_melt <- dat_clean %>% gather(key = vars,value = response, -dose) #%>% dplyr::select(-vars)
dat_melt2 <- dat %>% gather(key = vars,value = response,-dose) %>% dplyr::select(-vars)
# Mutate log transformation
dat_melt <- dat_melt %>% mutate(log_dose = log(dose))
# Fit model with imputed data
model <- drc::drm(data = dat_melt, response ~ dose, fct = LL.3())
# Fit original data
model2 <- drc::drm(data = dat_melt2, response ~ dose, fct = L.L4(), na.action = na.omit)
summary(model)
summary(model2)
plot(model2)
plot(model)
preds <- as.tibble(model$predres) %>% clean_names()
dat_all <- dat_melt %>% mutate(predict = preds$predicted_values)
dat_spread <- dat_all %>%
dplyr::select(-log_dose) %>%
group_by(dose) %>%
mutate(mean_response = mean(response),
std_dev = sd(response),
se = std_dev/sqrt(length(response))) %>%
dplyr::select(dose,mean_response,vars,se,predict)
# %>%
# spread(vars,mean_response) %>%
# dplyr::select(dose, se, mean_response = x10, predict) %>%
# ungroup() %>%
# mutate(norm_rep = (mean_response - min(mean_response)) /
# (max(mean_response) - min(mean_response)),
# norm_pred = (predict - min(predict)) / (max(predict) - min(predict)),
# norm_se = se/(mean_response))
dat_spread %>%
ggplot(aes(dose,mean_response)) +
geom_point() +
geom_line(aes(dose,predict)) +
geom_smooth(method = drm, fct = L.4(), se = FALSE) +
scale_x_log10()
dat_spread
# +geom_errorbar(aes(ymin = mean_response - norm_se,ymax = norm_rep + norm_se)) +
#
# #geom_smooth(aes(dose,norm_pred)) +
# scale_x_log10()
# dat_sprea
---
title: "test"
output: html_document
---
```{r echo=FALSE}
library(tidyverse)
library(drc)
library(janitor)
# Read data from thrashing analysis - at 60 min time point
dat <- read_csv("N2_DR_thrashing.csv") %>% clean_names()
dat1 <- read_csv("bus17_DR_thrashing.csv") %>%
clean_names()
# Drop dose and convert to matrix
dat_m <- dat %>% dplyr::select(-dose) %>% as.matrix()
dat_m1 <- dat1 %>% dplyr::select(-dose) %>% as.matrix()
# Find NAs
k <- which(is.na(dat_m), arr.ind=TRUE)
k1 <- which(is.na(dat_m1), arr.ind=TRUE)
# Copied the matrix
m <- dat_m
m1 <- dat_m1
# Fill missing values with row mean, mean for that dose
m[k] <- rowMeans(dat_m, na.rm=TRUE)[k[,1]]
m1[k1] <- rowMeans(dat_m, na.rm=TRUE)[k1[,1]]
# Convert back to tibble
d_m <- as.tibble(m)
d_m1 <- as.tibble(m1)
# Re-bind the dose column to complete data
dat_clean <- bind_cols(dose = dat$dose,d_m)
dat_clean1 <- bind_cols(dose = dat$dose,d_m1)
#combine data - look into this here
dat_comb <- bind_rows(dat_clean, dat_clean1)
# Gather according to dose
dat_melt <- dat_clean %>% gather(key = vars,value = response, -dose) #%>% dplyr::select(-vars)
dat_melt2 <- dat %>% gather(key = vars,value = response,-dose) %>% dplyr::select(-vars)
# Mutate log transformation
dat_melt <- dat_melt %>% mutate(log_dose = log(dose))
# Fit model with imputed data
model <- drc::drm(data = dat_melt, response ~ dose, fct = L.3())
# Fit original data
model2 <- drc::drm(data = dat_melt2, response ~ dose, fct = L.3(), na.action = na.omit)
summary(model2)
plot(model2)
plot(model)
preds <- as.tibble(model$predres) %>% clean_names()
dat_all <- dat_melt %>% mutate(predict = preds$predicted_values)
dat_spread <- dat_all %>% dplyr::select(-log_dose) %>%
group_by(dose) %>%
mutate(mean_response = mean(response),
std_dev = sd(response),
se = std_dev/sqrt(length(response))) %>%
dplyr::select(dose,mean_response,vars,se,predict) %>%
spread(vars,mean_response) %>%
dplyr::select(dose, se, mean_response = x10, predict) %>%
ungroup() %>%
mutate(norm_rep = (mean_response - min(mean_response)) /
(max(mean_response) - min(mean_response)),
norm_pred = (predict - min(predict)) / (max(predict) - min(predict)),
norm_se = se/(mean_response))
dat_spread %>%
ggplot(aes(dose,norm_rep)) +
geom_point() +
geom_errorbar(aes(ymin = norm_rep - norm_se,ymax = norm_rep + norm_se)) +
geom_line(aes(dose,norm_pred)) +
#geom_smooth(aes(dose,norm_pred)) +
scale_x_log10()
dat_spread
```
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment