[R] nls model singular gradient matrix at initial parameter estimates

oussama belmejdoub oussa.belm at hotmail.com
Wed May 27 03:23:35 CEST 2015


Greetings,
I'm trying to use the nls function in my statistics project but I'm really finding lot of difficulties.
I have a function called apinene_modele_prediction that calculates the estimations:
library(expm); #exp of a matrixapinene_modele_prediction <- function(t,theta) {	x0=c(100,0,0,0,0)	A=matrix(c(-(theta[1]+theta[2]),theta[1],theta[2],0,0,0,0,0,0,0,0,0,-(theta[3]+theta[4]),theta[3],theta[4],0,0,0,0,0,0,0,theta[5],0,-theta[5]),5,5)	X=x0	for (i in t[2:length(t)]){		X=c(X,x0%*%expm(A*i))		}return(X)}

My "t" vector is given by: 
t=seq(0,100,by=2) 
And the real observations "y" ara given to us  in a txt file called "data.txt" that I have joined to this message.
So when I try to fit the "theta" in my model starting with: theta=c(0.2,0.2,0.2,0.2,0.2) 
And doing:
theta_appr <-nls(y~apinene_modele_prediction(t,theta),start=list(theta=c(0.2,0.2,0.2,0.2,0.2)))
I always got the ERROR : singular gradient matrix at initial parameter estimates
And, when I try: nls(y~apinene_modele_prediction(t,c(theta,theta,theta,theta,theta)),start=list(theta=0.2))
I got the result: Nonlinear regression model  model: y ~ apinene_modele_prediction(t, c(theta, theta, theta, theta,     theta))   data: parent.frame()  theta0.04403 residual sum-of-squares: 219002
But I need to have the elements of the theta to be different and not equal.
Thanks in advance for your help. 		 	   		  
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: data.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150527/37052351/attachment.txt>


More information about the R-help mailing list