+ All Categories
Home > Documents > Stats Homework ( R)

Stats Homework ( R)

Date post: 25-Feb-2016
Category:
Upload: barid
View: 52 times
Download: 0 times
Share this document with a friend
Description:
Stats Homework ( R). help(swiss ) Fertility ‘common standardized fertility measure’ Examination % draftees receiving highest mark on army examination Education % education beyond primary school for draftees. Catholic % ‘catholic’ (as opposed to ‘protestant’ ) - PowerPoint PPT Presentation
Popular Tags:
15
Stats Homework (R) • help(swiss) – Fertility • ‘common standardized fertility measure’ – Examination • % draftees receiving highest mark on army examination – Education • % education beyond primary school for draftees. – Catholic • % ‘catholic’ (as opposed to ‘protestant’) • Is there a relationship between education and fertility? – Draw appropriate conclusions – Provide appropriate evidence (plots, stats) • Is there a relationship between education and examination? – Is the relationship the same for Catholic and Protestant provinces? – Provide appropriate evidence (plots, stats)
Transcript
Page 1: Stats  Homework ( R)

Stats Homework (R)• help(swiss)

– Fertility• ‘common standardized fertility measure’

– Examination• % draftees receiving highest mark on army examination

– Education• % education beyond primary school for draftees.

– Catholic• % ‘catholic’ (as opposed to ‘protestant’)

• Is there a relationship between education and fertility?– Draw appropriate conclusions– Provide appropriate evidence (plots, stats)

• Is there a relationship between education and examination?– Is the relationship the same for Catholic and Protestant provinces?– Provide appropriate evidence (plots, stats)

Page 2: Stats  Homework ( R)
Page 3: Stats  Homework ( R)

http://www.nytimes.com/2009/01/07/technology/business-computing/07program.html

Page 4: Stats  Homework ( R)

Plot Example

• help(ldeaths)• plot(mdeaths, col="blue", ylab="Deaths", sub="Male (blue),

Female (pink)", ylim=range(c(mdeaths, fdeaths)))• lines(fdeaths, lwd=3, col="pink")• abline(v=1970:1980, lty=3)• abline(h=seq(0,3000,1000), lty=3, col="red")

Page 5: Stats  Homework ( R)

Periodicity

• plot(1:length(fdeaths), fdeaths, type='l')• lines((1:length(fdeaths))+12, fdeaths, lty=3)

Page 6: Stats  Homework ( R)

Type Argument

par(mfrow=c(2,2))plot(fdeaths, type='p', main="points")plot(fdeaths, type='l', main="lines")plot(fdeaths, type='b', main="b")plot(fdeaths, type='o', main="o")

Page 7: Stats  Homework ( R)

ScatterPlot

• plot(as.vector(mdeaths), as.vector(fdeaths))• g=glm(fdeaths ~ mdeaths)• abline(g)• g$coef

(Intercept) mdeaths -45.2598005 0.4050554

Page 8: Stats  Homework ( R)

Hist & Density

• par(mfrow=c(2,1))• hist(fdeaths/mdeaths,

nclass=30)• plot(density(fdeaths/mdeaths))

Page 9: Stats  Homework ( R)

Data Frames

• help(cars)• names(cars)• summary(cars)• plot(cars)

• cars2 = cars• cars2$speed2 = cars$speed^2• cars2$speed3 = cars$speed^3• summary(cars2)• names(cars2)• plot(cars2)• options(digits=2)• cor(cars2)

Page 10: Stats  Homework ( R)

Normalitypar(mfrow=c(2,1))plot(density(cars$dist/

cars$speed))lines(density(rnorm(1000000,

mean(cars$dist/cars$speed), sqrt(var(cars$dist/ cars$speed)))), col="red")

qqnorm(cars$dist/cars$speed)

abline(mean(cars$dist/cars$speed), sqrt(var(cars$dist/cars$speed)))

Page 11: Stats  Homework ( R)

Stopping Distance Increases Quickly With Speed

• plot(cars$speed, cars$dist/cars$speed)

• boxplot(split(cars$dist/cars$speed, round(cars$speed/10)*10))

Page 12: Stats  Homework ( R)

Quadratic Model of Stopping Distance

plot(cars$speed, cars$dist)cars$speed2 = cars$speed^2g2 = glm(cars$dist ~ cars$speed2)lines(cars$speed, g2$fitted.values)

Page 13: Stats  Homework ( R)

Bowed Residualsg1 = glm(dist ~ poly(speed, 1),

data=cars)g2 = glm(dist ~ poly(speed, 2),

data=cars)par(mfrow=c(1,2))boxplot(split(g1$resid,

round(cars$speed/5))); abline(h=0)

boxplot(split(g2$resid, round(cars$speed/5))); abline(h=0)

Page 14: Stats  Homework ( R)

Help, Demo, Example• demo(graphics)

– example(plot)– example(lines)– help(cars)– help(WWWusage)– example(abline)– example(text)– example(par)

• boxplots– example(boxplot)– help(chickwts)

• demo(plotmath)

• pairs– example(pairs)– help(quakes)– help(airquality)– help(attitude)– Anorexia

• utils::data(anorexia, package="MASS")

• pairs(anorexia, col=c("red", "green", "blue")[anorexia$Treat])

• counting– example(table)– example(quantile)– example(hist)– help(faithful)

Page 15: Stats  Homework ( R)

• Randomness– example(rnorm)– example(rbinom)– example(rt)

• Normality– example(qqnorm)

• Regression– help(cars)– example(glm)– demo(lm.glm)


Recommended