Commit 380931fe authored by GoshaZotov's avatar GoshaZotov

add SKEW.P formula

parent 0ff883ee
......@@ -59,7 +59,7 @@
cFormulaFunctionGroup['Statistical'].push(cBINOM_DIST_RANGE, cCHISQ_TEST, cCOVARIANCE_P,
cCOVARIANCE_S, cF_TEST, cFORECAST_ETS, cFORECAST_ETS_CONFINT, cFORECAST_ETS_SEASONALITY, cFORECAST_ETS_STAT,
cHYPGEOM_DIST, cMODE_MULT, cMODE_SNGL, cNEGBINOM_DIST, cNORM_DIST, cNORM_INV, cNORM_S_DIST,
cNORM_S_INV, cPERMUTATIONA, cPHI, cSKEW_P, cSTDEV_P, cSTDEV_S,
cNORM_S_INV, cPERMUTATIONA, cPHI, cSTDEV_P, cSTDEV_S,
cT_TEST, cVAR_P, cVAR_S, cWEIBULL_DIST, cZ_TEST);
cFormulaFunctionGroup['Financial'] = cFormulaFunctionGroup['Financial'] || [];
cFormulaFunctionGroup['Financial'].push(cPDURATION, cRRI);
......@@ -75,7 +75,7 @@
cERF_PRECISE, cERFC_PRECISE, cDBCS, cUNICHAR, cUNICODE, cBINOM_DIST_RANGE, cCHISQ_TEST,
cCOVARIANCE_P, cCOVARIANCE_S, cF_TEST, cFORECAST_ETS, cFORECAST_ETS_CONFINT, cFORECAST_ETS_SEASONALITY,
cFORECAST_ETS_STAT, cHYPGEOM_DIST, cMODE_MULT, cMODE_SNGL, cNEGBINOM_DIST, cNORM_DIST,
cNORM_INV, cNORM_S_DIST, cNORM_S_INV, cPERMUTATIONA, cPHI, cSKEW_P,
cNORM_INV, cNORM_S_DIST, cNORM_S_INV, cPERMUTATIONA, cPHI,
cSTDEV_P, cSTDEV_S, cT_TEST, cVAR_P, cVAR_S, cWEIBULL_DIST, cZ_TEST, cPDURATION, cRRI, cAGGREGATE, cMUNIT,
cFORMULATEXT, cISFORMULA, cSHEET, cSHEETS);
......@@ -559,18 +559,6 @@
cSHEETS.prototype = Object.create(cBaseFunction.prototype);
cSHEETS.prototype.constructor = cSHEETS;
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
*/
function cSKEW_P() {
cBaseFunction.call(this, "SKEW.P");
this.isXLFN = true;
}
cSKEW_P.prototype = Object.create(cBaseFunction.prototype);
cSKEW_P.prototype.constructor = cSKEW_P;
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
......
......@@ -70,7 +70,7 @@
cLOGNORMDIST, cMAX, cMAXA, cMEDIAN, cMIN, cMINA, cMODE, cNEGBINOMDIST, cNORMDIST, cNORMINV, cNORMSDIST,
cNORMSINV, cPEARSON, cPERCENTILE, cPERCENTILE_EXC, cPERCENTILE_INC, cPERCENTRANK, cPERCENTRANK_EXC,
cPERCENTRANK_INC, cPERMUT, cPOISSON, cPOISSON_DIST, cPROB, cQUARTILE, cQUARTILE_EXC, cQUARTILE_INC, cRANK, cRANK_AVG, cRANK_EQ,
cRSQ, cSKEW, cSLOPE, cSMALL, cSTANDARDIZE, cSTDEV, cSTDEVA, cSTDEVP, cSTDEVPA, cSTEYX, cTDIST, cT_DIST,
cRSQ, cSKEW, cSKEW_P,cSLOPE, cSMALL, cSTANDARDIZE, cSTDEV, cSTDEVA, cSTDEVP, cSTDEVPA, cSTEYX, cTDIST, cT_DIST,
cT_DIST_2T, cT_DIST_RT, cT_INV, cT_INV_2T, cTINV, cTREND, cTRIMMEAN, cTTEST, cVAR, cVARA, cVARP, cVARPA,
cWEIBULL, cZTEST);
......@@ -1055,6 +1055,58 @@
return res;
}
function skew(x, bSkewp) {
var sumSQRDeltaX = 0, _x = 0, xLength = 0, sumSQRDeltaXDivstandDev = 0, i;
for (i = 0; i < x.length; i++) {
if (x[i] instanceof cNumber) {
_x += x[i].getValue();
xLength++;
}
}
if (xLength <= 2) {
return new cError(cErrorType.not_available);
}
_x /= xLength;
for (i = 0; i < x.length; i++) {
if (x[i] instanceof cNumber) {
sumSQRDeltaX += Math.pow(x[i].getValue() - _x, 2);
}
}
var standDev;
if(bSkewp){
standDev = Math.sqrt(sumSQRDeltaX / ( xLength ));
}else{
standDev = Math.sqrt(sumSQRDeltaX / ( xLength - 1 ));
}
for (i = 0; i < x.length; i++) {
if (x[i] instanceof cNumber) {
sumSQRDeltaXDivstandDev += Math.pow((x[i].getValue() - _x) / standDev, 3);
}
}
var res;
if(bSkewp){
res = sumSQRDeltaXDivstandDev / xLength;
}else{
res = xLength / (xLength - 1) / (xLength - 2) * sumSQRDeltaXDivstandDev;
}
return new cNumber(res);
}
function GAMMADISTFUNCTION(fp, fAlpha, fBeta){
this.fp = fp;
this.fAlpha = fAlpha;
......@@ -5988,45 +6040,54 @@
cSKEW.prototype.argumentsMin = 1;
cSKEW.prototype.Calculate = function (arg) {
function skew(x) {
var sumSQRDeltaX = 0, _x = 0, xLength = 0, sumSQRDeltaXDivstandDev = 0, i;
for (i = 0; i < x.length; i++) {
if (x[i] instanceof cNumber) {
_x += x[i].getValue();
xLength++;
}
}
if (xLength <= 2) {
return new cError(cErrorType.not_available);
}
_x /= xLength;
var arr0 = [];
for (i = 0; i < x.length; i++) {
for (var j = 0; j < this.getArguments(); j++) {
if (x[i] instanceof cNumber) {
sumSQRDeltaX += Math.pow(x[i].getValue() - _x, 2);
if (arg[j] instanceof cArea || arg[j] instanceof cArea3D) {
arg[j].foreach2(function (elem) {
if (elem instanceof cNumber) {
arr0.push(elem);
}
});
} else if (arg[j] instanceof cRef || arg[j] instanceof cRef3D) {
var a = arg[j].getValue();
if (a instanceof cNumber) {
arr0.push(a);
}
} else if (arg[j] instanceof cArray) {
arg[j].foreach(function (elem) {
if (elem instanceof cNumber) {
arr0.push(elem);
}
});
} else if (arg[j] instanceof cNumber || arg[j] instanceof cBool) {
arr0.push(arg[j].tocNumber());
} else if (arg[j] instanceof cString) {
continue;
} else {
return this.value = new cError(cErrorType.wrong_value_type);
}
var standDev = Math.sqrt(sumSQRDeltaX / ( xLength - 1 ));
for (i = 0; i < x.length; i++) {
if (x[i] instanceof cNumber) {
sumSQRDeltaXDivstandDev += Math.pow((x[i].getValue() - _x) / standDev, 3);
}
}
}
return this.value = skew(arr0);
};
return new cNumber(xLength / (xLength - 1) / (xLength - 2) * sumSQRDeltaXDivstandDev)
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
*/
function cSKEW_P() {
this.name = "SKEW.P";
this.value = null;
this.argumentsCurrent = 0;
}
}
cSKEW_P.prototype = Object.create(cBaseFunction.prototype);
cSKEW_P.prototype.constructor = cSKEW_P;
cSKEW_P.prototype.argumentsMin = 1;
cSKEW_P.prototype.isXLFN = true;
cSKEW_P.prototype.Calculate = function (arg) {
var arr0 = [];
......@@ -6058,7 +6119,7 @@
}
}
return this.value = skew(arr0);
return this.value = skew(arr0, true);
};
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment