Clear Filters
Clear Filters

Can one call nlinfit using bootstrp?

3 views (last 30 days)
Daniel Livsey
Daniel Livsey on 17 May 2017
Commented: Daniel Livsey on 30 May 2017
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.

Answers (1)

David Ding
David Ding on 26 May 2017
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 Comment
Daniel Livsey
Daniel Livsey on 30 May 2017
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!