Statistical Analysis - PowerPoint PPT Presentation

About This Presentation
Title:

Statistical Analysis

Description:

Simplest data structure is the numeric vector: Type at the command line: ... log, exp, sin, cos, tan, sqrt,... max, min, range. length, sum, prod ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 15
Provided by: fenBilk
Category:

less

Transcript and Presenter's Notes

Title: Statistical Analysis


1
Statistical Analysis
  • Programming in R

2
Vectors and assignment
  • Simplest data structure is the numeric vector
  • Type at the command line
  • gt xlt-c(10.4, 5.6, 3.1, 6.4, 21.7)
  • Type x at the command line to see the result
  • gt x
  • 1 10.4 5.6 3.1 6.4 21.7
  • gt

3
c() is a function
  • Function c() takes an arbitrary number of vector
    arguments and concatenates them.
  • gt ylt-c(x, 0, x)
  • gt y
  • 1 10.4 5.6 3.1 6.4 21.7 0.0 10.4 5.6 3.1
    6.4 21.7

4
Vector arithmetic
  • ,x,,/,
  • log, exp, sin, cos, tan, sqrt,
  • max, min, range
  • length, sum, prod

5
Calculate mean in R mean and variation
  • gt mean(x)
  • 1 9.44
  • gt
  • gt var(x)
  • 1 53.853
  • gt

6
Calculate mean in R mean and variation
  • mean(x) can be written as
  • gt sum(x)/length(x)
  • 1 9.44
  • var(x) can be written as
  • gt sum((x-mean(x))2)/(length(x)-1)
  • 1 53.853

7
Two sample t-statistic
  • twosam function(y1,y2)
  • n1length(y1) n2 length(y2)
  • yb1mean(y1) yb2mean(y2)
  • s1var(y1) s2var(y2)
  • s((n1-1)s1 (n2-1)s2)/(n1n2-2)
  • tst(yb1-yb2)/sqrt(s2(1/n11/n2))
  • tst

Copy and paste the above statements onto the
command line in R
8
Should look like this
gt twosam lt- function(y1,y2) n1lt-length(y1)
n2 lt-length(y2) yb1mean(y1) yb2mean(y2)
s1var(y1) s2var(y2) s((n1-1)s1
(n2-1)s2)/(n1n2-2) tst(yb1-yb2)/sqrt(s2(1/n1
1/n2)) tst
9
Test your function by calling it
  • gt tstattwosam(x,x1)
  • gt tstat
  • 1 -0.2154592
  • gt

10
Generating regular sequences
  • 130 is the same with c(1,2,3,,29,30)
  • operator has the highest priority within an
    expression. For example
  • gt 215
  • 1 2 4 6 8 10

11
factors
  • gt codonsc("GCA","GCC","GCG","GCU","UGC","UGU")
  • gt codons
  • 1 "GCA" "GCC" "GCG" "GCU" "UGC" "UGU"
  • gt aminoacidsc("Ala","Ala","Ala","Ala","Cys","Cys"
    )
  • gt aminoacids
  • 1 "Ala" "Ala" "Ala" "Ala" "Cys" "Cys"
  • gt aaffactor(aminoacids)
  • gt aaf
  • 1 Ala Ala Ala Ala Cys Cys
  • Levels Ala Cys
  • gt iitapply(codons,aaf,print)
  • 1 "GCA" "GCC" "GCG" "GCU"
  • 1 "UGC" "UGU"
  • gt

12
arrays
  • gt xarray(120,dimc(4,5))
  • gt x
  • ,1 ,2 ,3 ,4 ,5
  • 1, 1 5 9 13 17
  • 2, 2 6 10 14 18
  • 3, 3 7 11 15 19
  • 4, 4 8 12 16 20

13
arrays
  • gt xarray(0,dimc(4,5))
  • gt x
  • ,1 ,2 ,3 ,4 ,5
  • 1, 0 0 0 0 0
  • 2, 0 0 0 0 0
  • 3, 0 0 0 0 0
  • 4, 0 0 0 0 0
  • gt

14
Indexing arrays
  • gt iarray(c(13,31),dimc(3,2))
  • gt i
  • ,1 ,2
  • 1, 1 3
  • 2, 2 2
  • 3, 3 1
  • gt xarray(120,dimc(4,5))
  • gt x
  • ,1 ,2 ,3 ,4 ,5
  • 1, 1 5 9 13 17
  • 2, 2 6 10 14 18
  • 3, 3 7 11 15 19
  • 4, 4 8 12 16 20
  • gt xi
  • 1 9 6 3
  • gt xi0
  • gt x
  • ,1 ,2 ,3 ,4 ,5
  • 1, 1 5 0 13 17
Write a Comment
User Comments (0)
About PowerShow.com