Probability with R. Jane M. Horgan

Probability with R - Jane M. Horgan


Скачать книгу
this and alerts us to the possibility of an error.

      To compare the performance of females and males in Architecture in Semester 1, write

      gender <- factor(gender, levels = c("f", "m"), labels = c("Female", "Male"))

      which changes the labels from “f ” and “m” to “Female” and “Male,” respectively. Then

      boxplot(arch1∼gender, ylab = "Marks (%)", main = "Architecture Semester 1", font.main = 1)

c03f006

      Notice the effect of using main = "Architecture Semester 1" that puts the title on the diagram. Also, the use of font.main = 1 ensures that the main title is in plain font.

      We can display plots as a matrix using the par function: par(mfrow = c(2,2)) causes the outputs to be displayed in a images array.

      par(mfrow = c(2,2)) boxplot(arch1∼gender, main = "Architecture Semester 1", font.main = 1) boxplot(arch2∼gender, main = "Architecture Semester 2", font.main = 1) boxplot(prog1∼gender, main = "Programming Semester 1", font.main = 1) boxplot(prog2∼gender, main = "Programming Semester 2", font.main = 1)

c03f007

      To undo a matrix‐type output, write

      par(mfrow = c(1,1))

      which restores the graphics output to the full screen.

      A histogram is a graphical display of frequencies in categories of a variable and is the traditional way of examining the “shape” of the data.

      hist(prog1, xlab ="Marks (%)", main = "Programming Semester 1")

c03f008

      hist(prog1, xlab = "Marks (%)", main = "Programming Semester 1", breaks = 5)

c03f009

      par (mfrow = c(2,2)) hist(arch1, xlab = "Architecture", main = "Semester 1", 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)


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