I'm trying to build a nonlinear model as described in the manual for gmn in R. The desired form of the model is
y = b0*x0^g0 + b1*x1^g1 + ...
This would seem to be the simplest possible form of nonlinear model to me, but for some reason (and please correct me if I'm wrong!) I have to write a custom nonlinear function to fit it in R. Very well!
df=read.csv("d:/mydataframe.csv")
require(gnm)
mypower = function(x){
list(predictors = list(beta=1,gamma=1),
variables = list(substitute(x)),
term = function(predlabels,varlabels) {
paste(predlabels[1],"*(",varlabels[1],"**",predlabels[2],")")
}
)
}
class(mypower) <- "nonlin"
Now when I try
fit <- gnm(formula=y ~ mypower(x1), data=df)
I get a fitted value of beta and gamma from the model. But when I try
fit <- gnm(formula=y ~ mypower(x1)+mypower(x2), data=df)
I get the error
Algorithm failed - no model could be estimated.
So, question 1: how can I solve this?
Also, when - trying to match all xs - I try
fit <- gnm(formula=PedalCycles ~ mypower(.), data=df)
I get
Error in eval(expr, envir, enclos) : object '.' not found
Is this the right way to specify a sum of all xs each raised to a power?