IDS: Exam solution 10/09/2026

Open
#223 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
18/100
Issue type
Documentation
Clarity
Needs clarification
Activity status
Active
Domain
content

Research direction

Read the attached IDS_2026_SeptemberOUT.pdf and compare Exercise II with the textbook exercises referenced in the issue. The body includes a submitted MATLAB script but does not specify a change to make or what completion would look like.

Written by the indexing model from the issue text.

Description

IDS_2026_SeptemberOUT.pdf

Exercise II was identical to two exercises in the textbook. Therefore, anyone who did not complete it had evidently not even looked through the book.

As usual there was one student who submitted the following exam completely done by AI and completely wrong
INCREDIBLE


load citiesItaly.mat

% Numeric vars
PUL = varfun(@isnumeric, citiesItaly, 'OutputFormat','uniform');
numT = citiesItaly(:, PUL);

meds = varfun(@median, numT);
mads = varfun(@(x) mad(x,1), numT);

medVals = table2array(meds);
madVals = table2array(mads);
sigma = madVals / 0.6745;

names = numT.Properties.VariableNames;
Z = table(); 
for k = 1:numel(names)
    col = numT.(names{k});
    Z.( [names{k} '_robustz'] ) = (col - medVals(k)) ./ sigma(k);
end

citiesItalyRobust = [citiesItaly Z];

summaryStats = table(names', medVals', sigma', 'VariableNames', {'Variable','Median','UnbiasedMAD'});

robCols = endsWith(citiesItalyRobust.Properties.VariableNames,"_robustz");
Trob = citiesItalyRobust(:, robCols);
X = table2array(Trob);
names = Trob.Properties.VariableNames;
p = size(X,2);

figure;
hold on;
for k = 1:p
    h = boxchart(k*ones(size(X,1),1), X(:,k));  
    h.BoxFaceColor = [0.6 0.6 0.9];                
    h.MarkerStyle = 'none';
    h.DisplayName = names{k};                     
end
hold off;
xlim([0.5 p+0.5]);
set(gca, 'XTick', 1:p, 'XTickLabel', names, 'XTickLabelRotation', 45);

ylabel("addedval(1)");
title("addedval(1)");
legend("show", "Location", "bestoutside");

s = skewness(X,0);                 

% Find largest absolute skewness
[~, idxAbsMax] = max(abs(s));
varAbsMax = names{idxAbsMax};
skewAbsMax = s(idxAbsMax);

[skewPosMax, idxPosMax] = max(s);
[skewNegMin, idxNegMin] = min(s);
varPosMax = names{idxPosMax};
varNegMax = names{idxNegMin};

disp(table(names', s', 'VariableNames', {'Variable','Skewness'}));
fprintf('Largest absolute skewness: %s (skewness = %.4g)\n', varAbsMax, skewAbsMax);
fprintf('Largest positive skewness: %s (skewness = %.4g)\n', varPosMax, skewPosMax);
fprintf('Largest negative skewness: %s (skewness = %.4g)\n', varNegMax, skewNegMin);


load citiesItaly.mat   

want = {'addedval','depos'};
vars = citiesItaly.Properties.VariableNames;
if all(ismember(want,vars))
    sel = want;
else
    PUL = varfun(@isnumeric, citiesItaly, 'OutputFormat','uniform');
    numVars = citiesItaly.Properties.VariableNames(PUL);
    if numel(numVars) < 2
        error('Need at least two numeric variables in the table.');
    end
    sel = numVars(1:2);
end

x = table2array(citiesItaly(:,sel(1)));
y = table2array(citiesItaly(:,sel(2)));
XY = [x(:) y(:)];

if size(XY,2) ~= 2
    error('XY must be n-by-2.');
end
if size(XY,1) < 2 || all(var(XY)==0)
    error('Need at least two nonidentical observations.');
end

% Scatter
figure; hold on; axis equal;
scatter(XY(:,1), XY(:,2), 30, [0 0.4470 0.7410], 'filled');

mu = mean(XY,1);
S = cov(XY);

if ~isequal(size(S),[2 2])
    error('Covariance matrix is not 2-by-2. Check input data.');
end

k = chi2inv(0.99,2);

[V,D] = eig(S);

% Semi-axis lengths 
a = sqrt(k * D(1,1));
b = sqrt(k * D(2,2));

% Ellipse in eigen-coordinates and transform back
t = linspace(0,2*pi,300);
ellipse_eig = [a*cos(t); b*sin(t)];
ellipse = (V * ellipse_eig)' + mu;

% Plot ellipse and principal axes
plot(ellipse(:,1), ellipse(:,2), 'r-', 'LineWidth',1.5);
for i = 1:2
    vec = V(:,i) * sqrt(k * D(i,i));
    plot([mu(1)-vec(1), mu(1)+vec(1)], [mu(2)-vec(2), mu(2)+vec(2)], 'k--', 'LineWidth',1.2);
end

xlabel(sel{1}); ylabel(sel{2});
title(sprintf('Scatter of %s vs %s with 99%% Confidence Ellipse', sel{1}, sel{2}));
legend('Data','99% ellipse','Principal axes','Location','best');
grid on; hold off;


load citiesItaly.mat

% Select first two numeric variables
PUL = varfun(@isnumeric, citiesItaly, 'OutputFormat','uniform');
numVars = citiesItaly.Properties.VariableNames(PUL);
if numel(numVars) < 2
    error('Need at least two numeric variables in the table.');
end
x = table2array(citiesItaly(:,numVars{1}));
y = table2array(citiesItaly(:,numVars{2}));

figure('Name','Scatter with Bivariate (marginal) Boxplots','NumberTitle','off');

% Main scatter axes
mainPos = [0.15 0.15 0.65 0.65];
axMain = axes('Position',mainPos);
scatter(axMain, x, y, 30, [0 0.4470 0.7410], 'filled');
axis(axMain,'equal');
xlabel(axMain, numVars{1}); ylabel(axMain, numVars{2});
grid(axMain,'on');

% Top boxplot for X
topPos = [mainPos(1) mainPos(2)+mainPos(4)+0.02 mainPos(3) 0.12];
axTop = axes('Position',topPos);
boxplot(axTop, x, 'Orientation','horizontal','Labels',{''}, 'Colors','k');
set(axTop,'XAxisLocation','top','XTick',[],'YTick',[]);
xlim(axTop, xlim(axMain));

% Right boxplot for Y 
rightPos = [mainPos(1)+mainPos(3)+0.02 mainPos(2) 0.12 mainPos(4)];
axRight = axes('Position',rightPos);
boxplot(axRight, y, 'Orientation','vertical','Labels',{''}, 'Colors','k');
set(axRight,'YTick',[],'XTick',[]);
ylim(axRight, ylim(axMain));

% Link limits so they stay consistent when zooming/panning
linkaxes([axMain axTop], 'x');
linkaxes([axMain axRight], 'y');

box(axTop,'off'); box(axRight,'off');


load citiesItaly.mat   

% Pick first two numeric vars
PUL = varfun(@isnumeric, citiesItaly, 'OutputFormat','uniform');
numVars = citiesItaly.Properties.VariableNames(PUL);
if numel(numVars) < 2
    error('Need at least two numeric variables.');
end
X = table2array(citiesItaly(:, numVars(1:2)));

[robCov,robMean] = robustcov(X,'Method','fmcd');

md2 = sum(((X - robMean) / robCov) .* (X - robMean), 2);  

cut = chi2inv(0.99,2);

outIdx = find(md2 > cut);

if ~isempty(citiesItaly.Properties.RowNames)
    outNames = citiesItaly.Properties.RowNames(outIdx);
    disp('Rows outside robust bivariate boxplot (row names):');
    disp(outNames);
else
    disp('Rows outside robust bivariate boxplot (row indices):');
    disp(outIdx);
end
Dominant language
MATLAB
Stars
30
Forks
1
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from UniprJRC/DSwithMATLAB

All issues in UniprJRC/DSwithMATLAB

Similar issues

More MATLAB issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.