0

I'm trying to fit a cubic curve to my scatterplot. I was able to do this in minitab with no problem, but I'm finding it quite difficult to fit a cubic nonlinear regression to my data. my data is set up like:

AGE Value
3   10
4   10
5   11
5   13
6   10
7   9
8   8
ebrown1985
  • 65
  • 4
  • 9

1 Answers1

3

See ?poly which (by default) sets up a design matrix-ready orthogonal polynomial of the specified degree over the range of x-values you hand to it:

df <- read.table(text="AGE Value
3   10
4   10
5   11
5   13
6   10
7   9
8   8", header=TRUE)

lm(Value ~ poly(AGE, degree=3), data=df)

# Call:
# lm(formula = Value ~ poly(AGE, 3), data = df)
# 
# Coefficients:
#   (Intercept)  poly(AGE, 3)1  poly(AGE, 3)2  poly(AGE, 3)3  
#       10.1429        -2.0026        -2.3908         0.6019  
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455