1

I am pretty new to R - and I can't find a good answer to this via googling, so I appreciate your help. I have data that, when plotted, shows a logarithmic curve. I modeled it as lm(y~log(x)):

logEstimate <- lm(d$MaxHt~log(d$StemDens))
coef(logEstimate)
       (Intercept) log(Pycnan$TS) 
         51.37911       12.63334 

I'd like to fit a curve from this model onto a plot of my original variables (x, y). I tried several different ways using curve(), but I kept getting error messages:

plot(d$MaxHt~d$StemDens)

curve(logEstimate, from=0, to=45, n=101, add=TRUE)

Error in logEstimate(x) : could not find function "logEstimate"

curve(51.37911+12.63334*log(d$StemDens), from=0, to=45, n=101, add=TRUE)

Error in curve(51.37911 + 12.63334 * log(Pycnan$TS), add = TRUE, col = 2) : 'expr' must be a function, or a call or an expression containing 'x'

I'm not sure how to make logEstimate a function. I'm also not sure if I am missing a step to back transform my coefficients before I try to fit them to a plot of the original data. Any advice would be greatly appreciated!

Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
Rcard
  • 11
  • 1
  • It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample data that can be copy/pasted into R so that possible solutions can be tested and verified. But in most cases like this, you should use `predict()` rather than `curve()` – MrFlick Dec 18 '17 at 16:30
  • 1
    You need a function and not a data vector, just to use 'x' in place of d$StemDens. Use `curve(51.37911+12.63334*log(x), from=0, to=45, n=101, add=TRUE)` – Dave2e Dec 18 '17 at 20:15

0 Answers0