graddegrees<-read.file("/home/emesekennedy/Data/Ch1/graddegrees.txt")
## Reading data with read.table()
View the name of the variables in the data:
names(graddegrees)
## [1] "Degree" "PercentFemale"
Box plot of the chicken weight data grouped by the different diets:
bwplot(feed~weight,data=chickwts)
Create a data set with grades:
grades<-c(60, 65, 75, 80)
Look at the deviations from the mean:
grades-mean(grades)
## [1] -10 -5 5 10
Verify that the sum of the deviations from the mean is zero:
sum(grades-mean(grades))
## [1] 0
Find the standard deviation using the command sd() and the the favstats() command:
sd(grades)
## [1] 9.128709
favstats(grades)
## min Q1 median Q3 max mean sd n missing
## 60 63.75 70 76.25 80 70 9.128709 4 0
Transform the grades using a linear transformation:
newgrades<-1.1*grades+5
Look at the mean for of both the original and the new grades:
mean(grades)
## [1] 70
mean(newgrades)
## [1] 82
Verify that we can get the mean of the new grades by applying the same linear transformation to the mean of the original grades:
1.1*mean(grades)+5
## [1] 82
Save the statistics for both the original grades and the new grades:
stats<-favstats(grades)
newstats<-favstats(newgrades)
Compute the IQR for both the original grades and the new grades:
IQR<-stats[1,4]-stats[1,2]
IQR
## [1] 12.5
newIQR<-newstats[1,4]-newstats[1,2]
newIQR
## [1] 13.75
Verify that 1.1 times the IQR of the original grades gives the IQR of the new grades:
IQR*1.1
## [1] 13.75
Load and create a histogram of the timetostart24 data with a density curve:
time24<-read.file("/home/emesekennedy/Data/Ch1/timetostart24.txt")
## Reading data with read.table()
histogram(~TimeToStart,data=time24,density=T)
Note: the vertical axis for the histogram must be densities (i.e. type=“density”). This is the default option, which is why we did not have to specify the type.
Load a new data set that is formatted a little differently than our previous data sets:
state<-read.file("/home/emesekennedy/Data/Ch1/collegebystate.txt",sep="\t",header=T)
## Reading data with read.table()
Create a histogram with a density curve showing the distribution of Undergraduate students in the USA by states:
histogram(~Undergrads,data=state,density=T)
As both the histogram and the density curve shows, the data is skewed to the right.
Graph a Normal curve centered at 3, with standard deviation 4, and shade the area under the curve until the value 2:
xpnorm(2,mean=3,sd=4)
##
## If X ~ N(3,4), then
##
## P(X <= 2) = P(Z <= -0.25) = 0.4013
## P(X > 2) = P(Z > -0.25) = 0.5987
## [1] 0.4012937
Graph a Normal curve centered at 3, with standard deviation 4, and shade 90% of the area under the curve:
xqnorm(0.9, mean=3,sd=4)
## P(X <= 8.1262062621784) = 0.9
## P(X > 8.1262062621784) = 0.1
## [1] 8.126206
Graph a Normal curve centered at 0, with standard deviation 5, and shade 10% of the area under the curve:
xqnorm(0.1, mean=0,sd=5)
## P(X <= -6.407757827723) = 0.1
## P(X > -6.407757827723) = 0.9
## [1] -6.407758