Can one call nlinfit using bootstrp?

1 次查看(过去 30 天)
I would like to compute nonlinear regression parameter confidence intervals using bootstrp; however, I am having difficulty passing 'nlinfit' to the function 'bootstrp'. Below is an example code:
fun = @(b,x) b(1).*x.^b(2) + b(3); beta = bootstrp(iterations,'nlinfit',x,y,fun,rand(3,1));
% with x and y vectors of equal length and % beta a matrices of regression parameter estimates % of length iterations and width width equal to length of b. % 'rand' is called for random starting point for beta in nlinfit.
I have passed 'polyfit' to 'bootstrp' successfully but not 'nlinfit'. Any suggestions would be greatly appreciated.
Please note I am familiar with 'nlparci' but prefer bootstrap regression parameter confidence intervals. Also, I have written code to compute nonlinear regression parameter confidence intervals but would prefer to use 'bootstrp' for a cleaner code. I do not have access to the optimization toolbox.
% The above code produces this error code: Error using bootstrp>bootEvalCommand (line 289) Nonscalar arguments to BOOTFUN must have the same number of rows.

回答(1 个)

David Ding
David Ding 2017-5-26
Hi Daniel,
Function "nlinfit" can be one of the functions for the argument "bootfun". I was able to reproduce the error you saw. It is likely because the dimensions of your inputs for the function "fun" has a mismatch.
@(b,x)b(1).*x.^b(2)+b(3)
You have to ensure that the first argument, b, is a vector of size 3.
A quick code test below reveals that "bootstrp" with "nlinfit" works:
x = rand(3, 1);
y = x;
fun = @(b,x) b(1).*x.^b(2) + b(3);
beta = bootstrp(10,@nlinfit,x,y,fun,rand(3,1));
The output I get is:
beta =
0.9929 2.1711 0.1102
0.2567 1.9473 0.4512
0.9929 2.1711 0.1102
0.6877 5.1138 0.4988
0.7738 6.5739 0.5130
0.6396 3.3466 0.4505
1.0000 1.0000 0.0000
0.6877 5.1138 0.4988
0.7995 1.4732 0.2155
0.6429 2.9832 0.4305
Thanks,
David
  1 个评论
Daniel Livsey
Daniel Livsey 2017-5-30
David, thank you for answer. I think your code is really close to what I would like. I tried your code and it worked but the code does not work when I try to increase the number of observations in x and y. For example:
x = rand(100, 1);
y = x;
fun = @(b,x) b(1).*x.^b(2) + b(3);
beta = bootstrp(10,@nlinfit,x,y,fun,rand(3,1));
Below is the error code I received:
% Error using bootstrp>bootEvalCommand (line 289)
% Nonscalar arguments to BOOTFUN must have the same number of rows.
%
% Error in bootstrp (line 137)
% [n,booteval] = bootEvalCommand(bootfun,bootargs{:});
I am confused about the error code regarding nonscalar arguments. From the above code the vector b is of proper length (3,1). It seems that the code only works when x and b are of the same length; this should not be the case from my understanding of the input arguments for nlinfit.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by