それではゲームプランです。このデータセット (構造体オブジェクトになります) を下に取り、曲線回帰モデルを実行しようとしています。次に、各ポイントで傾き (つまり、各 x の 1 次導関数の値) を取得し、その傾き情報を含むデータ テーブルを独自の列に保存します。
入力.txt:
yval xval
0.198 0.125
0.18 0.0625
0.126 0.03125
0.078 0.015625
0.066 0.007813
0.03 0.0039065
0.00 0.0
script.r:
dat <- read.table("input.txt", header=T, sep="\t")
library(drc)
library(ggplot2)
mm <- structure(list(x = dat$xval, y = dat$yval), .Names= c("x","y"), class = "data.frame")
model.drm <- drm (y ~ x, data = mm, fct = MM.2())
mml <- data.frame(x = seq(0, max(mm$x), length.out = 100)) #I actually don't know what length does, and am unsure about this line
mml$y <- predict(model.drm, newdata = mml)
ggplot(mm, aes(x = x, y = y)) +
theme_bw() +
xlab("x lab") +
ylab("y lab") +
ggtitle("dose response curve") +
geom_point(alpha = 0.5) +
geom_line(data = mml, aes(x = x, y = y), colour = "blue")
ggsave("mm.pdf", width = 6, height = 4)
#Need to pass in vector (list) of x, into the derivative of mml's function.
#Output will be a list of corresponding slope values for each of those x's.
#append said slope values to the data frame and save it.
dev.off()
概要: データを取得し、回帰を実行し、各値で勾配を取得してから、同じデータを勾配とともに別の列に保存します。出力は同じテーブルになりますが、新しい 3 番目の列 (各 x 値に関連付けられた勾配) があります。出力は次のようになります。
output.txt:
yval xval slopes
0.198 0.125 slope1
0.18 0.0625 slope2
0.126 0.03125 slope3
0.078 0.01562 slope4
0.066 0.00781 slope5
0.03 0.00396 slope6
0.00 0.00 slope7
問題は、その情報を「取得」する方法と、それを再保存する方法が、適切に行う方法がわからないことです。Rが方程式の計算を行う方法に慣れていません。summary() から方程式の定数を取得できますが、それを処理する方法がありません。
適切な情報の組み合わせを見つけることができません (または、使用している検索用語だけでしょうか?)。これのいくつかが間違った疑似コードのように思われる場合は、お詫び申し上げます。ヘルプ?
R バージョン 3.2.4 Redhat Linux 4.1.2 データはhttps://plot.ly/~gwaligroski/15/michaelis-menten-equationから借用したもの コードはhttps://rpubs.com/RomanL/6752から改変