# i want this code to be converted to python and r language please please convert it b 5189491

I want this code to be converted to Python and R language. Please please convert it by yourself and not by any online software or converter. Please help me I am really worried for this.

flag = 1;
for j = 1:2;
if flag == 1
i = 0;
else
Y = Y(:,1:8)
i = 5;
end

D = (Y(2:end,:)- Y(1:end-1,:));
DM = D – ones(length(D),1)*mean(D);
n = (length(D)-1);
X = DM&#39;*DM/n;
cov(D);

if j == 2
D = Y(2:end,:);
DM = D – ones(length(D),1)*mean(D);
X = DM&#39;*DM/n
end

[FL,EVI] = eig(X)
X*FL(:,1)
EVI(1,1)*FL(:,1)

FL*EVI*FL&#39;
X

EV = diag(EVI)
EV = EV(end:-1:1)
FL = FL(:,end:-1:1)
diag(FL&#39;*FL)
figure(i+1)
subplot(2,1,j)
EXP = EV/sum(EV)*100
bar(EXP)
if j ==2
title(&#39;Variance Explained (Levels)&#39;)
else
title(&#39;Variance Explained (First Differences)&#39;)
end
sum(diag(X))
figure(i+2)
subplot(2,1,j)
plot(FL(:,1:3))
if j == 2
else
end
legend(&#39;PC1: level&#39;,&#39;PC2: slope&#39;,&#39;PC3:curvature&#39;,&#39;Location&#39;,&#39;SouthEast&#39;)
figure(i+3)
hold on
h = subplot(4,2,j)
bar(FL(:,1))
title(h,&#39;PC1&#39;)
h = subplot(4,2,j+2)
bar(FL(:,2))
title(h,&#39;PC2&#39;)
h=subplot(4,2,j+4)
bar(FL(:,3))
title(h,&#39;PC3&#39;)
h=subplot(4,2,j+6)
bar(h,FL(:,4))
title(&#39;PC4&#39;)
hold off
figure(i+4)
subplot(2,1,j)
PC = DM*FL
PC(1,:).*FL(:,1)&#39;
PC&#39;*PC/n
diag(PC&#39;*PC/n)
EV
mean(PC)
plot(PC(:,1:3))
if j == 1
title(&#39;Principal Components on First Differences&#39;)
else
title(&#39;Principal Components on Levels&#39;)
end
axis tight
legend(&#39;PC1: level&#39;,&#39;PC2: slope&#39;,&#39;PC3:curvature&#39;,&#39;Location&#39;,&#39;SouthEast&#39;)
figure(i+5)
subplot(2,1,j)
hold on
if j ==2
title(&#39;Levels overlayed with the 1st PC (rescaled)&#39;)
else
title(&#39;First differences overlayed with the 1st PC (rescaled)&#39;)
end
plot(DM)
h = plot(DM*FL(:,1)/sum(FL(:,1)),&#39;m–&#39;,&#39;linewidth&#39;,2)
legend(h,&#39;PC1: level&#39;,&#39;Location&#39;,&#39;NorthEast&#39;)
axis tight
hold off
corr(PC)
D2 = PC*FL&#39;
sum(sum(DM- D2))

end

figure(10+j)

hold on
h = plot(Y(2:end,:))

legend(h,&#39;Raw Data &#39;,&#39;Location&#39;,&#39;NorthEast&#39;)
axis tight
hold off