In general chemistry lab Chem 123, we have an atrocious tutorial on using Excel for linear regression. The problem with this is that as the Excel interface has changed, the tutorial itself has gotten more and more convoluted. It’s a really simple, 4-point-calibration data set, and the only things the students need from it are the coefficients.
Later, in Chem 126, we use Excel to graph an entire spectrum (absorbance as a function of wavelength), and then study the variation of these spectra as concentrations of two species change, and we try to model that using a weighted combination of reference spectra. I’d love to figure out how R can do that.
This tutorial assumes that you have already:
lattice libraryYou will see there are 4 rows in boyle. A team of students used a syringe and a force sensor to measure the pressure (atm) and volume (L) of a nitrogen gas sample under different levels of compression, and at constant temperature. They recorded these measurements into the data set boyle, which contains the variables ‘pressure’ and ‘volume’.
It’s a small data set, so let’s take a look at the numbers using the View command.
View(boyle)
Qualitatively, we can see that as the applied pressure was increased (at constant temperature), the gas’s volume decreased. What sort of relationship do these variables have to each other? Let’s use `xyplot’ to plot the data.
xyplot(volume~pressure, data=boyle)
There are few problems with the appearance of this graph. For example the axis labels are just the names of the variables defined in R, which do not indicate units. Rather than modifying the names, we can use xyplot to set the axis labels separately from the variable names. We do this by using the keywords xlab and ylab for the x-axis label and y-axis labels, respectively. Remember to place text in quotes.
xyplot(volume~pressure, data=boyle, xlab="Pressure (atm)", ylab="Volume(V)")