# Data description:
#This example comes from a June 96 Consumer Reports article
rating 69 brands of beer. The article gives several pieces of
information about each beer, including price, number of calories,
alcohol content, bitterness, maltyness, a quality rating, a category,
and an indication of where the beer are available (which we'll ignore
for the time being).
The variables (with abbreviated names) are as follows:
price price in dollars
qlty quality rating (0 = worst, 100=best)
N available in Northern US? (1=Yes, 0=No)
E East, see N above
W West, see N above
S South, see N above
cal number of calories per 12 oz serving
alc percent alcohol
bitter bitterness (0=less bitter, 100=most bitter)
malty maltyness (0=less malty, 100=most malty)
class beer category (1,2,3,4,5,6)
1 = craft lager
2 = craft ale
3 = imported lager
4 = regular or ice beer
5 = light beer
6 = nonalcoholic
R code
beer <- read.table(
'http://www.student.math.uwaterloo.ca/~stat441/stat441_09_01/beer.dat'
,head=TRUE,row.names=1)
# head option is for column names, row.names=1 says use first column
# of data for names of the rows.
# type the name of the object to see it displayed on the screen
beer
# you can also see/edit the data in a spreadsheet-like viewer
edit(beer) # for looking only
beer <- edit(beer) # will actually save changes
# make a new variable with the types in no-numeric format
beer$type <- as.factor(
c('c.lager','c.ale','imp.lager','reg','light','nalc')[beer$class])
# basic summaries of each column
summary(beer)
# some graphical summaries
hist(beer$price)
library(lattice) #for histogram and xyplot commands
histogram(~malty|class,data=beer)
plot(beer$price,beer$quality)
plot(beer$malty,beer$bitter)
pairs(beer[,c('price','qlty','malty','bitter')])
pairs(beer[,c('price','qlty','malty','bitter')],col=beer$class,pch=19)
pairs(beer[,c('price','qlty','malty','bitter')],pch=beer$class)
xyplot(bitter~malty | type,data=beer)
coplot(bitter~malty | type,data=beer) # coplot is similar here
coplot(bitter~malty | price,data=beer) # coplot shows bitter vs. malty
# for different slices of "price"
# look at dependence of price on type
stripplot(price~type,data=beer,pch=19)
mylm <- lm(price~qlty+bitter+malty+type,data=beer)
summary(mylm)
Tuesday, April 8, 2008
A sample R session
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment