我在 R 中创建了一个函数来执行 Bradford 校准曲线,以获得曲线的斜率和截距,从而分析我的实验室数据。这是我写的代码:
CalibrationLine <- function() {
BSAC <- readline("BSA concentrations (ug/uL): ")
BSAC <- str_split(BSAC, " ")
BSAC <- unlist(BSAC)
BSAC <- as.numeric(BSAC)
Absorbance <- readline("Absorbance (595 nm): ")
Absorbance <- str_split(Absorbance, " ")
Absorbance <- unlist(Absorbance)
Absorbance <- as.numeric(Absorbance)
Data <- data.frame(BSAC, Absorbance)
Plot <- ggplot(Data, aes(x = BSAC, y = Absorbance))+
geom_point()+
stat_smooth(method = lm)
Plot
paste("Correlation coefficient:", cor(Data$Absorbance, Data$BSAC), sep = " ")
model <- lm(Absorbance ~ BSAC, data = Data)
model
}
当我添加 BSA 浓度及其吸光度值时,我获得了线性回归模型系数(斜率和截距)。但是,散点图未绘制,粘贴函数未粘贴,变量未保存在我的全局环境中。这是我在控制台中得到的:
> CalibrationLine()
BSA concentrations (ug/uL): 0.125 0.5 1 2 4 5 7.5 10 14 18 22
Absorbance (595 nm): 0.006 0.032 0.065 0.203 0.33 0.364 0.55 0.661 0.846 1.022 1.123
Call:
lm(formula = Absorbance ~ BSAC, data = Data)
Coefficients:
(Intercept) BSAC
0.0719484 0.0524287