Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

R

Views: 4031
Kernel: R (R-Project)
options(jupyter.plot_mimetypes ='image/png')

Exercise 1

names<- c('Bob','Claire','Luisa','Matt','Marta','Mike') score<- c(34,82,59,72,50,100) game_cards<- data.frame(names,score,stringsAsFactors=FALSE) game_cards
namesscore
Bob 34
Claire 82
Luisa 59
Matt 72
Marta 50
Mike 100
game_cards$names
  1. 'Bob'
  2. 'Claire'
  3. 'Luisa'
  4. 'Matt'
  5. 'Marta'
  6. 'Mike'
names<- c('Bob','Claire','Luisa','Matt','Marta','Mike') score1<- c(34,82,59,72,50,100) score2<- c(64,82,36,48,29,85) game_cards<- data.frame(names,score1,score2,stringsAsFactors=FALSE) game_cards
namesscore1score2
Bob 34 64
Claire 82 82
Luisa 59 36
Matt 72 48
Marta 50 29
Mike 100 85
game_cards$score1
  1. 34
  2. 82
  3. 59
  4. 72
  5. 50
  6. 100
game_cards$score2
  1. 64
  2. 82
  3. 36
  4. 48
  5. 29
  6. 85

The additional field for the second match score is created by adding score2<- c( , , , , , ), with values of the same length as previous. score2 was also added to the data.frame. Each field is accessed seperately by game_cards$fieldname fieldname:score1/ score2

Ecercise 2

names(game_cards)<- c("names","match1","match2") game_cards
namesmatch1match2
Bob 34 64
Claire 82 82
Luisa 59 36
Matt 72 48
Marta 50 29
Mike 100 85
dim(game_cards)
  1. 6
  2. 3
min(game_cards$match1) min(game_cards$match2)
34
29

The minimum scores from match 1 and match 2 were 34 and 29 respectively.

max(game_cards$match1) max(game_cards$match2)
100
85

The maximum scores from mathc 1 and match 2 were 100 and 85 respectively.

min(game_cards[,2:3])
29

The minimum score from both matches was 29.

max(game_cards[,2:3])
100

The maximum score from both mathes was 100

which.min(game_cards$match1) which.min(game_cards$match2)
1
5
which.max(game_cards$match1) which.max(game_cards$match2)
6
6
names[which.min(game_cards$match1)] names[which.min(game_cards$match2)]
'Bob'
'Marta'
names[which.max(game_cards$match1)] names[which.max(game_cards$match2)]
'Mike'
'Mike'
x<- c(min(game_cards$match1)) y<- c(names[which.min(game_cards$match1)]) z<- c(y,as.character(x)) print(z) a<- c(min(game_cards$match2)) b<- c(names[which.min(game_cards$match2)]) c<- c(b,as.character(a)) print(c)
[1] "Bob" "34" [1] "Marta" "29"

The minimum score from match 1 was 34, which was scored by Bob. The minimum score from match 2 was 29, which was scored by Marta.

d<- c(max(game_cards$match1)) e<- c(names[which.max(game_cards$match1)]) f<- c(e,as.character(d)) print(f) g<- c(max(game_cards$match2)) h<- c(names[which.max(game_cards$match2)]) i<- c(h,as.character(g)) print(i)
[1] "Mike" "100" [1] "Mike" "85"

The maximum score from match 1 was 100, which was scored by Mike. The maximum score from match 2 was 85, which was also scored by Mike.

game_cards[order(game_cards$match1),]
namesmatch1match2
1Bob 34 64
5Marta 50 29
3Luisa 59 36
4Matt 72 48
2Claire 82 82
6Mike 100 85
game_cards[order(game_cards$match2),]
namesmatch1match2
5Marta 50 29
3Luisa 59 36
4Matt 72 48
1Bob 34 64
2Claire 82 82
6Mike 100 85

The function order() arranges the sequence of numbers into an ascending order. order(game_cards$score) rearranges the scores of the matches on the game cards into a sequential order. The output is the ordered sequence of numbers.

?plot

The command plot() is used for generic X-Y graph plotting of R objects, through the use of command plot(x,y,...). x = the coordinates of points in the plot. y = the y co-ordinates in the plot. ... = arguments to be passed to the methods, such as graphical parameters. "type" = the type of plot that should be drawn, eg. "p" for points, "l" for lines, "b" for both etc. To add an overall title to the plot, add "main", to add a subtitle fot the plot, add "sub", to add a title for the x and y axis, add "xlab" and "ylab" respectively.

par(mfrow=c(1,2)) barplot(game_cards$match1, names=game_cards$names) barplot(game_cards$match2, names=game_cards$names)
Error in barplot(game_cards$match1, names = game_cards$names): object 'game_cards' not found Traceback: 1. barplot(game_cards$match1, names = game_cards$names)

Exercise 4

?par

The par() command is used to set or query graphucal parameters. Parameters can be set by specifying them as arguments to par in tag = value form, or by passing them as a list of tagged values.

Exercise 5

match1<- c(34,82,59,72,50,100) match2<-c(64,29,36,48,82,85) plot(match1,match2) abline(0,1)
Image in a Jupyter notebook

Scatter plots are used to plot data points on a horizontal and vertical axis to show how much one variable is affected by another. It uses cartesian co-ordinates to display values for typically two variables of a set of data. A scatter plot can be used either when one continuous variable that is under the control of the experimenter and the other depends on it or when both continuous variables are independent. If a parameter exists that is systematically incremented and/or decremented by the other, it is called the control parameter or independent variable and is customarily plotted along the horizontal axis. The measured or dependent variable is customarily plotted along the vertical axis. If no dependent variable exists, either type of variable can be plotted on either axis and a scatter plot will illustrate only the degree of correlation (not causation) between two variables.

match1<- c(34,82,59,72,50,100) plot(match1,match1) abline(0,1)
Image in a Jupyter notebook

By plotting the values of a variable against itself, the resulting scatter plot shows the points falling along a straight line, with the line of best fit travelling directly through all points.

Exercise 6

data(iris) ?iris iris
Sepal.LengthSepal.WidthPetal.LengthPetal.WidthSpecies
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa
4.6 3.4 1.4 0.3 setosa
5.0 3.4 1.5 0.2 setosa
4.4 2.9 1.4 0.2 setosa
4.9 3.1 1.5 0.1 setosa
5.4 3.7 1.5 0.2 setosa
4.8 3.4 1.6 0.2 setosa
4.8 3.0 1.4 0.1 setosa
4.3 3.0 1.1 0.1 setosa
5.8 4.0 1.2 0.2 setosa
5.7 4.4 1.5 0.4 setosa
5.4 3.9 1.3 0.4 setosa
5.1 3.5 1.4 0.3 setosa
5.7 3.8 1.7 0.3 setosa
5.1 3.8 1.5 0.3 setosa
5.4 3.4 1.7 0.2 setosa
5.1 3.7 1.5 0.4 setosa
4.6 3.6 1.0 0.2 setosa
5.1 3.3 1.7 0.5 setosa
4.8 3.4 1.9 0.2 setosa
5.0 3.0 1.6 0.2 setosa
5.0 3.4 1.6 0.4 setosa
5.2 3.5 1.5 0.2 setosa
5.2 3.4 1.4 0.2 setosa
4.7 3.2 1.6 0.2 setosa
⋮⋮⋮⋮⋮
6.9 3.2 5.7 2.3 virginica
5.6 2.8 4.9 2.0 virginica
7.7 2.8 6.7 2.0 virginica
6.3 2.7 4.9 1.8 virginica
6.7 3.3 5.7 2.1 virginica
7.2 3.2 6.0 1.8 virginica
6.2 2.8 4.8 1.8 virginica
6.1 3.0 4.9 1.8 virginica
6.4 2.8 5.6 2.1 virginica
7.2 3.0 5.8 1.6 virginica
7.4 2.8 6.1 1.9 virginica
7.9 3.8 6.4 2.0 virginica
6.4 2.8 5.6 2.2 virginica
6.3 2.8 5.1 1.5 virginica
6.1 2.6 5.6 1.4 virginica
7.7 3.0 6.1 2.3 virginica
6.3 3.4 5.6 2.4 virginica
6.4 3.1 5.5 1.8 virginica
6.0 3.0 4.8 1.8 virginica
6.9 3.1 5.4 2.1 virginica
6.7 3.1 5.6 2.4 virginica
6.9 3.1 5.1 2.3 virginica
5.8 2.7 5.1 1.9 virginica
6.8 3.2 5.9 2.3 virginica
6.7 3.3 5.7 2.5 virginica
6.7 3.0 5.2 2.3 virginica
6.3 2.5 5.0 1.9 virginica
6.5 3.0 5.2 2.0 virginica
6.2 3.4 5.4 2.3 virginica
5.9 3.0 5.1 1.8 virginica
summary(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300 Median :5.800 Median :3.000 Median :4.350 Median :1.300 Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800 Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500 Species setosa :50 versicolor:50 virginica :50
plot(iris)
Image in a Jupyter notebook
plot(iris$Sepal.Length~iris$Petal.Length)
Image in a Jupyter notebook
par(mfrow=c(1,2)) plot(iris$Sepal.Length~iris$Petal.Length, xlab="Petal Length",ylab="Sepal Length", main= "Sepal Length vs Petal Length", col=iris$Species, las=1) plot(iris$Sepal.Width~iris$Petal.Width, xlab="Petal Width", ylab="Sepal Width", main= "Sepal Width vs Petal Width", col=iris$Species, las=1) reg1<- lm(iris$Sepal.Length~iris$Petal.Length) reg2<- lm(iris$Sepal.Width~iris$Petal.Width) abline(reg1,reg2)
Image in a Jupyter notebook

Exercise 7

plot(iris$Sepal.Length~iris$Petal.Length, xlab="Petal Length",ylab="Sepal Length", main= "Sepal Length vs Petal Length", col=iris$Species, las=1) reg1<-lm(iris$Sepal.Length~iris$Petal.Length) abline(reg1) plot(iris$Sepal.Width~iris$Petal.Width, xlab="Petal Width", ylab="Sepal Width", main= "Sepal Width vs Petal Width", col=iris$Species, las=1) reg2<-lm(iris$Sepal.Width~iris$Petal.Width) abline(reg2)
Image in a Jupyter notebookImage in a Jupyter notebook
iris_table <- table(iris$Species) lbls <- paste(names(iris_table), "\n", iris_table, sep="") pie(iris_table, labels = lbls, main="Pie Chart of Species of Iris\n (sample sizes)")
Image in a Jupyter notebook

Exercise 8

data(morley) ?morley morley
ExptRunSpeed
0011 1 850
0021 2 740
0031 3 900
0041 4 1070
0051 5 930
0061 6 850
0071 7 950
0081 8 980
0091 9 980
0101 10 880
0111 11 1000
0121 12 980
0131 13 930
0141 14 650
0151 15 760
0161 16 810
0171 17 1000
0181 18 1000
0191 19 960
0201 20 960
0212 1 960
0222 2 940
0232 3 960
0242 4 940
0252 5 880
0262 6 800
0272 7 850
0282 8 880
0292 9 900
0302 10 840
⋮⋮⋮⋮
714 11 910
724 12 920
734 13 890
744 14 860
754 15 880
764 16 720
774 17 840
784 18 850
794 19 850
804 20 780
815 1 890
825 2 840
835 3 780
845 4 810
855 5 760
865 6 810
875 7 790
885 8 810
895 9 820
905 10 850
915 11 870
925 12 870
935 13 810
945 14 740
955 15 810
965 16 940
975 17 950
985 18 800
995 19 810
1005 20 870
morley_table <- table(morley$Run) lbls <- paste(names(morley_table), "\n", morley_table, sep="") pie(morley_table, labels = lbls, main="Pie Chart of Run number within each experiment\n (sample sizes)")
Image in a Jupyter notebook
morley_table <- table(morley$Expt) lbls <- paste(names(morley_table), "\n", morley_table, sep="") pie(morley_table, labels = lbls, main="Pie Chart of the number of experiments\n (sample sizes)")
Image in a Jupyter notebook
morley_table <- table(morley$Speed) lbls <- paste(names(morley_table), "\n", morley_table, sep="") pie(morley_table, labels = lbls, main="Pie Chart of Speed of Light in the experiments\n (sample sizes)")
Image in a Jupyter notebook
boxplot(morley$Speed ~ morley$Expt, col='light grey', xlab='Experiment #', ylab="speed (km/s - 299,000)", main="Michelson–Morley experiment") mtext("speed of light data") sol=299792.458-299000 abline(h=sol, col='red')
Image in a Jupyter notebook

Exercise 9

quantile(morley$Speed,prob=0.75)[["75%"]] + 1.5*IQR(morley$Speed)
1020
quantile(morley$Speed,prob=0.25)[["25%"]] - 1.5*IQR(morley$Speed)
680
quantile(morley$Speed,prob=0.25)
25%: 807.5
quantile(morley$Speed,prob=0.50)
50%: 850
quantile(morley$Speed,prob=0.75)
75%: 892.5
IQR(morley$Speed)
85
mean(morley$Speed)
852.4
sd(morley$Speed)
79.0105478190518
Expt1<- (morley$Speed[morley$Expt==1]) Expt1 quantile(Expt1,prob=0.75)[["75%"]] + 1.5*IQR(Expt1) quantile(Expt1,prob=0.25)[["25%"]] - 1.5*IQR(Expt1) quantile(Expt1,prob=0.25) quantile(Expt1,prob=0.50) quantile(Expt1,prob=0.75) IQR(Expt1) mean(Expt1) sd(Expt1)
  1. 850
  2. 740
  3. 900
  4. 1070
  5. 930
  6. 850
  7. 950
  8. 980
  9. 980
  10. 880
  11. 1000
  12. 980
  13. 930
  14. 650
  15. 760
  16. 810
  17. 1000
  18. 1000
  19. 960
  20. 960
1175
655
25%: 850
50%: 940
75%: 980
130
909
104.926039114276
Expt2<- (morley$Speed[morley$Expt==2]) Expt2 quantile(Expt2,prob=0.75)[["75%"]] + 1.5*IQR(Expt2) quantile(Expt2,prob=0.25)[["25%"]] - 1.5*IQR(Expt2) quantile(Expt2,prob=0.25) quantile(Expt2,prob=0.50) quantile(Expt2,prob=0.75) IQR(Expt2) mean(Expt2) sd(Expt2)
  1. 960
  2. 940
  3. 960
  4. 940
  5. 880
  6. 800
  7. 850
  8. 880
  9. 900
  10. 840
  11. 830
  12. 790
  13. 810
  14. 880
  15. 880
  16. 830
  17. 800
  18. 790
  19. 760
  20. 800
1012.5
672.5
25%: 800
50%: 845
75%: 885
85
856
61.1641449836336
Expt4<- (morley$Speed[morley$Expt==4]) Expt4 quantile(Expt4,prob=0.75)[["75%"]] + 1.5*IQR(Expt4) quantile(Expt4,prob=0.25)[["25%"]] - 1.5*IQR(Expt4) quantile(Expt4,prob=0.25) quantile(Expt4,prob=0.50) quantile(Expt4,prob=0.75) IQR(Expt4) mean(Expt4) sd(Expt4)
  1. 890
  2. 810
  3. 810
  4. 820
  5. 800
  6. 770
  7. 760
  8. 740
  9. 750
  10. 760
  11. 910
  12. 920
  13. 890
  14. 860
  15. 880
  16. 720
  17. 840
  18. 850
  19. 850
  20. 780
1011.25
621.25
25%: 767.5
50%: 815
75%: 865
97.5
820.5
60.0416522091123
Expt5<- (morley$Speed[morley$Expt==5]) Expt5 quantile(Expt5,prob=0.75)[["75%"]] + 1.5*IQR(Expt5) quantile(Expt5,prob=0.25)[["25%"]] - 1.5*IQR(Expt5) quantile(Expt5,prob=0.25) quantile(Expt5,prob=0.50) quantile(Expt5,prob=0.75) IQR(Expt5) mean(Expt5) sd(Expt5)
  1. 890
  2. 840
  3. 780
  4. 810
  5. 760
  6. 810
  7. 790
  8. 810
  9. 820
  10. 850
  11. 870
  12. 870
  13. 810
  14. 740
  15. 810
  16. 940
  17. 950
  18. 800
  19. 810
  20. 870
963.75
713.75
25%: 807.5
50%: 810
75%: 870
62.5
831.5
54.219340111304

Ecercise 10

hist(morley$Speed)
Image in a Jupyter notebook
par(fg=rgb(0.5,0.4,0.2)) hist(morley$Speed, prob=F, col=rgb(0.3,0.4,0.9), main='Michelson-Morley Experiment ', ylab="Frequency", xlab='Difference from Speed of Light') par(fg='black')
Image in a Jupyter notebook
par(fg=rgb(0.9,0.4,0.4)) hist(morley$Speed, prob=F, col=rgb(0.9,0.2,0.3), main='Michelson-Morley Experiment ', ylab="Frequency", xlab='Difference from Speed of Light') par(fg='black') lines(density(morley$Speed)) abline(v=mean(morley$Speed), col=rgb(0.5,0.5,0.5)) abline(v=median(morley$Speed), lty=3, col=rgb(0.5,0.5,0.5)) abline(v=mean(morley$Speed)+sd(morley$Speed), lty=2, col=rgb(0.7,0.7,0.7)) abline(v=mean(morley$Speed)-sd(morley$Speed), lty=2, col=rgb(0.7,0.7,0.7)) rug(morley$Speed)
Image in a Jupyter notebook
par(fg=rgb(0.6,0.2,0.3)) hist(morley$Speed[morley$Expt==1], prob=F, col=rgb(0.7,0.1,0.3), main='Michelson-Morley Experiment 1 ', ylab="Frequency", xlab='Difference from Speed of Light') par(fg='black') lines(density(morley$Speed[morley$Expt==1])) abline(v=mean(morley$Speed[morley$Expt==1]), col=rgb(0.5,0.5,0.5)) abline(v=median(morley$Speed[morley$Expt==1]), lty=3, col=rgb(0.5,0.5,0.5)) abline(v=mean(morley$Speed[morley$Expt==1])+sd(morley$Speed[morley$Expt==1]), lty=2, col=rgb(0.7,0.7,0.7)) abline(v=mean(morley$Speed[morley$Expt==1])-sd(morley$Speed[morley$Expt==1]), lty=2, col=rgb(0.7,0.7,0.7)) rug(morley$Speed[morley$Expt==1])
Image in a Jupyter notebook
par(fg=rgb(0.6,0.5,0.7)) hist(morley$Speed[morley$Expt==2], prob=F, col=rgb(0.3,0.7,0.9), main='Michelson-Morley Experiment 2 ', ylab="Frequency", xlab='Difference from Speed of Light') par(fg='black') lines(density(morley$Speed[morley$Expt==2])) abline(v=mean(morley$Speed[morley$Expt==2]), col=rgb(0.5,0.5,0.5)) abline(v=median(morley$Speed[morley$Expt==2]), lty=3, col=rgb(0.5,0.5,0.5)) abline(v=mean(morley$Speed[morley$Expt==2])+sd(morley$Speed[morley$Expt==2]), lty=2, col=rgb(0.7,0.7,0.7)) abline(v=mean(morley$Speed[morley$Expt==2])-sd(morley$Speed[morley$Expt==2]), lty=2, col=rgb(0.7,0.7,0.7)) rug(morley$Speed[morley$Expt==2])
Image in a Jupyter notebook
par(fg=rgb(0.6,0.6,0.6)) hist(morley$Speed[morley$Expt==4], prob=F, col=rgb(0.4,0.9,0.2), main='Michelson-Morley Experiment 4 ', ylab="Frequency", xlab='Difference from Speed of Light') par(fg='black') lines(density(morley$Speed[morley$Expt==4])) abline(v=mean(morley$Speed[morley$Expt==4]), col=rgb(0.5,0.5,0.5)) abline(v=median(morley$Speed[morley$Expt==4]), lty=3, col=rgb(0.5,0.5,0.5)) abline(v=mean(morley$Speed[morley$Expt==4])+sd(morley$Speed[morley$Expt==4]), lty=2, col=rgb(0.7,0.7,0.7)) abline(v=mean(morley$Speed[morley$Expt==4])-sd(morley$Speed[morley$Expt==4]), lty=2, col=rgb(0.7,0.7,0.7)) rug(morley$Speed[morley$Expt==4])
Image in a Jupyter notebook
par(fg=rgb(0.6,0.6,0.6)) hist(morley$Speed[morley$Expt==5], prob=F, col=rgb(0.7,0.2,0.6), main='Michelson-Morley Experiment 5 ', ylab="Frequency", xlab='Difference from Speed of Light') par(fg='black') lines(density(morley$Speed[morley$Expt==5])) abline(v=mean(morley$Speed[morley$Expt==5]), col=rgb(0.5,0.5,0.5)) abline(v=median(morley$Speed[morley$Expt==5]), lty=3, col=rgb(0.5,0.5,0.5)) abline(v=mean(morley$Speed[morley$Expt==5])+sd(morley$Speed[morley$Expt==5]), lty=2, col=rgb(0.7,0.7,0.7)) abline(v=mean(morley$Speed[morley$Expt==5])-sd(morley$Speed[morley$Expt==5]), lty=2, col=rgb(0.7,0.7,0.7)) rug(morley$Speed[morley$Expt==5])
Image in a Jupyter notebook

Exercise 11

rnorm(morley$Speed)
  1. -1.32983839753494
  2. -0.442650500019424
  3. 1.62417390000007
  4. -1.67584448879818
  5. -1.22606692573905
  6. -1.19288617284262
  7. -1.89831059193453
  8. -0.715139088553884
  9. 1.07456486955929
  10. 1.38397130820677
  11. -0.594388635345226
  12. -1.15802346922851
  13. -1.51839543038494
  14. 0.974198551046387
  15. -0.955640119728177
  16. 0.894749513314877
  17. 1.72258460789887
  18. 0.612603626517112
  19. 1.41000194006057
  20. -0.0923231473325155
  21. -1.19137273591046
  22. -0.0901615856822621
  23. 0.198453244443982
  24. 0.76199937209954
  25. 0.273573214989069
  26. 0.0793028237723885
  27. -0.903510855037117
  28. -0.230321581796134
  29. -0.001180156462322
  30. -1.2701468849564
  31. -0.767412117905502
  32. -0.827985224767165
  33. -0.328776093812234
  34. 2.15043910397576
  35. 1.06180959667687
  36. 0.488887253257983
  37. -0.074941805342632
  38. 2.35558044249208
  39. -0.443076174694343
  40. 1.0869397433374
  41. 1.44632130461307
  42. 0.367796447248661
  43. 0.0241548061108222
  44. -0.828092892936713
  45. 0.790879343064088
  46. 0.586053077078761
  47. -1.60339751167525
  48. 0.481270772574882
  49. -0.121348176146382
  50. -0.393060711498406
  51. 2.43608140942002
  52. 1.8347063468031
  53. -2.26323120859589
  54. -0.0993808424205221
  55. -0.173495819812754
  56. -0.759511800114655
  57. -1.29239201507555
  58. 1.33220449431244
  59. -0.409402931595105
  60. 1.22006169606042
  61. 1.06758646263697
  62. -1.37302824574217
  63. -0.299992926985538
  64. -0.254254005922695
  65. 0.453610218093153
  66. -1.23159422338585
  67. 0.932072541036467
  68. 0.250752012760951
  69. 0.536277896231289
  70. 1.19309516838348
  71. -1.66467505248656
  72. 0.667111423406191
  73. -1.04942883115995
  74. -2.19346290160825
  75. -1.80496773927251
  76. -0.985561800397227
  77. 1.39745986921433
  78. -0.886809714104144
  79. 1.57835996235896
  80. 0.808882415910302
  81. 0.519870065363074
  82. 1.32123018847284
  83. 0.97851483774372
  84. -0.037514536486098
  85. -0.658181238838866
  86. -0.212091917063404
  87. 0.117860816075992
  88. -1.39473895379265
  89. -0.618698184711007
  90. -0.560472912953385
  91. -0.399376178911394
  92. 0.0167280955025305
  93. 1.19744591607392
  94. -0.0569608776567713
  95. 0.617217164472841
  96. 0.318102254568782
  97. 0.139614057023832
  98. -0.736671158674166
  99. -1.31446190001575
  100. 0.194511032191064
?rnorm()
runif(morley$Speed)
  1. 0.264518806245178
  2. 0.582811257336289
  3. 0.42062978236936
  4. 0.537996992468834
  5. 0.754302130779251
  6. 0.0922018121927977
  7. 0.681373225292191
  8. 0.798066514078528
  9. 0.232842233264819
  10. 0.641004926059395
  11. 0.244015408214182
  12. 0.570152970496565
  13. 0.811254309955984
  14. 0.798563710646704
  15. 0.24969592015259
  16. 0.136332410154864
  17. 0.0474268107209355
  18. 0.288467477541417
  19. 0.385370008647442
  20. 0.996502695605159
  21. 0.183566161431372
  22. 0.672800717642531
  23. 0.0643984866328537
  24. 0.620991089148447
  25. 0.834634169237688
  26. 0.253943306626752
  27. 0.967401105212048
  28. 0.520939820446074
  29. 0.620963342254981
  30. 0.437164880800992
  31. 0.800008459249511
  32. 0.784856268204749
  33. 0.753692883765325
  34. 0.206868261331692
  35. 0.470573494676501
  36. 0.514903036179021
  37. 0.713916168548167
  38. 0.0855489911045879
  39. 0.208472222089767
  40. 0.555995153728873
  41. 0.863345834659413
  42. 0.423687194706872
  43. 0.476202831370756
  44. 0.407577888807282
  45. 0.49562520859763
  46. 0.075463596964255
  47. 0.339054282521829
  48. 0.200695814564824
  49. 0.00622879504226148
  50. 0.787927633151412
  51. 0.951467270264402
  52. 0.918116616783664
  53. 0.627712194342166
  54. 0.727811112068594
  55. 0.243230506079271
  56. 0.678512015379965
  57. 0.717459577368572
  58. 0.764501367462799
  59. 0.528164511080831
  60. 0.602822620421648
  61. 0.926245340844616
  62. 0.722419350873679
  63. 0.348279399331659
  64. 0.649060261901468
  65. 0.326362984254956
  66. 0.155253336299211
  67. 0.140495303319767
  68. 0.349665948189795
  69. 0.57015626761131
  70. 0.649660609895363
  71. 0.454423484858125
  72. 0.866482872748747
  73. 0.401366396341473
  74. 0.187020024983212
  75. 0.869719553273171
  76. 0.252253205049783
  77. 0.791618789546192
  78. 0.0038271879311651
  79. 0.218274709302932
  80. 0.190541617572308
  81. 0.859617992537096
  82. 0.492092164233327
  83. 0.306638536509126
  84. 0.786544287344441
  85. 0.9585007710848
  86. 0.163091869559139
  87. 0.700145638082176
  88. 0.471447916468605
  89. 0.314486169489101
  90. 0.596971365157515
  91. 0.306181581923738
  92. 0.522562241414562
  93. 0.919712348375469
  94. 0.187213698634878
  95. 0.057803800329566
  96. 0.0254174668807536
  97. 0.427565331803635
  98. 0.278308807173744
  99. 0.911951158428565
  100. 0.794001728529111
rbinom(morley$Speed)
Error in rbinom(morley$Speed): argument "size" is missing, with no default Traceback: 1. rbinom(morley$Speed)

Exercise 12

t.test(morley$Speed[morley$Expt==1], morley$Speed[morley$Expt==2])
Welch Two Sample t-test data: morley$Speed[morley$Expt == 1] and morley$Speed[morley$Expt == 2] t = 1.9516, df = 30.576, p-value = 0.0602 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -2.419111 108.419111 sample estimates: mean of x mean of y 909 856

There is not a significant difference between the results of experiment 1 and 2, as p>0.05.

t.test(morley$Speed[morley$Expt==1], morley$Speed[morley$Expt==4])
Welch Two Sample t-test data: morley$Speed[morley$Expt == 1] and morley$Speed[morley$Expt == 4] t = 3.2739, df = 30.238, p-value = 0.002659 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 33.31171 143.68829 sample estimates: mean of x mean of y 909.0 820.5

There is a significance difference between the results of experiment 1 and 4, as p<0.05

t.test(morley$Speed[morley$Expt==1], morley$Speed[morley$Expt==5])
Welch Two Sample t-test data: morley$Speed[morley$Expt == 1] and morley$Speed[morley$Expt == 5] t = 2.9346, df = 28.471, p-value = 0.006538 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 23.44296 131.55704 sample estimates: mean of x mean of y 909.0 831.5

There is a significant difference between the results of experiment 1 and 5, as p<0.05.

t.test(morley$Speed[morley$Expt==2], morley$Speed[morley$Expt==4])
Welch Two Sample t-test data: morley$Speed[morley$Expt == 2] and morley$Speed[morley$Expt == 4] t = 1.8523, df = 37.987, p-value = 0.07176 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.298237 74.298237 sample estimates: mean of x mean of y 856.0 820.5

There is not a significant difference between the results of experiment 2 and 4 because p>0.05.

t.test(morley$Speed[morley$Expt==2], morley$Speed[morley$Expt==5])
Welch Two Sample t-test data: morley$Speed[morley$Expt == 2] and morley$Speed[morley$Expt == 5] t = 1.3405, df = 37.461, p-value = 0.1882 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -12.51683 61.51683 sample estimates: mean of x mean of y 856.0 831.5

There is not a significant difference between the results of experiment 2 and 5, as p>0.05.

t.test(morley$Speed[morley$Expt==4], morley$Speed[morley$Expt==5])
Welch Two Sample t-test data: morley$Speed[morley$Expt == 4] and morley$Speed[morley$Expt == 5] t = -0.60808, df = 37.611, p-value = 0.5468 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -47.63309 25.63309 sample estimates: mean of x mean of y 820.5 831.5

There is not a significant difference between the results of experiment 4 and 5 because p>0.05.