[R] Help fit 5 nonlinear models. - Plant growth curves
Alejandro Coca Castro
acocac at gmail.com
Tue May 17 12:32:13 CEST 2011
Hi!! Can anyone help me, i have problems to converge the following
data with 5 nonlinears models that i evaluated.
Firtly, i send my data (totalsinatipicos) that i just try to fit with
the nonlinear models.
Next, i have the following script where i called the data as
totalsinatipicos. I made selfstarting each nonlinear model.
###Library
library(NRAIA)
###Data
d<-totalsinatipicos
f=unique(d$TRAT)
dia=unique(d$DDT)
REG=4:15
###Models
monomolecular=function(x,a,b,c){return(a*(1-exp(-b*(x-c))))}
gompertz=function(x,a,b,c){return(a*exp(-exp(-b*(x-c))))}
logistico=function(x,a,b,c){return(a/(1+exp(-b*(x-c))))}
gauss=function(x,a,b,c){return(a*exp((-((x-c)*(x-c))/(2*(b*b)))))}
richards=function(x,a,b,c){return(a*(1+(m-1)*exp(-b*(x-c)))**(1/(1-m)))}
###Variables
#Altura
ALTURA0=subset(d,d$TRAT==f[1],select=c(1,REG[1]))
ALTURA_0=data.frame(dia,tapply(ALTURA0[,2],ALTURA0[,1],median, na.rm=TRUE))
colnames(ALTURA_0)=c("ddt","reg")
#PSEUDO
PSEUDO0=subset(d,d$TRAT==f[1],select=c(1,REG[5]))
PSEUDO_0=data.frame(dia,tapply(PSEUDO0[,2],PSEUDO0[,1],median, na.rm=TRUE))
colnames(PSEUDO_0)=c("ddt","reg")
#DIAM
DIAM0=subset(d,d$TRAT==f[1],select=c(1,REG[6]))
DIAM_0=data.frame(dia,tapply(DIAM0[,2],DIAM0[,1],median, na.rm=TRUE))
colnames(DIAM_0)=c("ddt","reg")
#AF
AF0=subset(d,d$TRAT==f[1],select=c(1,REG[7]))
AF_0=data.frame(dia,tapply(AF0[,2],AF0[,1],median, na.rm=TRUE))
colnames(AF_0)=c("ddt","reg")
#PSB
PSB0=subset(d,d$TRAT==f[1],select=c(1,REG[8]))
PSB_0=data.frame(dia,tapply(PSB0[,2],PSB0[,1],median, na.rm=TRUE))
colnames(PSB_0)=c("ddt","reg")
#PSA
PSA0=subset(d,d$TRAT==f[1],select=c(1,REG[11]))
PSA_0=data.frame(dia,tapply(PSA0[,2],PSA0[,1],median, na.rm=TRUE))
colnames(PSA_0)=c("ddt","reg")
#PST
PST0=subset(d,d$TRAT==f[1],select=c(1,REG[12]))
PST_0=data.frame(dia,tapply(PST0[,2],PST0[,1],median, na.rm=TRUE))
colnames(PST_0)=c("ddt","reg")
For example, i show the converge error for each variable for fitting
logistic model. In some cases, apparently the model works but it
doesnt show the number of iterations. Also, i put lower and upper
values, after graph each variable and estimate these with the data
behavior.
------------------------------------------------------------------------------
summary(ALTU <- nls(reg ~ logistico(ddt,a,b,c), ALTURA_0,
start=c(a=1.00001,b=0.00001,c=1.00001),algorithm = "port",
lower=c(a=10,b=0.1,c=40), upper=c(a=71,b=0.5,c=80)))
Error en nls(reg ~ logistico(ddt, a, b, c), ALTURA_0, start = c(a = 1.00001, :
Convergence failure: initial par violates constraints
summary(AF <- nls(reg ~ logistico(ddt,a,b,c), AF_0,
start=c(a=1.000001,b=0.000001,c=1.000001),algorithm = "port",
lower=c(a=0.01,b=0,c=0.01)), upper=c(a=700,b=0.5,c=90))
Error en nls(reg ~ logistico(ddt, a, b, c), AF_0, start = c(a = 1.000001, :
Convergence failure: singular convergence (7)
summary(PSEUDO <- nls(reg ~ logistico(ddt,a,b,c), PSEUDO_0,
start=c(a=1.000001,b=0.000001,c=50),algorithm = "port",
lower=c(a=0.01,b=0,c=50)), upper=c(a=2,b=0.5,c=90))
Formula: reg ~ logistico(ddt, a, b, c)
Parameters:
Estimate Std. Error t value Pr(>|t|)
a 2.26458 2.95827 0.766 0.500
b 0.02780 0.04687 0.593 0.595
c 50.00000 102.68111 0.487 0.660
Residual standard error: 0.3078 on 3 degrees of freedom
Algorithm "port", convergence message: relative convergence (4)
summary(DIAM <- nls(reg ~ logistico(ddt,a,b,c), DIAM_0,
start=c(a=1.000001,b=0.000001,c=1.000001),algorithm = "port",
lower=c(a=0.01,b=0,c=0.01)), upper=c(a=10,b=0.5,c=90))
Formula: reg ~ logistico(ddt, a, b, c)
Parameters:
Estimate Std. Error t value Pr(>|t|)
a 9.68748 0.93912 10.315 0.001943 **
b 0.07290 0.01345 5.419 0.012326 *
c 56.38424 3.92957 14.349 0.000734 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.4382 on 3 degrees of freedom
Algorithm "port", convergence message: relative convergence (4)
summary(PSB <- nls(reg ~ logistico(ddt,a,b,c), PSB_0,
start=c(a=1.000001,b=0.000001,c=1.000001),algorithm = "port",
lower=c(a=0.01,b=0,c=0.01)), upper=c(a=18,b=0.5,c=90))
Formula: reg ~ logistico(ddt, a, b, c)
Parameters:
Estimate Std. Error t value Pr(>|t|)
a 18.367752 0.680799 26.98 0.000112 ***
b 0.100945 0.005831 17.31 0.000420 ***
c 69.990010 1.006649 69.53 6.56e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.208 on 3 degrees of freedom
Algorithm "port", convergence message: relative convergence (4)
summary(PSA <- nls(reg ~ logistico(ddt,a,b,c), PSA_0,
start=c(a=1.000001,b=0.000001,c=1.000001),algorithm = "port",
lower=c(a=0.01,b=0,c=0.01)), upper=c(a=7,b=0.5,c=90))
Formula: reg ~ logistico(ddt, a, b, c)
Parameters:
Estimate Std. Error t value Pr(>|t|)
a 6.19659 0.42597 14.547 0.000704 ***
b 0.08874 0.01776 4.995 0.015432 *
c 49.10031 2.86108 17.161 0.000431 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.351 on 3 degrees of freedom
Algorithm "port", convergence message: relative convergence (4)
summary(PST <- nls(reg ~ logistico(ddt,a,b,c), PST_0,
start=c(a=1.000001,b=0.000001,c=1.000001),algorithm = "port",
lower=c(a=0.01,b=0,c=0.01)), upper=c(a=26,b=0.5,c=90),
control=nls.control(maxiter=1))
Formula: reg ~ logistico(ddt, a, b, c)
Parameters:
Estimate Std. Error t value Pr(>|t|)
a 27.950304 1.770967 15.783 0.000553 ***
b 0.081335 0.008213 9.903 0.002190 **
c 64.257293 2.168668 29.630 8.44e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.6266 on 3 degrees of freedom
Algorithm "port", convergence message: relative convergence (4)
-----------------------------------------------------------------------
Finally, my next step is to automatized the process, with loops, for
running each variable with each model in each treatment, which are 4,
but i am beginner in R program. Can anyone give a idea about it?.
Also, i just tried to use SSmodels, like SSlogis, SSgompertz and
SSRichards, but i have models as monomolecular and gauss function that
aren't defined in this algoritms.
Thanks for your help or suggestions.
--
Alejandro Coca
UN
-------------- next part --------------
DDT TRAT REP ALTURAM NHT NHE NHS PSEUDO DIAM AF PSB PSV PSR PSA PST
23 0 1 0 0.6 1 188.18 0.155 0.754 1.237
23 0 2 6 6 0 0.6 1 0.16 0.215 0.96
23 0 3 8 7 1 0.65 1 189 0.167 0.207 0.77 1.144
23 0 4 7 6 1 0.6 1.1 165.23 0.285 0.901 1.331
23 30 1 8 7 1 0.7 0.95 165.01 0.184 1.513
23 30 2 8 7 1 0.6 1.05 109.5 0.154 0.959 1.43
23 30 3 7 6 1 0.5 1.05 0.141 0.068 0.528
23 30 4 7 2 0.5 0.85 119.05 0.231 0.115 0.786 1.132
23 60 1 7 6 1 0.6 1 120 0.799 1.214
23 60 2 7 6 1 0.6 1.05 157.5 0.137 0.289 0.807 1.233
23 60 3 8 7 1 0.6 0.205 0.257
23 60 4 8 7 1 0.5 1.15 180 0.166 0.221 0.977 1.364
23 90 1 7 6 1 0.5 0.9 160 0.129 0.196 0.611 0.936
23 90 2 7 7 0 0.45 0.8 140 0.12 0.136 0.639 0.895
23 90 3 8 7 1 0.5 1.1 150 0.148 0.122 0.652 0.922
23 90 4 1
36 0 1 49 8 8 0 0.8 1.2 180.54 0.25 0.19 0.33 1.03 1.8
36 0 2 7 1 0.9 1.3 132.87 0.29
36 0 3 54 8 7 1 0.9 184.64 0.38 0.21 0.25 1.11 1.95
36 0 4 58 8 7 1 0.8 1.4 223.13 0.24 0.22 1.25 2.26
36 30 1 50 10 9 1 1.95 0.67 0.43
36 30 2 51 10 9 1 0.95 1.9 237.29 0.69 0.5 1.75 3.16
36 30 3 56 9 2 0.85 1.15 210.8 0.3 0.59 1.41 2.59
36 30 4 10 8 2 0.8 1.9 281.6 0.65 0.39 0.6 2.23 3.87
36 60 1 9 2 0.87 0.74
36 60 2 51 8 7 1 0.85 1.2 130.97 0.28 0.24 0.3 1.09 1.91
36 60 3 50 7 1 0.7 1.2 138.84 0.17 0.2 0.29 0.9 1.56
36 60 4 62 10 9 1 0.9 1.35 243.44 0.49 0.29
36 90 1 48 10 8 2 0.6 1.5 153.44 0.53 0.27 0.36 1.15 2.31
36 90 2 48 7 1 0.7 1.25 166.86 0.28 0.21 0.39 1.09 1.97
36 90 3 48 9 7 2 0.7 1.3 166.02 0.26 0.21 0.26 1.07 1.8
36 90 4 10 8 2 0.49 0.26 1.17 2.31
50 0 1 64 14 11 3 1.25 378.81 1.91 0.88 0.76 3.74 7.29
50 0 2 57 15 12 3 1.35 4.2 405.41 2.46 0.81 0.95 3.57 7.79
50 0 3 54 12 11 1 1.3 3.8 361.67 2.06 0.56 3.44 6.56
50 0 4 3 1.5 4.3 3.12 0.75
50 30 1 59 13 4 1.15 4.1 400.87 2.82 0.6 0.73 3.48 7.63
50 30 2 65 10 8 2 1.15 3.4 392.12 1.95 0.64 3.63 6.61
50 30 3 56 10 7 3 1.1 3.3 305.08 1.99 0.61 0.83 3.08 6.51
50 30 4 60.5 7 1 1 277.8 0.87 2.23
50 60 1 52 3 1 3.8 295.64 2.98 0.92 2.61 7.3
50 60 2 62 10 6 4 1 248.69 0.91 0.61 0.61 2.32 4.45
50 60 3 54.5 11 7 4 0.8 4.3 307.97 0.46 0.42 2.43 7.36
50 60 4 63.5 9 7 2 1.1 2.9 1.3 0.62 2.89 5.83
50 90 1 50.8 11 3 0.7 3.7 232.66 0.57 2.06
50 90 2 49 10 7 3 0.8 3.3 232.86 2.17 0.63 0.5 2 5.3
50 90 3 53 11 7 4 0.8 3.2 285.19 1.57 0.62 0.47 2.25 4.91
50 90 4 52 6 3 0.7 3.5 2.12 0.49 0.54 1.74 4.89
64 0 1 62 16 12 4 1.685 5.472 474.88 1.71 1.03 5.47 13.33
64 0 2 60 3 5.392 310.36 6.55 0.75 0.49 3.85 11.64
64 0 3 64 13 10 3 1.723 6.299 416.03 7.55 1.26 1.07 4.64 14.52
64 0 4 64 16 13 3 1.931 6.312 6.18 1.22
64 30 1 69 12 8 4 1.181 379.18 0.76 1.15 3.97
64 30 2 62 11 7 4 1.084 5.152 248.52 5.48 0.63 2.76 9.53
64 30 3 54 11 8 3 1.122 5.362 280.16 4.23 0.57 0.98 2.86 8.64
64 30 4 58 12 8 4 1.187 5.112 267.87 4.48 0.61 1.15 3.4 9.64
64 60 1 57 12 8 4 1.225 4.749 283.02 4.25 0.67 0.95 3.14 9.01
64 60 2 57 0.92 4.937 220.1 5.78 0.48 0.32 2.23 8.81
64 60 3 58 13 8 5 1.102 5.724 249.15 8.08 0.83 0.39 2.69 11.99
64 60 4 66 12 7 5 1.232 5.857 0.94
64 90 1 54 10 6 4 0.776 3.765 155.72 2.78 0.37 0.42 1.93 5.5
64 90 2 47 4 3.335 130.23 2.74 0.41 0.25 1.34 4.74
64 90 3 57 11 6 5 0.965 4.599 4.97
64 90 4 50 11 6 0.906 4.798 152.26 0.58 0.51 2.04 8.87
76 0 1 66 15 12 3 1.519 7.053 651.23 11.64 1.55 0.94 21.83
76 0 2 64 7 4 1.193 7.828 13.68 1.22 4.78 20.52
76 0 3 63 13 9 4 1.287 7.922 479.95 11.8 1.07 1.35 6.3 20.52
76 0 4 71 12 9 3 1.114 7.895 556.83 1.67 5.7
76 30 1 60 12 8 4 1.078 7.36 371.79 0.81 0.56 3.86 17.72
76 30 2 12 6 1.327 5.636 9.7 1.35 0.59 2.42 14.06
76 30 3 64 12 8 4 0.964 5.875 459.71 9.35 0.75 1.16 15.82
76 30 4 60 12 9 3 5.533 340.7 8.31 3.92
76 60 1 49 12 7 5 1.049 6.055 214.49 7.47 0.8 0.85 2.31 11.43
76 60 2 50 12 7 5 0.943 5.24 189.89 8.15 0.86 0.43 2.47 11.91
76 60 3 52 10 6 4 5.85 221.65 8.59 0.56 0.64 2.07 11.86
76 60 4 60 10 6 4 0.96 6.116 0.63 3.54
76 90 1 44 9 4 5 0.652 4.617 125.86 4.19 0.3 0.6 1.28
76 90 2 56 10 5 5 0.711 4.581 138.37 5.53 0.34 0.66 1.62 8.15
76 90 3 51 10 5 5 4.595 148.17 4.78 0.49 0.69 1.95 7.91
76 90 4 52 5 6 0.782 5.371 0.53 1.94 9.83
87 0 1 59 14 3 1.59 8.674 16.41 1.27 0.62 6.76 25.06
87 0 2 60.5 13 9 4 8.475 496.88 17.97 0.89 1.52 5.33 25.71
87 0 3 60 12 4 1.586 9.063 459.08 13.75 1.1 5.99 21.29
87 0 4 58 13 10 3 1.56 8.886 487.45 14.81 1.31 6.12 23.02
87 30 1 54 11 7 4 1.1 7.375 270.18 11.47 0.5 0.64 2.86 15.47
87 30 2 59 10 4 1.117 7.521 278.92 11.65 0.79 3.33 16.14
87 30 3 60 8 5 1.207 7.847 358.79 11.15 0.81 0.68 3.47 16.11
87 30 4 61 12 7 5 1.176 8.12 11.05 0.72 0.69 3.67 16.13
87 60 1 59 10 6 4 1.048 6.003 237.78 6.88 0.45 2.52 10.29
87 60 2 56 11 6 5 1.058 6.694 338.4 7.2 0.4 0.3 3.72 11.62
87 60 3 11 6 5 0.892 6.607 7.25 0.42 2.09 10.4
87 60 4 53 8 5 1.026 6.916 215.1 9.49 0.45 2.89
87 90 1 10 5 5 0.619 4.533 108.85 2.98 0.3 0.48 1.5 5.26
87 90 2 48 9 4 5 0.806 4.96 3.78 0.3 0.42 6.71
87 90 3 49 10 4 6 0.741 5.091 77.55 3.53 1.43 5.43
87 90 4 42 10 5 5 0.88 5.33 107.01 0.29 0.52 1.56 7.54
More information about the R-help
mailing list