Polynomial Fit in R
Projectile Data & Fit from Excel Time (s) Height (m) 0.0244 0.0667 0.0489 0.1207 0.0734 0.168 0.0979 0.2088 0.1226 0.2365 0.1472 0.2624 0.1719 0.282 0.1966 0.2955 0.2214 0.3029 0.2462 0.3044 0.271 0.2977 0.2959 0.2874 0.3208 0.27 0.3457 0.2451 0.3707 0.2198 0.3957 0.1857 0.4207 0.1413 0.4459 0.0875
Data in R #copy and paste times = c(0, 0.0244, 0.0489, 0.0734, 0.0979, 0.1226, 0.1472, 0.1719, 0.1966, 0.2214, 0.2462, 0.271, 0.2959, 0.3208, 0.3457, 0.3707, 0.3957, 0.4207, 0.4459) heights = c(0, 0.0667, 0.1207, 0.168, 0.2088, 0.2365, 0.2624, 0.282, 0.2955, 0.3029, 0.3044, 0.2977, 0.2874, 0.27, 0.2451, 0.2198, 0.1857, 0.1413, 0.0875) proj = data.frame(times, heights)
Plot Data in R
Note that the “x^2” term is inside I() Compare the coefficients to the fit equation from Excel
Isolating the coefficients Recall we are fitting to the form y(t) = y0 + v0 t + a t2 /2 So for us a (the acceleration) is twice the value from the fit
Displaying the equation
Displaying the curve
Another approach
Raw=TRUE Without the raw=TRUE option in poly, the R program will not use simple linear and quadratic powers of the variable, but will introduce “orthogonal” combinations of the variables. This makes for better statistics – to have “independent” variables, but it makes the results harder to read and interpret.
Isolating the coefficients in version 2