R is always pointed at a directory on your computer. By default,
R outputs files (Plain text files / Data files etc.) to this directory.
Menu - File - Change dir...
C:/Users/Admin/Documents/Konstanz_summer_school/Day2
(actrually Day 3) as my working directorymenu - Misc - Change Working Directory...
~/Documents/Konstanz_summer_school/Day2
as my working directorygetwd()
in R console prompt: after >
, then press enter
keyControl + S
or MacOS Shortcut : Command ⌘ + S
save as
data_GSH.txt
to your working directory (in my case /Documents/Konstanz_summer_school/Day2
)list.files()
in R console prompt: after >
, then press enter
keydata_GSH.txt
is listedCopy - Paste in R console prompt: after >
, then press enter
key
tmpData = readLines("https://antoinechn.github.io/Konstanz-SummerSchool/data/data_GSH.txt")
writeLines(tmpData, "data_GSH.txt")
rm(tmpData)
list.files()
in R console prompt: after >
, then press enter
keydata_GSH.txt
is listedlist.files()
This is GSH
(after 1h)
data_GSH = read.table("data_GSH.txt", sep="\t", header=TRUE)
head(data_GSH)
#> KBrO3_mM group pct_control
#> 1 0.000 1 91.521770
#> 2 0.375 1 63.591550
#> 3 0.750 1 50.508870
#> 4 1.500 1 14.285990
#> 5 3.000 1 2.477166
#> 6 6.000 1 0.377906
Try this
data_GSH = read.table("https://trello-attachments.s3.amazonaws.com/59552633a56853b5f6d1f1f9/5a92760183331b90626ce166/678efebfc21386538df65c23120fc741/data_GSH.txt", sep="\t", header=TRUE)
head(data_GSH)
Try this
data_GSH = read.table("https://antoinechn.github.io/Konstanz-SummerSchool/data/data_GSH.txt", sep="\t", header=TRUE)
head(data_GSH)
plot()
Plot the data to get a sense of it
plot(data_GSH$KBrO3_mM, data_GSH$pct_control)
You have plenty of options, the most useful are:
# nicer
plot(data_GSH$KBrO3_mM, data_GSH$pct_control, las=1)
# professional
plot(data_GSH$KBrO3_mM, data_GSH$pct_control, las=1,
xlab="KBrO3 (mM)", ylab="GSH decrease (%)")
# excellent
plot(data_GSH$KBrO3_mM, data_GSH$pct_control, las=1,
xlab="KBrO3 (mM)", ylab="GSH decrease (%)", main="My Beautiful Data")
# clever
plot(data_GSH$KBrO3_mM, data_GSH$pct_control, las=1,
xlab="KBrO3 (mM)", ylab="GSH decrease (%)", main="My Beautiful Data",
log="y") # you can use log="x" or "y" or "xy" or ""
# genius level
plot(data_GSH$KBrO3_mM, data_GSH$pct_control, las=1,
xlab="KBrO3 (mM)", ylab="GSH decrease (%)", main="My Beautiful Data",
log="y", pch=10, cex= 1.3, col="red") # set the type of mark, size, color
# etc. see help(par) or ?par for all the parameters you can set
# nicer
plot(data_GSH$KBrO3_mM, data_GSH$pct_control, las=1)
# professional
plot(data_GSH$KBrO3_mM, data_GSH$pct_control, las=1,
xlab="KBrO3 (mM)", ylab="GSH decrease (%)")
# excellent
plot(data_GSH$KBrO3_mM, data_GSH$pct_control, las=1,
xlab="KBrO3 (mM)", ylab="GSH decrease (%)", main="My Beautiful Data")
# clever
plot(data_GSH$KBrO3_mM, data_GSH$pct_control, las=1,
xlab="KBrO3 (mM)", ylab="GSH decrease (%)", main="My Beautiful Data",
log="y") # you can use log="x" or "y" or "xy" or ""
# genius level
plot(data_GSH$KBrO3_mM, data_GSH$pct_control, las=1,
xlab="KBrO3 (mM)", ylab="GSH decrease (%)", main="My Beautiful Data",
log="y", pch=10, cex= 1.3, col="red") # set the type of mark, size, color
Let’s get serious:
# define the Hill dose-response model as a function
Hill = function (x, EC50, n) {
return(x^n / (x^n + EC50^n))
}
# let's try it
Hill(x=10, EC50=1, n=1)
# plot it...
x = seq(0, 10, 0.1)
y = Hill(x=x, EC50=1, n=3)
plot(x, y, type="b")
# define the Hill dose-response model as a function
Hill = function (x, EC50, n) {
return(x^n / (x^n + EC50^n))
}
# let's try it
Hill(x=10, EC50=1, n=1)
#> [1] 0.9090909
# plot it...
x = seq(0, 10, 0.1)
y = Hill(x=x, EC50=1, n=3)
plot(x, y, type="b")
Problem:
So we change it a bit
# define an extended Hill dose-response model as a function
Hill = function (x, EC50, n, from, diff) {
return(from + diff * (x^n / (x^n + EC50^n)))
}
# try it
Hill(x=10, EC50=1, n=1, from=1, diff=10)
# plot it...
x = seq(0, 10, 0.1)
y = Hill(x=x, EC50=1, n=3, from=1, diff=10)
plot(x, y, type="b")
# define an extended Hill dose-response model as a function
Hill = function (x, EC50, n, from, diff) {
return(from + diff * (x^n / (x^n + EC50^n)))
}
# try it
Hill(x=10, EC50=1, n=1, from=1, diff=10)
#> [1] 10.09091
# plot it...
x = seq(0, 10, 0.1)
y = Hill(x=x, EC50=1, n=3, from=1, diff=10)
plot(x, y, type="b")
Question
# assign the values found to variables A and B
A =
B =
now replot the data and overlay with the model
Note : make sure to define the axes limits before doing overlays…
xlims = c(0, 6) # a vector of min and max
ylims = c(0, 120)
plot(data_GSH$KBrO3_mM, data_GSH$pct_control, xlim=xlims, ylim=ylims, col="red")
par(new=T) # will overlay the next plot
x = seq(0, 6, 0.1)
y = Hill(x=x, EC50=1, n=3, from=A, diff=B)
plot(x, y, type="l", xlim=xlims, ylim=ylims, xlab="", ylab="") # turn off labels
now play with EC50 and N to fit the data better
A = 100
B = -100
EC50 = 0.5
n = 1.8
\[y = A + B \times \frac{x^n}{x^n+ {EC_{50}}^n} \]
\[x = \;?\]
invs.hill = function(y, EC50, A, B, n){
YOUR CODE HERE
}
Some calculations
\[x =\; \sqrt[n]{ \frac{{EC_{50}}^n} {\frac{B}{y-A} -1} }\]
R function
invs.hill = function(y, EC50, A, B, n){
res = (EC50 ^n /(B/(y-A) - 1 ) )^(1/n)
return(res)
}
# A = 100
# B = -100
# EC50 = 0.5
# n = 1.8
Hi = seq(0.1, 100, by = 0.1)
KBr = invs.hill(y = Hi,
EC50 = 0.5,
A = 100,
B = -100,
n = 1.8)
plot(x = Hi, y = KBr, type = 'l',
main = "Invers Hill function plot")
There are many tools in R that can be used to fit automatically your model one of them is PROAST (from the RIVM) but we can also access PROAST online (more fun)
https://www.rivm.nl/en/Documents_and_publications/Scientific/Models/PROAST