-2

I have a logarithmic curve in x and y data (I know the curve is smooth and have 127 data points). Im trying to use R to find the equation for calculating Y when X = N.

I have put my data into R

x = c(0, 1, 2, 3, 4...
y = c(0 , 31.6 , 33.3 , 35.1 , 36.9....

Then can graph the data using

plot(x,y)

So I can see my curve is smooth.

But then Im stuck on how to get R to output an equation I can use for calculating Y when X = N

I have done a least squares regression and can find the residuals. However, Im stuck on how to get from the residuals to the equation I need for calculating Y.

tonytonov
  • 25,060
  • 16
  • 82
  • 98
Ke.
  • 2,484
  • 8
  • 40
  • 78
  • Please show how you do the least squares regression. – Roland Mar 14 '14 at 09:17
  • I do "fit <- lm(x ~ y)" and then "residuals(fit)", which gives me the residuals but im stuck there – Ke. Mar 14 '14 at 09:20
  • `fit$coef`? Have you looked at `?predict.lm` ? – Hugh Mar 14 '14 at 09:25
  • @Ke. There are numerous tutorials. Read one. – Roland Mar 14 '14 at 09:30
  • Thats not very helpful Roland. Ive been reading tutorials all night, otherwise I would not be posting on here. Ive read over 100 tutorials and none of them seem to put together an easy way of finding an equation from data sets – Ke. Mar 14 '14 at 09:36
  • Sorry, but if you had a minimal understanding how linear regression works, you should be able to construct the equation from the output of `summary(fit)` or `coef(fit)`. You might have read "over 100 tutorials" (I doubt that), but obviously you didn't understand them. Maybe you should read a textbook. – Roland Mar 14 '14 at 10:00

1 Answers1

0

plot(x,fit$fitted.values) should do the trick.

To know the fit coefficients:

fit$coef

To fit a new value:

N<-5 Y_N<-fit$coef[1]+fit$coef[2]*N

Pinemangoes
  • 1,158
  • 3
  • 11
  • 13
  • Im not trying to plot this on a graph. Im trying to get the equation for working out Y when X = N . Do you know how to get R to output an equation for the curve in the plot? – Ke. Mar 14 '14 at 09:56