www.gusucode.com > stats 源码程序 matlab案例代码 > stats/SimultaneouslySpecifytheVariablesandUseFormulaExample.m
%% Specify Response and Predictor Variables for Linear Model % Fit a linear regression model to sample data. Specify the response and % predictor variables, and include only pairwise interaction terms in the % model. %% % Load sample data. load hospital %% % Fit a linear model with interaction terms to the data. Specify weight as % the response variable, and sex, age, and smoking status as the predictor % variables. Also, specify that sex and smoking status are categorical % variables. mdl = fitlm(hospital,'interactions','ResponseVar','Weight',... 'PredictorVars',{'Sex','Age','Smoker'},... 'CategoricalVar',{'Sex','Smoker'}) %% % The weight of the patients do not seem to differ significantly according % to age, or the status of smoking, or interaction of these factors with % patient sex at the 5% significance level.