Probability with R. Jane M. Horgan

Чтение книги онлайн.

Читать онлайн книгу Probability with R - Jane M. Horgan страница 23

Probability with R - Jane M. Horgan

Скачать книгу

ylim = c(0, 35)) hist(arch2, xlab = "Architecture", main = "Semester 2", ylim = c(0, 35)) hist(prog1, xlab = "Programming", main = " ", ylim = c(0, 35)) hist(prog2, xlab = "Programming", main = " ", ylim = c(0, 35))

c03f010

      bins <- c(0, 40, 60, 80, 100)hist(prog1, xlab ="Marks (%)", main = "Programming Semester 1", breaks = bins)

c03f011

      In Fig. 3.11, observe that the images‐axis now represents the density. When the bins are not of equal length, R returns a normalized histogram, so that its total area is equal to one.

      To get a histogram of percentages, write in R

      h <- hist(prog1, plot = FALSE, breaks = 5) #this postpones the plot display h$density <- h$counts/sum(h$counts)*100 #this calculates percentages plot(h, xlab = "Marks (%)", freq = FALSE, ylab = "Percentage", main = "Programming Semester 1")

c03f012

      The marks obtained in Programming in Semester 1 are depicted as a stem and leaf diagram using

      stem(prog1)

       The decimal point is 1 digit(s) to the right of the | 1 | 2344 1 | 59 2 | 11 2 | 5556777889999 3 | 0113 3 | 6 4 | 00000000 4 | 6779 5 | 12223344 5 | 56679 6 | 0011123444 6 | 566777888999 7 | 0112344 7 | 5666666899 8 | 001112222334 8 | 5678899 9 | 0122 9 | 7778

      From Fig. 3.13, we are able to see the individual observations, as well as the shape of the data as a whole. Notice that there are many marks of exactly 40, whereas just one student obtains a mark between 35 and 40. One wonders if this has anything to do with the fact that 40 is a pass, and that the examiner has been generous to borderline students. This point would go unnoticed with a histogram.

      Plots of data are useful to investigate relationships between variables. To examine, for example, the relationship between the performance of students in Programming in Semesters 1 and 2, we could write

      plot(prog1, prog2, xlab = "Programming Semester 1", ylab = "Programming Semester 2")

c03f014

      To do this, first create a data frame of all the variables that you want to compare.

      courses <- results[2:5]

      This creates a data frame images containing the second to the fifth variables in images, that is, images and images. Writing

      pairs(courses)

      or equivalently

      pairs(results[2:5])

c03f015
Function

      In the case of the Programming subjects, we have a set of points (images, images), and having established, from the scatter plot, that a linear trend exists, we attempt to fit a line that best fits the

Скачать книгу