linear models homework 1 patr1. · 2019-10-02 · linear models homework 1 patr1. expand current...

9
Linear Models Homework 1 patr1. Expand Current expenditure per pupil in average daily attendance in public elementary and secondary schools,1994-1995(in thousands of dollars) ratio Average pupil/teacher ratio in public elementary and secondary schools ,Fall 1994 salary Estimated average annual salary of teachers in public elementary and secondary schools,1994-1995(in thousands of dollars) takers Percentage of all eligible students taking the SAT,1994- 1995 verbal Average verbal SAT score,1994-1995 math Average math SAT score,1994-1995 total Average total score on the SAT,1994-1995 >sat_data=read.table("http://www.stat.nthu.edu.tw/~swcheng/Teaching/ stat5410/data/sat_data.txt") > head(sat_data) (1) 50 7 50 SAT SAT ( ) (2) takers verbal math total NTHU STAT 5410, 2019 Solution to Homework 1 made by 邱奕豪, 黃俊閔 助教

Upload: others

Post on 14-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Linear Models Homework 1 patr1. · 2019-10-02 · Linear Models Homework 1 patr1. Expand Current expenditure per pupil in average daily attendance in public elementary and secondary

Linear Models Homework 1

patr1.

Expand

Current expenditure per pupil in average daily

attendance in public elementary and secondary

schools,1994-1995(in thousands of dollars)

ratio Average pupil/teacher ratio in public elementary and

secondary schools ,Fall 1994

salary

Estimated average annual salary of teachers in public

elementary and secondary schools,1994-1995(in thousands

of dollars)

takers Percentage of all eligible students taking the SAT,1994-

1995

verbal Average verbal SAT score,1994-1995

math Average math SAT score,1994-1995

total Average total score on the SAT,1994-1995

>sat_data=read.table("http://www.stat.nthu.edu.tw/~swcheng/Teaching/

stat5410/data/sat_data.txt")

> head(sat_data)

(1) 50 7 50

SAT SAT ( )

(2) takers verbal math

total

NTHU STAT 5410, 2019 Solution to Homework 1

made by 邱奕豪, 黃俊閔 助教

Page 2: Linear Models Homework 1 patr1. · 2019-10-02 · Linear Models Homework 1 patr1. Expand Current expenditure per pupil in average daily attendance in public elementary and secondary

:

> summary(sat_data)

:

(1) takers SAT

(2) SAT (verbal math total)

(3)

:

> par(mfrow=c(2,4))

> for(i in 1:ncol(sat_data)){

+ boxplot(sat_data[,i],main=names(sat_data)[i])

+ abline(h=apply(sat_data,2,mean)[i],col="red")

+ }

NTHU STAT 5410, 2019 Solution to Homework 1

made by 邱奕豪, 黃俊閔 助教

Page 3: Linear Models Homework 1 patr1. · 2019-10-02 · Linear Models Homework 1 patr1. Expand Current expenditure per pupil in average daily attendance in public elementary and secondary

> findoutlier = function(x){

+ row.names(sat_data)[x>quantile(x, probs=0.75) + 1.5*IQR(x) | x<qua

ntile(x, probs=0.25) - 1.5*IQR(x)]

+ }

> findoutlier(sat_data$expend)

[1] "Alaska" "Connecticut" "New_Jersey" "New_York"

> findoutlier(sat_data$ratio)

[1] "California" "Utah"

> findoutlier(sat_data$salary)

[1] "Connecticut"

:

(1) expand ratio salary

: , :

IQR : ( - )

[Q1-1.5 IQR , Q3+1.5 IQR]

expand Alaska Connecticut New_Jersey New_York

Ratio California Utah

Salary Connecticut

(2) expand ratio

(3) salary takers verbal math total

NTHU STAT 5410, 2019 Solution to Homework 1

made by 邱奕豪, 黃俊閔 助教

Page 4: Linear Models Homework 1 patr1. · 2019-10-02 · Linear Models Homework 1 patr1. Expand Current expenditure per pupil in average daily attendance in public elementary and secondary

:

> for(i in 1:ncol(sat_data)){

+ hist(sat_data[,i],main=names(sat_data)[i],prob=T)

+ lines(density(sat_data[,i]))

+ }

:

(1) takers verbal math total

(2) expand ratio salary

NTHU STAT 5410, 2019 Solution to Homework 1

made by 邱奕豪, 黃俊閔 助教

Page 5: Linear Models Homework 1 patr1. · 2019-10-02 · Linear Models Homework 1 patr1. Expand Current expenditure per pupil in average daily attendance in public elementary and secondary

( correlation) :

> pairs(sat_data)

> M=cor(sat_data)

> library(corrplot)

> corrplot(M, method = "shade")

NTHU STAT 5410, 2019 Solution to Homework 1

made by 邱奕豪, 黃俊閔 助教

Page 6: Linear Models Homework 1 patr1. · 2019-10-02 · Linear Models Homework 1 patr1. Expand Current expenditure per pupil in average daily attendance in public elementary and secondary

:

(1) expand verbal math total expand

SAT ( )

(2) SAT

(3)

(4) SAT SAT

(5)

(6) ratio verbal math total 0.1

(7) verbal math total

verbal SAT math SAT SAT

total = math + verbal math verbal total

Math verbal

NTHU STAT 5410, 2019 Solution to Homework 1

made by 邱奕豪, 黃俊閔 助教

Page 7: Linear Models Homework 1 patr1. · 2019-10-02 · Linear Models Homework 1 patr1. Expand Current expenditure per pupil in average daily attendance in public elementary and secondary

Part2

Data

> data=read.table("C:/Users/stat_pc/Desktop/linear model/wrinkle.txt

",header = T)

press durable press rating

HCHO formaldehyde concentration

catalyst catalyst ration

temp curing temperature

time curing time

press

HCHO {2,4,5,6,7,8,10} catalyst {1,4,7,10,13}

temp {100,120,140,160,180} time {1,3,5,7}

> par(mfrow=c(1,5))

> hist(data$press,main="press");barplot(table(data$HCHO),main="HCHO

");barplot(table(data$catalyst),main="catalyst")

> barplot(table(data$temp),main="temp");barplot(table(data$time),main

="time")

1. time 1 7

HCHO catalyst temp

NTHU STAT 5410, 2019 Solution to Homework 1

made by 邱奕豪, 黃俊閔 助教

Page 8: Linear Models Homework 1 patr1. · 2019-10-02 · Linear Models Homework 1 patr1. Expand Current expenditure per pupil in average daily attendance in public elementary and secondary

2. press [4.5,5] press 4.5~5

> par(mfrow=c(1,5))

> boxplot(data$press,main="press");boxplot(data$HCHO,main="HCHO")

> boxplot(data$catalyst,main="catalyst");boxplot(data$temp,main="temp

");boxplot(data$time,main="time")

summary(data) boxplot

1. press 50% [4.5,4.9]

2. HCHO catalyst

3. temp 25% temp 180

4. time time

1 7

NTHU STAT 5410, 2019 Solution to Homework 1

made by 邱奕豪, 黃俊閔 助教

Page 9: Linear Models Homework 1 patr1. · 2019-10-02 · Linear Models Homework 1 patr1. Expand Current expenditure per pupil in average daily attendance in public elementary and secondary

> pairs(data)

pairs(data) cor(data)

1. press time

time 1 7 press 2

press time

2. press HCHO temp

3. press catalyst 0.72

catalyst press

4. pairs(data) press

data HCHO catalyst temp time

experimental data

NTHU STAT 5410, 2019 Solution to Homework 1

made by 邱奕豪, 黃俊閔 助教