当前位置:网站首页>Implementing StdevP function of Excel with PHP
Implementing StdevP function of Excel with PHP
2022-06-23 02:49:00 【jwj】
stay Excel in ,stdevp Is a function of the population standard deviation of the sample , It reflects the degree of dispersion relative to the average . But in PHP There is no such function in , To calculate the standard deviation , You can only write your own algorithm , It's very inconvenient . So we can query relevant data and formulas , The following code is summarized .
The formula
First , Check Wikipedia , The complete formula and detailed calculation steps are obtained , The following image is captured in Wikipedia
Reference material : Wikipedia - Standard deviation
Encapsulate as a function
Then split according to the formula and steps , Write the following functions
/**
* The standard deviation of the sample population
* @param array $list sample
* @return float
*/
function stdevp($list)
{
// Number of samples
$count = count($list);
// Average
$avg = array_sum($list) / $count;
// Sum of the squares of the differences between all samples and the mean
$sum = 0.0;
foreach($list as $item) $sum += ($item - $avg) ** 2;
// Radical sign ( Sum of squares / Sample size )
return sqrt($sum / $count);
}test run
$list = [5,6,8,9]; var_dump(stdevp($list));
result
float(1.5811388300842)
You can see that the result is the same as the example in Wikipedia , stay Excel Medium test stdevp Function is the same result .
It's not exactly the same , Because the decimal length is inconsistent , But I believe the result is relatively accurate . If you want to get the specified decimal length , have access to
round()Round the result
MySQL
Of course , In development , Most of our data comes from databases , The database has its own function for calculating the population standard deviation of samples , By the way, record MySQL Use example of .
according to uid Group data , And then based on Standard deviation Sort the process from large to small .
SELECT `uid`, STDDEV_POP(score) ` Standard deviation `, AVG(score) ` Average ` FROM `test` GROUP BY `uid` ORDER BY ` Standard deviation ` DESC
This article is synchronously published to Zero blog .
Last, last , There's also a benefit . developers , Welcome to join us Tengyun pioneer (TDP) Feedback communication group , There are plenty of activities in the group to gain points and growth value , Exchange for surprise benefits . How to join :https://cloud.tencent.com/developer/article/1855195
We are the vanguard of Tengyun (TDP) The team , Tencent cloud GTS Officially established and operated technology developer group . There are the most professional developers in & Customer , Be able to have close contact with product personnel , Proprietary questions & Demand feedback channels , There are a group of like-minded brothers and sisters , Looking forward to your joining !
边栏推荐
- 5g spectrum
- Phpexcel export with picture Excel
- An article shows you the difference between high fidelity and low fidelity prototypes
- Extract NTDs with volume shadow copy service dit
- Soft exam information system project manager_ Information system comprehensive testing and management - Senior Information System Project Manager of soft test 027
- How does the easyplayer streaming video player set up tiling?
- 5 trends brought to us by customers
- Unity official case nightmare shooter development summary < I > realization of the role's attack function
- Buuctf misc-[actf freshman competition 2020]outline
- How to batch generate matrix 25 codes
猜你喜欢

Nfv and SDN

5g core network and core network evolution

Performance testing -- Interpretation and practice of 16 enterprise level project framework

Xgboost principle

5g access network and base station evolution

Log a log4j2 vulnerability handling

Small knowledge points of asset

Soft exam information system project manager_ Information system comprehensive testing and management - Senior Information System Project Manager of soft test 027

Quick sorting C language code + auxiliary diagram + Notes

5g spectrum
随机推荐
SAP WM cannot automatically obtain the special movement mark in the material master data when receiving Po goods?
Solution to the problem of easycvr switching MySQL database traffic statistics cannot be displayed
[data preparation and Feature Engineering] data cleaning
How to store, manage and view family photos in an orderly manner?
Calling applet demo modifying the default large screen view
Weekly Postgres world news 2022w04
Xgboost principle
Pyqt5 installation and use
February 1, 2022: painting house II. If there is a row of houses, N in total, each
No error is reported when using the Gorm framework to create a table, but the data cannot be inserted successfully
What is a smart farm?
Get the structure of the class through reflection, little chestnut
How does the easyplayer streaming video player set up tiling?
6. template for integer and real number dichotomy
Direct collection - super easy to use domestic color matching website
Markdown - enter a score (typora, latex)
Why do I use index, query or slow?
Mongodb aggregate query implements multi table associated query, type conversion, and returns specified parameters.
Ping your domain name to 127.0.0.1. The solution to DNS hijacking
Ugui empty button implementation