Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

R

6597 views
Kernel: R
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
names score 1 Bob 34 2 Claire 82 3 Luisa 59 4 Matt 72 5 Marta 50 6 Mike 100
game_cards$names
[1] "Bob" "Claire" "Luisa" "Matt" "Marta" "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
names score1 score2 1 Bob 34 64 2 Claire 82 82 3 Luisa 59 36 4 Matt 72 48 5 Marta 50 29 6 Mike 100 85
game_cards$score1
[1] 34 82 59 72 50 100
game_cards$score2
[1] 64 82 36 48 29 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

INSTRUCTOR FEEDBACK: excellent execution Score:1

Ecercise 2

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

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

max(game_cards$match1) max(game_cards$match2)
[1] 100
[1] 85

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

min(game_cards[,2:3])
[1] 29

The minimum score from both matches was 29.

max(game_cards[,2:3])
[1] 100

The maximum score from both mathes was 100

which.min(game_cards$match1) which.min(game_cards$match2)
[1] 1
[1] 5
which.max(game_cards$match1) which.max(game_cards$match2)
[1] 6
[1] 6
names[which.min(game_cards$match1)] names[which.min(game_cards$match2)]
[1] "Bob"
[1] "Marta"
names[which.max(game_cards$match1)] names[which.max(game_cards$match2)]
[1] "Mike"
[1] "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),]
names match1 match2 1 Bob 34 64 5 Marta 50 29 3 Luisa 59 36 4 Matt 72 48 2 Claire 82 82 6 Mike 100 85
game_cards[order(game_cards$match2),]
names match1 match2 5 Marta 50 29 3 Luisa 59 36 4 Matt 72 48 1 Bob 34 64 2 Claire 82 82 6 Mike 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.

INSTRUCTOR FEEDBACK: VERY GOOD. Score 1

?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)

INSTRUCTOR FEEDBACK: You answered the question and maybe you could have given some more examples. All good but you need to resolve the errors you get in teh code. Maybe you have to reexecute the cell that defined game_cards. Score 0.75

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.

INSTRUCTOR FEEDBACK: All good but can be improved with some examples. Score 1

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.

INSTRUCTOR FEEDBACK: very good. Score 1

Exercise 6

data(iris) ?iris iris
Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa 7 4.6 3.4 1.4 0.3 setosa 8 5.0 3.4 1.5 0.2 setosa 9 4.4 2.9 1.4 0.2 setosa 10 4.9 3.1 1.5 0.1 setosa 11 5.4 3.7 1.5 0.2 setosa 12 4.8 3.4 1.6 0.2 setosa 13 4.8 3.0 1.4 0.1 setosa 14 4.3 3.0 1.1 0.1 setosa 15 5.8 4.0 1.2 0.2 setosa 16 5.7 4.4 1.5 0.4 setosa 17 5.4 3.9 1.3 0.4 setosa 18 5.1 3.5 1.4 0.3 setosa 19 5.7 3.8 1.7 0.3 setosa 20 5.1 3.8 1.5 0.3 setosa 21 5.4 3.4 1.7 0.2 setosa 22 5.1 3.7 1.5 0.4 setosa 23 4.6 3.6 1.0 0.2 setosa 24 5.1 3.3 1.7 0.5 setosa 25 4.8 3.4 1.9 0.2 setosa 26 5.0 3.0 1.6 0.2 setosa 27 5.0 3.4 1.6 0.4 setosa 28 5.2 3.5 1.5 0.2 setosa 29 5.2 3.4 1.4 0.2 setosa 30 4.7 3.2 1.6 0.2 setosa â‹® â‹® â‹® â‹® â‹® â‹® 121 6.9 3.2 5.7 2.3 virginica 122 5.6 2.8 4.9 2.0 virginica 123 7.7 2.8 6.7 2.0 virginica 124 6.3 2.7 4.9 1.8 virginica 125 6.7 3.3 5.7 2.1 virginica 126 7.2 3.2 6.0 1.8 virginica 127 6.2 2.8 4.8 1.8 virginica 128 6.1 3.0 4.9 1.8 virginica 129 6.4 2.8 5.6 2.1 virginica 130 7.2 3.0 5.8 1.6 virginica 131 7.4 2.8 6.1 1.9 virginica 132 7.9 3.8 6.4 2.0 virginica 133 6.4 2.8 5.6 2.2 virginica 134 6.3 2.8 5.1 1.5 virginica 135 6.1 2.6 5.6 1.4 virginica 136 7.7 3.0 6.1 2.3 virginica 137 6.3 3.4 5.6 2.4 virginica 138 6.4 3.1 5.5 1.8 virginica 139 6.0 3.0 4.8 1.8 virginica 140 6.9 3.1 5.4 2.1 virginica 141 6.7 3.1 5.6 2.4 virginica 142 6.9 3.1 5.1 2.3 virginica 143 5.8 2.7 5.1 1.9 virginica 144 6.8 3.2 5.9 2.3 virginica 145 6.7 3.3 5.7 2.5 virginica 146 6.7 3.0 5.2 2.3 virginica 147 6.3 2.5 5.0 1.9 virginica 148 6.5 3.0 5.2 2.0 virginica 149 6.2 3.4 5.4 2.3 virginica 150 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

INSTRUCTOR FEEDBACK: Very nice exploration of teh data. Interpretation is missing but good use of graphical parameters. Score 0.75

Exercise 8

data(morley) ?morley morley
Expt Run Speed 001 1 1 850 002 1 2 740 003 1 3 900 004 1 4 1070 005 1 5 930 006 1 6 850 007 1 7 950 008 1 8 980 009 1 9 980 010 1 10 880 011 1 11 1000 012 1 12 980 013 1 13 930 014 1 14 650 015 1 15 760 016 1 16 810 017 1 17 1000 018 1 18 1000 019 1 19 960 020 1 20 960 021 2 1 960 022 2 2 940 023 2 3 960 024 2 4 940 025 2 5 880 026 2 6 800 027 2 7 850 028 2 8 880 029 2 9 900 030 2 10 840 â‹® â‹® â‹® â‹® 71 4 11 910 72 4 12 920 73 4 13 890 74 4 14 860 75 4 15 880 76 4 16 720 77 4 17 840 78 4 18 850 79 4 19 850 80 4 20 780 81 5 1 890 82 5 2 840 83 5 3 780 84 5 4 810 85 5 5 760 86 5 6 810 87 5 7 790 88 5 8 810 89 5 9 820 90 5 10 850 91 5 11 870 92 5 12 870 93 5 13 810 94 5 14 740 95 5 15 810 96 5 16 940 97 5 17 950 98 5 18 800 99 5 19 810 100 5 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)
[1] 1020
quantile(morley$Speed,prob=0.25)[["25%"]] - 1.5*IQR(morley$Speed)
[1] 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)
[1] 85
mean(morley$Speed)
[1] 852.4
sd(morley$Speed)
[1] 79.01055
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 740 900 1070 930 850 950 980 980 880 1000 980 930 650 760 [16] 810 1000 1000 960 960
[1] 1175
[1] 655
25% 850
50% 940
75% 980
[1] 130
[1] 909
[1] 104.926
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 940 960 940 880 800 850 880 900 840 830 790 810 880 880 830 800 790 760 [20] 800
[1] 1012.5
[1] 672.5
25% 800
50% 845
75% 885
[1] 85
[1] 856
[1] 61.16414
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 810 810 820 800 770 760 740 750 760 910 920 890 860 880 720 840 850 850 [20] 780
[1] 1011.25
[1] 621.25
25% 767.5
50% 815
75% 865
[1] 97.5
[1] 820.5
[1] 60.04165
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 840 780 810 760 810 790 810 820 850 870 870 810 740 810 940 950 800 810 [20] 870
[1] 963.75
[1] 713.75
25% 807.5
50% 810
75% 870
[1] 62.5
[1] 831.5
[1] 54.21934

INSTRUCTOR FEEDBACK: Very good data. You could organise the data in a table to make it more readable. See solution for reference Score 1

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

INSTRUCTOR FEEDBACK: Good use of teh graphical parameters. You could have used par(mfrow..) to create subplots.Score 1

Exercise 11

rnorm(morley$Speed)
[1] -1.329838398 -0.442650500 1.624173900 -1.675844489 -1.226066926 [6] -1.192886173 -1.898310592 -0.715139089 1.074564870 1.383971308 [11] -0.594388635 -1.158023469 -1.518395430 0.974198551 -0.955640120 [16] 0.894749513 1.722584608 0.612603627 1.410001940 -0.092323147 [21] -1.191372736 -0.090161586 0.198453244 0.761999372 0.273573215 [26] 0.079302824 -0.903510855 -0.230321582 -0.001180156 -1.270146885 [31] -0.767412118 -0.827985225 -0.328776094 2.150439104 1.061809597 [36] 0.488887253 -0.074941805 2.355580442 -0.443076175 1.086939743 [41] 1.446321305 0.367796447 0.024154806 -0.828092893 0.790879343 [46] 0.586053077 -1.603397512 0.481270773 -0.121348176 -0.393060711 [51] 2.436081409 1.834706347 -2.263231209 -0.099380842 -0.173495820 [56] -0.759511800 -1.292392015 1.332204494 -0.409402932 1.220061696 [61] 1.067586463 -1.373028246 -0.299992927 -0.254254006 0.453610218 [66] -1.231594223 0.932072541 0.250752013 0.536277896 1.193095168 [71] -1.664675052 0.667111423 -1.049428831 -2.193462902 -1.804967739 [76] -0.985561800 1.397459869 -0.886809714 1.578359962 0.808882416 [81] 0.519870065 1.321230188 0.978514838 -0.037514536 -0.658181239 [86] -0.212091917 0.117860816 -1.394738954 -0.618698185 -0.560472913 [91] -0.399376179 0.016728096 1.197445916 -0.056960878 0.617217164 [96] 0.318102255 0.139614057 -0.736671159 -1.314461900 0.194511032
?rnorm()
runif(morley$Speed)
[1] 0.264518806 0.582811257 0.420629782 0.537996992 0.754302131 0.092201812 [7] 0.681373225 0.798066514 0.232842233 0.641004926 0.244015408 0.570152970 [13] 0.811254310 0.798563711 0.249695920 0.136332410 0.047426811 0.288467478 [19] 0.385370009 0.996502696 0.183566161 0.672800718 0.064398487 0.620991089 [25] 0.834634169 0.253943307 0.967401105 0.520939820 0.620963342 0.437164881 [31] 0.800008459 0.784856268 0.753692884 0.206868261 0.470573495 0.514903036 [37] 0.713916169 0.085548991 0.208472222 0.555995154 0.863345835 0.423687195 [43] 0.476202831 0.407577889 0.495625209 0.075463597 0.339054283 0.200695815 [49] 0.006228795 0.787927633 0.951467270 0.918116617 0.627712194 0.727811112 [55] 0.243230506 0.678512015 0.717459577 0.764501367 0.528164511 0.602822620 [61] 0.926245341 0.722419351 0.348279399 0.649060262 0.326362984 0.155253336 [67] 0.140495303 0.349665948 0.570156268 0.649660610 0.454423485 0.866482873 [73] 0.401366396 0.187020025 0.869719553 0.252253205 0.791618790 0.003827188 [79] 0.218274709 0.190541618 0.859617993 0.492092164 0.306638537 0.786544287 [85] 0.958500771 0.163091870 0.700145638 0.471447916 0.314486169 0.596971365 [91] 0.306181582 0.522562241 0.919712348 0.187213699 0.057803800 0.025417467 [97] 0.427565332 0.278308807 0.911951158 0.794001729
rbinom(morley$Speed)
Error in rbinom(morley$Speed): argument "size" is missing, with no default Traceback: 1. rbinom(morley$Speed)

INSTRUCTOR FEEDBACK: When you want to store the data use assignment to ojects. In this case you used the correct commands but did not complete the exercise. score 0.5

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.

PEER-MARK = 10.75

  • Again you've done a very good job and only really dropped marks on clarity, and the fact that you got the title wrong on one of the experiments for historgram graphs on exercise 10, aside from that, good job.

INSTRUCTOR FEEDBACK: Score 10.75