Testing significance of overlap in R I have got an answer for it from Spacedman. But I am not entirely satisfied with the answer as it does not give me any sort of value (p or z value). So I am re-framing my question and posting it again. No offences to Mr.Spacedman.
I have a dictionary of say 61000 elements and out of this dictionary, I have two sets. Set A contains 23000 elements and Set B contains 15000 elements and an overlap of Set A and Set B gives 10000 elements. How can I estimate a p-value or z value to show that this overlap is significant and is not occuring by chance or vice versa. 
What I have been suggested till now includes MonteCarlo simulation methods. Is it possible to have an analytical method.
Thank you in advance.
 A: If my comment is right, then you can Monte-carlo simulate it:
sim=unlist(lapply(1:10000,
 function(i){A=sample(1:27511,23706);B=sample(1:27511,14557);return(sum(A %in% B))}))
hist(sim)

Probably neater ways to do that loop but whatever.
Your 10752 is waaaay over to the left of my histogram, so significantly fewer common elements than expected by chance.
There may be some exact test that does the same. There's probably a Normal approximation - in which case it looks about 20 sigma off the mean:
hist(sim,xlim=c(10752,12660))

A: A model for this situation is to put 61000 ($n$) balls into an urn, of which 23000 ($n_1$) are labeled "A".  15000 ($k$) of these are drawn randomly without replacement.  Of these, $m$ are found to be labeled "A".  What is the chance that $m \ge 10000$?
The total number of possible samples equals the number of $k$-element subsets of an $n$-set, $\binom{n}{k}$.  All are equally likely to be drawn, by hypothesis.  Let $i \ge 10000$.  The number of possible samples with $i$ A's is the number of subsets of an $n_1$-set having $i$ A's, times the number of subsets of an $n-n_1$-set having $k-i$ non-A's; that is, $\binom{n_1}{i}\binom{n-n_1}{k-i}$.  Summing over all possible $i$ and dividing by the chance of each sample gives the probability of observing an overlap of $m = 10000$ or greater:
$$\Pr(\text{overlap} \ge m) = \frac{1}{\binom{n}{k}} \sum_{i=m}^{\min(n_1,k)} \binom{n_1}{i}\binom{n-n_1}{k-i}.$$
This answer is exact.  For rapid calculation it can be expressed (in closed form) in terms of generalized hypergeometric functions; the details of this expression can be provided by a symbolic algebra program like Mathematica.  The answer in this particular instance is $3.8057078557887\ldots \times 10^{-1515}$.
We can also use a Normal approximation.  Coding A's as 1 and non-A's as 0, as usual, the mean of the urn is $p = 23000/61000 \sim 0.377$.  The standard deviation of the urn is $\sigma = \sqrt{p(1-p)}$.  Therefore the standard error of the observed proportion, $u = 10000/15000 \sim 0.667$, is
$$se(u) = \sigma \sqrt{(1 - \frac{15000-1}{61000-1})/15000} \sim 0.003436.$$
(see http://www.ma.utexas.edu/users/parker/sampling/woreplshort.htm).  Thus the observed proportion is $z = \frac{u - p}{se(u)} \sim 84.28$ standard errors larger than expected.  Obviously the corresponding p-value is low (it computes to $1.719\ldots \times 10^{-1545}$).  Although the Normal approximation is no longer very accurate at such extreme z values (it's off by 30 orders of magnitude!), it still gives excellent guidance.
A: You have a large enough sample size that a Chi-square test is reasonable.  If you are using R, then chisq.test() is the function to utilize; its help page can be found via ?chisq.test.
A: Well, if nothing else, you can do it by simulation:
Draw 23000 random elements out of 61000 and draw 15000 random elements from the same 61000. Now count the number of overlapped items.
Repeat 100000 times (should not take all too long): now you have an empirical distribution of the number of overlapped items, and you can easily find an empirical p-value for 10000 elements.
Code like the following will do this:
countOverlap<-function(total=61000, numgA=23000, numgB=15000, replace=FALSE){
    groupA<-sample.int(total, numgA, replace=replace)
    groupB<-sample.int(total, numgB, replace=replace)
    return(length(intersect(groupA, groupB)))
}

tmpres<-replicate(1000, countOverlap(total=100, numgA=20, numgB=30))

#if your true observed value was 10:
pval<-mean(tmpres >= 10)
pval

However, it is possible that an analytical solution exists, and that simulation is not needed. Maybe someone else can provide that for you.
A: The correct approach depends on what is fixed.  If the size of the 2 sets are "fixed" then this is just done by a chi-squared test of independence where the 2x2 table is "in /not in" each set.  If only the total number of items is fixed, then the chi-squared test is not correct.
