although I've found plenty of help regarding fitting models in general, I keep running into a specific issue with my data because of the way it's organized. It's from an intro stats book and is supposed to represent sample data of errors as a function of milligrams of some drug.
|-----|-------|-------|-------|
| 0mg | 100mg | 200mg | 300mg |
|-----|-------|-------|-------|
| 25 | 16 | 6 | 8 |
| 19 | 15 | 14 | 18 |
| 22 | 19 | 9 | 9 |
| 15 | 11 | 5 | 10 |
| 16 | 14 | 9 | 12 |
| 20 | 23 | 11 | 13 |
The data looks like it dips around group C, then goes up a bit for D, hence looking for a quadratic fit.
I've tried the following:
scores = c(25, 19, 22, 15, 16, 20,
16, 15, 19, 11, 14, 23,
6, 14, 9, 5, 9, 11,
8, 18, 9, 10, 12, 13)
x_groups = rep(c(0,100, 200, 300), each = 6)
scores.quadratic = lm(scores ~ poly(x_groups, 2, raw = TRUE))
I can then use the summary()
function to view the results. I'm confused about the lm()
function and how it's supposed to fit a quadratic function. My understanding is that it will take each index in x_groups
and square that, then use a linear fit with that new vector, but that doesn't seem correct to me.
Can someone provide feedback on how this is supposed to fit a quadratic to my data, or if it's not doing that, please help me understand where I'm going wrong.
Thank you.