当前位置:网站首页>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 !
边栏推荐
- Qingdao stadium has made headlines again, but it has nothing to do with sports
- How to generate DataMatrix code in batch through TXT file
- Summary of easy-to-use MySQL interview questions (Part 1)
- Summary of website navigation design and website link optimization
- Reinforcement learning series (III) -gym introduction and examples
- Handlebars dynamic adjustment
- Use Sakura FRP intranet penetration service to build your own website / game server
- Detailed explanation of various networking modes of video monitoring platform
- Aikuai multi dialing + load balancing overlay bandwidth
- 6. template for integer and real number dichotomy
猜你喜欢

Mongodb aggregate query implements multi table associated query, type conversion, and returns specified parameters.

Custom shapes for ugui skill learning

Unity official case nightmare shooter development summary < I > realization of the role's attack function

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

2021-11-11
What is sitelock? What is the function?

Vulnhub DC-5
![Buuctf misc-[bjdctf2020] Nani](/img/4e/ac6bf2f64cb68136581814da73db66.jpg)
Buuctf misc-[bjdctf2020] Nani

Spark broadcast variables and accumulators (cases attached)

5g core network and core network evolution
随机推荐
January 31, 2022: Maze III. There is a ball in the maze of open spaces and walls. ball
Automatically update site statistics with actions
The commercial s2b2b e-commerce platform of aquatic industry improves the competitiveness of enterprises and creates a strong engine for industrial development
Log a log4j2 vulnerability handling
Markdown - mark above / below symbol (typora, latex)
Hypervisor Necromancy; Recover kernel protector (2)
Im web demo invite end hang up error avoidance
Goframe framework (RK boot): fast implementation of server-side JWT verification
Apache Druid's engineering practice in shopee
How to customize a finished label template
8. greed
[SaaS examination certification] apaas_ Tencent Qianfan magic pen
Goframe framework (RK boot): Based on cloud native environment, distinguish configuration files (config)
Detailed explanation of various networking modes of video monitoring platform
Small knowledge points of asset
Vs code remote SSH configuration
DNS Service Setup
Simple implementation of promise basic method
Implementation idea and solution of calling global monitoring for applet
Scanning technology (getting started with web security 06)