1. Home
  2. Explore
  3. Engineering
  4. Regression Models & Hypothesis Testing

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Regression Models & Hypothesis Testing

Transcript

- Hi, welcome back to the next steps of your journey as a data professional. I'm so excited to join you. We'll be discussing regression models and more hypothesis testing so that you can explore the relationships in your data. The tools we learn about together will allow you to uncover powerful insights about your data, tell compelling stories, and influence decisions and strategy-making. The modeling fundamentals we explore in this course will give you an even stronger foundation to pursue entry-level jobs in the data career space and to tackle more advanced topics in the future, like machine learning. I'm eager for us to connect all the pieces you've learned so far. You've come a long way since the start of your data journey, from the foundations of data science and Python fundamentals to exploratory data analysis and statistics, you've learned so much about the data landscape. Together we'll be applying your current skills to your first model, regressions.

My name is Tiffany. I'm a marketing science lead, and I work at the intersection of data science and marketing here at Google. As a child, I gravitated towards math, probably because it was my favorite subject. When I got to college, I was not exactly sure what I wanted to major in, but I was drawn towards quantitative fields. As many of you may have also experienced, I didn't love my first decision and had the opportunity to try out a few majors, exposing me to the variety of analytical career opportunities. Fast forward to my career, I've held positions in finance, statistical research, and data science consulting before joining Google. I've worked with a variety of data including patent, fraud, hardware sales and now marketing data. The great thing about being a data professional is that it's in high demand in most industries, which means that you can find interesting problems to solve across a huge variety of companies, products and countries.

I love the flexibility to find the right fit for me while also knowing that I will be able to deliver value to whatever team I'm on. I've learned so much in my career, and I'm excited to share my experience with you. In this course, we will talk about modeling relationships between variables. To do this, we will focus on regression analysis. Regression analysis or regression models are a group of statistical techniques that use existing data to estimate the relationship between a single dependent variable and one or more independent variables. We will unpack this definition together later in this program. The techniques we learn in this course will help you answer any number of questions with actionable steps to achieve your organization's goals. For example, regression models can help you understand what variables impact sales. They can also help you understand the factors that lead a customer to subscribe to a newsletter.

Regression models can even help you understand why a user keeps scrolling on a company's website. As we work through the course together, we'll continue discussing the role data professionals play in making responsible decisions, from data handling to modeling. No matter how good a potential data story is, how we arrive at our story is the priority in being honest and effective storytellers. Python programming will be critical to running and testing complex models, visualizing data and communicating results. Rigorous exploratory data analysis, or EDA, will inform which models we choose and how we approach the modeling process. Statistics will play a major role in helping us understand how our models work and will allow us to present actionable results to stakeholders. Our statistics toolkit will allow us to build the models we talk about. Regression analysis is a relevant and marketable skill. Regression models are flexible,

so you can design them based on the data that you have. Additionally, regression model results offer opportunities for interpretation and communication. Data professionals can provide insights from these models that align clearly with actionable steps. For example, we're able to build regression models to identify what actions on a website are indicative of high value customers. For instance, there is a high likelihood that customers who visit the sale page, watch a video or sign up for emails

are customers who will make multiple purchases in a year. Some of these indicators may seem obvious, but having a regression analysis that identifies and quantifies the relationship is powerful. We're able to use the information in marketing campaigns to attract new customers. Together, we'll be exploring regression analysis as the basis of a solid foundation for building more complex machine learning models. I'm so excited to show you each of the tools in your regression toolkit. You'll get a lot of practice in Python. We'll explain how to determine if a model is appropriate for the data, how to run the model, and how to understand the computer's results. We're also going to discuss some math and review the concept step-by-step the whole time. You can also review course resources whenever you want. I'm so excited to get started on regressions. So let's begin.

I can't wait to explore regression analysis with you. Together, we'll learn how data professionals go from a problem to actionable insights using regression analysis techniques. We'll begin by introducing regression analysis. The focus for regression analysis is about understanding relationships between variables. We'll use the PACE framework, plan, analyze, construct and execute, to guide us through the rest of the course. Next, you'll have the chance to apply PACE to simple linear regression,

which will be our first model we explore comprehensively. We'll go over the entire process from beginning to end using different scenarios and data. Then we'll examine multiple linear regression closely. Multiple linear regression expands upon a lot of the concepts from simple linear regression but will allow us to problem solve a larger variety of questions. We will focus on some more nuanced topics, like variable selection and model interpretation. We'll also consider a few hypothesis tests, such as chi-squared test and ANOVA. These tests will help us explore different groups in the data, allowing us to glean interesting insights. Finally, we will review the fundamentals of logistic regression. This is the last and most complex model, which will set you up well to approach the rest of the program on machine learning. Whenever you're ready, I'm excited to get started on the next video.

You may be familiar with terms like machine learning models or regression analysis, and if not, you're in the right program. Next up, we'll get started on our learning journey. To begin, we're going to discuss a few key terms and definitions. Regression models are based on a statistical foundation. Models used in the data career space are a family of techniques that rely on existing information or data points to inform what we might think other data points will look like. The goal is always to tell a story about the relationships between the variables and the data. The story will help stakeholders adjust their business strategy and decisions. Modeling follows an iterative process. You may be familiar with other frameworks such as the data lifecycle or the six steps of exploratory data analysis. In this course, we will cover each step of the modeling process using PACE. Outlined earlier in this program, PACE, plan, analyze, construct and execute,

provides us with the foundation for conducting regression analysis. Let's take some time to preview how PACE works in the context of regression analysis. In regression modeling, the plan stage is about understanding your data in the problem context. Knowledge you bring, whether from industry or others, can be instrumental in the plan stage. By considering what data you have access to, how the data was collected and what the business needs are, you'll be able to strategically analyze, construct and execute the rest of your work. The plan stage will guide the other three stages of PACE. After you plan, you have to analyze. In this stage, you examine your data more closely so you can choose a model or a couple of models you think might be appropriate. When working with regression analysis, this is where you use Python to perform EDA and check the model assumptions as needed. Model assumptions are statements about the data that must be true

to justify the use of particular data techniques. As a data professional, you'll use statistics to check whether model assumptions are met. A good understanding of statistics gives data professionals the power to construct meaningful models. After you analyze, you must construct. For regression analysis, this is where you actually build the model in Python or your coding language of choice. This step involves selecting variables, transforming the data as needed and writing code. Even though you checked model assumptions before you built the model, many model assumptions need to be rechecked after the model is built. So you'll do that in the construct phase as needed. The last part of construct phase is evaluating the model results. At this point, you are answering the questions, how good is my model? You'll choose metrics, compare models, and get preliminary results. Then based on your evaluation, you can use EDA to refine your model accordingly.

Of course, as a data professional, you must first and foremost be an honest storyteller. Studying the results produced by the regression will uncover relationships within your data and help you discover insights to tell the full story. This leads to the last part of PACE, execute. You'll interpret everything you learned from analyzing and constructing to share the story, you'll prepare formal results and visualizations and share them with stakeholders. To do this, you'll convert model statistics

into statements describing the relationship between the variables and the data. These descriptions must consider the context and initial questions from the plan phase. At the center of everything is data, and the PACE framework helps data professionals stay organized. The insides data professionals produce must be data-driven and accurate, and they have to make sense given the business or community context. We'll go over these steps using examples later in the course, but PACE is iterative.

As you grow as a data professional, your experience will help you decide when to pivot between stages of PACE. You might switch the order or repeat steps depending on the situation. Now that we've laid out the pieces of the modeling puzzle, we can talk about how correlation and regression are related. Then we will explore two foundational regression models, linear and logistic regression. These models will be covered in more depth in later videos. This overview will provide you with a solid basis of understanding. Time to start putting together our puzzle. Don't forget your statistical grammar tools. You'll need them.

Previously, we learned that regression analysis is about estimating relationships between a single dependent variable and one or more independent variables. In this video, we will discuss our first modeling technique, linear regression. Many patterns that you've observed in daily life can be expressed using linear regression models, which is pretty cool. For example, as a version of computer software gets older, online searches for that software version may decrease. As a social media personality gains followers, their book sales increase. These relationships can be modeled using a linear regression. The linear in linear regression indicates the kind of relationship we can visualize on a graph, a line. A line is a collection of an infinite number of points extending in two opposite directions. In a graph, the individual points show up as a line, and we only see a portion of the line. Linear regression is a technique that estimates the linear relationship

between a continuous dependent variable Y and one or more independent variables X. For example, we could model the relationship between the prices of a product and the number of sales. Our Y variable would be the number of sales, and our X variable would be the prices. In an earlier course, you learned the difference between continuous and categorical variables. As a reminder, continuous variables are variables that can take on any real value between its minimum and maximum value.

For example, product sales, vehicle speed and time spent on a webpage are all continuous variables. Whereas types of products and educational level are not. These are categorical. Categorical variables have a finite number of possible values. While linear regression allows us as data analytics professionals to estimate continuous dependent variables, there are other regression models that let us estimate categorical variables. We'll learn more about those in a later course.

Throughout this course, we'll talk about dependent and independent variables. The dependent variable is the variable a given model estimates. Sometimes the dependent variable is also called a response or outcome variable and is commonly represented with the letter Y. We assume that the dependent variable tends to vary based on the values of independent variables, typically represented by an X. Independent variables are also referred to as explanatory variables or predictor variables.

For example, let's say you're working at a cake shop, and you're trying to understand the factors that contribute to cake sales. The dependent or Y variable would be the number of cake slices sold on any given day. An independent or X variable could be how many cups of coffee are sold that day. Maybe as more coffee is purchased, more cake is also purchased. In linear regression, you might encounter two more terms, slope and intercept. The slope refers to the amount we expect Y,

the dependent variable, to increase or decrease per one unit increase of X, the independent variable. The intercept is the value of Y, the dependent variable, when X, the independent variable, equals zero. Going back to cake and coffee, the slope would be how many slices of cake are purchased per cup of coffee purchase. The intercept would be the number of cake slices that are sold when zero cups of coffee are sold. When two variables X and Y are related in a linear way,

we say they're correlated. Using statistics, we can actually calculate how strong the linear relationship between X and Y is. Pretty cool. There are two kinds of correlation, positive and negative. Positive correlation is a relationship between two variables that tend to increase or decrease together. For example, as more cups of coffee are purchased, more cake slices are purchased. Negative correlation, on the other hand, is an inverse relationship between two variables.

When one variable increases, the other variable tends to decrease, and the reverse is true too. For example, let's say you're still working at the cake shop and you're estimating how often to refill the iced coffee dispenser. You can model the relationship between iced coffee and hot coffee sales. As hot coffee sales increase, you might notice iced coffee sales tend to decrease. Or perhaps you're working at a media company, and you're analyzing readership.

As the length of new articles increases, the number of people that finish reading the article might decrease. This is also an example of negative correlation. Identifying these kinds of relationships can be incredibly useful in the workplace and in everyday life. Determining linear relationships helps us answer questions such as which factors are associated with an increase or decrease in product sales? Which factors make a social service providers increase resources in a given region?

Which factors lead to more or less demand for public transportation? In the cases mentioned, how big the slope of the regression is tells us how much sales resource allocation and public transportation increase or decrease. Using linear regression, you can help answer similar questions in any industry. However, it is important to note that correlation is not causation. For example, in your cake shop, people buying coffee does not cause cake sales to increase.

When modeling variable relationships, a data scientist must be mindful of the extent of their claims. Causation describes a cause-and-effect relationship where one variable directly causes the other to change in a particular way. Proving causation statistically requires much more rigorous methods and data collection than correlation. For a data professional, the distinction between correlation and causation is especially important when presenting results.

For example, although we can say that as someone gets older, the number of places they have visited tends to rise. We cannot necessarily say that someone's age causes the number of places they have visited to increase. There could be other factors causing you to travel more that coincide with your aging, such as visiting family or traveling more for work. Any of these factors could be correlated to aging, but it's hard to say whether age or other factors are causing the traveling.

Articulating that correlation is not causation is part of a data professional's best practices and ethical toolbox. Both correlational and causal relationships provide useful insights. Regression analysis helps data analytics professionals tell nuanced stories without needing to prove causation. That concludes a high-level overview of your first modeling technique. To recap, linear regression is a way to model linear relationships. Dependent variables vary according to independent variables.

The slope identifies how much the dependent variable changes per one unit change in the independent variable. Positive and negative correlation describe linear relationships between variables. Always be mindful when interpreting regression results. Correlation is not causation. There are lots of linear relationships in the world and in industry. In this video, we've provided just a few examples, but there are plenty more.

That's all for now. Next, we'll address the math behind linear regression. Your ever-growing statistical foundations will help you explain regression results in the clearest way possible. In an ideal world, you would want every data point relevant to the question you are trying to answer. In a previous course, you learned that data professionals describe this as population. Let's imagine you're working for a publishing company. You want to understand the relationship between an author's social media following and their book sales. You would need data on every book author's social media follower account and every book sale of all time. This is an impossible task, but luckily,

you don't actually need an entire population to run meaningful regression analysis. You can get a reasonable estimate with a representative sample. A sample is a part of the population, which is just the statistical way of saying a sample is some of the data you could possibly have. If you have a set of sample data, each data point can be represented with its own set of attributes or X and Y values. In that case, the sample does not contain all possible values from the population of data.

The observed values or actual values are the existing sample of data. Each data point in this sample is represented by an observed value of the dependent variable and an observed value of the independent variable. In the publishing company example, the dependent variable is book sales, and the independent variable is how many followers the author has on social media. An observed value you might have in your dataset would be X or number of followers equals 10,000,

and Y or number of book sales equals 500. The goal of the regression analysis is to define a relationship mathematically between the sample Ys and Xs to understand how the two variables interact. You can imagine that at every X value, there are many possible values that Y could take on. To simplify this understanding, linear regression analysis focuses on the mean of Y given a particular value of X. This mean of Y is the value on the line in a linear regression and is denoted with a Greek letter that looks like a lowercase M. You can remember M is for mean. The Greek symbol is mu.

As described previously, in order to define a linear relationship, we need a slope and an intercept. In statistics, we write the intercept as beta-zero, which we sometimes call beta-naught, and the slope is written as beta-one. Mu of Y and the betas are sometimes called parameters. Parameters are properties of populations and not samples. So we can never know their true value since we can't observe the whole population, but we can calculate estimates of the parameters using our sample data.

To differentiate between the population parameters and the estimates of the parameters, we denote the estimates with a hat. The calculation is beta-zero-hat, beta-one-hat and mu-hat are all parameter estimates. Although it's valuable to recognize the mu notation, for the remainder of this course, we'll use a simplified notation. Y equals beta-zero plus beta-one times X. For example, let's say that we estimate beta-zero as negative one and beta-one as five. Now let's input some values for X.

If X equals zero, we get negative one, which is the Y-intercept or beta-zero. If X equals one, we get Y equals four. If X equals two, we get Y equals nine. If X equals three, we get Y equals 14. From just four data points, a pattern emerges. For every one unit increase in X, we get a five unit increase in Y. Remembering our equation, five is our slope or beta-one. The slope tells us how much Y increases for every one unit increase in X. These estimated betas

are also called regression coefficients. So now whenever you see the hat symbol, you'll know that you are estimating betas, also known as regression coefficients. In the prior formula, the regression coefficients where the slope and intercept. They described the linear relationship found in the sample data. In order to enter values of X and get estimated values for Y, we assumed that beta-zero was negative one and that beta-one was five, but how did we arrive at those regression coefficients?

One of the most common ways to calculate linear regression coefficients is ordinary least squares estimation or OLS for short. We will go over the math behind OLS later in the course. For now though, let's discuss an overview of how OLS works. In linear regression analysis, we as data professionals are trying to minimize something called a loss function. The loss function is a function that measures the distance between the observed values and the model's estimated values.

Theoretically, we could draw an infinite number of lines that model the data we have, but we don't want to find just any line. We wanna find the best-fit line, so we want to minimize the loss function. With this foundational understanding of how linear regression works, we will be able to talk about PACE in linear regression analysis, which readdressed earlier. Later in the course, we'll build on the concepts we covered in the video to learn more about how regression works, when to use linear regression, its variance and OLS and Python.

I still remember being on a sports team needing to determine which team first played offense or defense using a coin toss. What's the chance the coin will come up heads? What's the chance the coin will come up tails? The probability of either event occurring is 0.5 or 50%. This is a classic probability problem, but in the field of data analytics, we get to use a technique called logistic regression to model much more complex probability problems.

For example, what factors lead to someone subscribing or not subscribing to a newsletter? Under what circumstances does someone comment on an online video or social media post? Given certain factors, how likely is it that someone renews their membership to an organization? All of these questions are tackling discreet events or categorical data. There are a specific set of possible outcomes, subscribe or don't subscribe, comment or don't comment, renew or don't renew.

To answer these kinds of questions, data professionals use a model called logistic regression. Logistic regression is a technique that models a categorical variable based on one or more independent variables. The dependent variable can have two or more possible discreet values. Let's say that your company has a newsletter and is interested in increasing readership. On the company website, users have the opportunity to subscribe to the newsletter. One factor related to the newsletter subscription

could be how many minutes the user spends on the webpage before leaving. Our dependent variable Y has two possibilities. Users don't subscribe, which we'll represent with a zero, or users do subscribe, which we'll represent with a one. Our independent variable X is continuous and measures how many minutes the users spend on the webpage before leaving. Let's graph the hypothetical data on a scatter plot like we would when doing EDA or exploratory data analysis. We can observe that the data points

are roughly in two horizontal lines. The higher one indicates the user subscribed. This is when Y equals one. The lower one indicates that the user did not subscribe. This is when Y equals zero. The X-axis indicates how long the user was on the site in minutes. Since the relationship between X and Y is not just a straight line, we need a new mathematical way of expressing the relationship between X and Y. Logistic progression will allow us to model

the probability a user will subscribe to the newsletter. The key concept is that the mean of Y given X is equal to the probability of Y equals one given X. Let's explore this idea. At this point, our observed Y values are just a bunch of zeros and ones. To find the mean, we would sum all of our observations and then divide the total by the number of observations. Because some of the observed data are zeros, when summing the observations, the zeros all add up to zero.

Therefore, the sum of all the observations is equal to the total number of ones. Then we divide by the total number of observations. This is equal to the probability of Y equaling one or someone becoming a subscriber. In this case, we know that the mean of Y given X is equal to the probability of Y equaling a certain outcome given X. Sometimes the probability of Y given X is written as P to reinforce the idea of probability. To help you remember, you can think P is for probability.

Now we want to understand what variables help explain those probabilities. Mathematically, we need a way to relate the X variables to the probability that Y equals one. Imagine we only have one independent variable. So then we need to relate the probability of Y equals one to beta-zero plus beta-one times X. In logistic regression, we use a link function to express the relationship between the Xs and the probability that Y equals some outcome. A link function is a non-linear function

that connects or links the dependent variable to the independent variables, mathematically. We will discuss how logistic regression and link functions work in more detail later on, but for now, just know that this is an example of the differences between linear and logistic regression models. Let's review a few more similarities and differences between modeling approaches. First, linear regression involves a Y that is continuous like book sales.

While logistic regression involves a Y that is categorical like newsletter subscription. Choosing one model over the other is about the kind of data you have. You can answer similar questions about what factors impact an outcome of interest. Secondly, since linear regression models a continuous variable, we're estimating the mean of Y, but logistic regression models a categorical variable. So we're modeling the probability of an outcome. For example, if Y equals one or if Y equals zero.

Lastly, for linear regression, we can express Y directly as a function of X, but for logistic regression, we need a link function to connect the probability of Y with X. We'll continue focusing on logistic regression with just two categories like the subscription problem, but there are more complex version of logistic regression that can model multiple outcomes or categories, such as types of skincare products people buy or types of services that people receive.

In this video, we covered the basics of logistic regression. We also compared and contrasted linear and logistic regression models. Later in this course, we'll cover an estimation technique for logistic regression called maximum likelihood estimation, and we'll uncover a bit more of the math. For now, know that computers are incredibly powerful and enable us as data practitioners to focus less on the math and more on the storytelling. The rest of the course will provide you with a solid understanding so you know what's going on in that powerful machine of yours.

Together, we've covered a lot of high-level regression concepts already. You should be proud of yourself for learning all of these new concepts. It's been incredible starting you off on your regression journey. In prior courses, you learned about the data career space, the importance of communication in data-driven work, considerations for how data is cared for, the value of Python programming as a data tool, EDA and statistics. In this course, we've started connecting these concepts together

to prepare you to build your first models. So far we've talked about PACE in regression analysis. Planning allows you to consider how the data was collected and what the business needs are in a particular instance. In the analyze phase, you perform EDA, which helps you determine whether one model is more suitable than another. When constructing your model, you'll be amazed by the power of your computer and the Python programming language. Through model construction, you'll apply your creativity as you visualize your data and regression models as well. You'll then rely again on statistics and math to evaluate any model you encounter. Finally, in the execute phase, you have to focus on communication as you interpret the results of your model. By combining the four steps of PACE, you'll start creating data-driven stories soon.

We covered two models briefly, linear regression and logistic regression. These models are able to estimate common relationships between variables that we observe in our personal and professional lives. Regression models help us answer questions about what factors are associated with a variable of interest and by how much. The data always leads us to the questions we can ask and answer. Linear regression needs a continuous dependent variable so it can help model anything measurable and quantifiable. Logistic regression needs a categorical dependent variable so it can determine the probability of something occurring. Linear regression focuses on positive correlation, variables that increase or decrease together, or negative correlation. One variable goes up, and the other goes down. Logistic regression models use a link function to relate the Xs and the categorical Y. Later we will learn how to use estimation techniques

in Python with real data, and we'll go through more use-cases of regression. Although you'll encounter many formulas along the way, keep in mind that the end goal is to figure out the story the data is trying to tell. You have many resources available to you in this course. Good luck with the rest of this section and be patient with yourself. I'm thrilled to join you again next time. Welcome back to Google's course on regression models. It's great to be with you again. Previously, we provided a high level overview of regression analysis and two core foundational regression models, linear and logistic regression. In this section of the course, we'll go over how to set up, build, evaluate and interpret our first regression model. We'll also review model assumptions, construction, evaluation and interpretation as we've previously defined. There are a lot of new concepts.

So if you ever need to get reorganized, remember the PACE framework, plan, analyze, construct and execute. Each part of PACE aligns with a part of the process of regression analysis. Sometimes we have to repeat some steps, but these are the phases to keep in mind, and we'll go through the process concretely together using examples to help guide you. To recap, linear regression is a technique that estimates the linear relationship between a continuous dependent variable

and one or more independent variables. Recall that an independent variable is the variable whose trends are associated with the dependent variable. Independent variables are commonly represented by the letter X. Meanwhile, the pining variable is the variable that a given model estimates, also known as the outcome variable. The dependent variable is commonly represented by the letter Y. We'll learn more about simple linear regression. Simple linear regression is a technique that estimates the linear relationship between one independent variable X and one continuous dependent variable Y. The model assumptions, code, evaluation metrics and interpretation skills we review here will extend directly into more complex models like multiple linear regression. By solidifying your foundation through simple linear regression, you'll be prepared to tackle advanced models that can answer more complex questions in different industries and business contexts.

As we go through simple linear regression together, you'll combine many of your prior skill sets, including Python programming, exploratory data analysis, or EDA, and statistics. These tools will allow you to construct a simple linear regression model that can help you influence strategy and decision-making in any company or organization. The key terms, activities and learning resources that we explore together in these videos will also be important in the rest of this course,

which will refer back to our discussions of simple linear regression. Together, we'll go through all the stages of PACE while learning regression modeling. We'll first review the linear regression equation and then learn about estimating parameters using ordinary least squares. Then will define each of the four key assumptions of simple linear regression. As for the analyze stage, we'll use Python and EDA to verify if our data meets these assumptions. In the construct stage, we'll build your first regression model in Python together. You'll also have opportunities to practice both Python and EDA on your own as well. We'll also learn several evaluation metrics and a technique to help you quantify how good your model is. Lastly, aligned with the execute stage, we'll use our metrics to practice interpreting our results for stakeholders and non-technical audiences. I'm so excited to get started on simple linear regression modeling, so let's begin.

In prior videos, we've mentioned simple linear regression, which is a regression technique that estimates the linear relationship between one independent variable X and one continuous dependent variable Y. Recall that the linear in linear regression indicates what the data looks like when plotted on an X-Y coordinate plane, a line. In simple linear regression, we're only interested in two variables, one X and one Y variable. So the equation for a regression line

is Y equals intercept plus slope times X, which is represented as beta-zero plus beta-one times X. Since we'll have a number of data points for any given problem, there are many different lines we could draw that might fit the data. However, we're looking for the best-fit line, the line that fits the data best by minimizing a loss function or error. In order to find the best-fit line, we need to measure error. We can consider error as some difference

between the data we have, the observed values, and the predicted values generated by a given model. The predicted values are the estimated Y values for each X calculated by a model. The difference between observed or actual values and the predicted values of the regression line are what's known as a residual. The equation for residual value is residual equals observed value minus predicted value. Each data point has one residual. Using mathematical notation, the equation for the residual of an individual data point is epsilon-I equals Y-I minus Y-I-hat.

Epsilon is a Greek letter that resembles the letter E as in E for error. We can calculate individual residuals for each data point, but an important thing to note is that the sum of the residuals is always equal to zero for OLS estimators. For some estimators, the sum of the residuals is not always equal to zero. In order to capture a summary of total error in the model, we square each residual and then add up the residuals for every data point. This is called the sum of squared residuals.

The sum of squared residuals, or SSR, is the sum of the squared differences between each observed value and the associated predicted value. For linear regression, we'll be using a technique called ordinary least squares to get our best-fit line. Ordinary least squares, also known as OLS, is a method that minimizes the sum of squared residuals to estimate parameters in a linear regression model. Using OLS, we can calculate beta-zero-hat and beta-one-hat using properties of the sample data.

Recall that the hat symbol means it is an estimate of a parameter. We will never know the exact parameter. Remember, parameters, or betas, are a characteristics of a population. Since we will only ever have sample data, our goal is to get a reasonable estimate of the parameter. Let's say that we have a certain sample of data, and we now want to determine a line that fits the data well. For our first attempt at a best-fit line, the slope is one and the intercept is 2.5.

To calculate the sum of squared residuals, first we calculate the predicted values for each X. Next, we can find the residual for every observed value of X. On the graph, we've plotted the residuals. The residuals are the difference between each observed value and what the line predicted, so this line is okay, but let's try to get a little bit closer to the points. Let's try another line. This time we'll set the slope equal to 1.25 and the intercept equal to three.

Again, we have to plot the residuals and calculate the sum of squared residuals. From the graph, it seems we're getting closer, but it's hard to tell if we've got the best line. We could just keep trying different lines, and through trial and error, pick a line that we think is closest to the data points, but that's very time-consuming. The good news is that, in Python, the computer will use OLS, or the ordinary least squares estimation technique, to test out many lines and identify which one is the best-fit line. With OLS estimation, we find that beta-zero-hat equals 1.5, and beta-one-hat equals 3.2. The lines we're estimating represent the best fit of the model to the data. Later, we'll talk about uncertainty using P-values and confidence intervals to aid in the interpretation of results. Now that we've covered what simple linear regression is, we'll go back to PACE in our regression analysis framework. We'll examine the model assumptions

that the data needs to follow for us to use this cool new tool in our regression toolbox. Alright, let's begin with the analyze stage of the PACE framework. The first task in simple linear regression analysis is checking the assumptions of the model. In addition to the technical needs of the model, you'll need to consider the business context of the problem you're working on. This will come in the plan stage. Previously, I spoke about model assumptions as statements about the data that must be true in order to justify the use of a particular modeling technique.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent