Assume a sample size of 200, with mean (mu) = 20, and standard deviation (sigma) = 10.
import numpy as np
mu, sigma = 20, 10 # mean and standard deviation
s = np.random.normal(mu, sigma, 200)
np.quantile(s, 0.25)
np.quantile(s, 0.75)
I'm using Python for this example, but you can see that we are:
1) generating an array of 200 normally distributed random numbers
2) Obtaining the 25th and 75th quantile.
>>> np.quantile(s, 0.25)
11.700325588242732
>>> np.quantile(s, 0.75)
26.11671871467393
Now, when you say "90% margin of error", I am assuming you mean a 90% "confidence interval". In this case, your margin of error is 10%.
Using the scipy library (also from Python), we can obtain a 90% confidence interval as follows:
from scipy import stats
stats.norm.interval(0.90, loc=mu, scale=s)
More detail can be found on the above here.
You can now see that we generate an array where the values would fall within the 90% confidence interval:
>>> stats.norm.interval(0.90, loc=mu, scale=s)
(array([-20.1017426 , -50.41395259, -15.74140484, -34.9162548 ,
-14.55505407, -26.20186343, -8.38349335, -28.15329328,
............
0.3405667 , 14.1913693 , -44.18605464, -18.30478346]),
array([60.1017426 , 90.41395259, 55.74140484, 74.9162548 , 54.55505407,
66.20186343, 48.38349335, 68.15329328, 42.42820445, 70.17147704,
............
55.23983044, 41.10373296, 51.30638793, 57.20990033, 47.99641712]))
The above is obviously dependent on which software you are using and what dataset you are working with, but hopefully you might find these guidelines useful.
Best Answer
The formulas concerning the calculation of the sample size to estimate a proportion $p$ in for finite populations are provided on this website. It also contains the derivations.
In short, the sample size necessary for estimating a population proportion $p$ of a finite population with $(1-\alpha)100\%$ confidence and a margin of error no larger than $\epsilon$ is:
$$ n = \frac{m}{1+\frac{m-1}{N}} $$ where $$ m=\frac{z_{1-\alpha/2}^{2}\hat{p}(1-\hat{p})}{\epsilon^{2}}. $$ $N$ denotes the population size, $z_{1-\alpha/2}$ the $(1-\alpha/2)$-quantile of the standard normal distribution and $\hat{p}$ the estimated proportion.
For $N=580, \alpha=0.05, \epsilon=0.1, \hat{p}=0.5$ (i.e. 95% confidence), we get $n\approx 83$. If we take $\alpha = 0.1$ which corresponds to 90% confidence, we get $n\approx 61$.
The more precise we want our estimate of the popultion proportion to be, the higher our sample size needs to be.
This means that the lower $\alpha$, the higher the necessary sample size will be. The following graph illustrates this (for $N=580, \epsilon=0.1, \hat{p}=0.5$):
The necessary sample size will also increase with decreasing margin of error $\epsilon$ (note the reversed $x$-axis; graph for $N=580, \alpha=0.05, \hat{p}=0.5$):