



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Lab 1 STAT 3000
dbinom(3,5,.5) Notice that the first argument issued to the 'dbinom' function is the realization of interest, the second is the number of trials, and the third is the probability of a success. We can check that this is indeed the correct probability by using R and the actual equation of the PDF directly: choose(5,3)(.5^3)((1-.5)^(5-3)) Notice that the 'choose' function calculates combinations for us. If you want or need to compute actual factorials, use the 'factorial' command (rather than the '!' symbol, which will not work).
help(dbinom)
pnorm(9,10,3)-pnorm(7,10,3)
qexp(.75,1/2)
barplot(dbinom(0:5,5,.5),names=0:5,ylab="f(x)", xlab="x") The CDF can be viewed using a similar command: barplot(pbinom(0:5,5,.5),names=0:5,ylab="F(x)", xlab="x")
Now you have created a data frame that contains two components: the data for UU students and the data for USU students. You can access each one separately in a couple of different ways:
weights.df$USU weights.df[,2] The first uses the dollar sign to select a portion of the data frame while the latter uses matrix indices. The advantage in using the matrix indices is that you can identify rows as well as columns. For example, suppose we wanted to view (or use) the third and fourth observations from both samples: weights.df[3:4,1:2] To find the size of the data frame you should use the 'dim' command. This command outputs the number of rows and columns, respectively: dim(weights.df)
min(weights.df$UU) max(weights.df$UU) sum(weights.df$UU) mean(weights.df$UU) var(weights.df$UU) sd(weights.df$UU) median(weights.df$UU) q1=quantile(weights.df$UU,.25) q3=quantile(weights.df$UU,.75) q3-q Typing all of these commands can be tedious if you want to examine several datasets. However, if each variable is stored in the same data frame, some commands can be applied to all elements of the data frame simultaneously. For example, the sample mean and standard deviation work this way:
mean(weights.df) sd(weights.df) Another useful function that will simultaneously provide several sample statistics is the 'summary' function: summary(weights.df)
hist(weights.df$UU) We can also plot several histograms together. To construct a plot containing both histograms from USU and UU students: first define the bins you want to use, and then issue the histogram functions twice (with different options for plot specifics like color and shading): bins=seq(130,200,,8) hist(weights.df$UU,breaks=bins,ylim=c(0,5),col=2, density=10,main="histogram") hist(weights.df$USU,breaks=bins,col=4, angle=-45,density=10,add=TRUE) To create a boxplot from a sample, we use the 'boxplot' function in R: boxplot(weights.df$UU,range=0) Boxplots are excellent tools for graphically viewing numerous samples simultaneously. Consider the side-by-side boxplots for UU and USU student weights: boxplot(weights.df,col=c(2,4),range=0)
Lab Assignment 1 1.) If X is a Poisson random variable with mean 10, find the following probabilities using R (hint: use the 'dpois' and 'ppois' function): a. P(X=12) b. P(X>12) c. € P ( 3 ≤ X < 13 ) 2.) Create a plot of the PMF for a Binomial random variable resulting from 15 trials and with success probability equal to one third. Print out, label, and hand it with your assignment. 3.) Production lines in a manufacturing plant are set to make steel ball bearings with a diameter of 1 micron. Ten ball bearings were randomly selected from two production lines. The diameters of the ball bearings measured in microns were as follows: Line 1 Line 2 1.18 1. 1.42 1. 0.69 1. 0.88 0. 1.62 1. 1.09 0. 1.53 1. 1.02 1. 1.19 1. 1.32 0. a. Use R to calculate and report the following statistics for each line: sample mean, sample median, sample standard deviation, sample IQR. b. Construct side-by-side boxplots using data from the two production lines. c. Pool the data together and use it to construct a single histogram for measured bearing diameters from this plant. Use 'bins=seq(.5,2,,6)'; this will give you 5 bins of equal width between a half micron and 2 microns. d. Estimate the mean bearing size for each of the production lines (separately) with 90% confidence intervals (assume the data are normally distributed). e. Based on answers to the above questions, do you think the mean diameter sizes from the two production lines are significantly different? Explain. f. Construct a 90% confidence interval for the mean bearing size of the plant (like in part c). That is, consider data from both lines as one dataset (consisting of 20 observations). Is this interval narrower or wider than the other two you computed? Why?