Category Error when using FitGLME

8 views (last 30 days)
Sam Litvin
Sam Litvin on 18 Dec 2020
Commented: Sam Litvin on 22 Dec 2020
So I have several data sets with ordtinal and categorical values, I see no big difference in them. However, some of hese data sets give no errors while others give me this strange value for which I can find no explanation. Anyone have this issue? By the way, taking out that categorical variable didn't solve the issue.
Thanks!
Error using categorical (line 434)
Unable to create default category names. Specify category names using the CATEGORYNAMES input argument.
Error in nominal (line 152)
b = b@categorical(a,args{:},'Ordinal',false);
Error in classreg.regr.LinearLikeMixedModel/makeInteractionVar (line 806)
G = nominal(ds.(interactionVars{1}));
Error in classreg.regr.LinearLikeMixedModel/extractGroupingInfo (line 205)
model.makeInteractionVar(ds,interactionVars);
Error in GeneralizedLinearMixedModel.fit (line 2377)
model.GroupingInfo = extractGroupingInfo(model,dssubset);
Error in fitglme (line 398)
glme = GeneralizedLinearMixedModel.fit(T,formula,varargin{:});
Error in GLMFinal (line 35)
glmeVw2 = fitglme(bat1,'Vw ~ Td + (1|ThetaX) + (1|ThetaY) + (1|ThetaZ)','FitMethod','Laplace')
  3 Comments
Walter Roberson
Walter Roberson on 18 Dec 2020
Do the variable names Vw, Td, ThetaX, ThetaY, and ThetaZ all exist in your table bat1 ?
Sam Litvin
Sam Litvin on 18 Dec 2020
Ive Ive
function GLMFinal(bat,noL)
%GLM of combined files for each bats Thetas and Trident distance versus
%Vertical and horizontal beam widths and beam direction
%If you do not want to use data for L, enter 1, otherwise 0 for nol
%input is taken from GLMFinal file
%output saved as bat_pvals in the pvals folder
dirf='Results/';
if bat==2
bat='2';
elseif bat==5
bat='5';
elseif bat==6
bat='6';
elseif bat==9
bat='9';
end
bat1=load([dirf,'GLM_',bat,'.mat']);
bat1=struct2table(bat1.b4)
bat1.Td;
bat1.Ph=categorical(bat1.Ph);
%bat1.Ph = categorical(bat1.Ph);
%bat1.Ph;
%
% lmeVw = fitlme(bat1,'Vw ~ Td + (1|Ph)+ (1|ThetaX) + (1|ThetaY) + (1|ThetaZ)', 'DummyVarCoding', 'reference');
% glmeVd = fitlme(bat1,'Vd ~ 1 + Td + (ThetaX) + (ThetaY) + (ThetaZ) + (Ph)')
% glmeHw = fitlm(bat1,'Hw ~ 1 + Td + (ThetaX) + (ThetaY) + (ThetaZ) + (Ph)')
% glmeHd = fitlm(bat1,'Hd ~ 1 + Td + (ThetaX) + (ThetaY) + (ThetaZ) + (Ph)')
% anova(lmeVw)
%Fitting the model and getting p values for angles and trident.
glmeVw2 = fitglme(bat1,'Vw ~ Td + (1|ThetaX) + (1|ThetaY) + (1|ThetaZ)','FitMethod','Laplace')
glmeVw = fitglme(bat1,'Vw ~ Td + (1|Ph)+ (1|ThetaX) + (1|ThetaY) + (1|ThetaZ)+ (1+Td|ThetaX)+(1+Td|ThetaY)','FitMethod','Laplace')

Sign in to comment.

Answers (1)

Sam Litvin
Sam Litvin on 18 Dec 2020
yes, I print the table, prior to using fitglm to make sure, like i say, it works on one data set but not on another, the data sets look the same.
this set doesn't work:
ThetaX ThetaY ThetaZ Td Vd Vw Hw Hd Ld Lw
________ ________ _______ _______ _______ ____ ____ _______ _______ ____
1.2333 1.2445 0.52498 0.53232 6.5127 34.5 71.5 -15.891 NaN NaN
1.6859 2.1313 0.93286 0.90519 6.5127 37.5 NaN NaN NaN NaN
1.3092 0.5145 3.7508 0.58472 29.102 41 55 -15.891 NaN NaN
-0.52485 1.4835 4.1045 1 29.102 37 NaN NaN NaN NaN
-11.536 -4.3153 13.498 0 36.438 38 NaN NaN NaN NaN
-4.6048 -3.5271 7.2064 0.55741 14.538 41.5 NaN NaN NaN NaN
13.477 -2.3554 2.5966 0 -1.105 39 35 15.911 15.182 14.5
26.936 -4.7887 5.1617 0.84217 -18.806 40 39 15.911 15.182 37.5
26.93 -4.7895 5.1617 0.84233 -1.105 42 45.5 15.911 15.182 45.5
26.926 -4.7841 5.1623 0.84255 -1.105 33.5 28 15.911 15.182 41
26.922 -4.7668 5.1672 0.84266 -1.105 34 46.5 31.931 -33.431 27
27.116 -4.4235 5.3232 0.85596 6.448 29 44.5 15.911 -23.12 47
27.539 -4.2149 5.3918 0.85807 6.448 33 52.5 15.911 NaN NaN
27.843 -4.0407 5.5783 0.83484 -1.105 35 50.5 15.911 -23.12 41.5
28.616 -3.5122 6.3644 0.76825 -1.105 31.5 46.5 -16.014 NaN NaN
28.765 -3.3351 6.5384 0.77406 -1.105 39.5 43.5 -16.014 -23.12 46.5
30.946 -2.51 8.2508 0.64673 6.448 45.5 57 -9.2986 -33.431 35.5
37.91 1.9361 16.855 0.44011 -1.105 31 40 -16.014 15.182 60.5
42.227 3.8641 22.334 0.41069 -1.105 35 53 15.911 15.182 15.5
36.45 2.6909 16.286 0.43821 -1.105 35 58.5 15.911 15.182 44
31.617 -0.96164 9.4995 0.64966 -1.105 33.5 40.5 40.184 22.574 45.5
29.221 -3.4149 6.1208 0.86041 -1.105 32 38 31.931 31.814 32
This one does
bat1 =
87×11 table
ThetaX ThetaY ThetaZ Td Vd Vw Hw Hd Ld Lw Ph
_________ _________ _________ ________ _______ ____ _____ _______ _______ ____ __
1.1022 -1.0173 0.067847 0.60151 31.072 45 60.5 -16.492 NaN NaN 0
1.2061 -1.0606 0.16396 1 15.428 44.5 62.5 -16.492 NaN NaN 0
0.97804 -1.0005 0.19531 0.27491 6.9766 39.5 36.5 -16.492 NaN NaN 0
0.76398 -0.97725 0.1889 0 6.9766 41.5 12.5 -16.492 NaN NaN 0
0.0093436 0.27112 0.17762 0.099879 6.9766 29.5 34.5 -16.492 24.472 59.5 0
-0.059496 0.4879 0.39032 0.21028 22.845 34 85.5 -16.492 NaN NaN 0
0.12878 0.50104 0.34031 0.32137 31.072 12 14 -16.492 NaN NaN 0
-0.040724 0.63091 0.40665 0.20183 6.9766 23.5 35.5 -16.492 NaN NaN 0
0.17804 0.53765 0.25413 0.16974 22.845 19 31 -23.81 NaN NaN 0
-0.15602 0.4878 0.26046 0.16388 -1.2509 13.5 35.5 -16.492 NaN NaN 0
-0.25819 0.35799 0.31463 0.042781 6.9766 22 15.5 -16.492 -23.583 32.5 0
-0.16243 0.2936 0.3419 0.048818 22.845 58.5 16.5 -9.5427 -23.583 6 0
-0.10334 0.26443 0.39344 0.019838 6.9766 51.5 39.5 -9.5427 NaN NaN 0
-0.43722 0.25071 0.30092 0.12248 -1.2509 37.5 17.5 -9.5427 -8.965 32.5 0
-0.64473 0.16058 0.28473 0.32896 -1.2509 12 21 -16.492 16.562 50 0
-0.47479 0.32879 0.36768 0.29809 -1.2509 23.5 39.5 9.8324 16.562 25 0
-0.43228 0.38063 0.4039 0.25806 -1.2509 25.5 68 9.8324 16.562 19.5 0
-0.47773 0.36195 0.36284 0.17181 -9.9903 32 100.5 24.033 24.472 43.5 0
-0.5734 0.22027 0.27696 0.22512 -1.2509 39.5 77 9.8324 16.562 19 0
-0.59505 0.16465 0.25177 0.032086 -1.2509 20.5 49 -9.5427 16.562 56.5 0
-0.52266 0.26686 0.25899 0.23961 -1.2509 14.5 25.5 -9.5427 -23.583 14.5 0
-0.53232 0.36506 0.2831 0.276 -9.9903 66.5 39.5 -9.5427 -23.583 38.5 0
-0.51283 0.41519 0.26584 0.31275 -31.993 48.5 21.5 -9.5427 -23.583 39 0
-0.52028 0.22885 0.20798 0.24116 -1.2509 34 30 -9.5427 -23.583 9 0
-0.64073 -0.23303 0.3239 0.096257 -1.2509 30.5 14 -16.492 -23.583 15.5 0
-0.58313 -0.47048 0.21717 0.61101 6.9766 22 17.5 -16.492 16.562 42 0
-0.66566 -0.60853 0.32624 0.50543 6.9766 39 20 -16.492 16.562 52 0
-0.72746 -0.70762 0.42629 1 -1.2509 29.5 17 -9.5427 -23.583 49.5 0
-0.88344 -0.74499 -0.066155 0.90357 -1.2509 28.5 23.5 -9.5427 16.562 31.5 0
-0.89546 -0.67987 0.018943 0.94204 -1.2509 20.5 25.5 -16.492 -8.965 61.5 0
  2 Comments
Ive J
Ive J on 18 Dec 2020
I could not reproduce your error for both datasets you mentioned:
head(t1)
ThetaX ThetaY ThetaZ Td Vd Vw Hw Hd Ld Lw
________ _______ _______ _______ _______ ____ ____ _______ ______ ____
1.2333 1.2445 0.52498 0.53232 6.5127 34.5 71.5 -15.891 NaN NaN
1.6859 2.1313 0.93286 0.90519 6.5127 37.5 NaN NaN NaN NaN
1.3092 0.5145 3.7508 0.58472 29.102 41 55 -15.891 NaN NaN
-0.52485 1.4835 4.1045 1 29.102 37 NaN NaN NaN NaN
-11.536 -4.3153 13.498 0 36.438 38 NaN NaN NaN NaN
-4.6048 -3.5271 7.2064 0.55741 14.538 41.5 NaN NaN NaN NaN
13.477 -2.3554 2.5966 0 -1.105 39 35 15.911 15.182 14.5
26.936 -4.7887 5.1617 0.84217 -18.806 40 39 15.911 15.182 37.5
mdl1 = fitglme(t1,'Vw ~ Td + (1|ThetaX) + (1|ThetaY) + (1|ThetaZ)','FitMethod','Laplace'); % no error
mdl1
Generalized linear mixed-effects model fit by ML
Model information:
Number of observations 22
Fixed effects coefficients 2
Random effects coefficients 65
Covariance parameters 4
Distribution Normal
Link Identity
FitMethod Laplace
Formula:
Vw ~ 1 + Td + (1 | ThetaX) + (1 | ThetaY) + (1 | ThetaZ)
Model fit statistics:
AIC BIC LogLikelihood Deviance
133.39 139.94 -60.696 121.39
Fixed effects coefficients (95% CIs):
Name Estimate SE tStat DF
{'(Intercept)'} 38.1 2.2593 16.864 20
{'Td' } -3.1335 3.2122 -0.97551 20
pValue Lower Upper
2.7251e-13 33.388 42.813
0.34096 -9.834 3.567
Random effects covariance parameters:
Group: ThetaX (22 Levels)
Name1 Name2 Type
{'(Intercept)'} {'(Intercept)'} {'std'}
Estimate
0.67125
Group: ThetaY (22 Levels)
Name1 Name2 Type
{'(Intercept)'} {'(Intercept)'} {'std'}
Estimate
0.67125
Group: ThetaZ (21 Levels)
Name1 Name2 Type
{'(Intercept)'} {'(Intercept)'} {'std'}
Estimate
3.7062
Group: Error
Name Estimate
{'sqrt(Dispersion)'} 0.98473
also for second dataset:
head(t2)
ThetaX ThetaY ThetaZ Td Vd Vw Hw Hd Ld Lw Ph
_________ ________ ________ ________ ______ ____ ____ _______ ______ ____ __
1.1022 -1.0173 0.067847 0.60151 31.072 45 60.5 -16.492 NaN NaN 0
1.2061 -1.0606 0.16396 1 15.428 44.5 62.5 -16.492 NaN NaN 0
0.97804 -1.0005 0.19531 0.27491 6.9766 39.5 36.5 -16.492 NaN NaN 0
0.76398 -0.97725 0.1889 0 6.9766 41.5 12.5 -16.492 NaN NaN 0
0.0093436 0.27112 0.17762 0.099879 6.9766 29.5 34.5 -16.492 24.472 59.5 0
-0.059496 0.4879 0.39032 0.21028 22.845 34 85.5 -16.492 NaN NaN 0
0.12878 0.50104 0.34031 0.32137 31.072 12 14 -16.492 NaN NaN 0
-0.040724 0.63091 0.40665 0.20183 6.9766 23.5 35.5 -16.492 NaN NaN 0
mdl2 = fitglme(t2,'Vw ~ Td + (1|ThetaX) + (1|ThetaY) + (1|ThetaZ)','FitMethod','Laplace'); % no error
mdl2
Generalized linear mixed-effects model fit by ML
Model information:
Number of observations 30
Fixed effects coefficients 2
Random effects coefficients 90
Covariance parameters 4
Distribution Normal
Link Identity
FitMethod Laplace
Formula:
Vw ~ 1 + Td + (1 | ThetaX) + (1 | ThetaY) + (1 | ThetaZ)
Model fit statistics:
AIC BIC LogLikelihood Deviance
253.16 261.56 -120.58 241.16
Fixed effects coefficients (95% CIs):
Name Estimate SE tStat DF
{'(Intercept)'} 32.695 3.6806 8.883 28
{'Td' } -2.3505 8.4533 -0.27805 28
pValue Lower Upper
1.2288e-09 25.155 40.234
0.78301 -19.666 14.965
Random effects covariance parameters:
Group: ThetaX (30 Levels)
Name1 Name2 Type
{'(Intercept)'} {'(Intercept)'} {'std'}
Estimate
6.7341
Group: ThetaY (30 Levels)
Name1 Name2 Type
{'(Intercept)'} {'(Intercept)'} {'std'}
Estimate
6.7341
Group: ThetaZ (30 Levels)
Name1 Name2 Type
{'(Intercept)'} {'(Intercept)'} {'std'}
Estimate
6.7341
Group: Error
Name Estimate
{'sqrt(Dispersion)'} 6.7341
Sam Litvin
Sam Litvin on 22 Dec 2020
Thanks Ive, I only included part of the data sets. I found that when I exclude some of the data it works. It seems to be connected with some of the subsets of the data. When I excluded it, it worked. I noticed it was tied to number of NaN's in a data set.

Sign in to comment.

Tags

Products

Community Treasure Hunt

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

Start Hunting!