# Matlab built-in function not identified

조회 수: 7 (최근 30일)
Jacopo Cantoni 2023년 2월 3일
댓글: Steven Lord 2023년 2월 3일
I am trying to use the function coefTest from the Statistics and Machine Learning Toolbox after calling the function I recive the error message
Undefined function or variable 'coefTest'.
I have checked that the statistics and machine learning toolbox is installed and enabled, has anybody else has an idea on how to further truble shoot this issue?
Thanks

댓글을 달려면 로그인하십시오.

### 답변 (2개)

Bora Eryilmaz 2023년 2월 3일
편집: Bora Eryilmaz 2023년 2월 3일
coefTest is not a "function". It is a "method" of the LinearModel object/class. So, in order to call it, you need to create a linear model first. Something like this:
m = fitlm(array2table(rand(10,2)))
m =
Linear regression model: Var2 ~ 1 + Var1 Estimated Coefficients: Estimate SE tStat pValue ________ _______ ________ ________ (Intercept) 0.80105 0.27121 2.9536 0.018324 Var1 -0.4655 0.48461 -0.96057 0.3649 Number of observations: 10, Error degrees of freedom: 8 Root Mean Squared Error: 0.327 R-squared: 0.103, Adjusted R-Squared: -0.00866 F-statistic vs. constant model: 0.923, p-value = 0.365
coefTest(m)
ans = 0.3649
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
Bora Eryilmaz 2023년 2월 3일
편집: Bora Eryilmaz 2023년 2월 3일
Seems to be working for me and here. It probably has something to do with the creation of a LinearModel that brings the help for the coefTest() method into scope:
help coefTest
--- help for classreg.regr.CompactGeneralizedLinearModel/coefTest --- coefTest Linear hypothesis test on coefficients. P = coefTest(M) computes the p-value for an F test that all coefficient estimates in the regression model M except the intercept are zero. P = coefTest(M,H), with H a numeric matrix having one column for each coefficient, performs an F test that H*B=0, where B represents the coefficient vector. P = coefTest(M,H,C) accepts a vector C having one value for each row of H, and it performs an F test that H*B=C. [P,F,R] = coefTest(...) also returns the F-statistic F and the rank R of the matrix H. The F statistic has R degrees of freedom in the numerator and M.DFE degrees of freedom in the denominator. Example: % Test the significance of the Weight^2 coefficient, and note that % the p-value is the same as in the coefficients display. load carsmall d = dataset(MPG,Weight); d.Year = ordinal(Model_Year); lm = fitlm(d,'MPG ~ Year + Weight + Weight^2') p = coefTest(lm,[0 0 0 0 1]) % Test the significance of both coefficients for the categorical % predictor Year, and note that the p-value is the same as in the % anova table display. anova(lm) p = coefTest(lm,[0 0 1 0 0;0 0 0 1 0]) See also LinearModel, GeneralizedLinearModel, NonLinearModel, linhyptest. Help for classreg.regr.CompactGeneralizedLinearModel/coefTest is inherited from superclass classreg.regr.CompactTermsRegression Documentation for classreg.regr.CompactGeneralizedLinearModel/coefTest doc classreg.regr.CompactGeneralizedLinearModel/coefTest Other uses of coefTest classreg.regr.CompactParametricRegression/coefTest RepeatedMeasuresModel/coefTest
Steven Lord 2023년 2월 3일
Fresh start from MATLAB, "help coefTest" shows nothing but "doc coefTest" gives doc
That's correct. Not all classes in MATLAB are loaded into memory on MATLAB startup, IIRC. If the classes aren't loaded MATLAB won't know about the methods. Constructing an instance of a class makes MATLAB load the class definition into memory and I believe help looks at what's in memory. The doc function doesn't care what's in memory.

댓글을 달려면 로그인하십시오.

Steven Lord 2023년 2월 3일
According to a search there are several different functions named coefTest in Statistics and Machine Learning Toolbox. From a quick scan of their documentation pages I believe the reason you're unable to call the function is that each of them requires that their first input is a certain type of object. If you were to try to call them with something other than one of those specific types of objects as the first input, MATLAB would not know to call that function.
coefTest(1:10) % won't work
Unrecognized function or variable 'coefTest'.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Gaussian Process Regression에 대해 자세히 알아보기

R2019a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by