主要内容

Analysis of Covariance

协方差分析介绍

协方差分析是一种分析具有响应的分组数据的技术(y, the variable to be predicted) and a predictor (x, the variable used to do the prediction). Using analysis of covariance, you can modely作为线性功能x, with the coefficients of the line possibly varying from group to group.

Analysis of Covariance Tool

TheAoctool.功能打开与分析协方差(ANOCOVA)模型的拟合和预测的交互式图形环境。它适合以下模型i群体:

同样的意思

Y =α+ε

单独的手段

y = (α + αi) + ε

同一行

y = α + βx + ε

平行线

y = (α + αi) + βx + ε

Separate lines

y = (α + αi) + (β + βi)x + ε

例如,在并行线模型中,拦截从一个组变化到下一个组,但是每个组的斜率相同。在相同的均值模型中,存在共同的截距和没有斜率。为了使组系数良好确定,该工具施加了约束

α j = β j = 0

以下步骤描述了使用Aoctool.

  1. 加载数据。The Statistics and Machine Learning Toolbox™ data setcarsmall.matcontains information on cars from the years 1970, 1976, and 1982. This example studies the relationship between the weight of a car and its mileage, and whether this relationship has changed over the years. To start the demonstration, load the data set.

    load carsmall

    工作区浏览器显示数据集中的变量。

    You can also useAoctool.使用您自己的数据。

  2. Start the tool.The following command callsAoctool.适合列向量的单独行WeightMPGfor each of the three model group defined inmodel_year.。The initial fit models theyvariable,MPG,作为线性函数xvariable,Weight

    [h,atab,ctab,stats] = aoctool(重量,mpg,model_year);

    看看Aoctool.功能reference page for detailed information about callingAoctool.

  3. 检查输出。The graphical output consists of a main window with a plot, a table of coefficient estimates, and an analysis of variance table. In the plot, eachmodel_year.group has a separate line. The data points for each group are coded with the same color and symbol, and the fit for each group has the same color as the data points.

    The coefficients of the three lines appear in the figure titled ANOCOVA Coefficients. You can see that the slopes are roughly –0.0078, with a small deviation for each group:

    • 1970年型号年份:y = (45.9798 – 8.5805) + (–0.0078 + 0.002)x + ε

    • 1976年式模型年:y = (45.9798 – 3.8902) + (–0.0078 + 0.0011)x + ε

    • 1982年模型年份:Y =(45.9798 + 12.4707)+(-0.0078 - 0.0031)x +ε

    Because the three fitted lines have slopes that are roughly similar, you may wonder if they really are the same. Themodel_year.*Weightinteraction expresses the difference in slopes, and the ANOVA table shows a test for the significance of this term. With anF5.23和a的统计数据p值为0.0072,斜坡显着不同。

  4. 约束斜坡是相同的。要检查斜率限制为相同时的适合,返回Anocova预测绘图窗口并使用模型弹出菜单选择a平行线模型。窗口更新以显示以下图形。

    虽然这适合看起来合理,但它明显差Separate Lines模型。Use the模型pop-up menu again to return to the original model.

信心界

这个例子Analysis of Covariance Tool提供对关系之间的关系估计MPGWeightfor eachmodel_year.,但这些估计有多准确?要了解一下,您可以一次将它们审视一个组来叠加着适合的信心范围。

  1. 在里面model_year.图右下方的菜单,更改设置所有团体to 82. The data and fits for the other groups are dimmed, and confidence bounds appear around the 82 fit.

    The dashed lines form an envelope around the fitted line for model year 82. Under the assumption that the true relationship is linear, these bounds provide a 95% confidence region for the true line. Note that the fits for the other model years are well outside these confidence bounds forWeight之间的价值20003000

  2. Sometimes it is more valuable to be able to predict the response value for a new observation, not just estimate the average response value. Use theAoctool.功能Boundsmenu to change the definition of the confidence bounds fromLinetoObservation。由此产生的更宽的间隔反映了参数估计中的不确定性以及新观察的随机性。

    polytool功能, theAoctool.功能has cross hairs that you can use to manipulate theWeight和watch the estimate and confidence bounds along they-axis update. These values appear only when a single group is selected, not when所有团体被选中。

Multiple Comparisons

You can perform a multiple comparison test by using thestatsoutput structure fromAoctool.as input to the多人节目功能。The多人节目功能可以测试斜坡,截距或群体边缘手段(每个组的平均重量的预测MPG)。这个例子Analysis of Covariance Toolshows that the slopes are not all the same, but could it be that two are the same and only the other one is different? You can test that hypothesis.

Multcompare(统计数据,0.05,'ON','','S')ANS = 1.0000 2.0000 -0.0012 0.0008 0.0029 1.0000 3.0000 0.0011 0.0051 0.0088 2.0000 3.0000 0.0005 0.0042 0.0079

This matrix shows that the estimated difference between the intercepts of groups 1 and 2 (1970 and 1976) is 0.0008, and a confidence interval for the difference is [–0.0012, 0.0029]. There is no significant difference between the two. There are significant differences, however, between the intercept for 1982 and each of the other two. The graph shows the same information.

Note that thestats结构是在初始呼叫中创建的Aoctool.功能, so it is based on the initial model fit (typically a separate-lines model). If you change the model interactively and want to base your multiple comparisons on the new model, you need to runAoctool.again to get anotherstats结构,这次将您的新模型指定为初始模型。