# Question:How to program Multivariate statistics with MapleTA?

## Question:How to program Multivariate statistics with MapleTA?

My questions about Multivariate Statistics are all programmed the hard way. When using R in the classroom, which has all the commands available this looks a little awkward. Thing is that every command should give a specific answer which can be related to a question box.

A little help would be nice. I am more than happy to share questions

\$e=maple("Vector([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1])");
\$n=maple("evalf(Statistics[Count](\$e))");
\$k=2;
:// data input;
:// dependent variable Y;
\$Y=maple("[11.259,11.238,11.492,11.479,11.016,11.241,10.949,10.690,10.964,10.733,10.493,10.684,10.459,10.595,10.953,10.838,10.545,10.806,10.455,10.299,10.608,10.605,10.536,10.492]");
\$vY=maple("Vector([\$Y])");
\$nY=maple("evalf(Statistics[Count](\$Y))");
\$muY=maple("evalf(Statistics[Mean](\$Y))");
:// independent variable X1;
\$X1=maple("[7.5,7.5,6.5,7,8,7.5,7.5,8,8.5,8,8,8.5,8,8,8,8,8,8,8.5,8.5,8.5,8,8,8]");
\$vX1=maple("Vector([\$X1])");
\$nX1=maple("evalf(Statistics[Count](\$X1))");
\$muX1=maple("evalf(Statistics[Mean](\$X1))");
:// independent variable X2;
\$X2=maple("[22,22,20,22.5,21.5,22,21.5,21,21.5,21,20.35,21,20.35,20.75,21.5,21.35,20.75,21.1,20.35,20,20.75,20.75,20.75,20.35]");
\$vX2=maple("Vector([\$X2])");
\$nX2=maple("evalf(Statistics[Count](\$X2))");
\$muX2=maple("evalf(Statistics[Mean](\$X2))");
\$stdvX2=maple("evalf(Statistics[StandardDeviation](\$X2))");
:// independent variable X3;
\$X3=maple("[8.01,9.1,8.39,8.37,8.73,9.11,7.52,7.17,7.54,7.24,6.79,7.09,3.6,6.95,7.52,7.34,5.82,7.29,5.68,5.45,6.97,8.03,5.8,4.69]");
\$vX3=maple("Vector([\$X3])");
\$nX3=maple("evalf(Statistics[Count](\$X3))");
\$muX3=maple("evalf(Statistics[Mean](\$X3))");
\$stdvX3=maple("evalf(Statistics[StandardDeviation](\$X3))");
\$X3s=maple("\$vX3.\$vX3");
:// small variables based on deviation around average value;
\$y=maple("\$vY-\$muY*\$e");
\$x1=maple("\$vX1-\$muX1*\$e");
\$x2=maple("\$vX2-\$muX2*\$e");
\$x3=maple("\$vX2-\$muX2*\$e");
:// summation of deviation values;
\$sumysq=maple("\$y.\$y");
\$sumx1sq=maple("\$x1.\$x1");
\$sumx2sq=maple("\$x2.\$x2");
\$sumx3sq=maple("\$x3.\$x3");
\$sumyx1=maple("\$y.\$x1");
\$sumyx2=maple("\$y.\$x2");
\$sumyx3=maple("\$y.\$x3");
\$sumx1x2=maple("\$x1.\$x2");
\$sumx1x3=maple("\$x1.\$x3");
\$sumx2x3=maple("\$x2.\$x3");
:// calculation of the coefficients;
:// coefficient betha1;
\$b1=maple("((\$sumyx1)*(\$sumx2sq)-(\$sumyx2)*(\$sumx1x2))/((\$sumx1sq)*(\$sumx2sq)-(\$sumx1x2)^2)");
\$b2=maple("((\$sumyx2)*(\$sumx1sq)-(\$sumyx1)*(\$sumx1x2))/((\$sumx1sq)*(\$sumx2sq)-(\$sumx1x2)^2)");
\$a=maple("(\$muY)-(\$b1)*(\$muX1)-(\$b2)*(\$muX2)");
:// calculate estimate based on given values;
\$valuex1=range(8,8,1/10);
\$valuex2=range(21,21,1/10);
\$yhatvalue=\$a+(\$b1)*\$valuex1+(\$b2)*\$valuex2;
:// standard deviations;
\$stdvy=maple("evalf(Statistics[StandardDeviation](\$y))");
\$stdvx1=maple("evalf(Statistics[StandardDeviation](\$x1))");
\$stdvx2=maple("evalf(Statistics[StandardDeviation](\$x2))");
\$stdvx3=maple("evalf(Statistics[StandardDeviation](\$x3))");
:// correlation coefficients;
\$ryx1=maple("(\$sumyx1)/(\$n*\$stdvy*\$stdvx1)");
\$ryx2=maple("(\$sumyx2)/(\$n*\$stdvy*\$stdvx2)");
\$ryx3=maple("(\$sumyx3)/(\$n*\$stdvy*\$stdvx3)");
\$rx1x2=maple("(\$sumx1x2)/(\$n*\$stdvx1*\$stdvx2)");
\$rx1x3=maple("(\$sumx1x3)/(\$n*\$stdvx1*\$stdvx3)");
\$rx2x3=maple("(\$sumx2x3)/(\$n*\$stdvx2*\$stdvx3)");
:// estimated values;
\$Yhat=maple("(\$a)*\$e+(\$b1)*\$vX1+(\$b2)*\$vX2");
\$error=maple("\$vY-\$Yhat");
\$sumerror=maple("\$error.\$e");
\$sumerrorsq=maple("\$error.\$error");
:// \$errortr=maple("LinearAlgebra[Transpose](\$error)");
:// \$sumerrorsq=maple("LinearAlgebra[MatrixMatrixMultiply](\$errortr,\$error)");
\$errorstdv=maple("sqrt(\$sumerrorsq/(\$n-2-1))");
:// standard error of the coefficients;
\$errorb1=maple("\$errorstdv/sqrt(((\$sumx1sq*\$sumx2sq)-((\$sumx1x2)^2))/(\$sumx2sq))");
\$errorb2=maple("\$errorstdv/sqrt(((\$sumx1sq*\$sumx2sq)-((\$sumx1x2)^2))/(\$sumx1sq))");
:// R-squared;
\$Rsq=maple("1-\$sumerrorsq/\$sumysq");
\$Rasq=maple("1-(\$sumerrorsq/(\$n-\$k-1))/(\$sumysq/(\$n-1))");
:// hypothesis: does variable X[i] influence Y? H[0]: it does not so b=0;
\$tb1=maple("\$b1/\$errorb1");
\$tb2=maple("\$b2/\$errorb2");
\$Tdf=\$n-\$k-1;
\$alpha=range(0.05,0.05,1/100);
\$T=maple("Statistics[Quantile](StudentT(\$Tdf),(1-\$alpha/2))");
\$ptb1=maple("Statistics[CDF](StudentT(\$Tdf),\$tb1)");
\$ptb2=maple("1-Statistics[CDF](StudentT(\$Tdf),\$tb2)");

﻿