This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

Detecting Outliers in Multiple Sampling Results Without Thresholds

Yu-Fu Shen label=e1][email protected]\orcid0000-0003-4445-6504 [ Changchun Observatory, National Astronomical Observatories, Chinese Academy of Sciences presep= , ]e1
Abstract

Bayesian statistics emphasizes the importance of prior distributions, yet finding an appropriate one is practically challenging. When multiple sample results are taken regarding the frequency of the same event, these samples may be influenced by different selection effects. In the absence of suitable prior distributions to correct for these selection effects, it is necessary to exclude outlier sample results to avoid compromising the final result. However, defining outliers based on different thresholds may change the result, which makes the result less persuasive. This work proposes a definition of outliers without the need to set thresholds.

Bayes method,
Selection effect,
Unknown prior distribution,
Data Cleaning,
keywords:
\startlocaldefs\endlocaldefs

1 Introduction

People often determine the probability of occurrence of event through random sampling, but results are unreliable if the number of the sample is too small. The probability density function, which depends on both the number of samples and the number of events, is superior to a single probability value. Bayesian statistics goes further by emphasizing the importance of the prior distribution; for example, if there is a strong selection effect during sampling, no matter how large the sample is, the result still be unreliable. However, it is difficult to obtain an appropriate prior distribution in practical situations, and sometimes we may not even be aware of the selection effect during sampling, mistakenly assuming that all samples are equally weighted. This is especially common in social investigations and astronomical spectroscopic surveys. All investigations or observations have different environments, it is difficult to assess the selection effect of each of them. Bayesian linear statistics[1] take this issue into account, but this work argues that some sampling results with strong selection effects should be identified first, and they can be defined as outliers.

Sometimes sampling results with strong selection effects may be identified manually. Regardless of whether they can be manually identified, if one wants to exclude some sampling results, they must either find clear evidence of the problem within these sampling results or classify them as outliers using a strict definition, otherwise there may be suspicion of cheating. Of course, sometimes the majority of samples make the same error, and the best sampling results may end up being outliers.

The method based on the standard score (Z-score) can be employed to find outliers. However, it is difficult to account for the impact of sample size unless the sample results are weighted according to their size, but there is no unified form of weighting, and thresholds must be set. Methods that require setting thresholds lack persuasiveness because conclusions may differ with different thresholds.

The method proposed in this paper uses the probability density function to consider the impact of sample size and defines outliers for multiple random sampling results without setting thresholds. For a set of probability density functions corresponding to multiple sampling results, under the definition of this work, there may be no outliers, one outlier or multiple outliers. Sometimes all probability density functions in the set are outliers, resembling a “fragmented” set, which indicates extremely unstable sampling quality and cannot give reliable results.

2 Method for finding outliers

When there is no selection effect, assuming N events are detected, the more samples (n), the more reliable θ=N/n\theta=N/n. However, θ\theta cannot reflect n, so a probability density function is needed to replace θ\theta. The larger n, the smaller the information entropy[5] of the corresponding probability density function. Now suppose we want to investigate how many stars in a sky area are giants; we perform spectroscopic observations of that region and obtain spectra for n stars, analyzing and finding that N of them are giants. The probability of finding a giant in this sky area fits the binomial distribution

p(Nθ,n)=θN(1θ)nNp(N\mid\theta,n)=\theta^{N}(1-\theta)^{n-N} (1)

Equation 1 indicates that even if the proportion of giants (θ\theta) in this sky area is constant, the probability of finding nθn\theta giants from nn stars in that sky area is not equal to 1, which is consistent with the Theorem of Large Numbers[2, 3, 4]. In Bayesian Statistics, we have

p(θN,n)p(Nθ,n)p(θ)p(\theta\mid N,n)\propto p(N\mid\theta,n)p(\theta) (2)

A prior distribution p(θ)p(\theta) is required, but we know nothing about it. For example, in this scenario, we need to test the galactic model using the proportion of giants, so we cannot correct the observational results based on the prior parameters obtained from the model. Besides, during astronomical observations, we are bound to see more giants because they are brighter than non-giants (turn-off stars) at the same distance. Therefore, we do not expect to obtain a truly complete θ\theta; it is good enough to be complete within a certain brightness (magnitude) range. However, sometimes observers also tend to select stars that are either bluer or redder, and the color distribution of giants differs from that of non-giants. Thus, color bias can affect the proportion of giants. Even if the observer’s color bias is known, it is difficult to quantify its impact on the proportion of giants. In summary, the prior distribution cannot be estimated, so the prior distribution is assumed to be an uniform distribution

p(θ)={10<θ<10 otherwise p(\theta)=\left\{\begin{array}[]{ll}1&0<\theta<1\\ 0&\text{ otherwise }\end{array}\right. (3)

then we have

p(θN,n)θN(1θ)nNp(\theta\mid N,n)\propto\theta^{N}(1-\theta)^{n-N} (4)

To ensure 01p(θN)𝑑θ=1\int_{0}^{1}p(\theta\mid N)d\theta=1, it has been proved that

p(θN,n)=Beta(θN+1,nN+1)p(\theta\mid N,n)=\text{Beta}(\theta\mid N+1,n-N+1) (5)

where

Beta(θa,b)=Γ(a+b)θa1(1θ)b1Γ(a)Γ(b)\text{Beta}(\theta\mid a,b)=\frac{\Gamma(a+b)\theta^{a-1}(1-\theta)^{b-1}}{\Gamma(a)\Gamma(b)} (6)

where a=N+1a=N+1, b=nN+1b=n-N+1, and

Γ(x)=0+tx1etdt\Gamma(x)=\int_{0}^{+\infty}t^{x-1}e^{-t}\mathrm{~{}d}t (7)

If there is only one sampling result, it ends here. However, in practical situations, the conditions during sampling are always changing. Even if it is unclear whether these specific conditions will actually lead to selection effects, the sampling result should be divided into multiple sampling results based on these conditions. In this scenario, there are always multiple observations of the same sky area, and in each observation the selection biases differ. For instance, one observation might be biased towards bluer stars, another towards redder stars, and another might even have undergone pre-filtering to exclude giants, albeit with a pre-filter accuracy that is not one hundred percent, leaving a small number of giants behind. As a result, even if an observation provides a vast sample size, it can still be unreliable, whereas a result with a much smaller sample size might actually be closer to the truth. If sampling results with strong selection biases are not treated as outliers and removed, it will inevitably lead to biases in the overall probability density function. Here comes the definition of outliers without setting thresholds.

Now assuming this sky area has been observed k times (k¿3), then we have N1N_{1}, N2N_{2}, N3N_{3}NkN_{k} and n1n_{1}, n2n_{2}, n3n_{3}nkn_{k}. So,

pi(θ)=p(θNi,ni)=Beta(θNi+1,niNi+1)p_{i}(\theta)=p(\theta\mid N_{i},n_{i})=\text{Beta}(\theta\mid N_{i}+1,n_{i}-N_{i}+1) (8)

If, in a few sampling results, a non-uniform prior distribution assumption is used, resulting in a different form of the corresponding pi(θ)p_{i}(\theta) from that in Equation 5, this is acceptable and will not affect the following definitions.

Now we have Obsk={p1,p2,,pk}\text{Obs}_{k}=\{p_{1},p_{2},...,p_{k}\}. Make sure no repeated elements in the set Obsk\text{Obs}_{k}. Then define Similarity SS,

Sij=01min(pi(θ),pj(θ))𝑑θS_{i}^{j}=\int_{0}^{1}\text{min}(p_{i}(\theta),p_{j}(\theta))d\theta (9)

Then define

Slist(Obsk)={S12,S13,S1k,S23,S24,S2k,Sk1k}S_{list}(\text{Obs}_{k})=\{S_{1}^{2},S_{1}^{3},...S_{1}^{k},S_{2}^{3},S_{2}^{4},...S_{2}^{k},...S_{k-1}^{k}\} (10)

where |Slist(Obsk)|=1/2k(k1)|S_{list}(\text{Obs}_{k})|=1/2\cdot k\cdot(k-1). Define

min1({A})=min({A})\text{min}_{1}(\{A\})=\text{min}(\{A\}) (11)

and

min2({A})=min({A}\min1({A}))\text{min}_{2}(\{A\})=\text{min}(\{A\}\verb|\|\text{min}_{1}(\{A\})) (12)

so we have

minx({A})=min({A}\\displaystyle\text{min}_{x}(\{A\})=\text{min}(\{A\}\verb|\| (13)
{min1({A}),min2({A}),,minx1({A})})\displaystyle\{\text{min}_{1}(\{A\}),\text{min}_{2}(\{A\}),...,\text{min}_{x-1}(\{A\})\})

Then define

MINn({A})\displaystyle\text{MIN}_{n}(\{A\}) (14)
={min1({A}),min2({A}),minn({A})}\displaystyle=\{\text{min}_{1}(\{A\}),\text{min}_{2}(\{A\}),...\text{min}_{n}(\{A\})\}
(n<|{A}|)\displaystyle(n<|\{A\}|)

and

Checklist(Slist(Obsk))\displaystyle Checklist(S_{list}(\text{Obs}_{k})) (15)
=MINk1(Slist(Obsk))\displaystyle=\text{MIN}_{k-1}(S_{list}(\text{Obs}_{k}))
={Sa1b1,Sa2b2,Sak1bk1}\displaystyle=\{S_{a_{1}}^{b_{1}},S_{a_{2}}^{b_{2}},...S_{a_{k-1}}^{b_{k-1}}\}

and a check function

Check(xSab)={1a=x|b=x0 otherwise Check(x\mid S_{a}^{b})=\left\{\begin{array}[]{ll}1&\quad a=x|b=x\\ 0&\quad\text{ otherwise }\end{array}\right. (16)

and an operator

C^i({A})={Check(ia)aA)}\hat{C}_{i}(\{A\})=\{Check(i\mid a)\mid a\in A)\} (17)

then define

Unsi(iObsk)=C^i(Checklist(Slist(Obsk)))Unsi(i\mid\text{Obs}_{k})=\sum\hat{C}_{i}(Checklist(S_{list}(\text{Obs}_{k}))) (18)

if observation i is an outlier in k observations, we have

Unsi(iObsk)=|Checklist(Slist(Obsk))|=k1Unsi(i\mid\text{Obs}_{k})=|Checklist(S_{list}(\text{Obs}_{k}))|=k-1 (19)

we can also define an operator

Out^1(Obsk)\displaystyle\hat{Out}_{1}(\text{Obs}_{k})
=\displaystyle= {piUnsi(iObsk)=|Obsk|1NoneUnsi(aObsk)<|Obsk|1,1ak\displaystyle\left\{\begin{array}[]{ll}p_{i}&\ Unsi(i\mid\text{Obs}_{k})=|\text{Obs}_{k}|-1\\ None&\ Unsi(a\mid\text{Obs}_{k})<|\text{Obs}_{k}|-1,\ \forall 1\leq a\leq k\end{array}\right. (23)

and

Out^2(Obsk)=Outlier^1(Obsk\Out^1(Obsk))\hat{Out}_{2}(\text{Obs}_{k})=\hat{Outlier}_{1}(\text{Obs}_{k}\verb|\|\hat{Out}_{1}(\text{Obs}_{k})) (24)

then we have

(25)
Out^n(Obsk)\displaystyle\hat{Out}_{n}(\text{Obs}_{k})
=Out^1(Obsk\\displaystyle=\hat{Out}_{1}(\text{Obs}_{k}\verb|\|
{Out^1(Obsk)),Out^2(Obsk)),,Out^n1(Obsk)})\displaystyle\{\hat{Out}_{1}(\text{Obs}_{k})),\hat{Out}_{2}(\text{Obs}_{k})),...,\hat{Out}_{n-1}(\text{Obs}_{k})\})

If Out^n\hat{Out}_{n} is undefined, Out^m,m>n\hat{Out}_{m},\ \forall m>n are undefined. If Out^k3(Obsk)\hat{Out}_{k-3}(\text{Obs}_{k}) is defined, Out^k(Obsk)\hat{Out}_{k}(\text{Obs}_{k}) is defined so Obsk\text{Obs}_{k} is “fragmented”, no reliable results should be given by a “fragmented” set.

Figure 1 are some examples.

Refer to caption
Refer to caption
Refer to caption
Refer to caption
Figure 1: All curves in the four panels are probability density distributions given by synthetic observations. Each observation corresponds to a curve. Red curves are outliers. From left to right and from top to bottom, the first panel shows an example of five observations without outliers, the second panel shows a very sharp outlier compared with other curves, the third panel shows a common type of outlier, and the fourth panel shows the case with two outliers. The pictures can be drawn by the code provided in the appendix.
{supplement}\stitle

Python code \sdescriptionThe code for drawing the sketch map is also included

import numpy as np
from scipy.stats import beta
from collections import Counter
def S(Ni,ni,Nj,nj):
    h=0.001#integration step size
    theta=np.arange(0,1,h)
    pi=beta.pdf(theta,Ni+1,ni-Ni+1)
    pj=beta.pdf(theta,Nj+1,nj-Nj+1)
    minij=[min(a,b) for a,b in zip(pi,pj)]
    minij=np.array(minij)
    return np.sum(minij*h)
def out(N,n):
    k=len(N)
    Slist=[]
    ilist=[]
    jlist=[]
    for i in range(k):
        for j in range(k):
            if i>=j:
                continue
            else:
                Slist.append(
                S(N[i],n[i],N[j],n[j])
                )
                ilist.append(i)
                jlist.append(j)
    ilist=np.array(ilist)
    jlist=np.array(jlist)
    Slist=np.array(Slist)
    ilist=ilist[np.argsort(Slist)]
    jlist=jlist[np.argsort(Slist)]
    ilist=ilist[:k-1].tolist()
    jlist=jlist[:k-1].tolist()
    l=ilist+jlist
    counter = Counter(l)
    mce, mcc = counter.most_common(1)[0]
    if mcc<k-1:
        return -1
    else:
        return mce

def main(N,n):
    if len(N)!=len(n):
        print(’len(N)!=len(n)’)
        return -1
    d=np.array(n)-np.array(N)
    if len(d[d<0])>0:
        print("n < N")
        return -1
    outN=[]
    outn=[]
    output=len(N)+1
    while output>=0:
        output=out(N,n)
        if output>=0:
            outliersN.append(N[output])
            outliersn.append(n[output])
            N=N[:output]+N[output+1:]
            n=n[:output]+n[output+1:]
            if len(N)==1:
                print(’Fragmented!’)
                outN.append(N[0])
                outn.append(n[0])
                return N,n,outN,outn
        else:
            return N,n,outN,outn



#example:
import matplotlib.pyplot as plt
N=[15,11,7,29,100]
n=[30,20,15,60,200]
newN,newn,outN,outn=main(N,n)
print(outN)
print(outn)
theta=np.arange(0,1,0.001)
for i in range(len(newN)):
    plt.plot(theta, \
    beta.pdf(theta,newN[i]+1, \
    newn[i]-newN[i]+1),color=’black’)
for i in range(len(outN)):
    plt.plot(theta, \
    beta.pdf(theta,outN[i]+1, \
    outn[i]-outN[i]+1),color=’red’)
plt.xlabel(’$\\theta$’,fontsize=16)
plt.ylabel(’Probability density’, \
    fontsize=16)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
plt.tight_layout()
plt.show()

References

  • [1] {barticle}[author] \bauthor\bsnmAnnis, \bfnmDavid H.\binitsD. H. (\byear2008). \btitleBayes Linear Statistics: Theory and Methods. \bjournalJournal of the American statistical association \bvolume103 \bpagesp.1319. \endbibitem
  • [2] {bbook}[author] \bauthor\bsnmBernoulli, \bfnmJakob\binitsJ. (\byear1713). \btitleJacobi Bernoulli,… Ars conjectandi, opus posthumum. Accedit Tractatus de seriebus infinitis, et epistola Gallice scripta De ludo pilae reticularis. \bpublisherimpensis Thurnisiorum, fratrum. \endbibitem
  • [3] {barticle}[author] \bauthor\bsnmKhintchine, \bfnmA Ya\binitsA. Y. (\byear1936). \btitleSu una legge dei grandi numeri generalizzata. \bjournalGiorn. Ist. Ital. Attuari \bvolume7 \bpages365–377. \endbibitem
  • [4] {bbook}[author] \bauthor\bsnmLoève, \bfnmMichel\binitsM. and \bauthor\bsnmLoève, \bfnmM\binitsM. (\byear1977). \btitleElementary probability theory. \bpublisherSpringer. \endbibitem
  • [5] {barticle}[author] \bauthor\bsnmShannon, \bfnmC. E.\binitsC. E. (\byear1948). \btitleA mathematical theory of communication. \bjournalThe Bell System Technical Journal \bvolume27 \bpages379-423. \bdoi10.1002/j.1538-7305.1948.tb01338.x \endbibitem