Hi @Laura ,
To address your issue with the `boxchart` function after running ANOVA with the `anovan` function, let me break down the process and identify potential causes for the error you're encountering.When you run:
aov = anovan(MPG, {org, when}, 'model', 2, 'varnames', {'Origin', 'Model_Year'});
You are correctly obtaining p-values and other outputs from the ANOVA analysis. The output variable `aov` contains statistical results but not in a format directly usable by `boxchart`. The `boxchart` function is designed to create box plots based on categorical data. To use it effectively, you need to ensure that you're passing appropriate data structures to it. The error message suggests that the parameters you are providing to `boxchart` do not align with its expected input. Instead of passing the output of `anovan` directly to `boxchart`, you should extract your group variable (in this case, 'Origin') and the corresponding data (MPG) separately. Here’s how you can structure your code:
% Assuming carbig dataset is already loaded
load carbig;
% Perform ANOVA
[p, tbl, stats] =
anovan(MPG, {org, when}, 'model', 2, 'varnames', {'Origin', 'Model_Year'});
% Create a box chart for MPG based on Origin
boxchart(categorical(org), MPG);
legend('Origin');
So, as you can see, I use ‘categorical(org)` to convert your grouping variable into a categorical format suitable for box charts and directly use `MPG` as the response variable for plotting.
I also noticed that you are using R2023b, make that your MATLAB installation is up-to-date. Occasionally, functions may behave differently across versions due to updates or bug fixes. Also, before plotting, it’s good practice to check if both `MPG` and `org` contain valid data without missing values or inconsistencies. You can use:
disp(sum(isnan(MPG))); % Check for NaN values in MPG
disp(unique(org)); % View unique values in org
Now, you should be able to successfully create your box chart without encountering parameter errors. If issues persist, double-check the inputs and consult MATLAB documentation for any changes specific to your version. Please let me know if you still have any further questions.