Introduction to Mathematica for Statisticians

[Pages:28]Introduction to Mathematica, for Statisticians

Contents:

Ken's introductory slides (6 pages) Accompanying notebook file (3 pages)

Fotios's notebook file, with more detailed examples (3 pages)

Becky's notes on her example (3 pages) and accompanying graph (1 page)

Ken's example (5 pages)

...and some bonus material!

Richard's slides (4 pages) and notebook file (2 pages) for his unseen example

Mathematica information sharing session

11th November 2003 Ken + Becky, Fotios, Richard

`How to' Mathematica

? What does Mathematica do?

? symbolic maths manipulation (algebra) ? highly accurate numerical work ? fancy graphics

? What doesn't it do?

? statistical `tools'; residuals, R2, anova ? nice data manipulation ? nice data input/output

1/5

Syntax

? Use to evaluate expressions

? Generally as close as possible to `real' maths

? Objects/functions work similarly to R/S ? Functions have sensible names ? Everything stored in `notebook' files

(.nb); input, output, annotation, pictures

2/5

Syntactical details

? Functions start with capital letters, use [ ] for function arguments

? Use = for assignment ? NewFunction[x_] := ? ` Evaluate at'; expression /. x->x0

? Use { } for lists/vectors/matrices

? == represents equality (like R/S) ? Use ( ) intuitively, stops confusion

Abs[-22] N[Sqrt[2]] y = 10 MyFunc[x_]:= x^2 MyFunc[10] MyFunc[y]/.y->10 Plot[y,{y,0,10}] ylist={0,2,25} Solve[x^2==4,x] z^2/.z->10+5

3/5

A real example

? CHI problem:

hospitals' death

rates Yi follow

Y i

~

N (?i , i 2 )

?i

~

(1

-

)

N

(

?0

,

2 0

)

+ F

Zi

? Three unknown parameters, plus have to make a good guess for F

?0 , 0

F

?iZ=1

?iZ=0

?i i

Yi

4/5

Other useful things

? Good tutorial + help system (master index) ? Add-ons for extra functionality - MathStatica ? Batch mode for e.g. simulations ? Abort: ? Numerical iteration methods not perfect ?

just like other packages ? Not foolproof (integration) ? Limited number of licenses!

5/5

Examples of Mathematica syntax

Use to evaluate expressions; 11 2

2 ^ 50 2 ^ 50 1125899906842624

1 1125899906842624 Functions start with capital letters, and generally have sensible names; Abs 22 22

Many functions have default settings, usually ignored, as in R N Sqrt 2 N Sqrt 2 , 40 1.41421 1.414213562373095048801688724209698078570

Assign values using = A semi-colonafterwards stops output

y 10 10

y 10; y^2 N Sqrt y 100 3.16228

Defining new functions, and evaluating expressions at particular values MyFunc x_ : x ^ 2 MyFunc 10 100

MyFunc y 100

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download