Simulate responses for nonlinear regression model
Create a nonlinear model of car mileage as a function of weight, and simulate the response.
Create an exponential model of car mileage as a function of weight from the
carsmall data. Scale the weight by a factor of 1000 so all the variables are roughly equal in size.
load carsmall X = Weight; y = MPG; modelfun = 'y ~ b1 + b2*exp(-b3*x/1000)'; beta0 = [1 1 1]; mdl = fitnlm(X,y,modelfun,beta0);
Create simulated responses to the data.
Xnew = X; ysim = random(mdl,Xnew);
Plot the original responses and the simulated responses to see how they differ.
W — Weights
no weights (default) | vector | function handle
Vector of real, positive value weights or a function handle.
If you specify a vector, then it must have the same number of elements as the number of observations (or rows) in
If you specify a function handle, the function must accept a vector of predicted response values as input, and returns a vector of real positive weights as output.
the error variance at observation
MSE*(1/W(i)), where MSE is the mean squared
For predictions without added noise, use
Introduced in R2012a