ONLYOFFICE COVARIANCE.S: Sample Covariance and the n-minus-one Divisor
Calculate sample covariance in ONLYOFFICE, reconstruct its n-minus-one divisor, normalize with sample spreads and diagnose duplicated observations.
Verification status: See the evidence and test scope described in this guide. How formula examples are checked
Quick answer: =COVARIANCE.S(A2:A5,B2:B5) has an independently expected result of 14/3, approximately 4.666666667, for the four pairs below. The sample divisor is nā1, so it differs from the population result 3.5 even though the input data is identical.
Availability and version history
- Introduced: The first introduction release and date are not established by the checked sources.
- Availability: Currently documented in ONLYOFFICE’s rolling function help; no final supported-version endpoint is established.
- Scope: Shared Spreadsheet Editor documentation, with the calculation divisor corroborated by an explicitly pinned official source-code revision. Individual client/build parity is unverified.
- Checked: October 14, 2026, against the official COVARIANCE.S reference, source and vendor screenshot. Example outputs were independently calculated; these cases were not tested in the native application.
Syntax and the sample divisor
=COVARIANCE.S(array1, array2)
Supply both ranges, containing the same number of aligned elements. The official entry calls this sample covariance and says text, logical values and empty cells are ignored while zeros are included.
Its short description uses the word average. For the sample form, the official implementation at commit 72b0421 divides the centered cross-product sum by nā1. The official screenshot also agrees with that divisor. It is not the ordinary arithmetic mean obtained by dividing those products by n.
Use more than one complete numeric pair. The sample formula is undefined at n=1; this guide’s examples avoid that boundary and do not claim native testing of exact error behavior.
Work through all four centered products
Create a blank sheet named SamplePairs. Enter x, y, Centered x, Centered y and Product in A1:E1, then enter:
| Row | A: x | B: y |
|---|---|---|
| 2 | 2 | 1 |
| 3 | 4 | 3 |
| 4 | 6 | 2 |
| 5 | 8 | 6 |
Use G for result labels. Put =AVERAGE(A2:A5) in H2 and =AVERAGE(B2:B5) in H3; expect 5 and 3. Enter =A2-$H$2 in C2, =B2-$H$3 in D2 and =C2*D2 in E2. Fill C2:E2 through row 5.
Expected C values are -3,-1,1,3; D values are -2,0,-1,3; products in E are 6,0,-1,9. Put =SUM(E2:E5) in H5; expect 14.
| Cell | Formula | Independent target |
|---|---|---|
| H6 | =COVARIANCE.S(A2:A5,B2:B5) |
4.666666667 approximately |
| H7 | =H5/(4-1) |
4.666666667 approximately |
| H8 | =COVARIANCE.P(A2:A5,B2:B5) |
3.5 |
| H9 | =H8*4/(4-1) |
4.666666667 approximately |
The literal 4 is the number of complete observations. If you change the fixture, revise that count as well. The two covariance forms share the same centered numerator here; their different denominators explain the difference.
Advanced: standardize using sample spreads
Put =STDEV.S(A2:A5) in H11 and =STDEV.S(B2:B5) in H12. Expected values are approximately 2.581988897 and 2.160246899. In H13 enter =H6/(H11*H12); expect approximately 0.836660027.
Put =CORREL(A2:A5,B2:B5) in H14 to compare with the same target. Using sample covariance and both sample standard deviations cancels the common nā1 factors. Mixing a sample covariance with population standard deviations does not perform that consistent normalization.
This is a check on the complete numeric fixture, not a promise that separately filtered or incomplete ranges describe the same sample. Keep matching observations together.
Duplicating rows does not create new evidence
On a separate sheet named DuplicatedPairs, copy the four original numeric pairs twice into A2:B9, with x and y headers in row 1. The x column is 2,4,6,8,2,4,6,8 and the y column is 1,3,2,6,1,3,2,6.
Put =COVARIANCE.S(A2:A9,B2:B9) in D2 and =COVARIANCE.P(A2:A9,B2:B9) in D3. Independent targets are 4 and 3.5. The centered numerator doubles to 28; sample division uses 8ā1, giving 4. Population division uses 8, still giving 3.5.
The changed sample result is a mechanical consequence of the duplicated rows and divisor. Repeating records does not make them independent new observations. Remove accidental duplicates according to the dataset’s identity rules before treating the output as a statistical estimate.
Reproduce the official screenshot
Create another sheet named VendorSample. Enter 12,65,178,45,98 in A1:E1 and 45,78,34,90,147 in A2:E2, with no headers in this block. Enter =COVARIANCE.S(A1:E1,A2:E2) in G2.
The screenshot displays -311.1. Independent means are 79.6 and 78.8, and the centered cross-product sum is -1244.4. Dividing by 5ā1 gives -311.1; dividing by five instead would give the population value -248.88.
Errors, interpretation and related functions
The function needs a meaningful paired sample, not two unrelated columns of the same length. Do not sort one range alone or shift surviving values after deleting missing observations independently. Numeric zero remains a data value rather than a missing-data marker under the documented rule.
The short help does not establish all exact error tokens, mixed-array edge cases or historical client versions. The inspected source commit supports the stated divisor; it does not prove deployed runtime behavior for every build.
Covariance has x-unit Ć y-unit dimensions, can be negative, and is not bounded by one. It does not establish causation. COVARIANCE.P describes a complete population, COVAR uses the population-style calculation in the checked source, and CORREL normalizes co-movement. STDEV.S provides the sample spread of one variable.