Chapter 8 Loops. For Loop >Executes a block of statements a specified number of times. Form: for loop variable=first:incr:last statements end.

Slides:



Advertisements
Similar presentations
While loops.
Advertisements

AP Statistics.  Least Squares regression is a way of finding a line that summarizes the relationship between two variables.
Probabilistic & Statistical Techniques Eng. Tamer Eshtawi First Semester Eng. Tamer Eshtawi First Semester
Correlation and Regression
Definition  Regression Model  Regression Equation Y i =  0 +  1 X i ^ Given a collection of paired data, the regression equation algebraically describes.
Simple Linear Regression
The Best-Fit Line Linear Regression. PGCC CHM 103 Sinex How do you determine the best-fit line through data points? x-variable y-variable Fortunately.
LINEAR REGRESSION: What it Is and How it Works Overview What is Bivariate Linear Regression? The Regression Equation How It’s Based on r.
LINEAR REGRESSION: What it Is and How it Works. Overview What is Bivariate Linear Regression? The Regression Equation How It’s Based on r.
Lecture 5 Review Programming Program Structures Comparison Repetition: looping or iteration Conditional execution: branching Bubble Sort.
Lecture 5 Curve fitting by iterative approaches MARINE QB III MARINE QB III Modelling Aquatic Rates In Natural Ecosystems BIOL471 © 2001 School of Biological.
Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
REGRESSION Predict future scores on Y based on measured scores on X Predictions are based on a correlation from a sample where both X and Y were measured.
X = =2.67.
Least Squares Regression
Loops are MATLAB constructs that permit us to execute a sequence of statements more than once. There are two basic forms of loop constructs: i. while.
Chapters 8, 9, 10 Least Squares Regression Line Fitting a Line to Bivariate Data.
Linear Regression.
Chapter 1 Functions and Linear Models Sections 1.3 and 1.4.
Relationship of two variables
Statistics for Business and Economics 8 th Edition Chapter 11 Simple Regression Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall Ch.
Chapter 14: Generating Data with Do Loops OBJECTIVES Understand iterative DO loops. Construct a DO loop to perform repetitive calculations Use DO loops.
Mr. Huynh.  A linear equation can contain many parts such as this one: y = 2 x + 6. What does this all mean? To break it down, we must look at the initial.
Managerial Economics Demand Estimation. Scatter Diagram Regression Analysis.
Section 5.2: Linear Regression: Fitting a Line to Bivariate Data.
Chapter 3 Section 3.1 Examining Relationships. Continue to ask the preliminary questions familiar from Chapter 1 and 2 What individuals do the data describe?
Chapter 20 Linear Regression. What if… We believe that an important relation between two measures exists? For example, we ask 5 people about their salary.
Y=a+bx Sum of squares of errors Linear Regression: Method of Least Squares The Method of Least Squares is a procedure to determine the best fit line to.
Sullivan – Fundamentals of Statistics – 2 nd Edition – Chapter 4 Section 2 – Slide 1 of 20 Chapter 4 Section 2 Least-Squares Regression.
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
STA291 Statistical Methods Lecture LINEar Association o r measures “closeness” of data to the “best” line. What line is that? And best in what terms.
Matlab Programming for Engineers
Least Squares Regression.   If we have two variables X and Y, we often would like to model the relation as a line  Draw a line through the scatter.
Economics 173 Business Statistics Lecture 10 Fall, 2001 Professor J. Petry
^ y = a + bx Stats Chapter 5 - Least Squares Regression
1 Simple Linear Regression and Correlation Least Squares Method The Model Estimating the Coefficients EXAMPLE 1: USED CAR SALES.
Section 1.6 Fitting Linear Functions to Data. Consider the set of points {(3,1), (4,3), (6,6), (8,12)} Plot these points on a graph –This is called a.
V. Rouillard  Introduction to measurement and statistical analysis CURVE FITTING In graphical form, drawing a line (curve) of best fit through.
3.2 - Residuals and Least Squares Regression Line.
Copyright © 2013, 2010 and 2007 Pearson Education, Inc. Chapter Describing the Relation between Two Variables 4.
Method 3: Least squares regression. Another method for finding the equation of a straight line which is fitted to data is known as the method of least-squares.
Chapter 5 Lesson 5.2 Summarizing Bivariate Data 5.2: LSRL.
Chapters 8 Linear Regression. Correlation and Regression Correlation = linear relationship between two variables. Summarize relationship with line. Called.
OLS Regression What is it? Closely allied with correlation – interested in the strength of the linear relationship between two variables One variable is.
Chapter 14 Introduction to Regression Analysis. Objectives Regression Analysis Uses of Regression Analysis Method of Least Squares Difference between.
AP STATISTICS LESSON 3 – 3 (DAY 2) The role of r 2 in regression.
Copyright © 2015 McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
Chapter 5: Looping. Using the while Loop Loop – A structure that allows repeated execution of a block of statements Loop body – A block of statements.
4.2 – Linear Regression and the Coefficient of Determination Sometimes we will need an exact equation for the line of best fit. Vocabulary Least-Squares.
Describing Bivariate Relationships. Bivariate Relationships When exploring/describing a bivariate (x,y) relationship: Determine the Explanatory and Response.
Least Square Regression Line. Line of Best Fit Our objective is to fit a line in the scatterplot that fits the data the best As just seen, the best fit.
Linear Regression:. The relationship between two variables (e.g. height and weight; age and IQ) can be described graphically with a scatterplot : shortmediumlong.
The simple linear regression model and parameter estimation
LEAST – SQUARES REGRESSION
Linear Regression Special Topics.
CHAPTER 3 Describing Relationships
Ch 7: JavaScript Control Statements I.
CHM 103 Sinex The Best-Fit Line Linear Regression.
Data Analysis and Statistical Software I ( ) Quarter: Autumn 02/03
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Lecture 4 MATLAB programming (2)
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
© 2016 Pearson Education, Ltd. All rights reserved.
Chapter 5 LSRL.
Least-Squares Regression
Lesson 2.2 Linear Regression.
Lesson 2.2 Linear Regression.
Warm up 21 1.) Determine the slope and y intercept of the line y=7x ) Determine the slope and the yintercept of the line 7x- 4y=3 3.) Graph y=1/2.
Presentation transcript:

Chapter 8 Loops

For Loop >Executes a block of statements a specified number of times. Form: for loop variable=first:incr:last statements end

For Loop Example Calculate the factorials for positive values of n. n! = n * (n-1)*…* 3 * 2 *1 0! = 1

For Loop Example Design code that will read in a set of measurements (data) and calculate the mean & standard deviation of the input data set.

While Loop >Executes a block of statements indefinitely as long as some condition is satisfied. Form: while logical expression statements end

Example While Loop >>x=5; >>while x > Disp(x) >> x=2*x – 1; >>end

Example While Loop >>k=1; b=-2; x= -1; y=-2; >>while k > k, b, x, y >> y=x^2 – 3; >> if y > b=y; >> end >> x=x+1; >> k=k+1; >>end

 While Loop Example Design code that will read in a set of measurements (data) and calculate the mean & standard deviation of the input data set.

While Loop Example Use a While Loop to determine how long it will take to accumulate $1,000,000 in a bank account if you deposit $10,000 initially and $10,000 at the end of each year. Assume 6% annual interest.

Loop Control Statements > Break Terminates execution of the loop. Control goes to end. > Continue Terminates only the current iteration. Control goes to the top of the loop.

Example Break for k = 1:10 x=50 – k^2; if x < 0 break end y=sqrt(x) end

Example Continue x= [10, 1000, -10, 100] y=NaN*x; for k=1:length(x) if x(k) < 0 continue end y(k)=log10(x(k)); end y

Regression Analysis Investigation of the relationship between two or more variables related in a non-deterministic fashion.

Least Squares Method The best fit is the one that minimizes the sum of the squares of the vertical differences between the line and the data points.

Least Squares Method Calculations Slope: a = (  xy) – (  x)y (  x 2 ) – (  x)x y-intercept: b = y – a x

Least-Squares Example Write a program that will calculate the least-squares slope and y-axis intercept for a given set of noisy measured data points(x,y). The data points can be read from the keyboard.