Isa
Isa

Reputation: 13

Logarithmic function in R

I am currently working on a growth model with the lme package of the statistical software R. I've already built models with a linear and poly(Time,2) trend, whereas the latter fits better. Additionally, I would like to test for a logarithmic trend but don't know what the function in R looks like or how to transform it as most guides only cover linear, quadratic, cubic trends but exclude logarithmic ones.

Therefore, I would highly appreciate if someone could help me out and provide me with a function for a logarithmic trend.

In order to make it more clear what I'm currently doing -> my current models look like:

model.linear<-lme(DV~1+Time,random=~1|Subnum,data=dataset,na.action=na.omit,control=list(opt="optim"))

model.quadratic<-lme(DV~poly(Time,2),random=~1|Subnum,data=dataset,na.action=na.omit,control=list(opt="optim"))

Upvotes: 1

Views: 815

Answers (1)

ulfelder
ulfelder

Reputation: 5335

I think you're looking for:

model.logistic<-lme(DV~log1p(Time),random=~1|Subnum,data=dataset,na.action=na.omit,control=list(opt="optim"))

The function log1p() adds 1 to each observation before logging it, which works well with count variables or other variables with a lower bound of 0 and whole-number increments.

Upvotes: 2

Related Questions