predict
Class:LinearMixedModel
Predict response of linear mixed-effects model
句法
Description
返回条件预测响应的向量ypred
=预测(lme
,,,,tblnew
)ypred
来自拟合的线性混合效应模型lme
一个t the values in the new table or dataset arraytblnew
。Use a table or dataset array forpredict
if you use a table or dataset array for fitting the modellme
。
If a particular grouping variable intblnew
has levels that are not in the original data, then the random effects for that grouping variable do not contribute to the“有条件”
prediction at observations where the grouping variable has new levels.
返回条件预测响应的向量ypred
=预测(lme
,,,,Xnew
,,,,znew
)ypred
来自拟合的线性混合效应模型lme
一个t the values in the new fixed- and random-effects design matrices,Xnew
一个ndznew
, 分别。znew
也可以是矩阵的单元格数组。在这种情况下,分组变量G
is一个(n,1)
,,,,wherenis the number of observations used in the fit.
Use the matrix format forpredict
if using design matrices for fitting the modellme
。
返回预测响应的向量ypred
=预测(___,,,,Name,Value
)ypred
来自拟合的线性混合效应模型lme
with additional options specified by one or moreName,Value
配对参数。
For example, you can specify the confidence level, simultaneous confidence bounds, or contributions from only fixed effects.
Input Arguments
lme
-Linear mixed-effects model
LinearMixedModel
目的
线性混合效应模型,指定为LinearMixedModel
目的constructed usingfitlme
orfitlmematrix
。
tblnew
-New input data
table|d一个taset
大批
New input data, which includes the response variable, predictor variables, and分组变量,指定为表或数据集数组。预测变量可以是连续的或分组变量。tblnew
must have the same variables as in the original table or dataset array used to fit the linear mixed-effects modellme
。
Xnew
-New fixed-effects design matrix
n-经过-p矩阵
新的固定效应设计矩阵,指定为n-经过-p矩阵,哪里nis the number of observations andpis the number of fixed predictor variables. Each row ofX
corresponds to one observation and each column ofX
对应于一个变量。
Data Types:single
|double
znew
-New random-effects design
n-经过-问矩阵|长度的细胞阵列r
新的随机效应设计,指定为n-经过-问矩阵or一个cell array ofr设计矩阵z{r}
,,,,wherer=1, 2, ...,r。Ifznew
是一个单元格数,然后z{r}
is ann-经过-问((r)矩阵,哪里nis the number of observations, and问((r)是随机预测变量的数量。
Data Types:single
|double
|cell
Gnew
-New grouping variable or variables
vector|cell array of grouping variables of lengthr
Newgrouping variable or variables,,,,specified as a vector or a cell array, of lengthr,,,,of grouping variables with the same levels or groups as the original grouping variables used to fit the linear mixed-effects modellme
。
Data Types:single
|double
|分类
|逻辑
|char
|string
|cell
名称值参数
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
,,,,whereName
是参数名称和Value
是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。
Before R2021a, use commas to separate each name and value, and encloseName
in quotes.
Alpha
-Significance level
0.05((default) |范围0到1的标量值
显着性水平,指定为逗号分隔对,由'Alpha'
范围0到1中的标量值,对于一个值α,置信度水平为100*(1 -α)%。
例如,对于99%的置信区间,您可以按以下方式指定置信度。
Example:'Alpha',0.01
Data Types:single
|double
Conditional
-有条件预测的指标
true
((default) |错误的
Indicator forconditional predictions,指定为逗号分隔对,由“有条件”
以及以下内容之一。
true |
固定效应和随机效应(条件)的贡献 |
错误的 |
Contribution from only fixed effects (marginal) |
Example:'有条件,假
dfmethod
-计算大约自由度的方法
'residual'
((default) |'satterthwaite'
|'没有任何'
计算大约在置信区间计算中使用自由度的方法,该计算指定为逗号分隔对'DFMethod'
以及以下内容之一。
'residual' |
Default. The degrees of freedom are assumed to be constant and equal ton-p,,,,wherenis the number of observations andp是固定效果的数量。 |
'satterthwaite' |
Satterthwaite近似。 |
'没有任何' |
所有自由度都设定为无限。 |
例如,您可以按以下方式指定Satterthwaite近似。
Example:“ dfmethod','satterthwaite'
同时
-Type of confidence bounds
错误的
((default) |true
置信界的类型,指定为逗号分隔对'同时'
以及以下内容之一。
错误的 |
Default. Nonsimultaneous bounds. |
true |
同时界限。 |
Example:“同时”,真实
预言
-预测类型
'curve'
((default) |'observation'
预测类型,,,,specified as the comma-separated pair consisting of'预言'
以及以下内容之一。
'curve' |
Default. Confidence bounds for the predictions based on the fitted function. |
'observation' |
Variability due to observation error for the new observations is also included in the confidence bound calculations and this results in wider bounds. |
Example:'预言',,,,'observation'
Output Arguments
ypred
-Predicted responses
vector
Predicted responses, returned as a vector.ypred
can contain the conditional or marginal responses, depending on the value choice of the“有条件”
名称值对参数。条件预测包括固定和随机效应的贡献。
DF
-Degrees of freedom
向量|标量值
计算置信区间的自由度,作为向量或标量值返回。
If the
'同时'
n一个me-value pair argument is错误的
, 然后DF
is a vector.If the
'同时'
n一个me-value pair argument istrue
, 然后DF
is a scalar value.
Examples
Predict Responses at the Original Design Values
Load the sample data.
加载(('fertilizer.mat');
The dataset array includes data from a split-plot experiment, where soil is divided into three blocks based on the soil type: sandy, silty, and loamy. Each block is divided into five plots, where five different types of tomato plants (cherry, heirloom, grape, vine, and plum) are randomly assigned to these plots. The tomato plants in the plots are then divided into subplots, where each subplot is treated by one of four fertilizers. This is simulated data.
Store the data in a dataset array calledDS
,,,,for practical purposes, and defineTomato
,,,,土壤
,,,,一个ndFertilizer
一个s categorical variables.
DS =肥料;ds.tomato =名义(ds.tomato);ds.soil =名义(ds.soil);ds.fertierizer =名义(ds.fertilizer);
适合线性混合效应模型,其中Fertilizer
一个ndTomato
一个re the fixed-effects variables, and the mean yield varies by the block (soil type), and the plots within blocks (tomato types within soil types) independently.
lme = fitlme(ds,'Yield ~ Fertilizer * Tomato + (1|Soil) + (1|Soil:Tomato)');
预测原始设计值的响应值。用观察到的响应值显示前五个预测。
yhat =预测(LME);[yhat(1:5)Ds.yield(1:5)]
一个ns =5×2115.4788 104.0000 135.1455 136.0000 152.8121 158.0000 160.4788 174.0000 58.0839 57.0000
情节预测与观察到的响应
Load the sample data.
加载carsmall
Fit a linear mixed-effects model, with a fixed effect for重量
,,,,一个nd一个随机的intercept grouped bymodel_year
。首先,将数据存储在表中。
tbl = table(MPG,Weight,Model_Year); lme = fitlme(tbl,'MPG ~ Weight + (1|Model_Year)');
Create predicted responses to the data.
yhat =predict(lme,tbl);
绘制原始响应和预测的响应,以了解它们的不同。按模型年对它们进行分组。
figure() gscatter(Weight,MPG,Model_Year) holdongScatter(重量,yhat,model_year,[],,'o+x')legend('70 -Data',,,,'76 -Data',,,,'82-data',,,,'70-pred',,,,'76-pred',,,,'82-pred')抓住off
在新数据集数组中预测值的响应
Load the sample data.
加载(('fertilizer.mat');
The dataset array includes data from a split-plot experiment, where soil is divided into three blocks based on the soil type: sandy, silty, and loamy. Each block is divided into five plots, where five different types of tomato plants (cherry, heirloom, grape, vine, and plum) are randomly assigned to these plots. The tomato plants in the plots are then divided into subplots, where each subplot is treated by one of four fertilizers. This is simulated data.
Store the data in a dataset array calledDS
,,,,for practical purposes, and defineTomato
,,,,土壤
,,,,一个ndFertilizer
一个s categorical variables.
DS =肥料;ds.tomato =名义(ds.tomato);ds.soil =名义(ds.soil);ds.fertierizer =名义(ds.fertilizer);
适合线性混合效应模型,其中Fertilizer
一个ndTomato
一个re the fixed-effects variables, and the mean yield varies by the block (soil type), and the plots within blocks (tomato types within soil types) independently.
lme = fitlme(ds,'Yield ~ Fertilizer * Tomato + (1|Soil) + (1|Soil:Tomato)');
Create a new dataset array with design values. The new dataset array must have the same variables as the original dataset array you use for fitting the modellme
。
DSnew = dataset(); dsnew.Soil = nominal({'Sandy';'Silty'}); dsnew.Tomato = nominal({'Cherry';'Vine'}); dsnew. Fertilizer = nominal([2;2]);
预测原始设计点处的条件和边际响应。
yhatC = predict(lme,dsnew); yhatM = predict(lme,dsnew,“有条件”,,,,错误的);[[yhatC yhatM]
一个ns =2×292.7505 111.6667 87.5891 82.6667
预测新设计矩阵中值的响应
Load the sample data.
加载carbig
拟合每加仑英里(MPG)的线性混合效应模型,具有固定的效果,可加速,马力和气缸,以及模型年度分组的截距和加速度的潜在相关随机效应。
First, prepare the design matrices for fitting the linear mixed-effects model.
X=[[ones(406,1) Acceleration Horsepower]; Z = [ones(406,1) Acceleration]; Model_Year = nominal(Model_Year); G = Model_Year;
Now, fit the model usingfitlmematrix
with the defined design matrices and grouping variables.
lme = fitlmematrix(X,MPG,Z,G,'FixedEffectPredictors',,,,。。。。{'Intercept',,,,“加速”,,,,'Horsepower'},'randomeffectpredictors',,,,。。。{{'Intercept',,,,“加速”}},'RandomEffectGroups',,,,{'model_year'});
创建包含可以预测响应值的数据的设计矩阵。Xnew
must have three columns as inX
。The first column must be a column of 1s. And the values in the last two columns must correspond toAcceleration
一个ndHorsepower
, 分别。第一列znew
必须是1列,第二列必须包含相同的Acceleration
values as inXnew
。The original grouping variable inG
is the model year. So,Gnew
必须包含模型年度的值。注意Gnew
must contain nominal values.
Xnew = [1,13.5,185;1,17,205;1,21.2,193];Znew = [1,13.5;1,17;1,21.2];% alternatively Znew = Xnew(:,1:2);Gnew=nominal([73 77 82]);
Predict the responses for the data in the new design matrices.
yhat =预测(LME,XNew,Znew,Gnew)
yhat =3×18.7063 5.4423 12.5384
现在,对于具有无关的随机效应项以进行截距和加速度的线性混合效应模型,重复此操作。首先,更改原始的随机效果设计和随机效应分组变量。然后,重新安装模型。
z={ones(406,1),Acceleration}; G = {Model_Year,Model_Year}; lme = fitlmematrix(X,MPG,Z,G,'FixedEffectPredictors',,,,。。。。{'Intercept',,,,“加速”,,,,'Horsepower'},'randomeffectpredictors',,,,。。。{{'Intercept'},{“加速”}},'RandomEffectGroups',,,,{'model_year',,,,'model_year'});
Now, recreate the new random effects design,znew
,以及分组变量设计,Gnew
,,,,using which to predict the response values.
Znew = {[1; 1; 1],[13.5; 17; 21.2]};my =名义([[73 77 82]);gnew = {my,my};
使用新设计矩阵预测响应。
yhat =预测(LME,XNew,Znew,Gnew)
yhat =3×18.6365 5.9199 12.1247
Compute Confidence Intervals for Predictions
Load the sample data.
加载carbig
拟合每加仑英里(MPG)的线性混合效应模型,具有固定的效果,可加速,马力和气缸,以及模型年度分组的截距和加速度的潜在相关随机效应。First, store the variables in a table.
tbl = table(MPG,Acceleration,Horsepower,Model_Year);
Now, fit the model usingfitlme
with the defined design matrices and grouping variables.
lme = fitlme(tbl,'mpg〜加速度 +马力 +(加速度| model_year)');
Create the new data and store it in a new table.
tblNew = table();tblNew.Acceleration = linspace(8,25)';tblnew.horsepower = linspace(最小值(马力),最大功能(马力))';tblnew.model_year = repmat(70,100,1);
linspace
creates 100 equally distanced values between the lower and the upper input limits.model_year
is fixed at 70. You can repeat this for any model year.
计算和绘制预测的值和95%的置信度限制(非同步)。
[ypred,yci,df] =预测(lme,tblNew);数字();h1 = line(tblNew.Acceleration,ypred);抓住on;h2 = plot(tblnew.Acceleration,yCI,'G-。');
显示自由度。
DF(1)
ANS = 389
Compute and plot the simultaneous confidence bounds.
[ypred,yci,df] =预测(lme,tblNew,'同时',,,,true); h3 = plot(tblnew.Acceleration,yCI,'r--');
显示自由度。
DF
DF=389
Compute the simultaneous confidence bounds using the Satterthwaite method to compute the degrees of freedom.
[ypred,yci,df] =预测(lme,tblNew,'同时',,,,true,'DFMethod',,,,'satterthwaite');h4 =图(tblnew.acceleration,yci,'k:');抓住offXlabel(“加速”)ylabel('Response')ylim([-50,60]) xlim([8,25]) legend([h1,h2(1),h3(1),h4(1)],“预测回应”,,,,'95%',,,,'95%sim',,,,。。。'95% Sim-Satt',,,,'Location',,,,'最好的')
显示自由度。
DF
DF=3.6001
更多关于
条件和边际预测
一个条件预测包括贡献from both fixed and random effects, whereas a marginal model includes contribution from only fixed effects.
Suppose the linear mixed-effects modellme
有一个n-经过-p固定效应设计矩阵X
和n-经过-问随机的-effects design matrixz
。Also, suppose the estimatedp-经过-1 fixed-effects vector is
,,,,一个ndthe问-经过-1 estimated best linear unbiased predictor (BLUP) vector of random effects is
。预测的条件响应是
which corresponds to the“有条件”,“ true”
名称值对参数。
预测的边缘响应是
which corresponds to the“有条件”,“ false”
名称值对参数。
When making predictions, if a particular grouping variable has new levels (1s that were not in the original data), then the random effects for the grouping variable do not contribute to the“有条件”
prediction at observations where the grouping variable has new levels.
也可以看看
Abrir Ejemplo
Tiene unaversiónmodificada de esjemplo。„ Desea abrir este ejemplo con s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s ejemplo?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
You can also select a web site from the following list:
How to Get Best Site Performance
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
Americas
- AméricaLatina((Español)
- C一个n一个d一个((English)
- United States((English)
Europe
- Belgium((English)
- 丹麦((English)
- Deutschland((Deutsch)
- España((Español)
- 芬兰((English)
- France(Français)
- Ireland((English)
- Italia(意大利语)
- Luxembourg((English)
- Netherlands((English)
- Norway((English)
- Österreich((Deutsch)
- Portugal((English)
- Sweden((English)
- Switzerland
- United Kingdom((English)