Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

What is sampling and why it’s important?
Latest   Machine Learning

What is sampling and why it’s important?

Last Updated on July 26, 2023 by Editorial Team

Author(s): Ibrahim Israfilov

Originally published on Towards AI.

Statistics

Intro

This article will cover the basic notions of econometrics and OLS which include the first steps before starting the analysis, namely testing the assumptions for the unbiasedness of OLS. No matter whether you are a data scientist, econometrician, or statistician to know how to have a correct Ordinary Least Squares is the first task you need to undertake.

Random Sampling

Sampling is the action of taking some proportion of the total amount (population) for the non-experimental (not in laboratory) analysis. In statistics, the population is usually denoted by N and the sample by n. Sometimes we have too large a population (let’s say the youngsters in the U.S.A) that we cannot take them all as our dataset so we use the sampling method to get the representation of the whole population.

In this article, we will talk about sampling for linear regressions. The core of the linear regressions is the OLS (Ordinary Least Squares) line which minimizes the variance between squares of all observations in the dataset (Which are taken through sampling). There are several assumptions that should be satisfied in order to have an unbiased OLS.
1. Linear relation
2. Random Sampling
3. E(uU+007Cx)=0 Conditional error given the regressor should be 0
4. No perfect collinearity
5. Homoscedasticity
6. Errors should be normally distributed

We will stick today, particularly with the second assumption. We cannot obtain ceteris paribus it’s unpractical, meaning our observations cannot have the regressand difference and other factors equal as an apple-to-apple. So to solve this problem we randomly choose our sample data and later on infer it with statistical techniques in order to represent it for all the population.

Imagine the sampling as the next image which fails our assumption because obviously, it’s not a random sample.

Failing Assumption 2 of OLS

Run a sample in R

Below is one line R code to do it automatically.

sample(1:nrow(data), nrow(data)*0.7)

The sample() function is R built-in function so you don’t need to install other packages.

Whenever you need to have the same results always you need to add the set.seed function before to the code as the next example.

set.seed(1,sample.kind = "Rejection")

don’t forget to run the code together with the set.seed() the sample() function otherwise you will get always different results.

Run a sample in Python

Likely, in Python, you can do the same with sample() function.

from random import sampledata = [1, 2, 3, 4, 5]print(sample(data,3))

Sampling on Excel

You can even sample your data on excel. In order to do so, you need to use the data analysis tool pack on the ribbon in the data section.

and then choose the sampling.

By default, you don’t have a data analysis tool pack on the menu. To add it you need to type on the search bar add-ins

Then you will have an option to incorporate the data analysis tool pack into your menu

Real-Life Example

Imagine you are a new principal of a school and you would love to know whether the free meal program has influenced the GPA of the students or not. Luckily, you have your degree in economics and you had an econometrics class back in your student times. Now what you want to do is to take a sample of students (You have a huge school so can’t take all of them). But you know that not all students are the same. So you remember your econometrics class and the second assumption of the OLS unbiasedness? Let’s go you randomly choose 200 students and start your analysis. You check whether the outcome variable and regressors are linear, you check whether there is heteroscedasticity and whether the errors are normally distributed.
The good news, your all assumptions are correct and you can now run the regression analysis and inference the estimates.

Hope you find it useful. Please share your opinion and critics about this article in the comments. If you are interested in the details of the assumptions I would recommend you to look at the Introduction to Econometrics Book by Wooldridge.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓