R: Using the natural logarithm equation in nls

Good afternoon,

I am struggling with R and the natural logarithm (ln). Firstly, I cannot find the ln (x) function in R. I noticed that log (x) is the same as ln (x) (when using ln (x) with a calculator).

In R:

log(5) = 1.609438 

And with a calculator:

 ln(5) = 1.609438 log(5) = 0.69897 

I am trying to set the equation in R (this is exactly what I found in the literature of 3 references):

y = a + b ( x / 305 ) + c ( x / 305 ) 2 + d ln ( 305 / x ) + f ln 2 ( 305 / <sub> hsub>)

Is it correct to use the following syntax in R to use the equation?

 y ~ a + b*(x/305) + c*((x/305)^2) + d*log(305/x) + f*(log(305/x))^2 

The idea is to use this function with nls () in R. Thanks in advance!

+9
source share
3 answers

In R, log is the natural logarithm. In calculators, a log usually means the logarithm of base 10. To achieve this in R, you can use the log10 function.

 log(5) ## [1] 1.609438 log10 ## [1] 0.69897(5) 

As for your formula, it seems correct, as log is the natural logarithm.

+19
source

In addition, I will indicate that your model

 y ~ a + b*(x/305) + c*((x/305)^2) + d*log(305/x) + f*(log(305/x))^2 

is linear in a statistical sense linear in coefficients; it should not be linear in x.

You do not need nls for this model, you can use lm ().

But don't forget to look at the function I () to express expressions like (x / 305) ^ 2.

ETA Example:

 aDF <- data.frame(x=abs(rnorm(100)), y=rnorm(100)) lm(y ~ 1 + I(x/305) + I((x/305)^2) + log(305/x) + I(log(305/x)^2), data=aDF) 
+4
source

In R, log calculates logarithms, by default, natural logarithms, log10 calculates the usual (i.e., base 10) logarithms, and log2 calculates the binary (i.e., base 2) logarithms. The general form log (x, base) computes the logarithms with a base. ("Documentation R")

0
source

Source: https://habr.com/ru/post/971050/


All Articles