(************** Content-type: application/mathematica ************** Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 10795, 305]*) (*NotebookOutlinePosition[ 11493, 329]*) (* CellTagsIndexPosition[ 11449, 325]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["T-Distributions and the Standard Normal Distribution", "Title", TextAlignment->Center, Background->RGBColor[0, 1, 1]], Cell["\<\ This notebook is by Steven Amgott. Please send any questions or comments to \ samgott1@swarthmore.edu. Feel free to use and distribute this notebook, but \ keep this author information in any copy you use or distribute.\ \>", "SmallText"], Cell[TextData[{ "In general, anything in ", StyleBox["magenta", FontColor->RGBColor[1, 0, 1]], " is something you can, and possibly should, change." }], "Text"], Cell[CellGroupData[{ Cell["\<\ Initialization (can be skipped, if you answer \"Yes\" to the initialization \ prompt)\ \>", "Section"], Cell["The cell below loads the packages needed for this notebook.", "Text"], Cell[BoxData[{ \(Needs["\"]\), "\n", \(Needs["\"]\)}], "Input", InitializationCell->True], Cell[TextData[{ "If you need to see if the packages loaded, evaluate the cell below. The \ output should include ", StyleBox["Graphics`Animation`", FontColor->RGBColor[0, 0, 1]], " and ", StyleBox["Statistics`NormalDistribution`", FontColor->RGBColor[0, 0, 1]], ", among others." }], "Text"], Cell[BoxData[ \($Packages\)], "Input"], Cell[CellGroupData[{ Cell["Eliminating some unnecessary warning messages", "Subsection"], Cell[BoxData[{ \(\(Off[General::"\"];\)\), "\n", \(\(Off[General::"\"];\)\)}], "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell["The distribution and graphing functions", "Subsection"], Cell["\<\ The next cell defines the pdfs and cdfs of the distributions.\ \>", "Text"], Cell[BoxData[{ \(Clear[pdfN, cdfN, pdfT, cdfT, x, r]\), "\[IndentingNewLine]", \(\(pdfN[x_] := PDF[NormalDistribution[0, 1], x];\)\), "\[IndentingNewLine]", \(\(cdfN[x_] := CDF[NormalDistribution[0, 1], x];\)\), "\[IndentingNewLine]", \(\(pdfT[x_, r_] := PDF[StudentTDistribution[r], x];\)\), "\[IndentingNewLine]", \(\(cdfT[x_, r_] := CDF[StudentTDistribution[r], x];\)\)}], "Input", InitializationCell->True], Cell["The next cell defines the plotting functions.", "Text"], Cell[BoxData[{\(Clear[tPlot, nPlot]\), "\[IndentingNewLine]", RowBox[{ RowBox[{\(tPlot[{x_, a_, b_}, r_]\), ":=", RowBox[{"Plot", "[", RowBox[{\(pdfT[x, r]\), ",", \({x, a, b}\), ",", \(PlotStyle \[Rule] RGBColor[0, 0, 1]\), ",", \(DisplayFunction \[Rule] Identity\), ",", RowBox[{"PlotLabel", "\[Rule]", RowBox[{"\"\<\!\(\* StyleBox[\"t\",\nFontColor->RGBColor[0, 0, 1]]\)\!\(\* StyleBox[\"-\",\nFontColor->RGBColor[0, 0, 1]]\)\!\(\* StyleBox[\"distribution\",\nFontColor->RGBColor[0, 0, 1]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[0, 0, 1]]\)\!\(\* StyleBox[\"with\",\nFontColor->RGBColor[0, 0, 1]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[0, 0, 1]]\)\>\"", StyleBox[ RowBox[{"<", StyleBox[">", FontColor->GrayLevel[0]]}]], \(ToString[r]\), StyleBox[ RowBox[{ StyleBox["<", FontColor->GrayLevel[0]], ">"}]], "\"\<\!\(\* StyleBox[\" \",\nFontColor->RGBColor[0, 0, 1]]\)\!\(\* StyleBox[\"degrees\",\nFontColor->RGBColor[0, 0, 1]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[0, 0, 1]]\)\!\(\* StyleBox[\"of\",\nFontColor->RGBColor[0, 0, 1]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[0, 0, 1]]\)\!\(\* StyleBox[\"freedom\",\nFontColor->RGBColor[0, 0, 1]]\)\!\(\* StyleBox[\".\",\nFontColor->RGBColor[0, 0, 1]]\)\>\""}]}], ",", RowBox[{"TextStyle", "\[Rule]", RowBox[{"{", RowBox[{\(FontWeight \[Rule] "\"\), ",", RowBox[{"FontSize", "\[Rule]", StyleBox["14", FontColor->RGBColor[1, 0, 1]]}]}], "}"}]}]}], "]"}]}], ";"}], "\[IndentingNewLine]", \(nPlot[{x_, a_, b_}] := Plot[pdfN[x], {x, a, b}, PlotStyle \[Rule] RGBColor[1, 0, 0], DisplayFunction \[Rule] Identity];\)}], "Input", InitializationCell->True] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Tails of the distributions", "Section"], Cell[TextData[{ "The cell below graphs the pdf of the t-distribution with ", StyleBox["degFreedom", FontColor->RGBColor[1, 0, 1]], " degrees of freedom (curve in ", StyleBox["blue", FontColor->RGBColor[0, 0, 1]], ") on the same axes as the graph of the pdf of the standard normal \ distribution (curve in ", StyleBox["red", FontColor->RGBColor[1, 0, 0]], "). The graphs run from ", StyleBox["xmin", FontColor->RGBColor[1, 0, 1]], " to ", StyleBox["xmax", FontColor->RGBColor[1, 0, 1]], ". The area between the graphs is calculated and shown below the graphs, \ provided the graphs do not cross on the interval. You may adjust the size of \ the output graphics by changing the value of ", StyleBox["ImageSize", FontColor->RGBColor[1, 0, 0]], " (which initially is ", StyleBox["500", FontColor->RGBColor[1, 0, 1]], "), or by clicking on the graph and dragging the edges of the graph to the \ desired size.." }], "Text"], Cell[BoxData[{ RowBox[{ RowBox[{"xmin", "=", StyleBox["3", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xmax", "=", StyleBox["7", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"degFreedom", "=", StyleBox["5", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Show", "[", RowBox[{\(tPlot[{x, xmin, xmax}, degFreedom]\), ",", \(nPlot[{x, xmin, xmax}]\), ",", \(PlotRange \[Rule] All\), ",", \(DisplayFunction \[Rule] $DisplayFunction\), ",", RowBox[{"ImageSize", "\[Rule]", StyleBox["500", FontColor->RGBColor[1, 0, 1]]}]}], "]"}], ";"}], "\[IndentingNewLine]", \(Print["\", xmin, "\< onward is \>", N[1 - cdfT[xmin, degFreedom]], "\<.\>"]\), "\[IndentingNewLine]", \(Print["\", xmin, "\< onward is \>", N[1 - cdfN[ xmin]], "\<.\>"]\), "\[IndentingNewLine]", \(Print["\", N[\(-cdfT[xmin, degFreedom]\) + cdfN[xmin]], "\<.\>"]\)}], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Animating the convergence of t-distributions to the standard normal \ distribution\ \>", "Section"], Cell[TextData[{ "The cell below animates the convergence of the t-distribution to the \ standard normal distribution as the degrees of freedom of the t-distribution \ increases. The graphs run from ", StyleBox["xmin", FontColor->RGBColor[1, 0, 1]], " to ", StyleBox["xmax", FontColor->RGBColor[1, 0, 1]], ". The maximum number of degrees of freedom is ", StyleBox["maxDegFree", FontColor->RGBColor[1, 0, 1]], ", which is also the number of animation cells that are produced. You may \ adjust the size of the output graphics by changing the value of ", StyleBox["ImageSize", FontColor->RGBColor[1, 0, 0]], " (which initially is ", StyleBox["500", FontColor->RGBColor[1, 0, 1]], ")." }], "Text"], Cell[BoxData[{\(Clear[r, xmin, xmax, maxDegFree]\), "\[IndentingNewLine]", RowBox[{ RowBox[{"xmin", "=", StyleBox["3", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xmax", "=", StyleBox["7", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"maxDegFree", "=", StyleBox["50", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\[IndentingNewLine]", RowBox[{"Animate", "[", RowBox[{ RowBox[{"Show", "[", RowBox[{\(tPlot[{x, xmin, xmax}, r]\), ",", \(nPlot[{x, xmin, xmax}]\), ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{ "If", "[", \(\((xmin < 0 < xmax)\) \[Or] \((\((0 \[LessEqual] xmin)\) \[And] \((pdfN[xmin] > pdfT[xmin, 1])\))\) \[Or] \((\((xmax \[LessEqual] 0)\) \[And] \((pdfN[xmax] > pdfT[xmax, 1])\))\), All, If[0 < xmin, {0, pdfT[xmin, 1]}, If[xmax < 0, {0, pdfT[xmax, 1]}]]\), StyleBox["]", FontColor->GrayLevel[0]]}]}], ",", \(DisplayFunction \[Rule] $DisplayFunction\), ",", RowBox[{"ImageSize", "\[Rule]", StyleBox["500", FontColor->RGBColor[1, 0, 1]]}]}], "]"}], ",", \({r, 1, maxDegFree, 1}\)}], "]"}]}], "Input"] }, Closed]] }, Open ]] }, FrontEndVersion->"4.1 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 720}}, AutoGeneratedPackage->None, WindowToolbars->"EditBar", WindowSize->{721, 601}, WindowMargins->{{0, Automatic}, {Automatic, 0}} ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1727, 52, 127, 2, 186, "Title"], Cell[1857, 56, 250, 4, 44, "SmallText"], Cell[2110, 62, 170, 5, 33, "Text"], Cell[CellGroupData[{ Cell[2305, 71, 112, 3, 59, "Section"], Cell[2420, 76, 75, 0, 33, "Text"], Cell[2498, 78, 155, 3, 50, "Input", InitializationCell->True], Cell[2656, 83, 310, 9, 52, "Text"], Cell[2969, 94, 42, 1, 30, "Input"], Cell[CellGroupData[{ Cell[3036, 99, 67, 0, 47, "Subsection"], Cell[3106, 101, 141, 3, 50, "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell[3284, 109, 61, 0, 31, "Subsection"], Cell[3348, 111, 85, 2, 33, "Text"], Cell[3436, 115, 463, 9, 110, "Input", InitializationCell->True], Cell[3902, 126, 61, 0, 33, "Text"], Cell[3966, 128, 2010, 40, 150, "Input", InitializationCell->True] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[6025, 174, 45, 0, 39, "Section"], Cell[6073, 176, 978, 27, 109, "Text"], Cell[7054, 205, 1312, 30, 210, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[8403, 240, 109, 3, 39, "Section"], Cell[8515, 245, 738, 20, 90, "Text"], Cell[9256, 267, 1511, 34, 190, "Input"] }, Closed]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)