原文链接:http:tecdat。cn?p9529 目录 怎么做测试 协方差分析 拟合线的简单图解 模型的p值和R平方 检查模型的假设 具有三类和II型平方和的协方差示例分析 协方差分析 拟合线的简单图解 组合模型的p值和R平方 检查模型的假设 怎么做测试 具有两个类别和II型平方和的协方差示例的分析 本示例使用II型平方和。参数估计值在R中的计算方式不同, Dataread。table(textConnection(Input),headerTRUE) plot(xDataTemp,yDataPulse,colDataSpecies,pch16,xlabTemperature,ylabPulse) legend(bottomright,legendlevels(DataSpecies),col1:2,cex1,pch16) 协方差分析 AnovaTable(TypeIItests) SumSqDfFvaluePr(F) Temp4376。111388。8392。2e16 Species598。01189。7899。907e14 Temp:Species4。311。3570。2542 Interactionisnotsignificant,sotheslopeacrossgroups isnotdifferent。 model。2lm(PulseTempSpecies,dataData) library(car) Anova(model。2,typeII) AnovaTable(TypeIItests) SumSqDfFvaluePr(F) Temp4376。111371。42。2e16 Species598。01187。46。272e14 Thecategoryvariable(Species)issignificant, sotheinterceptsamonggroupsaredifferent Coefficients: EstimateStd。ErrortvaluePr(t) (Intercept)7。210912。550942。8270。00858 Temp3。602750。0972937。0322e16 Speciesniv10。065290。7352613。6896。27e14 butthecalculatedresultswillbeidentical。 Theslopeestimateisthesame。 Theinterceptforspecies1(ex)is(intercept)。 Theinterceptforspecies2(niv)is(intercept)Speciesniv。 ThisisdeterminedfromthecontrastcodingoftheSpecies variableshownbelow,andthefactthatSpeciesnivisshownin coefficienttableabove。 niv ex0 niv1 拟合线的简单图解 plot(xDataTemp,yDataPulse,colDataSpecies,pch16,xlabTemperature,ylabPulse) 模型的p值和R平方 MultipleRsquared:0。9896,AdjustedRsquared:0。9888 Fstatistic:1331on2and28DF,pvalue:2。2e16 检查模型的假设 线性模型中残差的直方图。这些残差的分布应近似正态。 残差与预测值的关系图。残差应无偏且均等。 additionalmodelcheckingplotswith:plot(model。2)alternative:library(FSA);residPlot(model。2) 具有三类和II型平方和的协方差示例分析 本示例使用II型平方和,并考虑具有三个组的情况。 Analysisofcovariance,hypotheticaldata Dataread。table(textConnection(Input),headerTRUE) plot(xDataTemp,yDataPulse,colDataSpecies,pch16,xlabTemperature,ylabPulse) legend(bottomright,legendlevels(DataSpecies),col1:3,cex1,pch16) 协方差分析 options(contrastsc(contr。treatment,contr。poly))ThesearethedefaultcontrastsinR Anova(model。1,typeII) SumSqDfFvaluePr(F) Temp7026。012452。41872e16 Species7835。721367。53772e16 Temp:Species5。220。91260。4093 Interactionisnotsignificant,sotheslopeamonggroups isnotdifferent。 Anova(model。2,typeII) SumSqDfFvaluePr(F) Temp7026。012462。22。2e16 Species7835。721373。02。2e16 Residuals125。644 Thecategoryvariable(Species)issignificant, sotheinterceptsamonggroupsaredifferent summary(model。2) Coefficients: EstimateStd。ErrortvaluePr(t) (Intercept)6。357291。907133。3330。00175 Temp3。569610。0719449。6212e16 Speciesfake19。814290。6633329。8712e16 Speciesniv10。185710。6633315。3552e16 TheslopeestimateistheTempcoefficient。 Theinterceptforspecies1(ex)is(intercept)。 Theinterceptforspecies2(fake)is(intercept)Speciesfake。 Theinterceptforspecies3(niv)is(intercept)Speciesniv。 ThisisdeterminedfromthecontrastcodingoftheSpecies variableshownbelow。 contrasts(DataSpecies) fakeniv ex00 fake10 niv01 拟合线的简单图解 组合模型的p值和R平方 MultipleRsquared:0。9919,AdjustedRsquared:0。9913 Fstatistic:1791on3and44DF,pvalue:2。2e16 检查模型的假设 hist(residuals(model。2),coldarkgray) 线性模型中残差的直方图。这些残差的分布应近似正态。 plot(fitted(model。2),residuals(model。2)) 残差与预测值的关系图。残差应无偏且均等。 additionalmodelcheckingplotswith:plot(model。2)alternative:library(FSA);residPlot(model。2)