Top Banner
MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression
18

MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

MATH 3359 Introduction to Mathematical

Modeling

Linear System, Simple Linear Regression

Page 2: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

OutlineLinear System

Solve Linear SystemCompute the Inverse MatrixCompute Eigenvalues and Eigenvectors

Simple Linear RegressionMake scatter plots of the data Fit linear regression modelPrediction

Page 3: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

Linear System3x1 +  x2 – 6x3 = –102 x1 +  x2 – 5 x3 =  –86 x1 – 3 x2 + 3 x3 =  0

In matrix form:

Page 4: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

Function ‘solve’ in R

1. Solve

x = solve ( A, b )

2. Find the inverse matrix

A_inverse = solve ( A )

Page 5: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

Function ‘eigen’ in R

y = eigen ( A, symmetric= TRUE or FALSE,

only.values= TRUE or FALSE )

Eigenvalues: y$val

Eigenvectors: y$vec

Page 6: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

Exercisex1 + 2 x2 + 3 x3 = −5

— x1 + x3 = −3

3 x1 + x2 + 3x3 = −3

1. Solve the linear system

2. Find the inverse of the coefficient matrix

3. Compute the eigenvalues and eigenvectors of the

coefficient matrix

Page 7: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

Given a data set {yi, xi, i=1,…,n} of n observations,

yi is dependent variable, xi is independent variable,

the linear regression model is

or where

Simple Linear Regression

Page 8: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

ExampleAs Earth’s population continues to grow, the solid waste generated by the population grows with it. Governments must plan for disposal and recycling of ever growing amounts of solid waste. Planners can use data from the past to predict future waste generation and plan for enough facilities for disposing of and recycling the waste.

Page 9: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

ExampleAs Earth’s population continues to grow, the solid waste generated by the population grows with it. Governments must plan for disposal and recycling of ever growing amounts of solid waste. Planners can use data from the past to predict future waste generation and plan for enough facilities for disposing of and recycling the waste.

Let 1990 be x=0

01234

Page 10: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

1. Scatter Plots — Function ‘plot’

x=c(0:4)

y=c(19358,19484,20293,21499,23561)

plot ( x, y, main = 'Tons of Solid Waste Generated From 1990 to 1994’, xlab = 'year', ylab = 'Tons of Solid Waste Generated (in thousands)’ , xlim = c(0,4) , ylim = c(19000,25000) )

Page 11: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

1. Scatter Plots — Function ‘plot’

Page 12: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

2. Fit Linear Regression Model

— Function ‘lm’ in Rreg= lm ( formula , data )  

summary ( reg )

In our example,x=c(0:4)y=c(19358,19484,20293,21499,23561)reg=lm(y~x)summary(reg)

Page 13: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

> summary(reg)Call:lm(formula = y ~ x)

Residuals: 1 2 3 4 5 603.2 -312.9 -546.0 -382.1 637.8

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 18754.8 512.4 36.603 4.48e-05 ***x 1042.1 209.2 4.982 0.0155 * ---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 661.5 on 3 degrees of freedomMultiple R-squared: 0.8922, Adjusted R-squared: 0.8562 F-statistic: 24.82 on 1 and 3 DF, p-value: 0.01555

Hence, the function of best fit isy = 1042.1x + 18754.8

Page 14: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

3. Graph the function of best fit with the

scatterplot of the data ——Function ‘abline’

plot ( x, y, main = 'Tons of Solid Waste Generated From 1990 to 1994’, xlab = 'year', ylab = 'Tons of Solid Waste Generated (in thousands)’ , xlim = c(1990,1994) , ylim = c(19000,25000) )

abline(reg)

Page 15: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.
Page 16: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

4. Prediction — Function ‘predict’ in R

predict the average tons of waste in 2000 and 2005:

predict ( reg , data.frame( x=c(10,15) ) )

Result:

1 2

29175.8 34386.3

Page 17: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

Exercise

Education: Average education of occupational incumbents, years, in 1971.Income: Average income of incumbents, dollars, in 1971.Women: Percentage of incumbents who are women.Prestige: Pineo-Porter prestige score for occupation, from a social survey conducted in the mid-1960s.Census: Canadian Census occupational code.Type: Type of occupation. A factor with levels (note: out of order): bc, Blue Collar; prof, Professional, Managerial, and Technical; wc, White Collar.

Page 18: MATH 3359 Introduction to Mathematical Modeling Linear System, Simple Linear Regression.

ExerciseImport data:

library (car)

View ( Prestige )

education=Prestige$education

prestige=Prestige$prestige

Make a scatterplot of the data, letting x represent the education and y represent the prestige.

Find the line that best fit the above measurements.

Graph the function of best fit with the scatterplot of the data.

With the function found in part 2, predict the average prestige when education=16 and 17.