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.                                          
"y"
99.9232
5.7485
0.6644
-0.4988
0.5019
83.3796
16.0905
3.4184
-0.1619
4.3231
67.6461
17.6714
6.1861
0.4555
3.4022
58.3199
24.0947
7.009
1.3153
7.0712
47.587
35.4656
6.4072
0.715
9.0156
42.3778
34.0976
6.0112
1.0316
14.0637
34.4176
38.188
6.0135
0.8093
14.7598
29.2941
56.7453
5.7462
1.24
15.5634
24.2075
49.4543
4.8968
1.3849
21.834
21.2213
51.3734
5.2268
1.7867
19.4716
18.9238
55.3147
4.5223
2.6202
22.053
13.9119
65.6723
4.4736
2.4025
20.5307
14.0519
64.1892
4.3354
2.6657
23.0909
9.6691
62.9989
4.8074
3.1438
20.2343
8.018
59.7792
3.9934
2.7481
23.0476
7.6965
58.3577
3.6449
3.8192
25.8571
5.7062
54.7404
4.2607
3.1089
25.4888
5.6596
58.5899
3.6794
3.541
25.3896
5.4871
65.4693
3.6679
3.5918
25.7453
2.5278
70.9596
3.933
3.8858
22.8982
5.3682
74.6359
3.7192
4.1048
25.37
3.159
66.7303
3.3373
4.0423
25.6204
-0.3612
72.2608
3.9413
4.9181
22.8085
3.1431
68.0772
3.5597
4.5132
22.3135
0.7453
66.8462
3.9621
4.1373
25.5405
0.8502
63.7415
3.8063
4.9193
24.9146
1.4089
71.1166
3.7259
4.2357
21.76
1.7045
71.7744
3.3515
4.899
23.7245
0.6204
61.9383
3.8477
5.561
22.3485
0.3335
63.1572
3.3009
5.7315
26.3752
1.6638
62.4002
3.1931
5.2699
23.3077
1.7851
66.0386
3.3138
5.79
25.2986
0.3481
61.4702
3.3343
5.6509
22.9967
0.088
59.5469
3.2485
5.9959
21.0902
-0.9691
70.1917
3.3433
5.8771
27.0169
-0.1861
66.933
3.1346
6.0566
20.7277
1.1325
74.0641
3.7472
6.0475
22.177
1.7875
61.0552
3.1733
5.8029
18.2692
-0.6303
69.7692
3.3849
6.6513
22.7722
0.8757
62.7373
2.7142
6.6476
20.6708
-0.5705
61.1083
3.4895
6.077
23.3414
-0.3324
69.8406
3.1186
6.6764
22.7215
0.2536
63.2522
3.2815
7.3864
21.1594
-1.1912
65.0752
3.2217
5.9924
23.3834
0.3408
68.4797
2.7571
6.9196
21.9287
0.6937
75.7468
3.6325
7.5853
21.6415
1.6548
70.4596
2.7858
6.9878
25.7793
-0.2572
73.3611
3.0593
7.6976
21.6229
1.5903
72.4284
2.8289
8.1584
25.5773
-0.5075
63.7588
3.3313
8.1676
23.3128
-0.836
71.0337
3.1666
7.638
20.2517
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to