nlsfit: Fit nonlinear models

Description Usage Arguments Value Author(s) References See Also Examples

Description

The function fit some nonlinear models

Usage

1
nlsfit(data, model = 1, start = c(a = 1, b = 1, c = 1, d = 1, e = 1))

Arguments

data

data is a data.frame

The first column should contain the treatments (explanatory variable) and the remaining columns the response variables.

model

define the model

1 = "y~a+b*x" linear

2 = "y~a+b*x+c*x^2" quadratic

3 = "y ~ a + b * (x - c) * (x <= c)" linear plateau

4 = "y ~ (a + b * x + c * I(x^2)) * (x <= -0.5 * b/c) + (a + I(-b^2/(4 * c))) * (x > -0.5 * b/c)" quadratic plateau

5 = "ifelse(x>=d,(a-c*d)+(b+c)*x, a+b*x)" two linear

6 = "y~a*exp(b*x)" exponential

7 = "y~a*(1+b*(exp(-c*x)))^-1" logistic

8 = "y~a*(1-b*(exp(-c*x)))^3" van bertalanffy

9 = "y~a*(1-b*(exp(-c*x)))" brody

10 = "y~a*exp(-b*exp(-c*x)" gompertz

11 = "y~(a*x^b)*exp(-c*x)" lactation curve

12 = "y ~ a + b * (1 - exp(-c * x))" ruminal degradation curve

13 = "y~(a/(1+exp(2-4*c*(x-e))))+(b/(1+exp(2-4*d*(x-e))))" logistic bi-compartmental

start

start iterations values of model

Value

Returns coefficients of the models, t test for coefficients, R squared, adjusted R squared, AIC, BIC and the maximum (or minimum) values of y and critical point of x

Author(s)

Emmanuel Arnhold <emmanuelarnhold@yahoo.com.br>

References

KAPS, M. and LAMBERSON, W. R. Biostatistics for Animal Science: an introductory text. 2nd Edition. CABI Publishing, Wallingford, Oxfordshire, UK, 2009. 504p.

See Also

nls, nls2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# data represent weights of an Angus cow at ages from 8 to 108 months (Kaps and Lamberson, 2009)

weight=c(280,340,430,480,550,580,590,600,590,600)
age=c(8,12,24,36,48,60,72,84,96,108)

data1=data.frame(age, weight)

# linear
nlsfit(data1, model=1)

# quadratic
nlsfit(data1, model=2)

# linear plateau
nlsfit(data1, model=3)

# quadratic plateau
nlsfit(data1, model=4)

# two linear
nlsfit(data1, model=5, start=c(250,6,2,50))

# exponential
nlsfit(data1, model=6, start=c(250,0.05))

# logistic
nlsfit(data1, model=7, start=c(600,4,0.05))

# van bertalanffy
nlsfit(data1, model=8, start=c(600,2,0.05))

# brody
nlsfit(data1, model=9, start=c(600,4,0.05))

# gompertz
nlsfit(data1, model=10, start=c(600,4,0.05))



# describe the growth of Zagorje turkeys (Kaps and Lamberson, 2009)


weight=c(44,66,100,150,265,370,455,605,770)
age=c(1,7,14,21,28,35,42,49,56)

data2=data.frame(age,weight)

# two linear
nlsfit(data2, model=5, start=c(25,6,10,20))

# using segmented regression to estimate a plateau
# the requirement for the methionine will be estimated measurements of gain of turkey poults 
#(Kaps and Lamberson, 2009)

methionine=c(80,85,90,95,100,105,110,115,120)
gain=c(102,115,125,133,140,141,142,140,142)

data3=data.frame(methionine, gain)

# linear
nlsfit(data3, model=1)

# quadratic
nlsfit(data3, model=2)

# linear plateau
nlsfit(data3, model=3)

# quadratic plateau
nlsfit(data3, model=4)

# lactation curve
 milk=c(25,24,26,28,30,31,27,26,25,24,23,24,22,21,22,20,21,19,
18,17,18,18,16,17,15,16,14)
 days=c(15,15,15,75,75,75,135,135,135,195,195,195,255,255,255,
315,315,315,375,375,375,435,435,435,495,495,495)
    
 data4=data.frame(days,milk)
	

nlsfit(data4, model=11, start=c(16,0.25,0.004))

# ruminal degradation 
time=c(2,6,9,24,48,72,96)
deg=c(20,33,46,55,66,72,76)

data5=data.frame(time,deg)

nlsfit(data5, model=12)

# logistic bi-compartmental (gas production)
time=c(0,12,24,36,48,60,72,84,96,108,120,144,168,192)
gas=c(0.002,3.8,8,14.5,16,16.5,17,17.4,17.9,18.1,18.8,
19,19.2,19.3)
    
data6=data.frame(time,gas)

nlsfit(data6, model=13, start=c(19,4,0.025,0.004,5))

Example output

$Model
[1] "y~a+b*x"

$Parameters
                       weight
coefficient a        339.4654
coefficient b          3.0025
p-value t.test for a   0.0000
p-value t.test for b   0.0004
r-squared              0.8035
adjusted r-squared     0.7789
AIC                  112.3822
BIC                  113.2899

$Model
[1] "y~a+b*x+c*x^2"

$Parameters
                                 weight
coefficient a                  232.7150
coefficient b                    8.8342
coefficient c                   -0.0518
p-value t.test for a             0.0000
p-value t.test for b             0.0000
p-value t.test for c             0.0000
r-squared                        0.9874
adjusted r-squared               0.9838
AIC                             86.9145
BIC                             88.1249
maximum or minimum value for y 609.5294
critical point in x             85.3082

$Model
[1] "y ~ a + b * (x - c) * (x <= c)"

$Parameters
                                 weight
coefficient a                  592.0000
coefficient b                    6.3873
coefficient c                   53.1548
p-value t.test for a             0.0000
p-value t.test for b             0.0000
p-value t.test for c             0.0000
r-squared                        0.9869
adjusted r-squared               0.9831
AIC                             87.3110
BIC                             88.5213
maximum or minimum value for y 592.0000
critical point in x             53.1548

$Model
[1] "y ~ (a + b * x + c * I(x^2)) * (x <= -0.5 * b/c) + (a + I(-b^2/(4 * c))) * (x > -0.5 * b/c)"

$Parameters
                                 weight
coefficient a                  216.0022
coefficient b                   10.1285
coefficient c                   -0.0676
p-value t.test for a             0.0000
p-value t.test for b             0.0000
p-value t.test for c             0.0000
r-squared                        0.9945
adjusted r-squared               0.9929
AIC                             78.6308
BIC                             79.8412
maximum or minimum value for y 595.1217
critical point in x             74.8622

$Model
[1] "ifelse(x>=d,(a-c*d)+(b+c)*x, a+b*x)"

$Parameters
                       weight
coefficient a        244.1667
coefficient b          6.9167
coefficient c         -6.2262
coefficient d         46.0918
p-value t.test for a   0.0000
p-value t.test for b   0.0001
p-value t.test for c   0.0003
p-value t.test for d   0.0000
r-squared              0.9866
adjusted r-squared     0.9800
AIC                   89.5001
BIC                   91.0130

$Model
[1] "y~a*exp(b*x)"

$Parameters
                       weight
coefficient a        368.2618
coefficient b          0.0055
p-value t.test for a   0.0000
p-value t.test for b   0.0019
r-squared              0.7411
adjusted r-squared     0.7087
AIC                  115.1412
BIC                  116.0490

$Model
[1] "y~a*(1+b*(exp(-c*x)))^-1"

$Parameters
                       weight
coefficient a        602.8890
coefficient b          1.6953
coefficient c          0.0579
p-value t.test for a   0.0000
p-value t.test for b   0.0000
p-value t.test for c   0.0000
r-squared              0.9931
adjusted r-squared     0.9911
AIC                   80.9263
BIC                   82.1366

$Model
[1] "y~a*(1-b*(exp(-c*x)))^3"

$Parameters
                       weight
coefficient a        608.6197
coefficient b          0.3165
coefficient c          0.0444
p-value t.test for a   0.0000
p-value t.test for b   0.0000
p-value t.test for c   0.0000
r-squared              0.9929
adjusted r-squared     0.9908
AIC                   81.2191
BIC                   82.4294

$Model
[1] "y~a*(1-b*(exp(-c*x)))"

$Parameters
                       weight
coefficient a        612.8656
coefficient b          0.7272
coefficient c          0.0380
p-value t.test for a   0.0000
p-value t.test for b   0.0000
p-value t.test for c   0.0000
r-squared              0.9922
adjusted r-squared     0.9900
AIC                   82.0835
BIC                   83.2938

$Model
[1] "y~a*exp(-b*exp(-c*x)"

$Parameters
                       weight
coefficient a        606.9001
coefficient b          1.0915
coefficient c          0.0476
p-value t.test for a   0.0000
p-value t.test for b   0.0000
p-value t.test for c   0.0000
r-squared              0.9930
adjusted r-squared     0.9911
AIC                   80.9729
BIC                   82.1833

$Model
[1] "ifelse(x>=d,(a-c*d)+(b+c)*x, a+b*x)"

$Parameters
                      weight
coefficient a        38.2992
coefficient b         4.3228
coefficient c        12.8404
coefficient d        20.5018
p-value t.test for a  0.1891
p-value t.test for b  0.1811
p-value t.test for c  0.0070
p-value t.test for d  0.0018
r-squared             0.9938
adjusted r-squared    0.9900
AIC                  88.6271
BIC                  89.6133

$Model
[1] "y~a+b*x"

$Parameters
                        gain
coefficient a        38.7778
coefficient b         0.9233
p-value t.test for a  0.0771
p-value t.test for b  0.0016
r-squared             0.7793
adjusted r-squared    0.7478
AIC                  64.7925
BIC                  65.3841

$Model
[1] "y~a+b*x+c*x^2"

$Parameters
                                    gain
coefficient a                  -377.1169
coefficient b                     9.3822
coefficient c                    -0.0423
p-value t.test for a              0.0001
p-value t.test for b              0.0000
p-value t.test for c              0.0000
r-squared                         0.9892
adjusted r-squared                0.9856
AIC                              39.6409
BIC                              40.4298
maximum or minimum value for y  143.1995
critical point in x             110.9156

$Model
[1] "y ~ a + b * (x - c) * (x <= c)"

$Parameters
                                   gain
coefficient a                  141.0000
coefficient b                    2.0600
coefficient c                   98.3010
p-value t.test for a             0.0000
p-value t.test for b             0.0000
p-value t.test for c             0.0000
r-squared                        0.9937
adjusted r-squared               0.9916
AIC                             34.7552
BIC                             35.5441
maximum or minimum value for y 141.0000
critical point in x             98.3010

$Model
[1] "y ~ (a + b * x + c * I(x^2)) * (x <= -0.5 * b/c) + (a + I(-b^2/(4 * c))) * (x > -0.5 * b/c)"

$Parameters
                                    gain
coefficient a                  -474.4471
coefficient b                    11.4890
coefficient c                    -0.0536
p-value t.test for a              0.0000
p-value t.test for b              0.0000
p-value t.test for c              0.0000
r-squared                         0.9969
adjusted r-squared                0.9958
AIC                              28.4725
BIC                              29.2614
maximum or minimum value for y  141.4498
critical point in x             107.2147

$Model
[1] "y~(a*x^b)*exp(-c*x)"

$Parameters
                                  milk
coefficient a                  18.3409
coefficient b                   0.1344
coefficient c                   0.0022
p-value t.test for a            0.0000
p-value t.test for b            0.0000
p-value t.test for c            0.0000
r-squared                       0.9396
adjusted r-squared              0.9345
AIC                            90.9676
BIC                            96.1510
maximum or minimum value for y 27.9360
critical point in x            62.2340

$Model
[1] "y ~ a + b * (1 - exp(-c * x))"

$Parameters
                         deg
coefficient a        17.4030
coefficient b        55.6709
coefficient c         0.0554
p-value t.test for a  0.0337
p-value t.test for b  0.0005
p-value t.test for c  0.0273
r-squared             0.9664
adjusted r-squared    0.9495
AIC                  45.5423
BIC                  45.3259

$Model
[1] "y~(a/(1+exp(2-4*c*(x-e))))+(b/(1+exp(2-4*d*(x-e))))"

$Parameters
                         gas
coefficient a        15.1675
coefficient b         4.3371
coefficient c         0.0362
coefficient d         0.0073
coefficient e         9.7433
p-value t.test for a  0.0000
p-value t.test for b  0.0004
p-value t.test for c  0.0000
p-value t.test for d  0.0047
p-value t.test for e  0.0001
r-squared             0.9955
adjusted r-squared    0.9934
AIC                  26.1631
BIC                  29.9974

easynls documentation built on May 2, 2019, 3:30 p.m.