0
I am creating several models, to then make the selection based on Aicc. Among these models that I am creating, I have a categorical predictive variable (fire) that I need to include in the nonlinear regression model. The three models I need to run are:
fire_vertical <- nls(R~0.23-exp(A*lnNt+C)+d*fire,
start=list(A=-0.33,C=0.45,d=-0.001),trace=T)
fire_lateral <- nls(R~0.23-exp((A*lnNt)+(C+d*fire)),
start=list(A=-0.33,C=0.45,d=-0.001),trace=T)
fire_nonlinear <- nls(R~0.23-exp((A+d*fire)*lnNt+C),
start=list(A=-0.33,C=0.45,d=-0.001),trace=T)
Considering the following data:
R <- c(0.02,0.00,-0.06,0.11,0.06,0.00,-0.05,-0.06,
0.02,-0.26,0.00,0.07,-0.07,0.23,0.06,-0.14,-0.04,
0.09,-0.09,0.09,-0.02)
lnNt <- c(6.14,6.14,5.76,6.42,6.81,
6.81,6.49,6.14,6.24,4.81,4.81,5.14,
4.81,6.03,6.42,5.59,5.39,5.90,5.39,5.90,5.76)
fire <- c("before","before","before",
"before","before","before",
"before","afterone","afterone","afterone",
"afterone","afterone","afterone","afterone",
"aftertwo","aftertwo","aftertwo","aftertwo","aftertwo",
"aftertwo","aftertwo")
Where lnNt
is a continuous predictive variable, while fire is a categorical predictor with three levels: before
, afterone
, aftertwo
.
I need to transform the fire into a dummie variable and make the three models presented spin this way.
Anyone who can help, I’d like to thank.
Instead of turning into dummy, turn into
factor
and try to see what you can do. Almost all (or even all) R modeling functions recognize characters or factors and automatically create Dummies, it is not necessary to do it manually– Rui Barradas
But if you want to create Dummies, see the package Dummies or the package dummy.
– Rui Barradas
Hi Rui. I tried to do as you suggested, but could not run any of the models. The following error message appeared: "Error in numericDeriv(form[[3L]], Names(Ind), env) : Obtained missing or infinite value when evaluating the model In addition: Warning messages: 1: In Ops.factor(d, fire) :'not Meaningful for factors 2: In Ops.factor(d, fire):' not Meaningful for factors"
– Benjamin Guidon