nhlbooij

10 Reputation

0 Badges

6 years, 206 days

MaplePrimes Activity


These are questions asked by nhlbooij

Dear reader,

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))");
$sumY=maple("add($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))");
$sumX1=maple("add($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))");
$sumX2=maple("add($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))");
$sumX3=maple("add($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");
:// adjusted R-squared;
$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)");
 

 

Our students use R for solving digital questions about Multivariate Statistics made with MapleTA.

How to use a MLE in MapleTA. Below the code I used in a question?

Remaks about how to program this better or more easy are more than welcome.

://noise. In Dutch ruis means noise;
$ruislow=range(1,5,1);
$ruishigh=range(6,9,1);
://data 1;
$x1=10+rand($ruislow,$ruishigh,1);
$x2=30+rand($ruislow,$ruishigh,1);
$x3=50+rand($ruislow,$ruishigh,1);
$x4=70+rand($ruislow,$ruishigh,1);
$x5=90+rand($ruislow,$ruishigh,1);
$x6=125+rand($ruislow,$ruishigh,1);
$x7=175+rand($ruislow,$ruishigh,1);
$X=maple("Vector([$x1,$x2,$x3,$x4,$x5,$x6,$x7])");
$displayX=maple("printf(MathML:-ExportPresentation($X))");
$TX=maple("LinearAlgebra[Transpose]($X)");
$displayTX=maple("printf(MathML:-ExportPresentation($TX))");
://data 2;
$y1=4+rand($ruislow,$ruishigh,1);
$y2=12+rand($ruislow,$ruishigh,1);
$y3=32+rand($ruislow,$ruishigh,1);
$y4=36+rand($ruislow,$ruishigh,1);
$y5=42+rand($ruislow,$ruishigh,1);
$y6=36+rand($ruislow,$ruishigh,1);
$y7=19+rand($ruislow,$ruishigh,1);
$Y=maple("Vector([$y1,$y2,$y3,$y4,$y5,$y6,$y7])");
$displayY=maple("printf(MathML:-ExportPresentation($Y))");
$TY=maple("LinearAlgebra[Transpose]($Y)");
$displayTY=maple("printf(MathML:-ExportPresentation($TY))");
://data 3;
$z1=76+rand($ruislow,$ruishigh,1);
$z2=108+rand($ruislow,$ruishigh,1);
$z3=128+rand($ruislow,$ruishigh,1);
$z4=54+rand($ruislow,$ruishigh,1);
$z5=18+rand($ruislow,$ruishigh,1);
$z6=4+rand($ruislow,$ruishigh,1);
$z7=1+rand($ruislow,$ruishigh,1);
$Z=maple("Vector([$z1,$z2,$z3,$z4,$z5,$z6,$z7])");
$displayZ=maple("printf(MathML:-ExportPresentation($Z))");
$TZ=maple("LinearAlgebra[Transpose]($Z)");
$displayTZ=maple("printf(MathML:-ExportPresentation($TZ))");
://totals;
$t1=$y1+$z1;
$t2=$y2+$z2;
$t3=$y3+$z3;
$t4=$y4+$z4;
$t5=$y5+$z5;
$t6=$y6+$z6;
$t7=$y7+$z7;
$T=maple("Vector([$t1,$t2,$t3,$t4,$t5,$t6,$t7])");
$displayT=maple("printf(MathML:-ExportPresentation($T))");
:// percentage Y;
$py1=$y1/$t1;
$py2=$y2/$t2;
$py3=$y3/$t3;
$py4=$y4/$t4;
$py5=$y5/$t5;
$py6=$y6/$t6;
$py7=$y7/$t7;
:// percentage Z;
$pz1=$z1/$t1;
$pz2=$z2/$t2;
$pz3=$z3/$t3;
$pz4=$z4/$t4;
$pz5=$z5/$t5;
$pz6=$z6/$t6;
$pz7=$z7/$t7;
://odds;
$o1=$py1/$pz1;
$o2=$py2/$pz2;
$o3=$py3/$pz3;
$o4=$py4/$pz4;
$o5=$py5/$pz5;
$o6=$py6/$pz6;
$o7=$py7/$pz7;
://logit;
$ln1=ln($o1);
$ln2=ln($o2);
$ln3=ln($o3);
$ln4=ln($o4);
$ln5=ln($o5);
$ln6=ln($o6);
$ln7=ln($o7);
$L=maple("Vector([$ln1,$ln2,$ln3,$ln4,$ln5,$ln6,$ln7])");
$displayL=maple("printf(MathML:-ExportPresentation($L))");
://linreg;
://$fit1=maple("Statistics[LinearFit]([1,t],$X,$L,t)");
$fit=maple("map(rhs, Statistics[Fit](a*x+b, $X, $L, x, output=parametervalues))");
$intercept=maple("$fit[2]");
$slope=maple("$fit[1]");
$r=maple("evalf(Statistics[Correlation]($X,$L))");

Best regards,

Nico

 

Page 1 of 1