简体   繁体   English

R 给定y计算x的点对点方法

[英]R point-to-point method for calculating x given y

I am using a commercial ELISA kit which contains four standards.我正在使用包含四种标准的商业 ELISA 试剂盒。 These standards are used to create a standard curve, with optical densities from the ELISA reader on the y axis and concentrations in international units per milileter on the x axis.这些标准品用于创建标准曲线,y 轴为 ELISA 阅读器的光密度,x 轴为每毫升国际单位的浓度。

I now need to use this standard curve to get concentrations for samples in which I only have the optical density readings.我现在需要使用此标准曲线来获取只有光密度读数的样品的浓度。 The ELISA kit instructions specifically state "Use “point-to-point” plotting for calculation of the standard curve by computer". ELISA 试剂盒具体说明 state “使用“点对点”绘图通过计算机计算标准曲线”。

I am assuming they mean derive the value of x by seeing where y is hitting the line between the points on the standard curve and dropping down to the x axis from there.我假设他们的意思是通过查看 y 在哪里击中标准曲线上各点之间的线并从那里下降到 x 轴来得出 x 的值。 The problem is I have no idea how to do this in r (which is what I am using for my full analytical pipeline).问题是我不知道如何在 r 中执行此操作(这是我用于完整分析管道的内容)。 I have searched in vain for any r packages, functions or code which correspond to "point-to-point" but can´t find anything.我徒劳地搜索了任何 r 对应于“点对点”但找不到任何东西的包、函数或代码。 All the R packages that deal with ELISA data and / or standard curves (eg drc and ELISAtools seem to do something much more complex, ie fit a log model and account for inter-plate variances etc., which is not what I need.所有处理 ELISA 数据和/或标准曲线的 R 包(例如drcELISAtools似乎做的事情要复杂得多,即适合日志 model 并考虑板间差异等,这不是我需要的。

Please note that I don´t need to visualise the standard curve - I just need a method to get the concentrations from the standard curve data based on the point-to-point line.请注意,我不需要可视化标准曲线——我只需要一种方法来根据点对点线从标准曲线数据中获取浓度。

Here is some sample data:这是一些示例数据:

# Data for standard curve:
scdt <- data.table(id = c("Cal1", "Cal2", "Cal3", "Cal4"), 
                   conc = c(200, 100, 25, 5), 
                   od = c(1.783, 1.395, 0.594, 0.164))

> scdt
     id conc    od
1: Cal1  200 1.783
2: Cal2  100 1.395
3: Cal3   25 0.594
4: Cal4    5 0.164

# Some example OD values for which I would like to derive concentration:
unknowns <- c(0.015, 0.634, 0.891, 1.510, 2.345, 3.105) 

In the example values I want to solve for x, I have also included some that are outside the range covered by the standards as this also occurs in my real data from time to time.在我想为 x 求解的示例值中,我还包括了一些超出标准范围的值,因为这在我的真实数据中也会不时发生。 The kit manufacturer advises against reporting IU/mL for anything with an OD exceeding that of the highest standard (Cal1) which is sensible.试剂盒制造商建议不要报告任何 OD 超过合理的最高标准 (Cal1) 的任何东西的 IU/mL。

How can I do the R equivalent of finding x with a ruler and graph paper from the standard curve and what is this formally called?我如何做 R 等价于用尺子和方格纸从标准曲线中找到 x,这正式称为什么? (I think one reason I might not have found anything is because "point-to-point" isn´ta mathematical term, but there must be one for this - is it interpolation?). (我认为我可能没有找到任何东西的一个原因是因为“点对点”不是数学术语,但必须有一个 - 它是插值吗?)。

It sounds like you want a simple linear interpolation.听起来你想要一个简单的线性插值。 This is achieved in R using the function approx .这是在 R 中使用 function approx实现的。 You feed it your known x values, your known y values and the new values for x for which you want the corresponding y values.您将已知的 x 值、已知的 y 值和您想要相应 y 值的 x 的新值提供给它。 (Note that it doesn't matter which variable you call x and which you call y, as long as you are consistent). (请注意,您将哪个变量称为 x 以及将哪个变量称为 y 并不重要,只要您保持一致即可)。

To get a result that is easier to work with, we can convert the response to a data frame with appropriate column names:为了获得更易于使用的结果,我们可以将响应转换为具有适当列名的数据框:

new_data <- approx(scdt$od, scdt$conc, xout = unknowns) |> 
  setNames(c("od", "conc")) |> 
  as.data.frame() 

new_data
#>      od      conc
#> 1 0.015        NA
#> 2 0.634  28.74532
#> 3 0.891  52.80899
#> 4 1.510 129.63918
#> 5 2.345        NA
#> 6 3.105        NA

Note that (as the manufacturer recommends), optical densities falling outside the extreme ranges of your calibration points will give NA values for concentration.请注意(如制造商建议的那样),落在校准点极端范围之外的光密度将给出浓度的NA值。 To get these you would need to extrapolate rather than interpolate要获得这些,您需要外推而不是内插

Just to confirm this is what you're looking for, let's plot the results of this interpolation in red over the curve formed from the initial data:只是为了确认这就是您要查找的内容,让我们 plot 在根据初始数据形成的曲线上以红色显示此插值的结果:

plot(scdt$od, scdt$conc, type = "l", lty = 2)
points(scdt$od, scdt$conc)
points(new_data$od, new_data$conc, col = "red")

在此处输入图像描述

We can see that the estimated concentrations at each new optical density lie on the lines connecting the calibration points.我们可以看到,每个新光密度下的估计浓度位于连接校准点的线上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM