因此,這裏是遊戲計劃。我正在嘗試下面這個數據集(將是一個結構對象),通過它運行一個曲線迴歸模型。 然後,我想在每個點處取斜率(即每個x的一階導數值),並將該斜率信息的數據表保存在其自己的列中。如何獲得曲線預測模型的斜率?並將它們保存爲表
input.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()
總結: 以數據,運行迴歸,取斜率的每個值,然後用在斜坡保存相同數據單獨的列。輸出將是相同的表格,但有一個新的第三列:與每個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一直......令人沮喪的學習,至少可以說。幫幫我?
[R版本3.2.4 紅帽Linux 4.1.2 數據從https://plot.ly/~gwaligroski/15/michaelis-menten-equation 典借改編自https://rpubs.com/RomanL/6752
這是一個好的開始。但那些點上的第一個派生物是什麼?我無法輕易訪問該公式,而且我不確定基於geom_line曲線我將如何能夠首先獲得一階導數。摘要中嵌入了支配geom_line的逆多項式的常量 – Tom