w-statistic
Version:
A tool for statistical analysis.
192 lines (147 loc) • 7.08 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>arrLogNormInv.mjs - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="w-statistic.html">w-statistic</a><ul class='methods'><li data-type='method'><a href="w-statistic.html#.arrAverage">arrAverage</a></li><li data-type='method'><a href="w-statistic.html#.arrAverageWithLogNormCI">arrAverageWithLogNormCI</a></li><li data-type='method'><a href="w-statistic.html#.arrAverageWithNormCI">arrAverageWithNormCI</a></li><li data-type='method'><a href="w-statistic.html#.arrCount">arrCount</a></li><li data-type='method'><a href="w-statistic.html#.arrGammaFit">arrGammaFit</a></li><li data-type='method'><a href="w-statistic.html#.arrGammaHist">arrGammaHist</a></li><li data-type='method'><a href="w-statistic.html#.arrGammaInv">arrGammaInv</a></li><li data-type='method'><a href="w-statistic.html#.arrGeometricAverage">arrGeometricAverage</a></li><li data-type='method'><a href="w-statistic.html#.arrGeometricStd">arrGeometricStd</a></li><li data-type='method'><a href="w-statistic.html#.arrLogNormHist">arrLogNormHist</a></li><li data-type='method'><a href="w-statistic.html#.arrLogNormInv">arrLogNormInv</a></li><li data-type='method'><a href="w-statistic.html#.arrMovingAverage">arrMovingAverage</a></li><li data-type='method'><a href="w-statistic.html#.arrNormHist">arrNormHist</a></li><li data-type='method'><a href="w-statistic.html#.arrNormInv">arrNormInv</a></li><li data-type='method'><a href="w-statistic.html#.arrQuartile">arrQuartile</a></li><li data-type='method'><a href="w-statistic.html#.arrStd">arrStd</a></li><li data-type='method'><a href="w-statistic.html#.bin">bin</a></li><li data-type='method'><a href="w-statistic.html#.histGen">histGen</a></li><li data-type='method'><a href="w-statistic.html#.regLine">regLine</a></li><li data-type='method'><a href="w-statistic.html#.regMpLine">regMpLine</a></li><li data-type='method'><a href="w-statistic.html#.regPoly">regPoly</a></li><li data-type='method'><a href="w-statistic.html#.regPower">regPower</a></li><li data-type='method'><a href="w-statistic.html#.sampleRandom">sampleRandom</a></li><li data-type='method'><a href="w-statistic.html#.studentTInv">studentTInv</a></li></ul></li></ul>
</nav>
<div id="main">
<h1 class="page-title">arrLogNormInv.mjs</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import get from 'lodash-es/get.js'
import size from 'lodash-es/size.js'
import map from 'lodash-es/map.js'
import isNumber from 'lodash-es/isNumber.js'
import isarr from 'wsemi/src/isarr.mjs'
import isnum from 'wsemi/src/isnum.mjs'
import cdbl from 'wsemi/src/cdbl.mjs'
import arrFilterByPnumAndToLog from 'wsemi/src/arrFilterByPnumAndToLog.mjs'
import arrNormInv from './arrNormInv.mjs'
/**
* 基於對數常態累加分布計算指定位置之反函數值,會先計算陣列內有效數字取對數(log)後之平均值和標準差,並基於其為常態累加分布,計算指定位置之反函數值後,再取指數(exp)值
*
* Unit Test: {@link https://github.com/yuda-lyu/w-statistic/blob/master/test/arrLogNormInv.test.js Github}
* @memberOf w-statistic
* @param {Array} arr 輸入陣列,只提取有效數字(或為字串的數字)進行計算
* @param {Number} ratio 輸入指定位置浮點數,需介於0至1之間
* @returns {Number} 回傳反函數取指數(exp)值
* @example
*
* async function test() {
*
* let arr
* let r
*
* arr = [6, 47, 49, 15, 42, 41, 7, 39, 43, 40, 36]
* r = await arrLogNormInv(arr, 0.25)
* console.log(r.inv)
* // => 16.096845206281877
*
* arr = [6, 47, 49, 15, 42, 41, 7, 39, 43, 40, 36]
* r = await arrLogNormInv(arr, 0.5)
* console.log(r.inv)
* // => 27.201738017491444
*
* arr = [6, 47, 49, 15, 42, 41, 7, 39, 43, 40, 36]
* r = await arrLogNormInv(arr, 0.75)
* console.log(r.inv)
* // => 45.96767513695641
*
* arr = ['abc', '-2.5', -2.5, '-1', -1, '-0.1', -0.1, '0', 0, '0.1', 0.1, '1', 1, '2.5', 2.5, 22.5, 'xyz']
* r = await arrLogNormInv(arr, 0.5)
* console.log(r.inv)
* // => 1.0499093195835956
*
* arr = ['abc', '0', 0, '0.1', 0.1, '1', 1, '2.5', 2.5, 22.5, 'xyz']
* r = await arrLogNormInv(arr, 0.5)
* console.log(r.inv)
* // => 1.0499093195835956
*
* }
* test()
* .catch((err) => {
* console.log(err)
* })
*
*/
async function arrLogNormInv(arr, ratio) {
//check arr
if (!isarr(arr)) {
return Promise.reject('arr is not an array')
}
if (size(arr) === 0) {
return Promise.reject('arr is not an effective array')
}
//check ratio
if (!isnum(ratio)) {
return Promise.reject(`ratio[${ratio}] is not a number`)
}
ratio = cdbl(ratio)
if (ratio < 0) {
return Promise.reject(`ratio[${ratio}] < 0`)
}
if (ratio > 1) {
return Promise.reject(`ratio[${ratio}] > 1`)
}
//取大於0數值並取log
let rs = arrFilterByPnumAndToLog(arr)
// console.log('arrFilterByPnumAndToLog', rs)
//n
let n = size(rs)
//check
if (n === 0) {
return Promise.reject(`no effective data`)
}
//arrNormInv
let r = await arrNormInv(rs, ratio)
// inv,
// avg,
// std,
// arr,
//check
if (!isNumber(get(r, 'inv'))) {
return Promise.reject(`invalid value from arrNormInv`)
}
//exp
r = {
inv: Math.exp(r.inv),
avg: Math.exp(r.avg),
std: Math.exp(r.std),
arr: map(r.arr, (v) => {
return Math.exp(v)
}),
}
return r
}
export default arrLogNormInv
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Tue Jul 29 2025 14:21:18 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>