Hi Faizan,
I understand that you have a working code for one independent variable. You want to know the way to generalise the above algorithm for the multivariate case.
To generalize the bootstrap approach for a multivariate model with multiple independent variables, you would need to make a few modifications to the code you provided. Here's a general outline of the steps involved:
- Update the data and independent variables: X = data(3:42, 2:end);
- Adjust the function definition of the Project_func function. You can change by using the linear combination of independent variables and modifying the model equation.
- Modify the bootstrap loop to include all independent variables. This is an example code for the changes in your previous code.
for j = 2:nboot
r = round(1 + (n - 1) .* rand(n, 1)); % Index of random integers from 1 to n
for i = 1:n
if mm == 1
tt(i) = t(r(i)); % tt(i) is the time for each bootstrapped datum
yboot(i) = Cobs(r(i)); % yboot(i) is the y value for each bootstrapped datum
end
if mm == 2
tt = t;
yboot(i) = Cpred(i) + resids(r(i));
if i == n
yboot = yboot'; % Make yboot a column
end
end
end
[betab(j, :), rr(j, :), J2, COVB2, mse2] = nlinfit(tt, yboot, @(beta) Project_func(beta, X), beta0, nlinfitcheck);
ypredb(j, :) = Project_func(betab(j, :), X);
clear yboot
end
These modifications will enable your code to generalise for multivariate cases. Make sure to adjust the code with respect to the changes.
Hope this helps!