cvdney
cvdney

Reputation: 11

How do I add 3 data points to a calibration curve in R Studio?

I am trying to add data of a pre, post and control absorbance values to my calibration curve graph.

The code below is what I currently have, which creates a scattergraph and a line of best fit. However I need to plot the absorbance values of...

Control: 0.008 Pre-Treatment: 0.280 Post-Treatment: 0.117

...onto the graph using the line of best fit to find their concentrations. Here is my code below:

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))

plot(BSA, ylab="Absorbance of BSA", xlab="Assay Concentration (ml/mg)", las=1) 
abline(lm(BSA$Absorbance ~ BSA$Concentration))

Graph I have created so far

I am struggling to find a method to do this and previous posts are very specific to the user's data set and do not work with my data for some reason.

Upvotes: 0

Views: 109

Answers (1)

Demetri Pananos
Demetri Pananos

Reputation: 7404

I'm still not entirely clear on what you need, but it sounds like you need to:

  • Fit a model to predict concentration from absorbance
  • Predict concentration for some new values, and
  • Plot those predictions on the same plot.

Here is how I would approach it

# 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'))

enter image description here

I'm not clear on what control/pre/post treatment mean here, maybe you can clarify if I've missed something.

Upvotes: 0

Related Questions