📄 linfit.m
字号:
%#
%# function [yhat,F,Ftab,lof,b0,b1] = linfit(x,y,intercept);
%#
%# AIM: Construct a linear regression model to fit a calibration line and
%# estimate lack-of-fit.
%#
%# PRINCIPLE: A univariate linear regression is performed to fit the calibration line.
%# If replicate measurements are available, ANOVA for lack-of-fit is
%# also performed.
%#
%# INPUT: x: Vector of descriptor levels, in any order. Can be a row vector
%# or a column vector. Some replicate measurements are necessary
%# to perform ANOVA.
%# y: Vector of the same format as x, with corresponding experimental
%# responses.
%# intercept: Intercept for regression model. 1:Intercept, 0: no intercept
%# (Optional. Default: intercept = 1);
%#
%# Example of inputs:
%# x = [2.00 3.00 1.00 2.00 2.00 4.00 5.00 3.00];
%# y = [0.65 0.82 0.25 0.53 0.66 0.91 1.10 0.73];
%#
%# OUTPUT: yhat: Vector of responses estimated with linear model.(Column vector)
%# F: The ANOVA calculated variance ratio.
%# Ftab: The tabulated F-value at level p, to be compared with F.
%# lof: Ratio F/Ftab. If lof>1 --> Significant lack-of-fit at level p.
%# b0: Model intercept.
%# b1: Model slope.
%#
%# SUBROUTINES: anovalof.m : performs ANOVA for lack-of-fit
%#
%# AUTHOR: Frederic Despagne
%# Copyright(c) 1998 for ChemoAC
%# Dienst FABI, Vrije Universiteit Brussel
%# Laarbeeklaan 103, 1090 Jette
%#
%# VERSION: 1.2 (07/05/1998)
%#
%# TEST:
%#
function [yhat,F,Ftab,lof,b0,b1] = linfit(x,y,intercept);
if nargin == 2
intercept = 1; % By default, an intercept is calculated.
end
lx = length(x);
x = reshape(x,lx,1); % Input vectors are systematically ordered in column.
y = reshape(y,lx,1);
[b0,b1] = mlr(x,y,intercept); % Estimation of linear model parameters.
yhat = b0+x*b1; % Responses predicted with linear model.
[F,Ftab,lof] = anovalof(x,y,yhat,2,0.05); % ANOVA for lack-of-fit.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -