当前位置:网站首页>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 !
边栏推荐
- [SaaS examination certification] apaas_ Tencent Qianfan magic pen
- Quick sorting C language code + auxiliary diagram + Notes
- How to make a borrowing card
- Exploit format string vulnerability in CDE
- Quic implementation in rust --- Quinn
- Optimization method of live weak network
- February 4, 2022: combined total IV. Give you a number composed of different integers
- Im web demo invite end hang up error avoidance
- Biological psychiatry: defining individualized functional neuroanatomy for precision psychiatry
- Docker builds redis3 master-slave cluster and expands the capacity
猜你喜欢
![Buuctf misc-[actf freshman competition 2020]outline](/img/a4/ac9d14a69e0759d1e7c65740415bf7.jpg)
Buuctf misc-[actf freshman competition 2020]outline

5g spectrum

Xgboost Guide

Third order magic cube formula

Custom shapes for ugui skill learning

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

6. template for integer and real number dichotomy

Vulnhub DC-5

Nfv and SDN

Docker installs mysql5.7 and mounts the configuration file
随机推荐
method
6. template for integer and real number dichotomy
2021-11-11
Docker builds redis3 master-slave cluster and expands the capacity
5 trends brought to us by customers
Supervisor multi process management exception automatic restart visual management
Hypervisor Necromancy; Recover kernel protector (1)
51. numerical arrangement
February 6, 2022: Arithmetic Sequence Division II - subsequence. Give you an integer array n
Learning about urldns chains
Delta oscillation in EEG
How to set up an H5 demo of easyplayer locally to play h265 video streams?
Evolution history of mobile communication
About the use of mock framework
Easygbs adds websocket message push, which can quickly locate video playback faults
Reading redis source code (IV) command request processing flow
Markdown - mark above / below symbol (typora, latex)
Web components series (I) - Overview
Qingdao stadium has made headlines again, but it has nothing to do with sports
Wechat applet camera compressed image is Base64