(Least-Squares Linear Regression)
Debugging
Hopefully, the warnings and error messages you receive will help your resolve any technical issues you have. If you are unable to solve your issues on your own, come to the help room.
Report any bugs to phy_introlabs@stonybrook.edu (but please make your own attempts, with TAs in the help room, to resolve said bugs first). Please include a screenshot of inputs (if using the manual interface) or the CSV file used (if using the CSV file interface).
Do not take a lack of warnings to indicate a perfect plot. Other errors (especially misplaced decimal points) can still cause problems, and you are responsible for making sure these do not occur.
You should check your data and make sure it follows the trendline (if you expect it to), and check that your error bars are reasonably sized (in particular, not larger than the range of your data!).
Note that slopes and intercepts with very large or small magnitude will display in scientific notation. Make sure to notive when this happens, so that your answers are not wring by orders of magnitude!
Advanced Techniques for Plotting Tool Use
Here are a few more technical features that can either make your life easier or can make your plot look nicer:
- If you do not include x/y min/max, the plotting tool will choose defaults based on the range of your data (10% of the range of your data above/below the top/bottom of your data).
- To input in scientific notation, format your numbers as "1.2e-6" (this is valid for any numerical input).
- To input mathematical expressions (such as \(x^2\)) in your title or axis labels, first write your expression in \(\LaTeX\), then enclose it between dollar signs. E.g.: "$\sqrt{\frac{L}{g}}$" will output as \(\sqrt{\frac{L}{g}}\); "$ax^2+bx+c$" will output as \(ax^2+bx+c\).
- An equation editor (which will give you the \(\LaTeX\) code for a mathematical expression) is available here.
- This is one way to have Greek letters in your axis labels, but you can also just copy-paste the character from elsewhere into the relevant text box.
- To have a multi-line title (or axis label), type a "\n" where you want the line break.
Your inputs here are first forwarded to a PHP script. This PHP script compiles your data (extracting it from the CSV file if you choose to use that interface) and runs basic validation on it (giving warnings or errors if something is wrong, and doing its best to fix such issues in a minimally-intrusive way).
This script then saves your actual data to a file, and calls a Python script (from the command line) with your other plot parameters. This python script reads your data back from that file, runs the fitting algorithm, and makes the plot. It then saves the plot as an image which is read by the (HTML surrounding the) PHP script.
The python script makes the plot using the Matplotlib library. If you want to make a plot with a similar style, you can read the documentation provided there.
The optimization is a standard vertical least-squares linear fit, either with or without intercept. This matches what most simple programs (such as Excel or Google Sheets' LINEST routine) will do if asked to estimate the best fit line.
More advanced methods are possible, but are difficult to execute due to needing to optimize more complicated functions of the data. Standard vertical least-squares fitting is analytically solvable with linear algebra; a more detailed orthogonal distance regression requires a numerical optimization routine.
As a result of this data-fitting procedure, your error bars are not actually used in performing the fit, nor estimating its uncertainty. Instead, the uncertainty is estimated based on the size of the scatter in your data.