More generally, to create a linear regression model, use the
fitlm() function. This function creates a
LinearModel object. The object in the workspace has a series of properties that can be immediately viewed by simply clicking on it. Methods such as
plotDiagnostics are available if you want to create plots and perform a diagnostic analysis.
LinearModel is an object comprising training data, model description, diagnostic information, and fitted coefficients for a linear regression.
fitlm() takes the last variable in the table or dataset array as the response. Otherwise, we have to specify predictors and response variables, for example, as a formula. In addition, we can set a specific column as the response variable by using the
ResponseVar name-value pair argument. To use a set of the columns as predictors, use the
PredictorVars name-value pair argument. Predictor variables can be numeric or of any grouping variable...