BPS21018 SEC Practical
BPS21018 SEC Practical
[[2]]
[1] "length" "speed" "algae" "NO3" "BOD"
> dimnames(bird)
[[1]]
[1] "blackbird" "chaffinch" "great tit" "house sparrow"
"robin" "song thrush"
[[2]]
[1] "garden" "hedgerow" "parkland" "pasture" "woodland"
> names(mf)
[1] "length" "speed" "algae" "NO3" "BOD"
> names(mf) = c('len','sp','alg','no3','bod)
+ ')
> names(mf)
[1] "len" "sp" "alg" "no3" "bod)\n"
> species = c('Bbird','C.Finch','Gt.Tit','Sparrow','Robin','Thrush')
> habitats = c('Gdn','Hegde','Park','Field','Wood')
> dinames(bird) = list(species,habitats)
Error in dinames(bird) = list(species, habitats) :
could not find function "dinames<-"
> dimnames(bird) = list(species,habitats)
> bird
Gdn Hegde Park Field Wood
Bbird 47 10 40 2 2
C.Finch 19 3 5 0 2
Gt.Tit 50 0 10 7 0
Sparrow 46 16 8 4 0
Robin 9 3 0 0 2
Thrush 4 0 6 0 0
> bird.t = t(bird)
> bird.t
Bbird C.Finch Gt.Tit Sparrow Robin Thrush
Gdn 47 19 50 46 9 4
Hegde 10 3 0 16 3 0
Park 40 5 10 8 0 6
Field 2 0 7 4 0 0
Wood 2 2 0 0 2 0
> mow
[1] 11 22 33 44 55
> unmow
[1] 8 9 7 9 NA
> data1
[1] 6 7 6 4 8 3 5 7 5 3 2 6 8 5 6 9
> data2
[1] 3 5 7 5 3 2 6 8 5 6 9 4 5 7 3 4
> data4
[1] 23.0 17.0 12.5 11.0 18.0 12.0 14.5 9.0 11.0 9.0 12.5 14.5 17.0
8.0 21.0
> grass.list = list(mow,unmow,data1,data2,data4)
> grass.list
[[1]]
[1] 11 22 33 44 55
[[2]]
[1] 8 9 7 9 NA
[[3]]
[1] 6 7 6 4 8 3 5 7 5 3 2 6 8 5 6 9
[[4]]
[1] 3 5 7 5 3 2 6 8 5 6 9 4 5 7 3 4
[[5]]
[1] 23.0 17.0 12.5 11.0 18.0 12.0 14.5 9.0 11.0 9.0 12.5 14.5 17.0
8.0 21.0
$unmow
[1] 8 9 7 9 NA
$data1
[1] 6 7 6 4 8 3 5 7 5 3 2 6 8 5 6 9
$data2
[1] 3 5 7 5 3 2 6 8 5 6 9 4 5 7 3 4
$`data4\n\n`
[1] 23.0 17.0 12.5 11.0 18.0 12.0 14.5 9.0 11.0 9.0 12.5 14.5 17.0
8.0 21.0
+ > mat
[,1] [,2]
[1,] 5 7
[2,] 6 9
[3,] 9 13
[4,] 12 10
[5,] 8 NA
> cram
[1] "garden" "hedgerow" "parkland" "pasture" "woodland"
> cnam = c('sample1','sample2')
> rnam = c("site1','site2','site3','site4','site5')
$sp
[1] 12 14 12 16 20 21
$alg
[1] 40 45 45 16 20 21
$no3
[1] 2.25 2.14 1.33 1.66 1.78 2.45
$`bod)\n`
[1] 200 180 135 120 110 120
$qtr2
[1] "apr" "may" "jun"
$qtr3
[1] "jul" "aug" "sep"
$qtr4
[1] "oct" "nov" "dec"
hi
height 0 1
5 0 0
6 0 0
7 0 0
9 0 0
11 0 0
14 0 0
15 0 0
17 0 0
19 0 0
28 0 1
31 0 1
32 0 1
, , lo = 1, mid = 0
hi
height 0 1
5 1 0
6 0 0
7 1 0
9 1 0
11 1 0
14 0 0
15 0 0
17 0 0
19 0 0
28 0 0
31 0 0
32 0 0
, , lo = 2, mid = 0
hi
height 0 1
5 0 0
6 1 0
7 0 0
9 0 0
11 0 0
14 0 0
15 0 0
17 0 0
19 0 0
28 0 0
31 0 0
32 0 0
, , lo = 0, mid = 1
hi
height 0 1
5 0 0
6 0 0
7 0 0
9 0 0
11 0 0
14 0 0
15 1 0
17 0 0
19 1 0
28 0 0
31 0 0
32 0 0
, , lo = 1, mid = 1
hi
height 0 1
5 0 0
6 0 0
7 0 0
9 0 0
11 0 0
14 0 0
15 0 0
17 0 0
19 0 0
28 0 0
31 0 0
32 0 0
, , lo = 2, mid = 1
hi
height 0 1
5 0 0
6 0 0
7 0 0
9 0 0
11 0 0
14 0 0
15 0 0
17 0 0
19 0 0
28 0 0
31 0 0
32 0 0
, , lo = 0, mid = 2
hi
height 0 1
5 0 0
6 0 0
7 0 0
9 0 0
11 0 0
14 1 0
15 0 0
17 1 0
19 0 0
28 0 0
31 0 0
32 0 0
, , lo = 1, mid = 2
hi
height 0 1
5 0 0
6 0 0
7 0 0
9 0 0
11 0 0
14 0 0
15 0 0
17 0 0
19 0 0
28 0 0
31 0 0
32 0 0
, , lo = 2, mid = 2
hi
height 0 1
5 0 0
6 0 0
7 0 0
9 0 0
11 0 0
14 0 0
15 0 0
17 0 0
19 0 0
28 0 0
31 0 0
32 0 0
> str(pw)
'data.frame': 12 obs. of 4 variables:
$ height: num 5 6 7 9 11 14 15 17 19 28 ...
$ hi : num 0 0 0 0 0 0 0 0 0 1 ...
$ lo : num 1 2 1 1 1 0 0 0 0 0 ...
$ mid : num 0 0 0 0 0 2 1 2 1 0 ...
> mf
len sp alg no3 bod)\n
1 20 12 40 2.25 200
2 21 14 45 2.14 180
3 22 12 45 1.33 135
4 23 16 16 1.66 120
5 21 20 20 1.78 110
6 20 21 21 2.45 120
> as.table(as.matrix(mf))
len sp alg no3 bod)\n
A 20.00 12.00 40.00 2.25 200.00
B 21.00 14.00 45.00 2.14 180.00
C 22.00 12.00 45.00 1.33 135.00
D 23.00 16.00 16.00 1.66 120.00
E 21.00 20.00 20.00 1.78 110.00
F 20.00 21.00 21.00 2.45 120.00
> as.table(mf)
Error in as.table.default(mf) : cannot coerce to a table
> is.table(bird)
[1] FALSE
> height = c(9,11,6,14,17,19,28,31,32,7,6,5,14,17,15,44,38,37)
> plant = c('vulgaris','sativa')
> water = c('lo','mid','hi')
> pw = data.frame(height,plant,water)
> pw
height plant water
1 9 vulgaris lo
2 11 sativa mid
3 6 vulgaris hi
4 14 sativa lo
5 17 vulgaris mid
6 19 sativa hi
7 28 vulgaris lo
8 31 sativa mid
9 32 vulgaris hi
10 7 sativa lo
11 6 vulgaris mid
12 5 sativa hi
13 14 vulgaris lo
14 17 sativa mid
15 15 vulgaris hi
16 44 sativa lo
17 38 vulgaris mid
18 37 sativa hi
> with(pw, ftable(height,plant,water))
water hi lo mid
height plant
5 sativa 1 0 0
vulgaris 0 0 0
6 sativa 0 0 0
vulgaris 1 0 1
7 sativa 0 1 0
vulgaris 0 0 0
9 sativa 0 0 0
vulgaris 0 1 0
11 sativa 0 0 1
vulgaris 0 0 0
14 sativa 0 1 0
vulgaris 0 1 0
15 sativa 0 0 0
vulgaris 1 0 0
17 sativa 0 0 1
vulgaris 0 0 1
19 sativa 1 0 0
vulgaris 0 0 0
28 sativa 0 0 0
vulgaris 0 1 0
31 sativa 0 0 1
vulgaris 0 0 0
32 sativa 0 0 0
vulgaris 1 0 0
37 sativa 1 0 0
vulgaris 0 0 0
38 sativa 0 0 0
vulgaris 0 0 1
44 sativa 0 1 0
vulgaris 0 0 0
> with(pw, ftable(height,water,plant))
plant sativa vulgaris
height water
5 hi 1 0
lo 0 0
mid 0 0
6 hi 0 1
lo 0 0
mid 0 1
7 hi 0 0
lo 1 0
mid 0 0
9 hi 0 0
lo 0 1
mid 0 0
11 hi 0 0
lo 0 0
mid 1 0
14 hi 0 0
lo 1 1
mid 0 0
15 hi 0 1
lo 0 0
mid 0 0
17 hi 0 0
lo 0 0
mid 1 1
19 hi 1 0
lo 0 0
mid 0 0
28 hi 0 0
lo 0 1
mid 0 0
31 hi 0 0
lo 0 0
mid 1 0
32 hi 0 1
lo 0 0
mid 0 0
37 hi 1 0
lo 0 0
mid 0 0
38 hi 0 0
lo 0 0
mid 0 1
44 hi 0 0
lo 1 0
mid 0 0
> ftable(plant ~ height + water, data = pw)
plant sativa vulgaris
height water
5 hi 1 0
lo 0 0
mid 0 0
6 hi 0 1
lo 0 0
mid 0 1
7 hi 0 0
lo 1 0
mid 0 0
9 hi 0 0
lo 0 1
mid 0 0
11 hi 0 0
lo 0 0
mid 1 0
14 hi 0 0
lo 1 1
mid 0 0
15 hi 0 1
lo 0 0
mid 0 0
17 hi 0 0
lo 0 0
mid 1 1
19 hi 1 0
lo 0 0
mid 0 0
28 hi 0 0
lo 0 1
mid 0 0
31 hi 0 0
lo 0 0
mid 1 0
32 hi 0 1
lo 0 0
mid 0 0
37 hi 1 0
lo 0 0
mid 0 0
38 hi 0 0
lo 0 0
mid 0 1
44 hi 0 0
lo 1 0
mid 0 0
> ftable(water ~ height + plant,data = pw)
water hi lo mid
height plant
5 sativa 1 0 0
vulgaris 0 0 0
6 sativa 0 0 0
vulgaris 1 0 1
7 sativa 0 1 0
vulgaris 0 0 0
9 sativa 0 0 0
vulgaris 0 1 0
11 sativa 0 0 1
vulgaris 0 0 0
14 sativa 0 1 0
vulgaris 0 1 0
15 sativa 0 0 0
vulgaris 1 0 0
17 sativa 0 0 1
vulgaris 0 0 1
19 sativa 1 0 0
vulgaris 0 0 0
28 sativa 0 0 0
vulgaris 0 1 0
31 sativa 0 0 1
vulgaris 0 0 0
32 sativa 0 0 0
vulgaris 1 0 0
37 sativa 1 0 0
vulgaris 0 0 0
38 sativa 0 0 0
vulgaris 0 0 1
44 sativa 0 1 0
vulgaris 0 0 0
> ftable(height ~ water + plant, data = pw)
height 5 6 7 9 11 14 15 17 19 28 31 32 37 38 44
water plant
hi sativa 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0
vulgaris 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0
lo sativa 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1
vulgaris 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0
mid sativa 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0
vulgaris 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0
> with(pw, ftable(water, plant, height))
height 5 6 7 9 11 14 15 17 19 28 31 32 37 38 44
water plant
hi sativa 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0
vulgaris 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0
lo sativa 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1
vulgaris 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0
mid sativa 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0
vulgaris 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0
> gr.t = ftable(plant ~ height + water, data = pw)
> gr.t
plant sativa vulgaris
height water
5 hi 1 0
lo 0 0
mid 0 0
6 hi 0 1
lo 0 0
mid 0 1
7 hi 0 0
lo 1 0
mid 0 0
9 hi 0 0
lo 0 1
mid 0 0
11 hi 0 0
lo 0 0
mid 1 0
14 hi 0 0
lo 1 1
mid 0 0
15 hi 0 1
lo 0 0
mid 0 0
17 hi 0 0
lo 0 0
mid 1 1
19 hi 1 0
lo 0 0
mid 0 0
28 hi 0 0
lo 0 1
mid 0 0
31 hi 0 0
lo 0 0
mid 1 0
32 hi 0 1
lo 0 0
mid 0 0
37 hi 1 0
lo 0 0
mid 0 0
38 hi 0 0
lo 0 0
mid 0 1
44 hi 0 0
lo 1 0
mid 0 0
> gr.t[1:3,]
[,1] [,2]
[1,] 1 0
[2,] 0 0
[3,] 0 0
> gr.sub = gr.t[1:3,]
> gr.sub
[,1] [,2]
[1,] 1 0
[2,] 0 0
[3,] 0 0
> colnames(gr.sub) = c('sativa','vulgaris')
> rownames(gr.sub) = c('hi','lo','mid')
> gr.sub
sativa vulgaris
hi 1 0
lo 0 0
mid 0 0
> fr.sub = matrix(gr.t[1:3,],ncol = 2, dimnames =
list(c('hi','lo','mid'),c('sativa','vulgaris')
+ ))
> gr.sub
sativa vulgaris
hi 1 0
lo 0 0
mid 0 0
> fr.sub
sativa vulgaris
hi 1 0
lo 0 0
mid 0 0
> with(pw, ftable(height == 14, water, plant))
plant sativa vulgaris
water
FALSE hi 3 3
lo 2 2
mid 3 3
TRUE hi 0 0
lo 1 1
mid 0 0
> with(pw, ftable(height == 14, water == 'hi', plant))
plant sativa vulgaris
FALSE FALSE 5 5
TRUE 3 3
TRUE FALSE 1 1
TRUE 0 0
> pw.t = pw[which(pw$height == 14),]
> pw.t
height plant water
4 14 sativa lo
13 14 vulgaris lo
> with(pw.t, ftable(height, plant, water))
water lo
height plant
14 sativa 1
vulgaris 1
> if(class(gr.t) == 'ftable') TRUE else FALSE
[1] TRUE
> bird
Gdn Hegde Park Field Wood
Bbird 47 10 40 2 2
C.Finch 19 3 5 0 2
Gt.Tit 50 0 10 7 0
Sparrow 46 16 8 4 0
Robin 9 3 0 0 2
Thrush 4 0 6 0 0
> rowSums(bird)
Bbird C.Finch Gt.Tit Sparrow Robin Thrush
101 29 67 74 14 10
> apply( bird, MARGIN = 2, FUN = sum)
Gdn Hegde Park Field Wood
175 32 69 13 6
> margin.table(bird)
[1] 295
> margin.table(bird,1)
Bbird C.Finch Gt.Tit Sparrow Robin Thrush
101 29 67 74 14 10
> margin.table(bird,margin = 2)
Gdn Hegde Park Field Wood
175 32 69 13 6
> prop.table(bird)
Gdn Hegde Park Field Wood
Bbird 0.15932203 0.03389831 0.13559322 0.006779661 0.006779661
C.Finch 0.06440678 0.01016949 0.01694915 0.000000000 0.006779661
Gt.Tit 0.16949153 0.00000000 0.03389831 0.023728814 0.000000000
Sparrow 0.15593220 0.05423729 0.02711864 0.013559322 0.000000000
Robin 0.03050847 0.01016949 0.00000000 0.000000000 0.006779661
Thrush 0.01355932 0.00000000 0.02033898 0.000000000 0.000000000
> prop.table(bird,margin = 1)
Gdn Hegde Park Field Wood
Bbird 0.4653465 0.0990099 0.3960396 0.01980198 0.01980198
C.Finch 0.6551724 0.1034483 0.1724138 0.00000000 0.06896552
Gt.Tit 0.7462687 0.0000000 0.1492537 0.10447761 0.00000000
Sparrow 0.6216216 0.2162162 0.1081081 0.05405405 0.00000000
Robin 0.6428571 0.2142857 0.0000000 0.00000000 0.14285714
Thrush 0.4000000 0.0000000 0.6000000 0.00000000 0.00000000
> addmargins( bird, 1, mean)
Gdn Hegde Park Field Wood
Bbird 47.00000 10.000000 40.0 2.000000 2
C.Finch 19.00000 3.000000 5.0 0.000000 2
Gt.Tit 50.00000 0.000000 10.0 7.000000 0
Sparrow 46.00000 16.000000 8.0 4.000000 0
Robin 9.00000 3.000000 0.0 0.000000 2
Thrush 4.00000 0.000000 6.0 0.000000 0
mean 29.16667 5.333333 11.5 2.166667 1
> addmargins(bird, 2, median)
Gdn Hegde Park Field Wood median
Bbird 47 10 40 2 2 10
C.Finch 19 3 5 0 2 3
Gt.Tit 50 0 10 7 0 7
Sparrow 46 16 8 4 0 8
Robin 9 3 0 0 2 2
Thrush 4 0 6 0 0 0
> birds
Error: object 'birds' not found
> species
[1] "Bbird" "C.Finch" "Gt.Tit" "Sparrow" "Robin" "Thrush"
> habitat
Error: object 'habitat' not found
> habitat = c('garden','parkland','hedgerow','woodland','pasture')
> qty = c(47,19,50,46,9,4,40,5,10,8,6,10,3,16,3,2,2,2,2,7,4)
> birds = data.frame(species,habitat,qty)
Error in data.frame(species, habitat, qty) :
arguments imply differing number of rows: 6, 5, 21
> birds = data.frame(species,habitat,qty)
Error in data.frame(species, habitat, qty) :
arguments imply differing number of rows: 6, 5, 21
> birds = data.frame(qty,species,habitat)
Error in data.frame(qty, species, habitat) :
arguments imply differing number of rows: 21, 6, 5
> pw
height plant water
1 9 vulgaris lo
2 11 sativa mid
3 6 vulgaris hi
4 14 sativa lo
5 17 vulgaris mid
6 19 sativa hi
7 28 vulgaris lo
8 31 sativa mid
9 32 vulgaris hi
10 7 sativa lo
11 6 vulgaris mid
12 5 sativa hi
13 14 vulgaris lo
14 17 sativa mid
15 15 vulgaris hi
16 44 sativa lo
17 38 vulgaris mid
18 37 sativa hi
> with(pw, table(plant,water))
water
plant hi lo mid
sativa 3 3 3
vulgaris 3 3 3
> with(pw, table(plant,water,height))
, , height = 5
water
plant hi lo mid
sativa 1 0 0
vulgaris 0 0 0
, , height = 6
water
plant hi lo mid
sativa 0 0 0
vulgaris 1 0 1
, , height = 7
water
plant hi lo mid
sativa 0 1 0
vulgaris 0 0 0
, , height = 9
water
plant hi lo mid
sativa 0 0 0
vulgaris 0 1 0
, , height = 11
water
plant hi lo mid
sativa 0 0 1
vulgaris 0 0 0
, , height = 14
water
plant hi lo mid
sativa 0 1 0
vulgaris 0 1 0
, , height = 15
water
plant hi lo mid
sativa 0 0 0
vulgaris 1 0 0
, , height = 17
water
plant hi lo mid
sativa 0 0 1
vulgaris 0 0 1
, , height = 19
water
plant hi lo mid
sativa 1 0 0
vulgaris 0 0 0
, , height = 28
water
plant hi lo mid
sativa 0 0 0
vulgaris 0 1 0
, , height = 31
water
plant hi lo mid
sativa 0 0 1
vulgaris 0 0 0
, , height = 32
water
plant hi lo mid
sativa 0 0 0
vulgaris 1 0 0
, , height = 37
water
plant hi lo mid
sativa 1 0 0
vulgaris 0 0 0
, , height = 38
water
plant hi lo mid
sativa 0 0 0
vulgaris 0 0 1
, , height = 44
water
plant hi lo mid
sativa 0 1 0
vulgaris 0 0 0
2 | 0000
4 | 000000
6 | 0000
8 | 00
2 | 0
3 | 000
4 | 00
5 | 0000
6 | 00
7 | 00
8 | 0
9 | 0
> data4
[1] 23.0 17.0 12.5 11.0 18.0 12.0 14.5 9.0 11.0 9.0 12.5 14.5 17.0
8.0 21.0
> stem(data4)
0 | 899
1 | 11233
1 | 55778
2 | 13
8 | 000
10 | 00
12 | 055
14 | 55
16 | 00
18 | 0
20 | 0
22 | 0
> hist(dt1)
> hist(dt1, col = 'gray75',main=NULL, xlab = 'Size class for dt1',ylim =
c(0,0.3),freq = FALSE)
>
> hist(dt1, col = 'gray75',main=NULL, xlab = 'Size class for dt1',ylim =
c(0,0.3),freq = FALSE)
> dens = density(dt1)
> dens
Call:
density.default(x = dt1)
x y
Min. :-0.8932 Min. :0.0002982
1st Qu.: 2.3034 1st Qu.:0.0134042
Median : 5.5000 Median :0.0694574
Mean : 5.5000 Mean :0.0781187
3rd Qu.: 8.6966 3rd Qu.:0.1396352
Max. :11.8932 Max. :0.1798531
> names(dens)
[1] "x" "y" "bw" "n" "call"
"data.name" "has.na"
> str(dt1)
num [1:16] 3 5 7 5 3 2 6 8 5 6 ...
> str(dens)
List of 7
$ x : num [1:512] -0.893 -0.868 -0.843 -0.818 -0.793 ...
$ y : num [1:512] 0.000313 0.000339 0.000367 0.000397 0.000429
...
$ bw : num 0.964
$ n : int 16
$ call : language density.default(x = dt1)
$ data.name: chr "dt1"
$ has.na : logi FALSE
- attr(*, "class")= chr "density"
> plot(dens$x, dens$y)
> plot(density(dt1))
> fw
c.9..25..15..2..14..25..24..47..2..3..5..9..14..24..29..34. ncol
dimnames.c..taw....torridge....ouse....exe....lyn....brook....ditch...
1 9 2
taw
2 25 2
torridge
3 15 2
ouse
4 2 2
exe
5 14 2
lyn
6 25 2
brook
7 24 2
ditch
8 47 2
fal
9 2 2
taw
10 3 2
torridge
11 5 2
ouse
12 9 2
exe
13 14 2
lyn
14 24 2
brook
15 29 2
ditch
16 34 2
fal
dimnames.c..count....speed..
1 count
2 speed
3 count
4 speed
5 count
6 speed
7 count
8 speed
9 count
10 speed
11 count
12 speed
13 count
14 speed
15 count
16 speed
> mf
len sp alg no3 bod)\n
1 20 12 40 2.25 200
2 21 14 45 2.14 180
3 22 12 45 1.33 135
4 23 16 16 1.66 120
5 21 20 20 1.78 110
6 20 21 21 2.45 120
> boxplot(mf$alg)
> hist(mf)
Error in hist.default(mf) : 'x' must be numeric
> hist(dt1)
> hist(dt1)
> hist(dt1)
>
R version 4.3.2 (2023-10-31 ucrt) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
> plot(density(dt1))
> hist(dt1,freq = F,col = 'gray85')
> lines(density(dt1), lty =2)
> lines(density(dt1, k= 'rectangular'))
> rnorm(20, mean = 5, sd =1)
[1] 4.961028 4.103988 4.395820 5.153047 4.963701 6.049925 4.218205
5.693877
[9] 4.051571 3.951315 4.544928 6.077120 4.609351 4.902176 4.143953
6.081976
[17] 6.567138 6.117462 4.304101 5.347486
> pnorm(5, mean =5, sd = 1)
[1] 0.5
> qnorm(0.5,5,1)
[1] 5
> dnorm(c(4,5,6),mean = 5, sd = 1)
[1] 0.2419707 0.3989423 0.2419707
> qnorm(c(0.05,0.95), mean = 5,sd =1 )
[1] 3.355146 6.644854
> hist(dt1.norm, freq = F, border = 'gray50',main = 'comparing two
distribution',xlab = 'data2 size classes')
Error: object 'dt1.norm' not found
> dt1.norm = rnorm(1000, mean(dt1), sd(dt1))
> hist(dt1.norm, freq = F, border = 'gray50',main = 'comparing two
distribution',xlab = 'data2 size classes')
> lines(density(dt1), lwd =2)
> rpois = (50, lambda = 10)
Error: unexpected ',' in "rpois = (50,"
> rpois(50 ,lambda = 10)
[1] 11 3 12 9 7 11 13 12 9 8 8 12 9 13 13 12 11 8 16 11 12 11 10
10 9
[26] 9 15 9 13 10 2 8 14 13 10 13 8 7 6 6 8 13 14 14 9 7 6 12
10 9
> pbinom(c(3,6,9,12), size = 17 ,prob =0.5)
[1] 0.006362915 0.166152954 0.685470581 0.975479126
> qt(0.975, df= c(5,10,100,Inf))
[1] 2.570582 2.228139 1.983972 1.959964
> (1-pt(c(1.6,1.9,2.2),df = Inf))*2
[1] 0.10959858 0.05743312 0.02780690
> pt(c(1.6,1.9,2.2),Inf)
[1] 0.9452007 0.9712834 0.9860966
> pt(c(1.6,1.9,2.2),Inf, lower.tail = FALSE)
[1] 0.05479929 0.02871656 0.01390345
> pt(c(1.6,1.9,2.2),Inf,lower.tail = FALSE)*2
[1] 0.10959858 0.05743312 0.02780690
> pf(seq(3,5,0.5),df1 = 2,df2 = 12, lower.tail= F)
[1] 0.08779150 0.06346962 0.04665600 0.03481543 0.02633610
> runif(10)
[1] 0.62719180 0.59776828 0.35578051 0.65856292 0.68811773 0.27971730
[7] 0.51853838 0.92647277 0.05495673 0.66096811
> runif(10,min=0, max=10)
[1] 5.8152710 3.2479174 9.4814383 6.6966261 0.7600207 5.3118883
9.8860684
[8] 8.6648400 6.2775698 2.2504481
> punif(6,min=0,max=10)
[1] 0.6
> RNGkind()
[1] "Mersenne-Twister" "Inversion" "Rejection"
> RNGkind(kind = 'Super',normal.kind = 'Box')
> RNGkind()
[1] "Super-Duper" "Box-Muller" "Rejection"
> Rngkind('default')
Error in Rngkind("default") : could not find function "Rngkind"
> RNGkind()
[1] "Super-Duper" "Box-Muller" "Rejection"
> RNGkind('default')
> RNGkind()
[1] "Mersenne-Twister" "Box-Muller" "Rejection"
> RNGkind('default','default')
> RNGkind()
[1] "Mersenne-Twister" "Inversion" "Rejection"
> set.seed()
Error in set.seed() : argument "seed" is missing, with no default
> set.seed(1)
> runif(1)
[1] 0.2655087
> runif(1)
[1] 0.3721239
> runif(1)
[1] 0.5728534
> set.seed(1)
> runif(3)
[1] 0.2655087 0.3721239 0.5728534
> set.seed(1, kind = 'Super')
> runif(3)
[1] 0.3714075 0.4789723 0.9636913
> RNGkind()
[1] "Super-Duper" "Inversion" "Rejection"
> set.seed(1,kind= 'default')
> runif(3)
[1] 0.2655087 0.3721239 0.5728534
> RNGkind()
[1] "Mersenne-Twister" "Inversion" "Rejection"
> dt1
[1] 3 5 7 5 3 2 6 8 5 6 9 4 5 7 3 4
> sample(dt1,size=4)
[1] 3 5 5 6
> sample(data8, size = 4,replace = TRUE)
Error: object 'data8' not found
> data8
Error: object 'data8' not found
> sample(dt1[dt1 > 5], size = 3)
[1] 8 6 7
> sample(dt1[dt1>5])
[1] 8 7 9 6 6 7
> dt1[dt1>5]
[1] 7 6 8 6 9 7
> sample(dt1[dt1>5])
[1] 7 6 8 7 6 9
> sample(dt1[dt1>5])
[1] 9 7 7 6 6 8
> sample(dt1[dt1>5])
[1] 6 7 9 7 6 8
> sample(dt1[dt1 > 8])
[1] 1 4 3 6 2 5 8 9 7
> set.seed(4)
> sample(dt1,size = 3)
[1] 8 9 7
> set.seed(4)
> resample(dt1,size = 3)
Error in resample(dt1, size = 3) : could not find function "resample"
> sample(dt1[dt1>8])
[1] 8 3 9 7 4 6 2 1 5
> shapiro.test(dt1)
data: dt1
W = 0.96332, p-value = 0.7223
> mf
len sp alg no3 bod)\n
1 20 12 40 2.25 200
2 21 14 45 2.14 180
3 22 12 45 1.33 135
4 23 16 16 1.66 120
5 21 20 20 1.78 110
6 20 21 21 2.45 120
> shapiro.test(mf$alg)
data: mf$alg
W = 0.81355, p-value = 0.07755
> ks.test(dt1,'pnorm',mean=5,sd=2)
data: dt1
D = 0.125, p-value = 0.9639
alternative hypothesis: two-sided
Warning message:
In ks.test.default(dt1, "pnorm", mean = 5, sd = 2) :
ties should not be present for the Kolmogorov-Smirnov test
> ks.test(dt1,pnorm(20,5,2))
> ks.test(dt1,'ppois',5)
data: dt1
D = 0.24096, p-value = 0.3108
alternative hypothesis: two-sided
Warning message:
In ks.test.default(dt1, "ppois", 5) :
ties should not be present for the Kolmogorov-Smirnov test
> qqnorm(dt1)
> qqnorm(dt1,main='QQ plot of example data',xlab='Theoritical'
+ ,ylab='Quantiles for dt1')
> qqline(dt1,lwd = 2,lty=2)
> qqplot(rpois(50,5),rnorm(50,5,1))
> qqplot(dt1,dt1)
> qqp = qqplot(dt1,rnorm(50,5,2))
> qqp
$x
[1] 2 3 3 3 4 4 5 5 5 5 6 6 7 7 8 9
$y
[1] 0.4841236 1.7161045 2.6810093 3.2554153 3.4037517 3.6608763
4.0070002
[8] 4.1174306 4.8623181 5.7228188 6.1032897 6.3309340 6.8435012
7.0733509
[15] 7.6626950 8.5921276
> fw
count speed
1 9 2
2 25 3
3 15 5
4 2 9
5 14 14
6 25 24
7 24 29
8 47 34
> plot(fw)
> head(mf)
len sp alg no3 bod)\n
1 20 12 40 2.25 200
2 21 14 45 2.14 180
3 22 12 45 1.33 135
4 23 16 16 1.66 120
5 21 20 20 1.78 110
6 20 21 21 2.45 120
> plot(mf)
> pairs(~ Length + Speed + NO3, data = mf)
Error in eval(predvars, data, env) : object 'Length' not found
> pairs(~ len + sp + no3, data = mf)
> pairs(~ len + sp + no3, data = mf , col ='red', cex = 2, pch = 'X')
> data11
[1] 3 5 7 5 3 2 6 8 5 6 9 8
> data8 = data5
> data8
[1] "jan" "feb" "mar" "apr" "may" "jun" "jul" "aug" "sep" "oct" "nov"
"dec"
> pie(data11, labels = data8)
> pc = c('gray40', 'gray50', 'gray60', 'gray70', 'gray80', 'gray90'
+ )
> pie(data11, labels = data8, col = pc, clockwise = TRUE, init.angle =
180)
> fw
count speed
1 9 2
2 25 3
3 15 5
4 2 9
5 14 14
6 25 24
7 24 29
8 47 34
> pc = c('gray65', 'gray70', 'gray75', 'gray80', 'gray85', 'gray90')
> pie(fw$count, labels = row.names(fw), col = pc, cex = 1.2)
> bird
Gdn Hegde Park Field Wood
Bbird 47 10 40 2 2
C.Finch 19 3 5 0 2
Gt.Tit 50 0 10 7 0
Sparrow 46 16 8 4 0
Robin 9 3 0 0 2
Thrush 4 0 6 0 0
> pie(bird[,1], col = pc)
> dotchart(data11, labels = data8)
> bird
Gdn Hegde Park Field Wood
Bbird 47 10 40 2 2
C.Finch 19 3 5 0 2
Gt.Tit 50 0 10 7 0
Sparrow 46 16 8 4 0
Robin 9 3 0 0 2
Thrush 4 0 6 0 0
> dotchart(bird)
> dotchart(t(bird))
> dotchart(bird, color = 'gray30', gcolor = 'black', lcolor = 'gray30',
cex = 0.8, xlab = 'Bird Counts', bg = 'gray90', pch = 21)
> dotchart(bird, gdata = colMeans(bird), gpch = 16, gcolor = 'blue')
> mtext('Grouping = mean', side =3, adj = 1)
> title(main = 'Bird species and Habitat')
> title(xlab = 'Bird abundance')
> rain = data11
> rain
[1] 3 5 7 5 3 2 6 8 5 6 9 8
> barplot(rain)
> barplot(rain, names = data8)
> barplot(rain, xlab = 'Month', ylab = 'Rainfall cm', ylim = c(0,10))
> barplot(rain, xlab = 'Month', ylab = 'Rainfall cm', ylim = c(0,10), col
= 'lightblue')
> abline(h = seq(1,9,2), lty = 2, lwd = 0.5, col = 'gray40')
> box()
> table(rain)
rain
2 3 5 6 7 8 9
1 2 3 2 1 2 1
> barplot(table(rain), ylab = 'Frequency', xlab = 'Numeric category')
> abline(h=0)
> barplot(fw$count, names = row.names(fw), ylab = 'Invertebrate Count' ,
col = 'tan')
> abline(h=0)
> barplot(bird)
> barplot(bird, beside = TRUE, ylab = 'Total birds counted', xlab =
'Habitat')
> barplot(bird, beside = TRUE, legend = TRUE)
> title(ylab = 'Total birds counted', xlab = 'Habitat')
> barplot(bird, beside = TRUE, legend = TRUE, col = c('black', 'pink',
'lightblue', 'tan', 'red', 'brown'))
> barplot(t(bird), beside = TRUE, legend = TRUE, cex.names = 0.8, col =
c('black', 'pink', 'lightblue', 'tan', 'red', 'brown'))
> title(ylab = 'Bird Count', xlab = 'Bird Species')
> barplot(bird, beside = TRUE, horiz = TRUE)
> bccol = c('black', 'pink', 'lightblue', 'tan', 'red', 'brown')
> barplot(bird, beside = TRUE, legend = TRUE, horiz = TRUE, xlim = c(0,
60), col = bccol)
> title(ylab = 'Habitat', xlab = 'Bird count')
> barplot(apply(mf, 2, median, na.rm = T), ylab = 'Median Measurement')
>
Histogram of dt1
4
3
Frequency
2
1
0
2 3 4 5 6 7 8 9
dt1
●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●
●●
●●
● ●
●●
●●
●
●●
●● ●●
●●
●
●●
● ●●
●●
●
●●
● ●●
●
●●
● ●●
●
●
●●
● ●
●●
●
●●
● ●●
●
●
●●
● ●
●●
●●
● ●●
●
●● ●●
●
●
0.15
●
●● ●
●
●●
● ●
●●
●
●● ●●
●●
● ●●
●● ●●
●● ●●
●● ●●
●● ●●
●● ●●
●
●● ●
●
●● ●
●●
●● ●●
●● ●●
●● ●●
●
●● ●
●●
●● ●●
●
●● ●
●●
●● ●●
●
●● ●
●●
●● ●●
●●
0.10
●● ●●
● ●●
●
● ●
dens$y
● ●●
●
●
● ●
●
● ●
●●
●● ●●
●
● ●
●●
●
● ●●
●
● ●
●●
●● ●●
●
● ●
●●
●
● ●●
●
● ●
●●
●● ●●
●
● ●
●●
●
● ●●
●
● ●
●●
●● ●●
●
● ●
●●
●
● ●●
●
● ●
●●
0.05
●● ●●
●
●● ●
●●
● ●●
●
●
● ●
●●
●
● ●●
●
●
● ●
●●
● ●●
●
●● ●
●●
●● ●●
●
●● ●
●●
●● ●●
●
●
●● ●
●●
●
● ●●
●
●
● ●
●●
●
●●
● ●
●●
●
●● ●●
●●
●●
● ●●
●●
●●
●● ●●
●●
●●
●● ●●
●●
●
●●
●● ●
●●
●●
●●
●●
●● ●●
●●
●●
●●
●●
●● ●●
●●
●●
●●
● ●
0.00
●●
●●
●●
●●
●●
● ●
●●
●●
●●
●●
●●
●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●● ●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●●
●
0 2 4 6 8 10 12
dens$x
density(x = dt1)
0.15
0.10
Density
0.05
0.00
0 2 4 6 8 10 12
N = 16 Bandwidth = 0.9644
Density
2
3
4
5
dt1
Histogram of dt1
6
7
8
9
comparing two distribution
0.20
0.15
Density
0.10
0.05
0.00
0 2 4 6 8 10 12
●
9
●
8
● ●
7
Sample Quantiles
● ●
6
● ● ● ●
5
● ●
4
● ● ●
3
●
2
−2 −1 0 1 2
Theoretical Quantiles
QQ plot of example data
●
9
●
8
● ●
7
Quantiles for dt1
● ●
6
● ● ● ●
5
● ●
4
● ● ●
3
●
2
−2 −1 0 1 2
Theoritical
●
9
●
8
●
7
●
6
dt1
●
5
●
4
●
3
●
2
2 3 4 5 6 7 8 9
dt1
●
8
●
●
●
●
6
●
rnorm(50, 5, 2)
●
●
4
●
●
●
●
2
2 3 4 5 6 7 8 9
dt1
16
14
richness
speciesrich
12
10
8
mow unmow
cuttinggraze
treatment
cuttinggraze
treatment
mow unmow
8
10
12
speciesrich
richness
14
16
●
40
30
Count of Mayfly
● ●
●
20
●
●
10
5 10 15 20 25 30 35
Speed m/s
Count of Mayfly
0 10 20 30 40 50
0
10
20
Speed m/s
30
40
50
Count of Mayfly
0 10 20 30 40 50
0
10
20
Speed m/s
30
40
50
●
40
30
count
● ●
●
20
●
●
10
5 10 15 20 25 30 35
speed
15 20 25 30 35 40 45
15 20 25 30 35 40 45
1
2
Value
15 20 25 30 35 40 45
count
Variable
speed
35
●
30
●
25
●
20
speed
15
●
10
●
5
●
●
10 20 30 40
count
12 16 20 1.4 1.8 2.2
23.0
● ● ● ●
● ● ● ●
21.5
len ● ● ● ● ● ● ● ●
20.0
● ● ● ● ● ● ● ●
● ● ● ●
20
● ● ● ●
sp
16
● ● ● ●
● ● ● ●
12
● ● ● ● ● ● ● ●
45
● ● ● ● ● ● ● ●
● ● ● ●
35
alg
25
● ● ● ● ● ● ● ●
15
● ● ● ●
● ● ● ●
2.2
● ● ● ●
● ● ● ●
no3
1.8
● ● ● ●
● ● ● ●
1.4
● ● ● ●
200
● ● ● ●
● ● ● ●
bod)
160
● ● ● ●
120
● ● ● ● ● ● ● ●
● ● ● ●
23.0
● ●
22.0
● ●
len
21.0
● ● ● ●
20.0
● ● ● ●
● ●
20
● ●
18
sp
16
● ●
14
● ●
12
● ● ● ●
● ●
● ●
2.2
● ●
no3
1.8
● ●
● ●
1.4
● ●
23.0
X X
22.0
X X
len
21.0
X X X X
20.0
X X X X
X X
X X
20
18
sp
X X
16
X X
14
X X X X
12
X X
X X
2.2
X X
no3
1.8
X X
X X
1.4
X X
20.0 21.0 22.0 23.0 1.4 1.8 2.2
apr
may mar
jun
jul feb
jan
aug
dec
sep
oct nov
apr
mar may
jun
feb jul
jan
aug
dec
sep
nov oct
3
4
5 2
6 1
7 8
C.Finch
Bbird
Thrush
Gt.Tit
Robin
Sparrow
dec ●
nov ●
oct ●
sep ●
aug ●
jul ●
jun ●
may ●
apr ●
mar ●
feb ●
jan ●
2 3 4 5 6 7 8 9
Gdn
Thrush ●
Robin ●
Sparrow ●
Gt.Tit ●
C.Finch ●
Bbird ●
Hegde
Thrush ●
Robin ●
Sparrow ●
Gt.Tit ●
C.Finch ●
Bbird ●
Park
Thrush ●
Robin ●
Sparrow ●
Gt.Tit ●
C.Finch ●
Bbird ●
Field
Thrush ●
Robin ●
Sparrow ●
Gt.Tit ●
C.Finch ●
Bbird ●
Wood
Thrush ●
Robin ●
Sparrow ●
Gt.Tit ●
C.Finch ●
Bbird ●
0 10 20 30 40 50
Bbird
Wood ●
Field ●
Park ●
Hegde ●
Gdn ●
C.Finch
Wood ●
Field ●
Park ●
Hegde ●
Gdn ●
Gt.Tit
Wood ●
Field ●
Park ●
Hegde ●
Gdn ●
Sparrow
Wood ●
Field ●
Park ●
Hegde ●
Gdn ●
Robin
Wood ●
Field ●
Park ●
Hegde ●
Gdn ●
Thrush
Wood ●
Field ●
Park ●
Hegde ●
Gdn ●
0 10 20 30 40 50
Bird species and Habitat
Gdn ● Grouping = mean
Thrush ●
Robin ●
Sparrow ●
Gt.Tit ●
C.Finch ●
Bbird ●
Hegde ●
Thrush ●
Robin ●
Sparrow ●
Gt.Tit ●
C.Finch ●
Bbird ●
Park ●
Thrush ●
Robin ●
Sparrow ●
Gt.Tit ●
C.Finch ●
Bbird ●
Field ●
Thrush ●
Robin ●
Sparrow ●
Gt.Tit ●
C.Finch ●
Bbird ●
Wood ●
Thrush ●
Robin ●
Sparrow ●
Gt.Tit ●
C.Finch ●
Bbird ●
0 10 20 30 40 50
Bird abundance
8
6
4
2
0
jan feb mar apr may jun jul aug sep oct nov dec
Rainfall cm
0 2 4 6 8 10
Month
Invertebrate Count
0 10 20 30 40
1
2
3
4
5
6
7
8
150
100
50
0
Bbird
C.Finch
Gt.Tit
40
Sparrow
Robin
Thrush
30
20
10
0
Gdn
Hegde
Park
40
Field
Wood
30
Bird Count
20
10
0
Bird Species
Median Measurement
0 20 40 60 80 100 120
len
sp
alg
no3
bod)