简体   繁体   中英

Nonlinear model in r

What is the problem with the following r code as I get error?

nonlinear <- function(G,Q,T) {
    Y=G+Q*X^T
}

Model <- nls(nonlinear, start = list(G=0.4467, Q=-0.0020537, T=1), data=sample1)

Error: object of type 'closure' is not subsettable

Taking the data from your other question Nonlinear modelling starting values and the code from @Roland this works:

sample1 <- read.table(header=TRUE, text=
"X         Y                  Z
135      -0.171292376      85  
91      0.273954718        54   
171     -0.288513438       107
88       -0.17363066       54
59     -1.770852012        50
1        0                 37
1       0                  32
1       0.301029996        36
2       -0.301029996       39
1       1.041392685        30
11      -0.087150176       42
9        0.577236408       20
34       -0.355387658      28
15        0.329058719      17
32        -0.182930683     24
21        0.196294645      21
33        0.114954516      91
43       -0.042403849      111
39       -0.290034611       88
20       -0.522878746       76
6        -0.301029995       108
3         0.477121254       78
9          0                63
9          0.492915522      51
28       -0.243038048       88
16        -0.028028724      17
15      -0.875061263        29
2       -0.301029996        44
1        0                  52
1        1.531478917        65")

nonlinear<-function(X,G,Q,T) G+Q*X^T
nls(Y ~ nonlinear(X,G,Q,T), start=list(G=-0.4, Q=0.2, T=-1), data=sample1)

Depending from the data I had to change the starting values!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM