如何在 R 中用散点图找到细胞的倍增时间?
How to find doubling time of cells with scatterplot in R?
我正在尝试使用散点图计算细胞的倍增时间。这是我的数据框
df = data.frame("x" = 1:5, "y" = c(246, 667, 1715, 4867, 11694))
并且我使用这段代码绘制了这个数据框
plot(df$x, df$y, xlab = "days", ylab = "cells mL -1")
有谁知道如何使用图表计算这些细胞的倍增时间?倍增时间的等式是 (ln(2)/rate constant)
您可以绘制点以显示指数上升,然后通过将 log2 应用于 y 值来线性化函数。有了它,您可以绘制并进行线性拟合:
df = data.frame("x" = 1:5, "y" = c(246, 667, 1715, 4867, 11694))
plot(df) # plot not displayed
plot(df$x, log2(df$y))
abline(lm(log2(y)~x,df))
lm(log2(y)~x,df)
#-------------------
Call:
lm(formula = log2(y) ~ x, data = df)
Coefficients:
(Intercept) x
6.563 1.401 #the x-coefficient is the slope of the line
#---------------------
log(2)/1.4
#[1] 0.4951051
检查原始图(未显示的图,看起来确实是对倍增时间的合理估计。如果这恰好是家庭作业问题,请务必引用此帖子。
如果我的任务是使用原始图形,请先手工绘制一条指数曲线。然后我会在 y= 2000 和 y=4000 处绘制两条水平线,然后从它们与曲线的交点处放下垂直线并读出水平方向上 x 值的差异 axis.That 就是我上面评论的意思我 "checked" 的 log2/x-coef 感性值。
您可以通过相应地缩放 y 轴来可视化 ggplot2
的恒定变化率:
library(dplyr)
library(ggplot2)
library(broom)
library(scales)
df = data.frame("x" = 1:5, "y" = c(246, 667, 1715, 4867, 11694))
fit <- lm(data = df, log2(y) ~ x)
tidy_fit <- tidy(fit) %>%
mutate(x = 3, y = 2048)
ggplot(df, aes(x = x, y = y)) +
geom_point() +
scale_y_continuous(name = "log2(y)",
trans = 'log2',
breaks = trans_breaks("log2", function(x) 2^x),
labels = trans_format("log2", math_format(2^.x))) +
geom_smooth(method = "lm", se = FALSE) +
geom_text(tidy_fit,
mapping = aes(
x = x,
y = y,
label = paste0("log2(y) = ", round(estimate[1], 2), " + ", round(estimate[2], 2), "x",
"\n", "Doubling Time: ", round(1 / tidy_fit$estimate[2], 2), " Days")
),
nudge_x = -1,
nudge_y = 0.5,
hjust = 0)
由 reprex package (v0.3.0)
于 2020-02-03 创建
绘制 log2(y)
与 x
抑制 Y 轴以便我们可以构建一个更好的。我们还略微改进了 Y 轴标签。然后用axis
做一个漂亮的坐标轴,计算倍增时间。请注意,如果速率常数是 log(y) ~ x 回归线的斜率,则问题中倍增时间的公式有效,但如果我们使用回归 log2(y) ~ x,即 log2 而不是 log,则正确公式只是 1/斜率。我们在下面展示两者。
plot(df$x, log2(df$y), xlab = "days", ylab = "cells/mL", yaxt = "n")
s <- 1:round(log2(max(df$y)))
axis(2, s, parse(text = sprintf("2^%d", s)))
fm <- lm(log2(y) ~ x, df)
abline(fm)
doubling.time <- 1/coef(fm)[[2]]
doubling.time
## [1] 0.7138163
log(2)/coef(lm(log(y) ~ x, df))[[2]] # same
## [1] 0.7138163
legend("topleft", paste("doubling time:", round(doubling.time, 3), "days"), bty = "n")
我正在尝试使用散点图计算细胞的倍增时间。这是我的数据框
df = data.frame("x" = 1:5, "y" = c(246, 667, 1715, 4867, 11694))
并且我使用这段代码绘制了这个数据框
plot(df$x, df$y, xlab = "days", ylab = "cells mL -1")
有谁知道如何使用图表计算这些细胞的倍增时间?倍增时间的等式是 (ln(2)/rate constant)
您可以绘制点以显示指数上升,然后通过将 log2 应用于 y 值来线性化函数。有了它,您可以绘制并进行线性拟合:
df = data.frame("x" = 1:5, "y" = c(246, 667, 1715, 4867, 11694))
plot(df) # plot not displayed
plot(df$x, log2(df$y))
abline(lm(log2(y)~x,df))
lm(log2(y)~x,df)
#-------------------
Call:
lm(formula = log2(y) ~ x, data = df)
Coefficients:
(Intercept) x
6.563 1.401 #the x-coefficient is the slope of the line
#---------------------
log(2)/1.4
#[1] 0.4951051
检查原始图(未显示的图,看起来确实是对倍增时间的合理估计。如果这恰好是家庭作业问题,请务必引用此帖子。
如果我的任务是使用原始图形,请先手工绘制一条指数曲线。然后我会在 y= 2000 和 y=4000 处绘制两条水平线,然后从它们与曲线的交点处放下垂直线并读出水平方向上 x 值的差异 axis.That 就是我上面评论的意思我 "checked" 的 log2/x-coef 感性值。
您可以通过相应地缩放 y 轴来可视化 ggplot2
的恒定变化率:
library(dplyr)
library(ggplot2)
library(broom)
library(scales)
df = data.frame("x" = 1:5, "y" = c(246, 667, 1715, 4867, 11694))
fit <- lm(data = df, log2(y) ~ x)
tidy_fit <- tidy(fit) %>%
mutate(x = 3, y = 2048)
ggplot(df, aes(x = x, y = y)) +
geom_point() +
scale_y_continuous(name = "log2(y)",
trans = 'log2',
breaks = trans_breaks("log2", function(x) 2^x),
labels = trans_format("log2", math_format(2^.x))) +
geom_smooth(method = "lm", se = FALSE) +
geom_text(tidy_fit,
mapping = aes(
x = x,
y = y,
label = paste0("log2(y) = ", round(estimate[1], 2), " + ", round(estimate[2], 2), "x",
"\n", "Doubling Time: ", round(1 / tidy_fit$estimate[2], 2), " Days")
),
nudge_x = -1,
nudge_y = 0.5,
hjust = 0)
由 reprex package (v0.3.0)
于 2020-02-03 创建绘制 log2(y)
与 x
抑制 Y 轴以便我们可以构建一个更好的。我们还略微改进了 Y 轴标签。然后用axis
做一个漂亮的坐标轴,计算倍增时间。请注意,如果速率常数是 log(y) ~ x 回归线的斜率,则问题中倍增时间的公式有效,但如果我们使用回归 log2(y) ~ x,即 log2 而不是 log,则正确公式只是 1/斜率。我们在下面展示两者。
plot(df$x, log2(df$y), xlab = "days", ylab = "cells/mL", yaxt = "n")
s <- 1:round(log2(max(df$y)))
axis(2, s, parse(text = sprintf("2^%d", s)))
fm <- lm(log2(y) ~ x, df)
abline(fm)
doubling.time <- 1/coef(fm)[[2]]
doubling.time
## [1] 0.7138163
log(2)/coef(lm(log(y) ~ x, df))[[2]] # same
## [1] 0.7138163
legend("topleft", paste("doubling time:", round(doubling.time, 3), "days"), bty = "n")