I want to fit the following Generalized Nonlinear Model: Probit(G)=K+1/Sigma*(Temp-T0)*Time. As naive model, I created Probits(G) by qnorm(G) and then fitted the Nonlinear Model. But I want to fit Nonlinear Model with logit link similar to glm function in R.
How can I fit such Generalized Nonlinear Model with logit link in R?
Data <-
structure(list(Temp = c(23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
27L, 27L, 27L, 27L, 27L, 27L, 33L, 33L, 33L, 33L, 33L, 33L, 33L,
35L, 35L, 35L, 35L, 35L), Time = c(144L, 168L, 192L, 216L, 240L,
264L, 288L, 312L, 120L, 144L, 168L, 192L, 216L, 240L, 72L, 96L,
120L, 144L, 168L, 192L, 216L, 96L, 120L, 144L, 168L, 192L), G = c(15,
25.5, 27, 28, 28.5, 39.5, 41.5, 43, 13, 21.5, 29.5, 30.5, 32.5,
35, 13.5, 28, 32.5, 33.5, 35, 39.5, 42, 6.5, 30, 39.5, 57, 58.5
)), .Names = c("Temp", "Time", "G"), class = "data.frame", row.names = c(NA,
-26L))
Data$GermRate <- 1/Data$Time
Data$Probits <- qnorm(p=Data$G/100) # Get Probits
fm1 <-
nls(
formula= Probits ~ K+1/Sigma*(Temp-T0)*Time
, data=Data
, start=list(K=1, Sigma=2, T0=2)
#, algorithm= "port"
)
fm1Summary <- summary(fm1)
fm1Coef <- summary(fm1)$coef
You can fit this type of model using the
gnmpackage for generalized nonlinear models. It takes a bit of work, asgnmuses pre-defined functions of class"nonlin"to specify nonlinear terms in the model and the ones provided by the package are generally insufficient to specify an arbitrary nonlinear function. However it is possible to define a custom"nonlin"function to use withgnm.In your model,
kis a linear parameter, so we only need to worry about the second term. This can be specified via the following"nonlin"functionIn the returned list,
predictorsspecifies thatsigmaandt0are predictors with a single intercept term (i.e. are individual parameters).variablesspecifies that there are two variables, to be supplied by the user via theTempandTimearguments.termspecifies a function to create a deparsed mathematical expression of the term, given labels for the predictors and the variables.More detail on
"nonlin"functions can be found in Section 3.5 of the gnm vignette.Now we can try fitting your model as follows
Note that, as in
glm, an intercept is added to the formula by default, which here will representk. Although the starting values are far from the solution, thegnmconvergence criteria are met at this point, so the algorithm does not perform any iterations. In this case a better starting estimate ofsigmais required forgnmto converge to something more sensibleActually it is possible to specify this model using the
Multfunction provided bygnm, as long as you don't mind re-parameterising the model:EDIT
The function of the parameters is specified in the
termcomponent of the list returned bycustomNonlin, which you can see viaSo if you just want to change the functional form, you will need to modify the
termfunction. If you want to add/remove parameters, you would also need to modify the list in thepredictorscomponent. Similarly if the new term requires you to add/remove variables, you would modify thevariablescomponent.