如何在 R Studio 中向校准曲线添加 3 个数据点?

问题描述 投票:0回答:1

我目前对 R Studio 还很陌生。我正在尝试将前、后和对照吸光度值的数据添加到我的校准曲线图中。

下面的代码是我目前拥有的代码,它创建了一个散点图和一条最佳拟合线。但是我需要绘制...的吸光度值

控制:0.008 预处理:0.280 处理后:0.117

...在图表上使用最佳拟合线找到它们的浓度。下面是我的代码:

BSA = data.frame(Concentration = c(0.0, 0.2, 0.4, 0.6, 0.8, 1.0), 
       Absorbance = c(0.000, 0.182, 0.159, 0.121, 0.311, 0.352))

values = data.frame(Sample = c("Control", "Pre-treatment", "Post-treatment"),
                    Absorbance = c(0.008, 0.280, 0.117))

BSA <- read.csv(file.choose(), header = T, na.strings = "", stringsAsFactors = T)
plot(BSA, ylab = "Absorbance of BSA", xlab = "Assay Concentration (ml/mg)", las = 1) 
abline(lm(BSA$Absorbance ~ BSA$Concentration))

我正在努力寻找一种方法来执行此操作,之前的帖子非常针对用户的数据集,并且由于某种原因不适用于我的数据。任何意见或建议将不胜感激!

r charts rstudio scatter-plot calibration
1个回答
0
投票

我仍然不完全清楚你需要什么,但听起来你需要:

  • 拟合模型以根据吸光度预测浓度
  • 预测一些新值的浓度,并且
  • 将这些预测绘制在同一个图上。

这是我的处理方法

# You provided...
BSA = data.frame(Concentration = c(0.0, 0.2, 0.4, 0.6, 0.8, 1.0), 
                 Absorbance = c(0.000, 0.182, 0.159, 0.121, 0.311, 0.352))

values = data.frame(Sample = c("Control", "Pre-treatment", "Post-treatment"),
                    Absorbance = c(0.008, 0.280, 0.117))


# Here is how I would do this...

# First, make a model
fit <- lm(Concentration ~ Absorbance, data=BSA)

# Next, plot your data
with(BSA, plot(Absorbance, Concentration))
# Add the line of best fit
abline(fit)

# Now, get the predictions from your "values" dataframe
predicted_concentration <- predict(fit, newdata = values)
values$predicted_concentration <- predicted_concentration

# Add the predictions to your plot, maybe in a different color

with(values, points(Absorbance, predicted_concentration, col='red'))

我不清楚这里的控制/治疗前/治疗后意味着什么,也许你可以澄清我是否遗漏了一些东西。

© www.soinside.com 2019 - 2024. All rights reserved.