Fitting the population dynamics statistical model

See Marginal Analyses for details about exporting the data table used in statistical analysis.
clc;
clearvars -except E D; % clear base workspace except for data struct/tables
if exist('E','var') == 0
E = getfield(load(defaults.files('exported_jpca_matfile')),'E');
end

Define model specifications

We use Wilkinson Notation to define two generalized linear mixed effects models; one simple model that ignores the behavioral covariate and one that accounts for Reach Duration.

Simple Model

We may include some or all of the following terms in our model (select from the drop-down box):

Response

Fixed Effects

Random Effects

Simple Model List (Wilkinson Model Specifications)

  1. "R2_Skew~GroupID*PostOpDay+(1+R2_Best*Explained_Skew|AnimalID)"
  2. "R2_Skew~GroupID*PostOpDay+R2_Best+Explained_Skew+(1|AnimalID)"
  3. "R2_Skew~GroupID*PostOpDay+R2_Best*Explained_Skew+(1|AnimalID)"
  4. "R2_Skew~GroupID*PostOpDay+(1|AnimalID)+(-1+R2_Best|GroupID)+(-1+Explained_Skew|GroupID)"
simple_model = "R2_Skew~GroupID*PostOpDay+(1+R2_Best*Explained_Skew|AnimalID)";

Complex Model

The complex model includes all the terms of the simple_model but additionally has one more fixed effect in the main interaction:

Complex Model List (Wilkinson Model Specifications)

  1. "R2_Skew~GroupID*PostOpDay*Area+(1+R2_Best*Explained_Skew*AverageDuration|GroupID:AnimalID)"
  2. "R2_Skew~GroupID*PostOpDay*AverageDuration+(1|AnimalID)+(-1+R2_Best*Explained_Skew|PlaneIndex)"
  3. "R2_Skew~GroupID*PostOpDay+AverageDuration+R2_Best+Explained_Skew+(1|AnimalID)"
  4. "R2_Skew~GroupID*PostOpDay+AverageDuration+R2_Best*Explained_Skew+(1|AnimalID)"
  5. "R2_Skew~GroupID*PostOpDay+AverageDuration+(1|AnimalID)+(-1+R2_Best|GroupID)+(-1+Explained_Skew|GroupID)"
  6. "R2_Skew~AverageDuration*GroupID+(1+PostOpDay|AnimalID)+(-1+R2_Best|GroupID)+(-1+Explained_Skew|GroupID)"
  7. "R2_Skew~GroupID*PostOpDay*R2_Best*Explained_Skew+(PostOpDay|GroupID:AnimalID)"
complex_model = "R2_Skew~GroupID*PostOpDay+(1+R2_Best*Explained_Skew*AverageDuration|GroupID:AnimalID)";
Specify a list of parameters to use with the fitglme method.
fit_params = {...
'Verbose',0,... % [0, 1, 2] -- how much is reported by optimizer
'FitMethod','ApproximateLaplace', ... {'Laplace', 'REMPL', or 'MPL'}
'DummyVarCoding','effects', ... {'effects','reference', or 'full'}
'UseSequential',false ...
};
Once the desired models have been selected, click Run Fit
fprintf(1,'Current simple model: <strong>"%s"</strong>\n',simple_model);
Current simple model: "R2_Skew~GroupID*PostOpDay+(1+R2_Best*Explained_Skew|AnimalID)"
fprintf(1,'Current complex model: <strong>"%s"</strong>\n',complex_model);
Current complex model: "R2_Skew~GroupID*PostOpDay+(1+R2_Best*Explained_Skew*AverageDuration|GroupID:AnimalID)"

Fit models

Use the fitglme function to recover two generalized linear mixed-effects models, which are then compared in order to determine if it is necessary to include Duration as a model term, since this has a substantial effect on interpreting the model. Here, we do not suppress the output to the Command Window so that we can see what statistics are returned. Note that in order to use a likelihood ratio test for comparison of the two models, we must use the Laplace (we use the approximate Laplace, which approximates the integrand of the likelihood over all latent variables in the model; the approximation is generally good unless the observations are sparse for a given level) fitting method, as MPL or REMPL methods do not allow models to be compared since in MPL the maximized log-likelihood of the pseudodata from the final pseudo likelihood iteration is used in the likelihood ratio test.

Fit simple models

glme_simple = fitglme(E,simple_model,fit_params{:})
glme_simple =
Generalized linear mixed-effects model fit by ML Model information: Number of observations 174 Fixed effects coefficients 4 Random effects coefficients 32 Covariance parameters 11 Distribution Normal Link Identity FitMethod ApproximateLaplace Formula: R2_Skew ~ 1 + GroupID*PostOpDay + (1 + Explained_Skew*R2_Best | AnimalID) Model fit statistics: AIC BIC LogLikelihood Deviance -339.86 -292.47 184.93 -369.86 Fixed effects coefficients (95% CIs): Name Estimate SE tStat DF pValue Lower Upper {'(Intercept)' } 0.61862 0.027378 22.595 170 4.392e-53 0.56458 0.67267 {'GroupID_Intact' } 0.0053387 0.027378 0.195 170 0.84563 -0.048707 0.059384 {'PostOpDay' } -0.00047206 0.0015696 -0.30075 170 0.76398 -0.0035705 0.0026264 {'GroupID_Intact:PostOpDay'} -0.00037039 0.0015696 -0.23597 170 0.81374 -0.0034689 0.0027281 Random effects covariance parameters: Group: AnimalID (8 Levels) Name1 Name2 Type Estimate {'(Intercept)' } {'(Intercept)' } {'std' } 0.47977 {'Explained_Skew' } {'(Intercept)' } {'corr'} 0.99977 {'R2_Best' } {'(Intercept)' } {'corr'} -0.66577 {'Explained_Skew:R2_Best'} {'(Intercept)' } {'corr'} -0.98847 {'Explained_Skew' } {'Explained_Skew' } {'std' } 0.31953 {'R2_Best' } {'Explained_Skew' } {'corr'} -0.68168 {'Explained_Skew:R2_Best'} {'Explained_Skew' } {'corr'} -0.98498 {'R2_Best' } {'R2_Best' } {'std' } 0.15763 {'Explained_Skew:R2_Best'} {'R2_Best' } {'corr'} 0.5451 {'Explained_Skew:R2_Best'} {'Explained_Skew:R2_Best'} {'std' } 2.5215 Group: Error Name Estimate {'sqrt(Dispersion)'} 0.073795
To interpret this result:
Note that the (Fixed-Effect) Intercept is different from the average of the Response variable:
disp(mean(E.R2_Skew));
0.3303
This difference is accounted for by the Random-Effect Intercept terms, which are grouped by AnimalID.
disp(glme_simple.Coefficients.Estimate(1)-mean(E.R2_Skew));
0.2883
disp(glme_simple.Rsquared)
Ordinary: 0.9034 Adjusted: 0.9017

Fit complex models

glme_complex = fitglme(E,complex_model,fit_params{:})
glme_complex =
Generalized linear mixed-effects model fit by ML Model information: Number of observations 174 Fixed effects coefficients 4 Random effects coefficients 64 Covariance parameters 37 Distribution Normal Link Identity FitMethod ApproximateLaplace Formula: R2_Skew ~ 1 + GroupID*PostOpDay + (1 + AverageDuration*Explained_Skew + AverageDuration*R2_Best + Explained_Skew*R2_Best + AverageDuration:Explained_Skew:R2_Best | GroupID:AnimalID) Model fit statistics: AIC BIC LogLikelihood Deviance -309.37 -179.85 195.69 -391.37 Fixed effects coefficients (95% CIs): Name Estimate SE tStat DF pValue Lower Upper {'(Intercept)' } 0.63913 0.036024 17.742 170 1.569e-40 0.56802 0.71025 {'GroupID_Intact' } -0.015108 0.036024 -0.41939 170 0.67546 -0.08622 0.056004 {'PostOpDay' } -0.0015931 0.0015163 -1.0507 170 0.2949 -0.0045862 0.0014 {'GroupID_Intact:PostOpDay'} 0.0017527 0.0015163 1.1559 170 0.24934 -0.0012405 0.0047458 Random effects covariance parameters: Group: GroupID:AnimalID (8 Levels) Name1 Name2 Type Estimate {'(Intercept)' } {'(Intercept)' } {'std' } 0.05352 {'AverageDuration' } {'(Intercept)' } {'corr'} -0.95246 {'Explained_Skew' } {'(Intercept)' } {'corr'} -0.76325 {'R2_Best' } {'(Intercept)' } {'corr'} -0.43127 {'AverageDuration:Explained_Skew' } {'(Intercept)' } {'corr'} 0.78199 {'AverageDuration:R2_Best' } {'(Intercept)' } {'corr'} 0.50231 {'Explained_Skew:R2_Best' } {'(Intercept)' } {'corr'} 0.96402 {'AverageDuration:Explained_Skew:R2_Best'} {'(Intercept)' } {'corr'} -0.84297 {'AverageDuration' } {'AverageDuration' } {'std' } 0.91195 {'Explained_Skew' } {'AverageDuration' } {'corr'} 0.92381 {'R2_Best' } {'AverageDuration' } {'corr'} 0.13589 {'AverageDuration:Explained_Skew' } {'AverageDuration' } {'corr'} -0.93471 {'AverageDuration:R2_Best' } {'AverageDuration' } {'corr'} -0.21498 {'Explained_Skew:R2_Best' } {'AverageDuration' } {'corr'} -0.8372 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration' } {'corr'} 0.63899 {'Explained_Skew' } {'Explained_Skew' } {'std' } 3.7047 {'R2_Best' } {'Explained_Skew' } {'corr'} -0.25375 {'AverageDuration:Explained_Skew' } {'Explained_Skew' } {'corr'} -0.99956 {'AverageDuration:R2_Best' } {'Explained_Skew' } {'corr'} 0.17529 {'Explained_Skew:R2_Best' } {'Explained_Skew' } {'corr'} -0.56405 {'AverageDuration:Explained_Skew:R2_Best'} {'Explained_Skew' } {'corr'} 0.29583 {'R2_Best' } {'R2_Best' } {'std' } 1.5434 {'AverageDuration:Explained_Skew' } {'R2_Best' } {'corr'} 0.22509 {'AverageDuration:R2_Best' } {'R2_Best' } {'corr'} -0.99677 {'Explained_Skew:R2_Best' } {'R2_Best' } {'corr'} -0.65558 {'AverageDuration:Explained_Skew:R2_Best'} {'R2_Best' } {'corr'} 0.84891 {'AverageDuration:Explained_Skew' } {'AverageDuration:Explained_Skew' } {'std' } 5.7129 {'AverageDuration:R2_Best' } {'AverageDuration:Explained_Skew' } {'corr'} -0.14615 {'Explained_Skew:R2_Best' } {'AverageDuration:Explained_Skew' } {'corr'} 0.58818 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration:Explained_Skew' } {'corr'} -0.32389 {'AverageDuration:R2_Best' } {'AverageDuration:R2_Best' } {'std' } 2.7583 {'Explained_Skew:R2_Best' } {'AverageDuration:R2_Best' } {'corr'} 0.71408 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration:R2_Best' } {'corr'} -0.8886 {'Explained_Skew:R2_Best' } {'Explained_Skew:R2_Best' } {'std' } 7.6386 {'AverageDuration:Explained_Skew:R2_Best'} {'Explained_Skew:R2_Best' } {'corr'} -0.95564 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration:Explained_Skew:R2_Best'} {'std' } 11.171 Group: Error Name Estimate {'sqrt(Dispersion)'} 0.067042
disp(glme_complex.Rsquared)
Ordinary: 0.9214 Adjusted: 0.9201
[~,~,stats] = randomEffects(glme_complex) %#ok<ASGLU>
stats =
Random effect coefficients: DFMethod = 'residual', Alpha = 0.05 Group Level Name Estimate SEPred tStat DF pValue Lower Upper {'GroupID:AnimalID'} {'Intact RC-14' } {'(Intercept)' } 0.0031224 0.025133 0.12424 170 0.90127 -0.04649 0.052735 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration' } 0.030664 0.30883 0.099292 170 0.92102 -0.57897 0.6403 {'GroupID:AnimalID'} {'Intact RC-14' } {'Explained_Skew' } 0.53575 1.1982 0.44713 170 0.65535 -1.8295 2.901 {'GroupID:AnimalID'} {'Intact RC-14' } {'R2_Best' } -0.44647 1.189 -0.37551 170 0.70775 -2.7935 1.9006 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration:Explained_Skew' } -0.78177 1.8067 -0.4327 170 0.66578 -4.3483 2.7848 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration:R2_Best' } 0.77904 2.1316 0.36548 170 0.71521 -3.4287 4.9868 {'GroupID:AnimalID'} {'Intact RC-14' } {'Explained_Skew:R2_Best' } 1.024 4.5291 0.2261 170 0.8214 -7.9165 9.9645 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration:Explained_Skew:R2_Best'} -2.3085 7.8422 -0.29437 170 0.76883 -17.789 13.172 {'GroupID:AnimalID'} {'Intact RC-43' } {'(Intercept)' } 0.033226 0.01519 2.1874 170 0.030082 0.0032407 0.063212 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration' } -0.94043 0.18124 -5.1888 170 5.9741e-07 -1.2982 -0.58266 {'GroupID:AnimalID'} {'Intact RC-43' } {'Explained_Skew' } -5.2116 0.82167 -6.3427 170 1.9686e-09 -6.8336 -3.5896 {'GroupID:AnimalID'} {'Intact RC-43' } {'R2_Best' } 1.5974 0.80846 1.9759 170 0.049787 0.0015054 3.1933 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration:Explained_Skew' } 7.9151 1.2252 6.4603 170 1.0582e-09 5.4965 10.334 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration:R2_Best' } -2.5837 1.4415 -1.7924 170 0.074849 -5.4293 0.26182 {'GroupID:AnimalID'} {'Intact RC-43' } {'Explained_Skew:R2_Best' } 1.6397 2.8518 0.57496 170 0.56608 -3.9898 7.2692 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration:Explained_Skew:R2_Best'} 2.8312 5.1063 0.55445 170 0.58 -7.2488 12.911 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'(Intercept)' } -0.033024 0.020599 -1.6032 170 0.11074 -0.073686 0.0076381 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'AverageDuration' } 0.30389 0.28867 1.0527 170 0.29395 -0.26594 0.87372 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'Explained_Skew' } -0.25443 1.4812 -0.17177 170 0.86382 -3.1784 2.6695 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'R2_Best' } 1.5737 1.1437 1.376 170 0.17064 -0.684 3.8314 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'AverageDuration:Explained_Skew' } 0.21745 2.2205 0.097928 170 0.9221 -4.1659 4.6008 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'AverageDuration:R2_Best' } -2.8469 2.0232 -1.4071 170 0.16121 -6.8407 1.1469 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'Explained_Skew:R2_Best' } -6.2396 3.7827 -1.6495 170 0.10089 -13.707 1.2274 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'AverageDuration:Explained_Skew:R2_Best'} 10.829 6.8763 1.5749 170 0.11715 -2.7446 24.403 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'(Intercept)' } 0.051587 0.01089 4.7371 170 4.5529e-06 0.03009 0.073084 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration' } -0.98434 0.073583 -13.377 170 2.4084e-28 -1.1296 -0.83908 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'Explained_Skew' } -3.9929 0.54943 -7.2674 170 1.27e-11 -5.0775 -2.9083 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'R2_Best' } 0.095764 0.7439 0.12873 170 0.89772 -1.3727 1.5642 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration:Explained_Skew' } 6.1916 0.77742 7.9642 170 2.278e-13 4.6569 7.7262 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration:R2_Best' } 0.072515 1.3222 0.054843 170 0.95633 -2.5376 2.6826 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'Explained_Skew:R2_Best' } 6.0226 2.3625 2.5493 170 0.011678 1.3591 10.686 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration:Explained_Skew:R2_Best'} -5.8943 4.5051 -1.3084 170 0.19252 -14.787 2.9988 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'(Intercept)' } 0.046212 0.0078099 5.9171 170 1.7589e-08 0.030795 0.061629 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration' } -0.9643 0.073297 -13.156 170 1.0268e-27 -1.109 -0.81961 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'Explained_Skew' } -4.2878 0.27911 -15.363 170 5.8163e-34 -4.8388 -3.7368 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'R2_Best' } 0.49937 0.42503 1.1749 170 0.24168 -0.33965 1.3384 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration:Explained_Skew' } 6.6041 0.40264 16.402 170 7.376e-37 5.8092 7.3989 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration:R2_Best' } -0.64344 0.76159 -0.84486 170 0.39938 -2.1468 0.85995 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'Explained_Skew:R2_Best' } 4.792 1.5283 3.1356 170 0.0020214 1.7752 7.8089 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration:Explained_Skew:R2_Best'} -3.4953 2.748 -1.2719 170 0.20513 -8.9199 1.9293 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'(Intercept)' } 0.095671 0.0067954 14.079 170 2.4447e-30 0.082257 0.10909 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration' } -1.236 0.056779 -21.769 170 4.922e-51 -1.3481 -1.1239 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'Explained_Skew' } -2.3264 0.24689 -9.4226 170 3.1757e-17 -2.8138 -1.839 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'R2_Best' } -2.7769 0.39508 -7.0288 170 4.8299e-11 -3.5568 -1.997 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration:Explained_Skew' } 3.9274 0.3489 11.256 170 2.5573e-22 3.2387 4.6161 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration:R2_Best' } 5.195 0.70653 7.3529 170 7.828e-12 3.8003 6.5898 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'Explained_Skew:R2_Best' } 15.478 1.3728 11.274 170 2.2753e-22 12.768 18.188 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration:Explained_Skew:R2_Best'} -23.682 2.511 -9.4314 170 3.007e-17 -28.638 -18.725 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'(Intercept)' } 0.059558 0.019836 3.0024 170 0.0030824 0.0204 0.098715 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'AverageDuration' } -1.0673 0.12986 -8.2193 170 5.0236e-14 -1.3237 -0.811 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'Explained_Skew' } -4.0147 1.3007 -3.0866 170 0.0023647 -6.5823 -1.4471 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'R2_Best' } -0.23566 1.5141 -0.15564 170 0.8765 -3.2246 2.7533 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'AverageDuration:Explained_Skew' } 6.2629 1.8624 3.3628 170 0.00095316 2.5865 9.9392 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'AverageDuration:R2_Best' } 0.67674 2.6797 0.25255 170 0.80092 -4.613 5.9664 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'Explained_Skew:R2_Best' } 7.4581 4.5154 1.6517 170 0.10044 -1.4554 16.372 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'AverageDuration:Explained_Skew:R2_Best'} -8.2991 8.8639 -0.93629 170 0.35045 -25.797 9.1983 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'(Intercept)' } 0.045592 0.0083457 5.463 170 1.6407e-07 0.029118 0.062067 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration' } -0.98225 0.06221 -15.789 170 3.7197e-35 -1.1051 -0.85945 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'Explained_Skew' } -4.4963 0.36023 -12.482 170 8.5416e-26 -5.2074 -3.7852 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'R2_Best' } 0.64745 0.52954 1.2226 170 0.22316 -0.39788 1.6928 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration:Explained_Skew' } 6.9113 0.50796 13.606 170 5.3884e-29 5.9085 7.914 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration:R2_Best' } -0.89991 0.94381 -0.95348 170 0.3417 -2.763 0.96319 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'Explained_Skew:R2_Best' } 4.5021 1.7516 2.5703 170 0.01102 1.0444 7.9598 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration:Explained_Skew:R2_Best'} -2.7805 3.2774 -0.84838 170 0.39742 -9.25 3.6891

Compare simple and complex models

if glme_simple.LogLikelihood > glme_complex.LogLikelihood
glme = glme_simple;
mdl = simple_model;
else
glme = glme_complex;
mdl = complex_model;
end
fprintf(1,'Selected Model: <strong>%s</strong>\n',mdl);
Selected Model: R2_Skew~GroupID*PostOpDay+(1+R2_Best*Explained_Skew*AverageDuration|GroupID:AnimalID)
If the pvalue is large, we should retain glme_simple; otherwise, the additional model complexity adds enough meaningful information that we should keep glme_complex.

Check the residuals

We can plot the residuals using a method of the glme object that we've recovered:
analyze.stat.panelized_residuals(glme);
The fitted residuals plot looks reasonable. It's balanced on both the X- and Y-axes. Our residuals are not going to pass a test of normality probably, but they look good enough for government work.

Plot residuals grouped by AnimalID

We should verify that there isn't an outlier Animal (as opposed to single-trial) that is biasing the regression.
[groupings,TID] = findgroups(E(:,{'AnimalID'}));
analyze.stat.plot_glme_residuals(glme,E,groupings,TID,'yVar','R2_Skew','scatterAlpha',0.45,'scatterSize',15);
It looks like RC-02 hand RC-26 are really mucking up our dataset. Both have very few observations, and since our model depends on estimating regressions from, among other terms, data grouped by each Animal, we should probably just exclude those two from our model. We should re-fit the model without these two categories.

Re-fit the model, excluding RC-02 and RC-26 observations

excludeRat = "RC-02";
Once we have re-fit, we should double-check our residuals once again and then we can begin interpreting our model.
exclusions = ismember(string(E.AnimalID),excludeRat);
E.Properties.UserData.ModelExclusions = exclusions;
E.Properties.UserData.Excluded.glme_outlier_residuals = sum(exclusions);
E.Properties.UserData.FinalGLMEparams = fit_params{:};
glme2 = fitglme(E,mdl,'Exclude',exclusions,fit_params{:})
glme2 =
Generalized linear mixed-effects model fit by ML Model information: Number of observations 171 Fixed effects coefficients 4 Random effects coefficients 56 Covariance parameters 37 Distribution Normal Link Identity FitMethod ApproximateLaplace Formula: R2_Skew ~ 1 + GroupID*PostOpDay + (1 + AverageDuration*Explained_Skew + AverageDuration*R2_Best + Explained_Skew*R2_Best + AverageDuration:Explained_Skew:R2_Best | GroupID:AnimalID) Model fit statistics: AIC BIC LogLikelihood Deviance -308.81 -180 195.4 -390.81 Fixed effects coefficients (95% CIs): Name Estimate SE tStat DF pValue Lower Upper {'(Intercept)' } 0.59533 0.021701 27.433 167 9.3298e-64 0.55249 0.63817 {'GroupID_Intact' } 0.036654 0.021701 1.689 167 0.093081 -0.0061901 0.079497 {'PostOpDay' } -0.0028359 0.0013372 -2.1207 167 0.035423 -0.005476 -0.00019582 {'GroupID_Intact:PostOpDay'} 0.00045593 0.0013372 0.34095 167 0.73357 -0.0021841 0.003096 Random effects covariance parameters: Group: GroupID:AnimalID (7 Levels) Name1 Name2 Type Estimate {'(Intercept)' } {'(Intercept)' } {'std' } 0.13193 {'AverageDuration' } {'(Intercept)' } {'corr'} -0.99873 {'Explained_Skew' } {'(Intercept)' } {'corr'} -0.91104 {'R2_Best' } {'(Intercept)' } {'corr'} -0.18594 {'AverageDuration:Explained_Skew' } {'(Intercept)' } {'corr'} 0.91881 {'AverageDuration:R2_Best' } {'(Intercept)' } {'corr'} 0.25903 {'Explained_Skew:R2_Best' } {'(Intercept)' } {'corr'} 0.87103 {'AverageDuration:Explained_Skew:R2_Best'} {'(Intercept)' } {'corr'} -0.66389 {'AverageDuration' } {'AverageDuration' } {'std' } 0.97458 {'Explained_Skew' } {'AverageDuration' } {'corr'} 0.93006 {'R2_Best' } {'AverageDuration' } {'corr'} 0.13806 {'AverageDuration:Explained_Skew' } {'AverageDuration' } {'corr'} -0.93696 {'AverageDuration:R2_Best' } {'AverageDuration' } {'corr'} -0.21189 {'Explained_Skew:R2_Best' } {'AverageDuration' } {'corr'} -0.84629 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration' } {'corr'} 0.62691 {'Explained_Skew' } {'Explained_Skew' } {'std' } 3.9328 {'R2_Best' } {'Explained_Skew' } {'corr'} -0.23549 {'AverageDuration:Explained_Skew' } {'Explained_Skew' } {'corr'} -0.99981 {'AverageDuration:R2_Best' } {'Explained_Skew' } {'corr'} 0.162 {'Explained_Skew:R2_Best' } {'Explained_Skew' } {'corr'} -0.59138 {'AverageDuration:Explained_Skew:R2_Best'} {'Explained_Skew' } {'corr'} 0.29682 {'R2_Best' } {'R2_Best' } {'std' } 1.7253 {'AverageDuration:Explained_Skew' } {'R2_Best' } {'corr'} 0.21673 {'AverageDuration:R2_Best' } {'R2_Best' } {'corr'} -0.99719 {'Explained_Skew:R2_Best' } {'R2_Best' } {'corr'} -0.64445 {'AverageDuration:Explained_Skew:R2_Best'} {'R2_Best' } {'corr'} 0.85818 {'AverageDuration:Explained_Skew' } {'AverageDuration:Explained_Skew' } {'std' } 5.9775 {'AverageDuration:R2_Best' } {'AverageDuration:Explained_Skew' } {'corr'} -0.14297 {'Explained_Skew:R2_Best' } {'AverageDuration:Explained_Skew' } {'corr'} 0.60679 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration:Explained_Skew' } {'corr'} -0.31515 {'AverageDuration:R2_Best' } {'AverageDuration:R2_Best' } {'std' } 3.2303 {'Explained_Skew:R2_Best' } {'AverageDuration:R2_Best' } {'corr'} 0.69994 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration:R2_Best' } {'corr'} -0.89424 {'Explained_Skew:R2_Best' } {'Explained_Skew:R2_Best' } {'std' } 8.0522 {'AverageDuration:Explained_Skew:R2_Best'} {'Explained_Skew:R2_Best' } {'corr'} -0.94558 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration:Explained_Skew:R2_Best'} {'std' } 11.804 Group: Error Name Estimate {'sqrt(Dispersion)'} 0.067065
disp(glme2.Rsquared)
Ordinary: 0.9187 Adjusted: 0.9173
[~,~,stats] = randomEffects(glme2) %#ok<ASGLU>
stats =
Random effect coefficients: DFMethod = 'residual', Alpha = 0.05 Group Level Name Estimate SEPred tStat DF pValue Lower Upper {'GroupID:AnimalID'} {'Intact RC-14' } {'(Intercept)' } -0.014916 0.047225 -0.31584 167 0.75252 -0.10815 0.078319 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration' } 0.10941 0.32752 0.33405 167 0.73876 -0.53721 0.75603 {'GroupID:AnimalID'} {'Intact RC-14' } {'Explained_Skew' } 0.38224 1.1474 0.33315 167 0.73944 -1.883 2.6475 {'GroupID:AnimalID'} {'Intact RC-14' } {'R2_Best' } 0.060319 1.3937 0.043281 167 0.96553 -2.6912 2.8118 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration:Explained_Skew' } -0.58772 1.7178 -0.34212 167 0.73269 -3.9792 2.8038 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration:R2_Best' } -0.13888 2.6228 -0.05295 167 0.95783 -5.3169 5.0392 {'GroupID:AnimalID'} {'Intact RC-14' } {'Explained_Skew:R2_Best' } -0.84934 4.9992 -0.16989 167 0.8653 -10.719 9.0205 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration:Explained_Skew:R2_Best'} 1.0115 8.842 0.11439 167 0.90906 -16.445 18.468 {'GroupID:AnimalID'} {'Intact RC-43' } {'(Intercept)' } 0.15944 0.019721 8.0849 167 1.2035e-13 0.1205 0.19837 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration' } -1.2137 0.13857 -8.759 167 2.1233e-15 -1.4873 -0.94014 {'GroupID:AnimalID'} {'Intact RC-43' } {'Explained_Skew' } -5.6042 0.72641 -7.715 167 1.0435e-12 -7.0383 -4.1701 {'GroupID:AnimalID'} {'Intact RC-43' } {'R2_Best' } 0.94388 0.76636 1.2316 167 0.21982 -0.56913 2.4569 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration:Explained_Skew' } 8.4913 1.0736 7.9089 167 3.3812e-13 6.3716 10.611 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration:R2_Best' } -1.4394 1.4257 -1.0096 167 0.31412 -4.2541 1.3752 {'GroupID:AnimalID'} {'Intact RC-43' } {'Explained_Skew:R2_Best' } 5.3726 2.3249 2.3108 167 0.022064 0.78253 9.9627 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration:Explained_Skew:R2_Best'} -2.5395 4.4403 -0.57194 167 0.56813 -11.306 6.2267 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'(Intercept)' } 0.11885 0.01394 8.5261 167 8.6826e-15 0.091332 0.14637 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration' } -0.90183 0.083812 -10.76 167 7.5991e-21 -1.0673 -0.73637 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'Explained_Skew' } -4.078 0.5606 -7.2743 167 1.2879e-11 -5.1848 -2.9712 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'R2_Best' } 0.59945 0.87463 0.68538 167 0.49406 -1.1273 2.3262 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration:Explained_Skew' } 6.1849 0.80198 7.712 167 1.0619e-12 4.6015 7.7682 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration:R2_Best' } -0.88132 1.6306 -0.54049 167 0.58958 -4.1006 2.3379 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'Explained_Skew:R2_Best' } 4.2478 2.597 1.6357 167 0.10379 -0.87935 9.375 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration:Explained_Skew:R2_Best'} -2.4353 5.0882 -0.47861 167 0.63284 -12.481 7.6103 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'(Intercept)' } 0.12147 0.012397 9.7981 167 3.4242e-18 0.096992 0.14594 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration' } -0.92011 0.07911 -11.631 167 2.7832e-23 -1.0763 -0.76393 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'Explained_Skew' } -4.1153 0.29807 -13.806 167 2.0455e-29 -4.7037 -3.5268 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'R2_Best' } 0.5579 0.52961 1.0534 167 0.29367 -0.4877 1.6035 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration:Explained_Skew' } 6.2446 0.4299 14.525 167 1.9578e-31 5.3958 7.0933 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration:R2_Best' } -0.79997 0.99336 -0.80532 167 0.42178 -2.7611 1.1612 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'Explained_Skew:R2_Best' } 4.4687 1.739 2.5696 167 0.011054 1.0354 7.902 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration:Explained_Skew:R2_Best'} -2.7736 3.2382 -0.85654 167 0.39293 -9.1667 3.6194 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'(Intercept)' } 0.17566 0.0095762 18.343 167 7.2094e-42 0.15675 0.19457 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration' } -1.214 0.058263 -20.837 167 2.5618e-48 -1.3291 -1.099 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'Explained_Skew' } -1.9518 0.27385 -7.1272 167 2.934e-11 -2.4925 -1.4112 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'R2_Best' } -3.377 0.48201 -7.0061 167 5.7417e-11 -4.3286 -2.4254 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration:Explained_Skew' } 3.2116 0.39079 8.2183 167 5.4678e-14 2.4401 3.9832 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration:R2_Best' } 6.5434 0.90175 7.2564 167 1.4248e-11 4.7631 8.3237 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'Explained_Skew:R2_Best' } 16.221 1.5135 10.718 167 9.981e-21 13.233 19.21 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration:Explained_Skew:R2_Best'} -25.796 2.8839 -8.9446 167 6.8434e-16 -31.489 -20.102 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'(Intercept)' } 0.13879 0.025579 5.426 167 1.9975e-07 0.088292 0.18929 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'AverageDuration' } -1.0264 0.16455 -6.2375 167 3.5209e-09 -1.3512 -0.70151 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'Explained_Skew' } -3.8441 1.3134 -2.9268 167 0.0039015 -6.4371 -1.2511 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'R2_Best' } -0.26038 1.7124 -0.15206 167 0.87933 -3.6412 3.1204 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'AverageDuration:Explained_Skew' } 5.8867 1.901 3.0967 167 0.002296 2.1337 9.6397 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'AverageDuration:R2_Best' } 0.73844 3.1813 0.23212 167 0.81673 -5.5423 7.0192 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'Explained_Skew:R2_Best' } 7.2006 4.836 1.489 167 0.13838 -2.3469 16.748 {'GroupID:AnimalID'} {'Ischemia RC-26'} {'AverageDuration:Explained_Skew:R2_Best'} -7.8445 9.6969 -0.80897 167 0.41968 -26.989 11.3 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'(Intercept)' } 0.11766 0.01111 10.59 167 2.2537e-20 0.095725 0.13959 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration' } -0.90752 0.067065 -13.532 167 1.2124e-28 -1.0399 -0.77512 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'Explained_Skew' } -4.5422 0.37385 -12.15 167 9.6299e-25 -5.2803 -3.8041 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'R2_Best' } 1.1218 0.62433 1.7967 167 0.074186 -0.11085 2.3543 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration:Explained_Skew' } 6.8577 0.53349 12.854 167 9.8839e-27 5.8044 7.9109 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration:R2_Best' } -1.8448 1.166 -1.5821 167 0.11551 -4.1469 0.45726 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'Explained_Skew:R2_Best' } 2.973 1.9077 1.5584 167 0.12103 -0.79336 6.7394 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration:Explained_Skew:R2_Best'} 0.33981 3.6849 0.092217 167 0.92664 -6.9351 7.6147
[~,~,stats_fixed] = fixedEffects(glme2)
stats_fixed =
Fixed effect coefficients: DFMethod = 'residual', Alpha = 0.05 Name Estimate SE tStat DF pValue Lower Upper {'(Intercept)' } 0.59533 0.021701 27.433 167 9.3298e-64 0.55249 0.63817 {'GroupID_Intact' } 0.036654 0.021701 1.689 167 0.093081 -0.0061901 0.079497 {'PostOpDay' } -0.0028359 0.0013372 -2.1207 167 0.035423 -0.005476 -0.00019582 {'GroupID_Intact:PostOpDay'} 0.00045593 0.0013372 0.34095 167 0.73357 -0.0021841 0.003096
analyze.stat.panelized_residuals(glme2);
[groupings,TID] = findgroups(E(~exclusions,{'AnimalID'}));
analyze.stat.plot_glme_residuals(glme2,E(~exclusions,:),groupings,TID,'yVar','R2_Skew','scatterAlpha',0.33);
The fits have improved after removing the two outlier rats (each of which only had very few observations. Clearly, the number of observations for RC-14 isn't great, but after exclusions only 2 animals remain in the Intact group to begin with so we will leave it in.

Verify that PostOpDay also doesn't have some funny residuals

[groupings,TID] = findgroups(E(~exclusions,{'PostOpDay'}));
analyze.stat.plot_glme_residuals(glme2,E(~exclusions,:),groupings,TID,'yVar','R2_Skew','scatterAlpha',0.33);
The residuals look pretty close to the reference line for the remaining post-operative days; therefore, we are done verifying the model. We could also try to re-run it by excluding some of the latest days, restricting the analysis to the first 20 days, which we have more data points for. Excluding the first week of data, when the rat in general is very inactive, may also be a good idea.

Define a second set of exclusions, and re-run the model

minPostOpDay = 8;
maxPostOpDay = 22;
combineExclusions = false;
Click Run once the range is set.
if combineExclusions
exclusions2 = exclusions | (E.PostOpDay < minPostOpDay) | (E.PostOpDay > maxPostOpDay);
else
exclusions2 = (E.PostOpDay < minPostOpDay) | (E.PostOpDay > maxPostOpDay); %#ok<*UNRCH>
end
E.Properties.UserData.ModelExclusions2 = exclusions2;
E.Properties.UserData.Excluded.glme_outlier_residuals2 = sum(exclusions2);
glme3 = fitglme(E,mdl,'Exclude',exclusions2,fit_params{:})
glme3 =
Generalized linear mixed-effects model fit by ML Model information: Number of observations 126 Fixed effects coefficients 4 Random effects coefficients 56 Covariance parameters 37 Distribution Normal Link Identity FitMethod ApproximateLaplace Formula: R2_Skew ~ 1 + GroupID*PostOpDay + (1 + AverageDuration*Explained_Skew + AverageDuration*R2_Best + Explained_Skew*R2_Best + AverageDuration:Explained_Skew:R2_Best | GroupID:AnimalID) Model fit statistics: AIC BIC LogLikelihood Deviance -189.66 -73.371 135.83 -271.66 Fixed effects coefficients (95% CIs): Name Estimate SE tStat DF pValue Lower Upper {'(Intercept)' } 0.17168 0.054982 3.1224 122 0.0022405 0.062834 0.28052 {'GroupID_Intact' } 0.1295 0.054982 2.3553 122 0.020102 0.020659 0.23834 {'PostOpDay' } 0.012155 0.0047375 2.5657 122 0.011506 0.0027768 0.021534 {'GroupID_Intact:PostOpDay'} 0.014896 0.0047375 3.1443 122 0.0020912 0.0055177 0.024274 Random effects covariance parameters: Group: GroupID:AnimalID (7 Levels) Name1 Name2 Type Estimate {'(Intercept)' } {'(Intercept)' } {'std' } 1.3414 {'AverageDuration' } {'(Intercept)' } {'corr'} -0.99927 {'Explained_Skew' } {'(Intercept)' } {'corr'} -0.99818 {'R2_Best' } {'(Intercept)' } {'corr'} -0.89519 {'AverageDuration:Explained_Skew' } {'(Intercept)' } {'corr'} 0.99889 {'AverageDuration:R2_Best' } {'(Intercept)' } {'corr'} 0.90819 {'Explained_Skew:R2_Best' } {'(Intercept)' } {'corr'} 0.96258 {'AverageDuration:Explained_Skew:R2_Best'} {'(Intercept)' } {'corr'} -0.95487 {'AverageDuration' } {'AverageDuration' } {'std' } 2.3417 {'Explained_Skew' } {'AverageDuration' } {'corr'} 0.99608 {'R2_Best' } {'AverageDuration' } {'corr'} 0.907 {'AverageDuration:Explained_Skew' } {'AverageDuration' } {'corr'} -0.99796 {'AverageDuration:R2_Best' } {'AverageDuration' } {'corr'} -0.9194 {'Explained_Skew:R2_Best' } {'AverageDuration' } {'corr'} -0.96541 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration' } {'corr'} 0.96027 {'Explained_Skew' } {'Explained_Skew' } {'std' } 7.9303 {'R2_Best' } {'Explained_Skew' } {'corr'} 0.86716 {'AverageDuration:Explained_Skew' } {'Explained_Skew' } {'corr'} -0.99953 {'AverageDuration:R2_Best' } {'Explained_Skew' } {'corr'} -0.88181 {'Explained_Skew:R2_Best' } {'Explained_Skew' } {'corr'} -0.94518 {'AverageDuration:Explained_Skew:R2_Best'} {'Explained_Skew' } {'corr'} 0.93529 {'R2_Best' } {'R2_Best' } {'std' } 3.8319 {'AverageDuration:Explained_Skew' } {'R2_Best' } {'corr'} -0.87827 {'AverageDuration:R2_Best' } {'R2_Best' } {'corr'} -0.99953 {'Explained_Skew:R2_Best' } {'R2_Best' } {'corr'} -0.96929 {'AverageDuration:Explained_Skew:R2_Best'} {'R2_Best' } {'corr'} 0.98294 {'AverageDuration:Explained_Skew' } {'AverageDuration:Explained_Skew' } {'std' } 14.025 {'AverageDuration:R2_Best' } {'AverageDuration:Explained_Skew' } {'corr'} 0.89242 {'Explained_Skew:R2_Best' } {'AverageDuration:Explained_Skew' } {'corr'} 0.94911 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration:Explained_Skew' } {'corr'} -0.94126 {'AverageDuration:R2_Best' } {'AverageDuration:R2_Best' } {'std' } 7.2694 {'Explained_Skew:R2_Best' } {'AverageDuration:R2_Best' } {'corr'} 0.97445 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration:R2_Best' } {'corr'} -0.98705 {'Explained_Skew:R2_Best' } {'Explained_Skew:R2_Best' } {'std' } 26.691 {'AverageDuration:Explained_Skew:R2_Best'} {'Explained_Skew:R2_Best' } {'corr'} -0.99773 {'AverageDuration:Explained_Skew:R2_Best'} {'AverageDuration:Explained_Skew:R2_Best'} {'std' } 45.081 Group: Error Name Estimate {'sqrt(Dispersion)'} 0.06576
disp(glme3.Rsquared)
Ordinary: 0.9281 Adjusted: 0.9264
[~,~,stats] = randomEffects(glme3)
stats =
Random effect coefficients: DFMethod = 'residual', Alpha = 0.05 Group Level Name Estimate SEPred tStat DF pValue Lower Upper {'GroupID:AnimalID'} {'Intact RC-14' } {'(Intercept)' } 0.37115 0.59612 0.62262 122 0.5347 -0.80892 1.5512 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration' } -0.66401 1.0737 -0.61843 122 0.53744 -2.7895 1.4615 {'GroupID:AnimalID'} {'Intact RC-14' } {'Explained_Skew' } -2.2631 3.5505 -0.63739 122 0.52507 -9.2917 4.7655 {'GroupID:AnimalID'} {'Intact RC-14' } {'R2_Best' } -0.79932 2.0457 -0.39072 122 0.69668 -4.8491 3.2504 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration:Explained_Skew' } 4.0766 6.4273 0.63427 122 0.52709 -8.6468 16.8 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration:R2_Best' } 1.5769 3.8264 0.41212 122 0.68098 -5.9978 9.1516 {'GroupID:AnimalID'} {'Intact RC-14' } {'Explained_Skew:R2_Best' } 5.3452 12.102 0.44167 122 0.65951 -18.612 29.303 {'GroupID:AnimalID'} {'Intact RC-14' } {'AverageDuration:Explained_Skew:R2_Best'} -9.549 21.429 -0.44561 122 0.65667 -51.97 32.872 {'GroupID:AnimalID'} {'Intact RC-43' } {'(Intercept)' } -1.7043 0.69494 -2.4525 122 0.015601 -3.08 -0.32863 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration' } 3.0153 1.2221 2.4673 122 0.015003 0.59597 5.4346 {'GroupID:AnimalID'} {'Intact RC-43' } {'Explained_Skew' } 9.6585 4.2785 2.2575 122 0.025758 1.1888 18.128 {'GroupID:AnimalID'} {'Intact RC-43' } {'R2_Best' } 5.7514 1.6775 3.4287 122 0.00082783 2.4307 9.0721 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration:Explained_Skew' } -17.312 7.5971 -2.2788 122 0.024419 -32.351 -2.2729 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration:R2_Best' } -10.861 3.2034 -3.3905 122 0.00094052 -17.203 -4.5198 {'GroupID:AnimalID'} {'Intact RC-43' } {'Explained_Skew:R2_Best' } -38.501 11.299 -3.4073 122 0.00088913 -60.87 -16.133 {'GroupID:AnimalID'} {'Intact RC-43' } {'AverageDuration:Explained_Skew:R2_Best'} 65.882 19.4 3.3959 122 0.00092382 27.476 104.29 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'(Intercept)' } 2.1463 0.51555 4.1632 122 5.8807e-05 1.1257 3.1669 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'AverageDuration' } -3.7083 0.95301 -3.8912 122 0.00016305 -5.5949 -1.8218 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'Explained_Skew' } -12.701 3.0116 -4.2172 122 4.776e-05 -18.662 -6.7388 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'R2_Best' } -5.2299 2.1225 -2.4641 122 0.01513 -9.4315 -1.0283 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'AverageDuration:Explained_Skew' } 22.311 5.5683 4.0067 122 0.00010632 11.288 33.333 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'AverageDuration:R2_Best' } 10.083 3.9446 2.5561 122 0.011813 2.2741 17.892 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'Explained_Skew:R2_Best' } 41.517 11.46 3.6228 122 0.00042596 18.831 64.203 {'GroupID:AnimalID'} {'Ischemia RC-02'} {'AverageDuration:Explained_Skew:R2_Best'} -68.329 20.889 -3.2711 122 0.0013932 -109.68 -26.978 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'(Intercept)' } 0.79479 0.44318 1.7934 122 0.075389 -0.082526 1.6721 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration' } -1.2866 0.82235 -1.5646 122 0.12027 -2.9146 0.34129 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'Explained_Skew' } -5.202 2.6207 -1.9849 122 0.049395 -10.39 -0.013993 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'R2_Best' } -0.050109 1.6184 -0.030962 122 0.97535 -3.2539 3.1537 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration:Explained_Skew' } 8.7157 4.8549 1.7952 122 0.07509 -0.89502 18.327 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration:R2_Best' } 0.36204 3.0417 0.11902 122 0.90545 -5.6593 6.3834 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'Explained_Skew:R2_Best' } 9.0188 8.3228 1.0836 122 0.28067 -7.4569 25.495 {'GroupID:AnimalID'} {'Ischemia RC-04'} {'AverageDuration:Explained_Skew:R2_Best'} -11.765 15.685 -0.75004 122 0.45467 -42.815 19.286 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'(Intercept)' } 1.2816 0.41419 3.0942 122 0.0024473 0.46167 2.1015 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration' } -2.1902 0.76917 -2.8475 122 0.0051724 -3.7128 -0.66754 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'Explained_Skew' } -8.102 2.4429 -3.3166 122 0.0012008 -12.938 -3.2661 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'R2_Best' } -1.4459 1.3829 -1.0456 122 0.29782 -4.1835 1.2916 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration:Explained_Skew' } 14.096 4.5334 3.1094 122 0.0023341 5.1216 23.07 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration:R2_Best' } 3.064 2.6296 1.1652 122 0.24621 -2.1415 8.2696 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'Explained_Skew:R2_Best' } 16.305 7.132 2.2862 122 0.023967 2.1867 30.424 {'GroupID:AnimalID'} {'Ischemia RC-05'} {'AverageDuration:Explained_Skew:R2_Best'} -25.868 13.601 -1.9018 122 0.059549 -52.793 1.0575 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'(Intercept)' } 1.0976 0.50616 2.1686 122 0.032055 0.095656 2.0996 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration' } -1.9445 0.94032 -2.0679 122 0.040764 -3.8059 -0.083025 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'Explained_Skew' } -5.9733 2.9161 -2.0483 122 0.042671 -11.746 -0.20048 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'R2_Best' } -4.4654 1.8651 -2.3942 122 0.018178 -8.1575 -0.77329 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration:Explained_Skew' } 10.739 5.4238 1.98 122 0.049952 0.002277 21.476 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration:R2_Best' } 8.3308 3.5262 2.3625 122 0.019732 1.3503 15.311 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'Explained_Skew:R2_Best' } 29.101 9.737 2.9887 122 0.0033889 9.8254 48.376 {'GroupID:AnimalID'} {'Ischemia RC-08'} {'AverageDuration:Explained_Skew:R2_Best'} -49.672 18.347 -2.7074 122 0.0077554 -85.991 -13.352 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'(Intercept)' } 0.29091 0.30799 0.94456 122 0.34675 -0.31878 0.90061 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration' } -0.35728 0.56704 -0.63009 122 0.52981 -1.4798 0.76522 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'Explained_Skew' } -2.0005 1.8706 -1.0695 122 0.28697 -5.7036 1.7025 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'R2_Best' } 0.76284 1.1172 0.68283 122 0.49601 -1.4487 2.9744 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration:Explained_Skew' } 2.8327 3.4344 0.82482 122 0.41108 -3.966 9.6314 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration:R2_Best' } -1.3232 2.0809 -0.63589 122 0.52604 -5.4426 2.7961 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'Explained_Skew:R2_Best' } 4.848 5.8049 0.83515 122 0.40527 -6.6435 16.339 {'GroupID:AnimalID'} {'Ischemia RC-30'} {'AverageDuration:Explained_Skew:R2_Best'} -2.971 10.789 -0.27537 122 0.7835 -24.33 18.388
analyze.stat.panelized_residuals(glme3);
[groupings,TID] = findgroups(E(~exclusions2,{'AnimalID'}));
analyze.stat.plot_glme_residuals(glme3,E(~exclusions2,:),groupings,TID,'yVar','R2_Skew','scatterAlpha',0.33);
[groupings,TID] = findgroups(E(~exclusions2,{'PostOpDay'}));
analyze.stat.plot_glme_residuals(glme3,E(~exclusions2,:),groupings,TID,'yVar','R2_Skew','scatterAlpha',0.33);

Interpreting the jPCA planes

This model tells us that there is something about the jPCA planes that separates the two groups, particularly during the early post-operative phase; however, we can use the projection matrices to track differences back to the original spike rates so that we can get a better "physical" interpretation of what they mean.

1) Find example Rat from Ischemia group with differences during Early and Late Post-Op recordings

RC-04 or RC-30 show low ability to reconstruct rotatory dimensions during early post-op recordings, but stronger rotations during late post-op recordings.
example_animal = "RC-04";
e = E(E.AnimalID==example_animal,:);
analyze.jPCA.scatter_R2skew(e);

2) Recover dynamic channel weightings as PCs evolve over time

The jPCA method allows us to recover M_skew, such that dX = M_skew * X; here, X is not the observed spike rates, but rather, the scores of principal components of the spike rates in terms of all their possible simultaneous combinations of "rate states." Indexing makes it easier for me to think about this: take M_skew(1,:) and M_skew(2,:) -- these should correspond to the primary jPC plane, assuming the vectors are sorted in ordered pairs. Each column of M_skew(1,:) corresponds to a weighting for each of the (probably 12 total) PCs (rows). In turn, columns of each row give us a time-series: how the scores vary across all the observed samples from each trial. Therefore, to get a single-channel weighting through time for a single jPC vector, we recover the original rates using the projected principal components: W = X*M_skew*(coeff') + repmat(mu,size(X,1),1) where coeff is the matrix of principal component vectors, and mu is the (row) vector of individual channel rates.
% if exist('D','var')==0 % Load in `multi_jPCA` exported data table
% D = getfield(load(defaults.files('multi_jpca_default_matfile')),'D');
% end
% d = D(D.AnimalID==example_animal,:);
% [groupings,tid] = findgroups(d(:,{'AnimalID','Alignment','PostOpDay'}));
% P = splitapply(@(P,S)analyze.jPCA.recover_channel_weights(P{:},S{:}),...
% d.Projection,d.Summary,groupings);

3) Approach as normal with "rosette" or "movie" strategy for visualization

% batch.exportMovies(P);