• General
• News
• Popular Stocks
• Personal Finance
• Reviews & Ratings
• Wealth Management
• Popular Courses
• Courses by Topic

# How Do I Calculate the Standard Error Using MATLAB?

It's possible to calculate the standard error in MATLAB by running a one-line command. MATLAB is a programming platform from MathWorks that's designed for and used by scientists and engineers.﻿﻿

## What Is Standard Error?

In statistics, the standard error is the standard deviation of the sampling statistical measure, and it's most commonly used for the sample mean. The standard error measures how accurately the sample represents the actual population from which the sample was drawn.

Since there could be different samples drawn from the population, there exists a distribution of sampled means. The standard error measures the standard deviation of all sample means drawn from the population.

The formula for calculating the standard error of the mean is the sample standard deviation divided by the square root of the sample size.

## The Command for Standard Error in MATLAB

To calculate the standard error of the mean in a sample, the user needs to run a one-line command in MATLAB:

﻿ \begin{aligned} &\text{stderror} = \text{ std( data ) / sqrt( length( data ))}\\ &\textbf{where:}\\ &\text{data} = \text{An array with sample values}\\ &\text{std} = \text{The MATLAB function that computes standard} \\ &\text{deviation of the sample}\\ &\text{sqrt} = \text{The MATLAB function that computes the square} \\ &\text{root of a non-negative number}\\ &\text{length} = \text{The MATLAB function that computes the total} \\ &\text{number of observations in the sample}\\ \end{aligned}﻿

## Example of Calculating Standard Error in MATLAB

Consider a sample of annual household incomes drawn from the general population of the United States. The sample contains five observations and consists of values $10,000,$100,000, $50,000,$45,000 and $35,000. First, the user needs to create an array called "data" containing these observations in MATLAB. Next, the user can calculate the standard error of the mean with the command "stderror = std( data ) / sqrt( length )". The result of this command says that the mean of this sample, which is$48,000, has a standard error of \$13,161.

### Article Sources

Investopedia requires writers to use primary sources to support their work. These include white papers, government data, original reporting, and interviews with industry experts. We also reference original research from other reputable publishers where appropriate. You can learn more about the standards we follow in producing accurate, unbiased content in our editorial policy.
1. MathWorks. "MATLAB." Accessed April 23, 2020.