Statistics 3 F71SC3
Contact Times (Summer Term 2008) Monday, , Lecture in LT1 Tuesday, , Maple Practical, in SR G12/13 Thursday, – 1.15 and , Data Analysis Practical, in SR G12/13 Friday, , Lecture in LT1 There are three practical groups. All students should, therefore, attend 2 lectures and 2 one hour practicals each week. AMS: Group on Tues and 3.15 on Thurs Group on Tues and 2.15 on Thurs
The web pages for this module on statistical computing and computer algebra are at and
Assessment
Two projects for John Phillips on Data Analysis. These will be given out in lectures and students work at them on their own. Three class tests, given in Tuesday labs, on Anatoly Konechny’s Maple work. No Exam!
Statistical Computing Using R
Using a statistical package is essential when you are faced with analysing a large data set. It would take a long time to do the calculations and diagrams by hand. There are many packages that can be used, such as MINITAB and Microsoft Excel, but the one covered in this course is called R.
Example : A survey produced the following 200 results of individuals salaries :
Graphical Representation Histogram Stem-and-Leaf Boxplot Frequency Polygon
>hist(salaries)
Remember, histograms are formed by taking class intervals, for example: Salary(£)Frequency under under under under under under
>hist(salaries, nclass=5)
> stem(salaries) The decimal point is 3 digit(s) to the right of the | 14 | 5 15 | 16 | | | | | | | | | | 48
>boxplot(salaries)
Summary Statistics
> mean(salaries)
> mean(salaries) [1]
> mean(salaries) [1] > median(salaries)
> mean(salaries) [1] > median(salaries) [1] 20020
> mean(salaries) [1] > median(salaries) [1] > sd(salaries)
> mean(salaries) [1] > median(salaries) [1] > sd(salaries) [1]
Scatter Diagrams
x y
>plot(x,y)
>plot(y~x,pch=4)
> plot(x,y) > abline(lm(y~x))
Pie Chart Example
> television=scan( ) 1: : Read 26 items
> television=scan( ) 1: : Read 26 items > barplot(table(television))
> television.counts=table(television) > names(television.counts)=c("BBC1","BBC2", "ITV1","CH4","Other") >pie(television.counts,col=c("purple","green2", "cyan","yellow","white"))
Installing R PC Caledonia
Simply double click on the “Installer” then select the “R” icon. This will produce a short-cut to R which should be available every time you log on.
Installing R On your own pc
Download free from the Comprehensive R Archive Network
R screen
Type Command here…appears in red
R screen Arrow keys on keyboard are very useful. Pressingrepeatedly allows you to retrieve previous commands entered.
Many keys and function names are very much as you would expect. > 6+4 [1] 10 > 18*3 [1] 54 > log(100) [1] > pi [1] > sin(pi) [1] e-16
Many keys and function names are very much as you would expect. > cos(pi) [1] -1 > x=7 > y=10 > x+y [1] 17 > sqrt(x*x+7*x*y-2*y*y) [1] >
Binomial Distribution It takes ages to calculate a series of probabilities
If n= 5, a=0.2 and x runs from 0 to 5 5! p(0)= ! 5! P(0) =
If n= 5, a=0.2 and x runs from 0 to 5 5! p(1)= ! 4! P(1) =
If n= 5, a=0.2 and x runs from 0 to 5 5! p(2)= ! 3! P(2) =
If n= 5, a=0.2 and x runs from 0 to 5 5! p(2)= ! 3! P(2) = …………and so on
Using R > dbinom(0:5,5,0.2) [1]
Using R > dbinom(0:5,5,0.2) [1] > pf=dbinom(0:5,5,0.2) > pf [1] >
Using R > pf [1] > barplot(pf) >