text:
# Homework Help: Electric field calculation

1. Mar 23, 2010

### yoni162

1. The problem statement, all variables and given/known data
We have a sphere with radius b, within that sphere there's another sphere with radius a. Between the two spheres we have an electric charge with density A/r. Also, we have a charge Q in the center. We need to find the constant A so that the field between a and b is independent of r (meaning, it's constant for a<=r<=b).

2. Relevant equations
Gauss' law.

3. The attempt at a solution
I added the scanned pages I've written, it should be understandable. As I said, I used Gauss' law to calculate the field, using a sphere with radius r (a<=r<=b) to calculate the electric flux. After finding the electric field as a function of r, I calculated d(E(r))/dr and demanded that it would be=0, but I can't seem to get a solution for A that's independent of r.

#### Attached Files:

File size:
13.3 KB
Views:
141
File size:
10.3 KB
Views:
127
• ###### 002.jpg
File size:
13.3 KB
Views:
130
2. Mar 23, 2010

### collinsmark

$$Qin = \frac{A}{r} \left[ \frac{4}{3}\pi r^3 - \frac{4}{3}\pi a^3 \right] + Q$$

That's not right. You're going to need to re-evaluate the volume integral. The $$(4/3)\pi r^3$$ terms only makes sense if the charge distribution is uniformly distributed about the sphere. You can't just multiply them by A/r. It doesn't work that way. You'll have to re-do the volume integral, integrating A/r' from r' = a to r in spherical coordinates (be careful to use the correct volume differential when performing the integral -- it's not simply dr') .

Once you have an expression for the electric field, E, don't worry about taking the derivative. Instead, find the electric field at r = a, and call that Ea. Then find Eb, the electric field at r = b. Set Ea and Eb equal to each other and solve for A.

3. Mar 25, 2010

### yoni162

How did I not notice that..thanks, that solved it.


text:
## 5.4 Stratified Random Sampling

The theory we developed in the previous section allows us to determinee the distribution of the three unbiased estimators $$\overline{y}$$, $$\hat{tau}$$, and $$p$$.

For instance, we have shown that if the size $$N$$ of a finite population $$\mathcal{U}=\{u_1,\ldots,u_N\}$$ of expectation $$\mu$$ and variance $$\sigma^2$$ and the size $$n$$ of the SRS $$\mathcal{Y}$$ from which the estimator $$\overline{y}$$ is constructed are sufficiently large, and if moreover the responses $$u_j$$ are i.i.d. for $$1\leq j\leq N$$, then $$\overline{y}$$ follows approximately a normal distribution whose parameters are $\text{E}(\overline{y})=\mu\quad\text{and}\quad \text{V}(\overline{y})=\frac{\sigma^2}{n}\Big(\frac{N-n}{N-1}\Big).$

The higher $$\sigma^2$$ is, the more the $$\overline{y}$$ values that result from a repeated SRS vary.

In practice, the normal approximation is:

• often acceptable – see average life expectancy, previous section;

• but it is not always so, which can lead to some challenges – cf. the $$\text{C.I.}(\mu;0.95)$$ for the average population which was in fact only an 80% C.I. for a SRS of size $$n=20$$ in the previous section.

In the presence of outliers or when $$n,N$$ are too small, the performance of an SRS may leave something to be desired.

Example: consider a finite population with $$N=16$$ elements: $2,2,2,2,0,0,0,0,1,1,1,1,5,5,5,5.$ The population mean and variance are, respectively: \begin{aligned} \mu&={\frac{1}{16}(4\cdot 2+4\cdot 0+4\cdot 1+4\cdot 5)=2}; \\ \sigma^2&={\frac{1}{16}(4\cdot 2^2+4\cdot 0^2+4\cdot 1^2+4\cdot 5^2)-2^2=\frac{7}{2}}.\end{aligned} Suppose that we draw an SRS of size $$n=4$$ from this population, in order to estimate the mean $$\mu$$.

From what we discussed in the previous section, the expectation and sampling variance of the estimator $$\overline{y}$$ are, respectively: $\text{E}(\overline{y})={2}\quad\mbox{and}\quad\text{V}(\overline{y})={\frac{\sqrt{7/2}^2}{4}\Big(\frac{16-4}{16-1}\Big)=\frac{7}{10}}.$

But we could also restrict the sampling structure in the following manner:

1. we start by separating the population into 4 segments (the strata): \begin{aligned} \mathbf{strata\ 1:\ }& 2,2,2,2 \\ \mathbf{strata\ 2:\ }& 0,0,0,0 \\ \mathbf{strata\ 3:\ }& 1,1,1,1 \\ \mathbf{strata\ 4:\ }& 5,5,5,5 \end{aligned}

2. we then draw a SRS of size $$n=4$$ by selecting one unit per stratum.

In such a situation (which is NOT a SRS$$(n=4,N=16)$$), each achieved sample takes the form $$\{2,0,1,5\}$$: the empirical mean is always $$2$$, and so the sampling variance is null.

In practice, this artificial situation rarely occurs, but if the units of the population can be grouped into natural strata, i.e., sub-populations for which:

• the response value is homogeneous within each stratum, but

• it is heterogeneous from one stratum to another, then

this approach can produce an estimator whose sampling variance is lower than that of the SRS estimator (as a bonus, the sample preserves certain population structures). $$\blacksquare$$

Example: find an approximate 95% C.I. for the average population per country (excluding China and India) in 2011.

Solution: the population distribution in the 2011 Gapminder dataset has the following characteristics:

gapminder.StS <- gapminder |>
filter(year==2011) |>
select(population) |>
filter(population < 1000000000)
summary(gapminder.StS$population)  Min. 1st Qu. Median Mean 3rd Qu. Max. 56441 2061342 7355231 23301958 22242334 312390368  The true average population, by country, is $$\mu=23,301,958$$. Recall that the population distribution is asymetrical: N = nrow(gapminder.StS) ggplot(data=gapminder.StS, aes(population)) + geom_histogram(col="black", fill="blue", alpha=.2) + geom_vline(xintercept=mean(gapminder.StS$population), color="red") +
geom_rug()

We use the following population strata: from 0 to 10M, from 10M to 25M, from 25M to 50M, from 50M to 100M, and 100M+.

gapminder.StS <- gapminder.StS |>
mutate(strata = ifelse(population<10000000,"S1",
ifelse(population<25000000,"S2",
ifelse(population<50000000,"S3",
ifelse(population<100000000,"S4","S5")))))

# sorting the observations from the smallest to the largest
gapminder.StS <- gapminder.StS[order(gapminder.StS$population),] # format conversion for the strata variable gapminder.StS$strata <- as.factor(gapminder.StS$strata) The number of countries in each stratum is: strata.N <- tapply(gapminder.StS$population, gapminder.StS$strata, length) strata.N  S1 S2 S3 S4 S5 105 35 21 13 9  For a sample size of $$n=20$$, we use approximately $$n_i$$ countries per stratum $$S_i$$: strata.N/sum(strata.N)*20  S1 S2 S3 S4 S5 11.4754098 3.8251366 2.2950820 1.4207650 0.9836066  Some practical considerations might suggest the use of a different allocation (more on this later). The distribution of the population by stratum has the following characteristics: tapply(gapminder.StS$population, gapminder.StS$strata, summary) $S1
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
56441  622957 2886010 3386819 5411377 9988846

$S2 Min. 1st Qu. Median Mean 3rd Qu. Max. 10027140 11234699 15177280 15682124 20213668 24928503$S3
Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
25016921 29427631 34499905 36211465 41655616 49356692

$S4 Min. 1st Qu. Median Mean 3rd Qu. Max. 52237272 63268405 73517002 73841185 83787634 94501233$S5
Min.   1st Qu.    Median      Mean   3rd Qu.      Max.
120365271 143211476 163770669 182154642 200517584 312390368

In the first attempt, we draw a SRS from each stratum, using the following sizes: $$(n_1,n_2,n_3,n_4,n_5)=(11,4,3,1,1)$$:

n=c()
n[1] = 11
n[2] = 4
n[3] = 3
n[4] = 1
n[5] = 1
indices = list()
set.seed(12345) # replicability

# draw a SRS of indices in each of the 5 strata
indices[[1]] <- sample(1:strata.N[1],n[1])
indices[[2]] <- sum(strata.N[1:1]) +  sample(1:strata.N[2],n[2])
indices[[3]] <- sum(strata.N[1:2]) + sample(1:strata.N[3],n[3])
indices[[4]] <- sum(strata.N[1:3]) + sample(1:strata.N[4],n[4])
indices[[5]] <- sum(strata.N[1:4]) + sample(1:strata.N[5],n[5])

The average population in the sample is computed as below (this value will change from one StS to another).

ind.StS <-unique(unlist(indices))
sample.StS <- gapminder.StS[ind.StS,]
mean(sample.StS$population) [1] 24378331 Despite the relative accuracy of the estimate, this naı̈ve approach is not ideal. The estimator $\overline{y}_{\text{StS}}=\textstyle{\frac{1}{20}(y_1+\cdots+y_{20})}$ implies that each observation had the same probability of being chosen, which is not the case in reality ($$\neg$$SRS). In the second attempt, the weight of each selected observation depends on the size of the stratum (we will discuss the theoretical details in the next section). cumul.n = cumsum(n) cumul.N = cumsum(strata.N) set.seed(123456) # replicability indices = list() indices[[1]] <- sample(1:strata.N[1],n[1]) for(j in 2:length(n)){ indices[[j]] <- cumul.N[j-1] + sample(1:strata.N[j],n[j]) } ind.StS <-unique(unlist(indices)) sample.StS <- gapminder.StS[ind.StS,] sample.StS = sample.StS[order(sample.StS$population),]

y.bar <- list()
y.bar[[1]] <- mean(sample.StS[1:n[1],c("population")])
for(j in 2:length(n)){
y.bar[[j]] <- mean(sample.StS[(cumul.n[j-1]+1):cumul.n[j],c("population")])
}

y.bar.StS <- 0
for(j in 1:length(n)){
y.bar.StS <- y.bar.StS + as.numeric(strata.N[j])*y.bar[[j]]
}
y.bar.StS/N
[1] 22668202

The estimate is very close to the actual value of $$\mu$$, but a lone point estimate does not tell the full story.

We repeat this procedure 500 times, using the size allocation $$(n_1,n_2,n_3,n_4,n_5)=(9,3,3,3,2)$$:

set.seed(12) # replicability
strata.N <- tapply(gapminder.StS$population, gapminder.StS$strata, length)
cumul.N = cumsum(strata.N)

n=c()
n[1] = 9
n[2] = 3
n[3] = 3
n[4] = 3
n[5] = 2
cumul.n = cumsum(n)

m=500
means <- c()
for(k in 1:m){
indices = list()
indices[[1]] <- sample(1:strata.N[1],n[1])
for(j in 2:length(n)){
indices[[j]] <- cumul.N[j-1] + sample(1:strata.N[j],n[j])
}
ind.StS <-unique(unlist(indices))
sample.StS <- gapminder.StS[ind.StS,]
sample.StS = sample.StS[order(sample.StSpopulation),] y.bar <- list() y.bar[[1]] <- mean(sample.StS[1:n[1],c("population")]) for(j in 2:length(n)){ y.bar[[j]] = mean(sample.StS[(cumul.n[j-1]+1):cumul.n[j],c("population")]) } y.bar.StS <- 0 for(j in 1:length(n)){ y.bar.StS <- y.bar.StS + as.numeric(strata.N[j])*y.bar[[j]] } means[k] <- y.bar.StS/N } For each sample $$1 \leq i \leq 500$$, we then compute the empirical mean – their distribution has the following characteristics: summary(means)  Min. 1st Qu. Median Mean 3rd Qu. Max. 17608174 21602380 22735650 23179372 24655297 29082447  Finally, we plot the histogram of the StS means (with their mean in red): ggplot(data=data.frame(means), aes(means)) + geom_rug() + geom_histogram(col="black", fill="blue", alpha=.2) + geom_vline(xintercept=mean(means), color="red")  Not only is the shape of the distribution closer to a normal distribution, compared to the distribution of $$overline{y}$$ obtained using SRS, but its variance is also much lower (compare the following image, on the same scale as the corresponding histogram for SRS in Section 5.3.2). ggplot(data=data.frame(means), aes(means)) + geom_rug() + geom_histogram(col="black", fill="blue", alpha=.2) + xlim(0,60000000) + geom_vline(xintercept=mean(means), color="red")  ### 5.4.1 Estimators and Confidence Intervals Assume that we are yet again interested in a finite population $$\mathcal{U}=\{u_1,\ldots,u_N\}$$, whose expectation is $$\mu$$ and variance is $$\sigma^2$$. Suppose that we can cover the population with $$M$$ disjoint strata, containing, respectively, $$N_1,\ldots,N_M$$ units: $\mathcal{U}_1=\{u_{1,1},\ldots, u_{1,N_1}\}, \ \cdots \ , \ \mathcal{U}_M=\{u_{M,1},\ldots, u_{M,N_M}\},$ with stratum mean and stratum variance $\mu_i={\frac{1}{N_i}\sum_{j=1}^{N_i}u_{i,j}}\quad\text{and}\quad \sigma_i^2={\frac{1}{N_i}\sum_{j=1}^{N_i}u_{i,j}^2-\mu_i^2},\quad 1\leq i\leq M.$ A stratified sample $$\mathcal{Y}$$ of size $$n\leq N$$ is a subset of the target population $$\mathcal{U}$$, with$$n_1+\cdots + n_M=n$$ and $$n_i\leq N_i$$ for $$1\leq i\leq M$$: $\{\underbrace{\strut y_{1,1},\ldots, y_{1,n_1}}_{{\text{\in strate \mathcal{U}_1}}},\ldots,\underbrace{\strut y_{M,1},\ldots, y_{M,n_m}}_{{\text{\in strate \mathcal{U}_M}}}\}\subseteq \bigcup_{i=1}^M\mathcal{U}_i=\mathcal{U}.$ If every sample $$\mathcal{Y}_i=\{y_{i,j}\mid 1\leq j\leq n_i\}$$ is drawn from the corresponding stratum $$\mathcal{U}_i$$ via a SRS, independently from one stratum to another, we obtain a stratified random sample (StS) of size $$n$$. The sample mean and the sample variance (which it is important to remember is not the same thing as the “sampling variance” of an estimator) of $$\mathcal{Y}_i$$ are denoted by $$\overline{y}_i$$ et $$s_i^2$$, respectively. In a StS design, each observation in a stratum has the same probability of being selected, but this probability may differ from one stratum to another. #### Mean $$\mu$$ In a StS, the sample mean of the observations of the sample $$\mathcal{Y}$$ falling in the stratum $$\mathcal{U}_i$$ is an estimator of $$\mu_i$$ given by $\overline{y}_i={\frac{1}{n_i}\sum_{\ell=1}^{n_i}y_{i,\ell}},\quad \text{where }n_i=|\mathcal{U}\cap \mathcal{Y}_i| ,\ 1\leq i\leq M.$ The true mean $$\mu$$ and the StS estimator of $$\mu$$ are thus: $\mu=\frac{1}{N}\sum_{j=1}^Nu_{j}={\frac{1}{N}\sum_{i=1}^M\sum_{j=1}^{N_i}u_{i,j}=\frac{1}{N}\sum_{i=1}^MN_i\mu_i}\quad \text{and}\quad \overline{y}_{\text{StS}}={\frac{1}{N}\sum_{i=1}^MN_i\overline{y}_i}.$ For the sake of completeness, the SRS estimator is sometimes denoted by $$\overline{y}_{\text{SRS}}$$. Since $$\mathcal{Y}_i$$ is a SRS drawn from $$\mathcal{U}_i$$, we have: $\text{E}(\overline{y}_i)={\mu_i}\quad\text{and}\quad \text{V}(\overline{y}_i)={\frac{\sigma_i^2}{n_i}\Big(\frac{N_i-n_i}{N_i-1}\Big)},\quad\text{pour } 1\leq i\leq M.$ The expectation of the StS estimator is thus: $\text{E}\left(\overline{y}_{\text{StS}}\right)=\text{E}\left({\frac{1}{N}\sum_{i=1}^MN_i\overline{y}_i}\right)={\frac{1}{N}\sum_{i=1}^MN_i\text{E}(\overline{y}_i)=\frac{1}{N}\sum_{i=1}^MN_i\mu_i=\mu},$ which is to say that $$\overline{y}_{\text{StS}}$$ is an unbiased estimator of the true mean $$\mu$$ for a population of size $$N$$ with variance $$\sigma^2$$.59 The sampling variance of the estimator $$\overline{y}_{\text{StS}}$$ is \begin{aligned} \text{V}\left(\overline{y}_{\text{StS}}\right)&=\text{V}\left({\frac{1}{N}\sum_{i=1}^MN_i\overline{y}_i}\right)={\frac{1}{N^2}\sum_{i=1}^M N_i^2\text{V}(\overline{y}_i)+\sum_{i\neq i'}^MN_iN_{i'}\underbrace{\strut \text{Cov}(\overline{y}_i,\overline{y}_{i'})}_{\text{=0}}} \\ &= {\frac{1}{N^2}\sum_{i=1}^M N_i^2\text{V}(\overline{y}_i)} = \frac{1}{N^2}\sum_{i=1}^M N_i^2\cdot \frac{\sigma_i^2}{n_i}\Big(\frac{N_i-n_i}{N_i-1}\Big).\end{aligned} Central Limit Theorem – StS: if $$n$$, $$N-n$$, $$n_i$$, and $$N_i-n_i$$ are all sufficiently large, for all i, then $\overline{y}_{\text{StS}}\sim_{\text{approx.}}{\mathcal{N}\left(\text{E}(\overline{y}_{\text{StS}}),\text{V}(\overline{y}_{\text{StS}})\right)=\mathcal{N}\left(\mu,\frac{1}{N^2}\sum_{i=1}^M N_i^2\cdot \frac{\sigma_i^2}{n_i}\Big(\frac{N_i-n_i}{N_i-1}\Big)\right)}.$ In a StS, the bound on the error of estimation is $B_{\mu;\text{StS}}=2\sqrt{\text{V}(\overline{y}_{\text{StS}})}={2\sqrt{\frac{1}{N^2}\sum_{i=1}^M N_i^2\cdot \frac{\sigma_i^2}{n_i}\Big(\frac{N_i-n_i}{N_i-1}\Big)}}$ and the corresponding approximate 95% C.I. for $$\mu$$ is $\text{C.I.}_{\text{StS}}(\mu;0.95):\quad {\overline{y}_{\text{StS}}\pm B_{\mu;\text{StS}}}.$ In practice, the population variance $$\sigma^2$$ is rarely known (as is the variance $$\sigma_i^2$$ in each stratum $$\mathcal{U}_i$$, $$1\leq i\leq M$$). We then use the sample variance (and the corresponding finite population correction factor). In each stratum, the empirical variance $$s_i^2$$ is $s_i^2={\frac{1}{n_i-1}\sum_{\ell=1}^{n_i}(y_{i,\ell}-\overline{y}_i)^2=\frac{1}{n_i-1}\Big[\sum_{\ell=1}^{n_i}y_{i,\ell}^2-n_i\overline{y}_i^2\Big]},\quad 1\leq i\leq M.$ We can then approximate the sampling variance in $$\mathcal{U}_i$$ as we did for a SRS, using $\hat{\text{V}}(\overline{y}_i)={\frac{s_i^2}{n_i}\Big(1-\frac{n_i}{N_i}\Big)}, \quad 1\leq i\leq M.$ The sampling variance of the estimator $$\overline{y}_{\text{StS}}$$ is thus $\hat{\text{V}}(\overline{y}_{\text{StS}})={\frac{1}{N^2}\sum_{i=1}^M N_i^2\text{V}(\overline{y}_i)=\frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot\frac{s_i^2}{n_i}\Big(1-\frac{n_i}{N_i}\Big)}.$ The bound of the estimation error is approximated by $B_{\mu;\text{StS}}\approx \hat{B}_{\mu;\text{StS}}=2\sqrt{\hat{\text{V}}(\overline{y}_{\text{StS}})}={2\sqrt{\frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot\frac{s_i^2}{n_i}\Big(1-\frac{n_i}{N_i}\Big)}},$ whence $\text{C.I.}_{\text{StS}}(\mu;0.95): \quad {\overline{y}_{\text{StS}}\pm \hat{B}_{\mu;\text{StS}}\equiv \overline{y}_{\text{StS}}\pm 2\sqrt{\frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot\frac{s_i^2}{n_i}\Big(1-\frac{n_i}{N_i}\Big)}}$ is an approximate 95% C.I. for $$\mu$$. In practice, when the stratum sampling rate $$\frac{n_i}{N_i}$$ is below 5%, we can drop the FPCF in the corresponding stratum. Example: consider a finite population $$\mathcal{U}$$ of size $$N=37,444$$, separated in two disjoint strata $$\mathcal{U}_1$$ and $$\mathcal{U}_2$$, of respective sizes $$N_1=21,123$$ and $$N_2=16,321$$. A StS sample $$\mathcal{Y}$$ of size $$n=132$$ is drawn from $$\mathcal{U}$$, with $$n_1=82$$ and $$n_2=50$$. Suppose the empirical mean and standard deviation in $$\mathcal{Y}_1$$ and $$\mathcal{Y}_2$$ are $$\overline{y}_1=120.7$$, $$\overline{y}_2=96.6$$, $$s_1=18.99$$, and $$s_2=14.31$$, respectively. Find a 95% C.I. for the mean $$\mu$$ of $$\mathcal{U}$$. Solution: the bound on the error of estimation is $$\approx\hat{B}_{\mu;\text{StS}}=2\sqrt{\hat{\text{V}}(\overline{y}_{\text{StS}})}$$: $2\sqrt{\frac{21123^2}{37444^2}\cdot\frac{18.99^2}{82}\Big(1-\frac{82}{21123}\Big)+\frac{16321^2}{37444^2}\cdot\frac{14.31^2}{50}\Big(1-\frac{50}{16321}\Big)}\approx 2.95,$ whence $$\text{C.I.}_{\text{StS}}(\mu;0.95)\approx \big(\textstyle{\frac{21,123(120.7)}{37,444}}+\textstyle{\frac{16,321(96.6)}{37,444}}\big)\pm 2.95\equiv (107.25,113.14).$$ $$\blacksquare$$ Example: find a 95% confidence interval for the average life expectancy by country in 2011 (including India and China), using a StS of size $$n=20$$ (stratifying using the country populations, as we did earlier in this section). Solution: we can basically re-use the same code: LE.1 <- gapminder |> filter(year==2011) |> select(population,life_expectancy) summary(LE.1)  population life_expectancy Min. :5.644e+04 Min. :46.70 1st Qu.:2.064e+06 1st Qu.:65.30 Median :7.563e+06 Median :73.70 Mean :3.708e+07 Mean :71.18 3rd Qu.:2.423e+07 3rd Qu.:77.40 Max. :1.348e+09 Max. :83.02  The average life expectancy is $$\mu=71.18$$. We now prepare the strata according to the population, and we sort the observations from the smallest population to the largest: LE.1 <- LE.1 |> mutate(strata = ifelse(population<10000000,"S1", ifelse(population<25000000,"S2", ifelse(population<50000000,"S3", ifelse(population<100000000,"S4","S5"))))) LE.1 <- LE.1[order(LE.1population),]
LE.1$strata <- as.factor(LE.1$strata)

The number of countries in each stratum is given below:

(strata.N <- tapply(LE.1$life_expectancy, LE.1$strata, length))
 S1  S2  S3  S4  S5
105  35  21  13  11

Unfortunately, the life expectancy distributions of each stratum overlap to a great extent: this is not a good sign as it suggests that a country’s population is not aligned with its life expectancy (and so the strata are not heterogeneous with respect to life expectancy).

ggplot(LE.1,aes(x=life_expectancy,fill=strata)) +
geom_density(alpha=0.5) + geom_rug()

Since there are $$N=185$$ observations in the data set, a sample of size $$n=20$$, allocated in such a way as to maintain the relative frequencies of the number of observations in each $$\mathcal{U}_i$$ (this is known as proportional allocation), would have the following stratum allocation:

N=sum(strata.N)
strata.N/sum(strata.N)*20
       S1        S2        S3        S4        S5
11.351351  3.783784  2.270270  1.405405  1.189189

In practice, we prefer to have at least 2 observations per stratum, so we might use $$(n_1,n_2,n_3,n_4,n_5)=(11,3,2,2,2)$$.

n=c(11,3,2,2,2)

We select a StS sample $$\mathcal{Y}$$ with these characteristics via:

cumul.n = cumsum(n)
cumul.N = cumsum(strata.N)

set.seed(123456) # replicability
indices = list()
indices[[1]] <- sample(1:strata.N[1],n[1])
for(j in 2:length(n)){
indices[[j]] <- cumul.N[j-1] + sample(1:strata.N[j],n[j])
}

ind.LE.1 <-unique(unlist(indices))

sam.LE.1 <- LE.1[ind.LE.1,]
sam.LE.1 <- sam.LE.1[order(sam.LE.1population),] Next, we compute the mean $$\overline{y}_i$$ and the standard deviation $$s_i$$ in each bucket $$\mathcal{Y}_i$$, $$1\leq i\leq 5$$. y.bar <- list() std.dev <- list() y.bar[[1]] <- mean(sam.LE.1[1:n[1],c("life_expectancy")]) std.dev[[1]] <- sd(sam.LE.1[1:n[1],c("life_expectancy")]) for(j in 2:length(n)){ y.bar[[j]] <- mean(sam.LE.1[(cumul.n[j-1]+1):cumul.n[j],c("life_expectancy")]) std.dev[[j]] <- sd(sam.LE.1[(cumul.n[j-1]+1):cumul.n[j],c("life_expectancy")]) } rbind(y.bar,std.dev)  [,1] [,2] [,3] [,4] [,5] y.bar 70.83636 71.6 67.55 72.15 76.2 std.dev 7.551327 3.774917 18.45549 2.757716 9.050967 There is not much variation in the means, but the standard deviation values are all over the place: this is due to small sample sizes in some strata, and overlapping distributions of life expectancy by strata. As we’ve already mentioned, the stratification of countries by population does not align with the estimate of mean life expectancy.60. The estimator $$\overline{y}_{\text{StS}}$$ is: mean.LE.1 <- 0 for(j in 1:length(n)){ mean.LE.1 <- mean.LE.1 + as.numeric(strata.N[j])*y.bar[[j]] } (mean.LE.1 <- mean.LE.1/N) [1] 71.01902 This is fairly close to the true $$\mu$$. The bound on the error of estimation $$\hat{B}_{\mu;\text{StS}}$$ is: B=0 for(j in 1:length(n)){ B <- B + as.numeric((strata.N[j]/N)^2*std.dev[[j]]^2/n[j]*(1-n[j]/strata.N[j])) } (B <- 2*sqrt(B)) [1] 3.883388 This is fairly large, all things considered. The 95% C.I. is thus: c(mean.LE.1 - B, mean.LE.1 + B) [1] 67.13563 74.90241 Compare with the $$\text{C.I.}_{\text{SRS}}(\mu;0.95)$$ obtained previously – it was much narrower. This is no doubt due to stratification on the basis of population being a poor choice when dealing with life expectancy. Example: find a 95% confidence interval for the average life expectancy by country in 2011 (including India and China), using a StS of size $$n=20$$ (stratifying using the country life expectations.61 Solution: we make some modifications to the code, this time using the following strata: $\mathcal{U}_1=\{u_{j} \mid u_j<70\},\quad \mathcal{U}_2=\{u_{j} \mid 70\leq u_j<80\},\quad\mathcal{U}_3=\{u_{j} \mid u_j\geq 80\}.$ LE.2 <- gapminder |> filter(year==2011) |> select(life_expectancy) LE.2 <- LE.2 |> mutate(strata = ifelse(life_expectancy<70,"S1", ifelse(life_expectancy<80,"S2","S3"))) LE.2 <- LE.2[order(LE.2life_expectancy),]
LE.2$strata <- as.factor(LE.2$strata)
(strata.N <- tapply(LE.2$life_expectancy, LE.2$strata, length))
S1 S2 S3
65 93 27

By construction, the life expectancy distributions do not overlap from stratum to stratum.

ggplot(LE.2,aes(x=life_expectancy,fill=strata)) +
geom_density(alpha=0.5) + geom_rug(aes(color=life_expectancy))

Since there are $$N=185$$ observations in the data set, with $$(N_1,N_2,N_3)=(65,93,27)$$, a sample of size $$n=20$$ could be drawn according to the followin allocation:

N=sum(strata.N)
strata.N/sum(strata.N)*20
       S1        S2        S3
7.027027 10.054054  2.918919

We use $$(n_1,n_2,n_3)=(7,10,3)$$.

n=c(7,10,3)

The rest of the code is used as it was in the previous example.

cumul.n = cumsum(n)
cumul.N = cumsum(strata.N)

set.seed(123456) # replicability
indices = list()
indices[[1]] <- sample(1:strata.N[1],n[1])
for(j in 2:length(n)){
indices[[j]] <- cumul.N[j-1] + sample(1:strata.N[j],n[j])
}

ind.LE.2 <-unique(unlist(indices))

sam.LE.2 <- LE.2[ind.LE.2,]
sam.LE.2 <- sam.LE.1[order(sam.LE.2\$life_expectancy),]

y.bar <- list()
std.dev <- list()
y.bar[[1]] <- mean(sam.LE.2[1:n[1],c("life_expectancy")])
std.dev[[1]] <- sd(sam.LE.2[1:n[1],c("life_expectancy")])
for(j in 2:length(n)){
y.bar[[j]] <- mean(sam.LE.2[(cumul.n[j-1]+1):cumul.n[j],c("life_expectancy")])
std.dev[[j]] <- sd(sam.LE.2[(cumul.n[j-1]+1):cumul.n[j],c("life_expectancy")])
}

With this sample $$\mathcal{Y}$$, the strata means and standard deviations are:

rbind(y.bar,std.dev)
        [,1]     [,2]     [,3]
y.bar   71.5     70.27    74.2
std.dev 8.469553 7.721838 7.277362

These quantities are more reasonable than with the previous stratification (why?), but they could change from one sample to the next. The values for $$\overline{y}_{\text{StS}}$$ and $$\hat{B}_{\mu;\text{StS}}$$ are:

mean.LE.2 <- 0
for(j in 1:length(n)){
mean.LE.2 <- mean.LE.2 + as.numeric(strata.N[j])*y.bar[[j]]
}
(mean.LE.2 <- mean.LE.2/N)

B=0
for(j in 1:length(n)){
B <- B + as.numeric((strata.N[j]/N)^2*std.dev[[j]]^2/n[j]*(1-n[j]/strata.N[j]))
}
(B <- 2*sqrt(B))
[1] 71.27573
[1] 3.35133

The estimator is farily close to the true value $$\mu=71.18$$, but it is when calculating the bound on the error of estimation that the StS approach proves superior: the 95% C.I. for $$\mu$$ is:

c(mean.LE.2 - B, mean.LE.2 + B)
[1] 67.92440 74.62706

These examples show that stratified sampling can improve SRS estimation, but that this is not always going to be the case.

#### Total $$\tau$$

Most of the work has already been done: since the total $$\tau$$ can be re-written as $\tau=\sum_{j=1}^Nu_j=N\mu,$ we can estimate the total with a StS using: $\hat{\tau}_{\text{StS}}={N\overline{y}_{\text{StS}}=\frac{N}{N}\sum_{i=1}^MN_i\overline{y}_i=\sum_{i=1}^MN_i\overline{y}_i}.$

It is an unbiased estimator of the total since its expectation is $\text{E}(\hat{\tau}_{\text{StS}})={\text{E}(N\overline{y}_{\text{StS}})=N\cdot \text{E}(\overline{y}_{\text{StS}})=N\mu=\tau}.$ Its sampling variance is $\text{V}(\hat{\tau}_{\text{StS}})={\text{V}(N\overline{y}_{\text{StS}})=N^2\cdot \text{V}(\overline{y}_{\text{StS}})=\sum_{i=1}^MN_i^2\cdot \frac{\sigma_i^2}{n_i}\Big(\frac{N_i-n_i}{N_i-1}\Big)},$ assuming that we know the variance $$\sigma_i^2$$ in each strata $$\mathcal{U_i}$$, $$1\leq i\leq M$$, whence the bound on the error of estimation is $B_{\tau;\text{StS}}=2\sqrt{\text{V}(\hat{\tau}_{\text{StS}})}={2\sqrt{\sum_{i=1}^MN_i^2\cdot \frac{\sigma_i^2}{n_i}\Big(\frac{N_i-n_i}{N_i-1}\Big)}=N\cdot B_{\mu;\text{StS}}}.$

Since the variances $$\sigma_i^2$$ are usually unknown, we often substitute $$\sigma_i^2$$ with the empirical stratum variance $$s_i^2$$ calculated from the sample, which is multiplied by the correction factor $${\frac{N_i-1}{N_i}}$$, $$1\leq i\leq M$$. The approximation of the sampling variance is then $\hat{\text{V}}(\hat{\tau}_{\text{StS}})={\hat{\text{V}}(N\overline{y}_{\text{StS}})=\sum_{i=1}^MN_i^2\cdot \frac{s_i^2}{n_i}\Big(1-\frac{n_i}{N_i}\Big)},$ whence the bound on the error of estimation is $B_{\tau;\text{StS}}\approx\hat{B}_{\tau;\text{StS}}=2\sqrt{\hat{\text{V}}(\hat{\tau}_{\text{StS}})}={2\sqrt{\sum_{i=1}^MN_i^2\cdot \frac{s_i^2}{n_i}\Big(1-\frac{n_i}{N_i}\Big)}=N\cdot\hat{B}_{\mu;\text{StS}}},$ and the approximate 95% C.I. for $$\tau$$ is $\text{C.I.}_{\text{StS}}(\tau;0.95):\quad {\hat{\tau}_{\text{StS}}\pm \hat{B}_{\tau;\text{StS}}}.$

Example: consider a finite population $$\mathcal{U}$$ of size $$N=37,444$$, split into two strata $$\mathcal{U}_1$$ and $$\mathcal{U}_2$$, of sizes $$N_1=21,123$$ and $$N_2=16,321$$, respectively. A StS $$\mathcal{Y}$$ of size $$n=132$$ is drawn from $$\mathcal{U}$$, with $$n_1=82$$ and $$n_2=50$$. Suppose the empirical mean and standard deviation in $$\mathcal{Y}_1$$ and $$\mathcal{Y}_2$$ are $$\overline{y}_1=120.7$$, $$\overline{y}_2=96.6$$, $$s_1=18.99$$, and $$s_2=14.31$$, respectively. Find a 95% C.I. of the total $$\tau$$ in $$\mathcal{U}$$.

Solution: The bound on the error of estimation is $$\approx\hat{B}_{\tau;\text{StS}}=2\sqrt{\hat{\text{V}}(\hat{\tau}_{\text{StS}})}$$: $2\sqrt{21123^2\cdot\frac{18.99^2}{82}\Big(1-\frac{82}{21123}\Big)+16321^2\cdot\frac{14.31^2}{50}\Big(1-\frac{50}{16321}\Big)}\approx 110312.3,$ so $$\text{C.I.}_{\text{StS}}(\tau;0.95)\approx 21123(120.7)+16321(96.6)\pm 110312.3\approx (4015842,4236467).$$ $$\blacksquare$$

#### Proportion $$p$$

If the response $$u_{i,\ell} \in \{0,1\}$$ represents the absence or the presence of a certain characteristic for the $$\ell$$th unit in the $$i$$th strata $$\mathcal{U}_i$$, the mean $p=\mu=\frac{1}{N}\sum_{i=1}^M\sum_{\ell=1}^{N_i}u_{i,\ell}$ is the proportion of all units in $$\mathcal{U}$$ which posess the characteristic.

This proportion can be estimated with a StS via $\hat{p}_{\text{StS}}={\frac{1}{N}\sum_{i=1}^MN_i\hat{p}_i,\quad\text{where } \hat{p}_i=\frac{1}{n_i}\sum_{\ell=1}^{n_i}u_{i,\ell}, \ 1\leq i\leq M}.$

This is an unbiased estimator of $$p$$ since $\text{E}(\hat{p}_{\text{StS}})={\text{E}(\overline{y}_{\text{StS}})=\mu=p}.$

Its sampling variance is: \begin{aligned} \text{V}(\hat{p}_{\text{StS}})&={\text{V}(\overline{y}_{\text{StS}})= \frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot \frac{\sigma_i^2}{n_i}\Big(\frac{N_i-n_i}{N_i-1}\Big)}\\&={\frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot \frac{p_i(1-p_i)}{n_i}\Big(\frac{N_i-n_i}{N_i-1}\Big)},\end{aligned} where $$\sigma_i^2=p_i(1-p_i)$$ is the variance of the response variable $$u$$ in the stratum $$\mathcal{U}_i$$.

The bound on the error of estimation is $B_{p;\text{StS}}=2\sqrt{\text{V}(\hat{p}_{\text{StS}})}={2\sqrt{\frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot \frac{p_i(1-p_i)}{n_i}\Big(\frac{N_i-n_i}{N_i-1}\Big)}}.$

Since the proportions $$p_i$$ are not usually known, the approximate sampling variance is used instead: $\hat{\text{V}}(\hat{p}_{\text{StS}})={\frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot \frac{\hat{p}_i(1-\hat{p}_i)}{n_i-1}\Big(1-\frac{n_i}{N_i}\Big)}.$

The approximate bound on the error of estimation is thus $B_{p;\text{StS}}\approx\hat{B}_{p;\text{StS}}=2\sqrt{\hat{\text{V}}(\hat{p}_{\text{StS}})}={\frac{2}{N}\sqrt{\sum_{i=1}^MN_i^2\cdot \frac{\hat{p}_i(1-\hat{p}_i)}{n_i-1}\Big(1-\frac{n_i}{N_i}\Big)}},$ and the corresponding approximate 95% C.I. for $$p$$ is $\text{C.I.}_{\text{StS}}(p;0.95):\quad {\hat{p}_{\text{StS}}\pm \frac{2}{N}\sqrt{\sum_{i=1}^MN_i^2\cdot \frac{\hat{p}_i(1-\hat{p}_i)}{n_i-1}\Big(1-\frac{n_i}{N_i}\Big)}}.$

If the sample size in a stratum is too small, we can use the conservative estimate $$\hat{p}_i=0.5$$.

Example: consider a finite population $$\mathcal{U}$$ of size $$N=37,444$$, split into two strata $$\mathcal{U}_1$$ and $$\mathcal{U}_2$$, of sizes $$N_1=21,123$$ and $$N_2=16,321$$, respectively. A StS $$\mathcal{Y}$$ of size $$n=132$$ is drawn from $$\mathcal{U}$$, with $$n_1=82$$ and $$n_2=50$$. Suppose that $$n_1=20$$ of the observations from $$\mathcal{Y}_1$$ and $$n_2=5$$ of the observations from $$\mathcal{Y}_2$$ possess a certain characteristic. Find a 95% C.I. for the proportion $$p$$ of the units in $$\mathcal{U}$$ that possess the characteristic.

Solution: In this case, $$\hat{p}_1=20/82\approx 0.24$$ and $$\hat{p}_2=5/50=0.10$$, from which we obtain $\hat{p}_{\text{StS}}=\frac{21123}{37444}(0.24)\frac{16321}{37444}(0.10)=0.181.$ The bound on the error of estimation is thus $\textstyle{\hat{B}_p=\frac{2}{37444}\sqrt{21123^2\frac{0.24(1-0.24)}{82-1}\Big(1-\frac{82}{21123}\Big)+16321^2\frac{0.1(1-0.1)}{50-1}\Big(1-\frac{50}{16321}\Big)}\approx 0.0654},$ from which we conclude that $\text{C.I.}(p;0.95)\approx 0.181\pm 0.0654 \equiv (0.116,0.247).\quad \blacksquare$

### 5.4.2 Sample Size and Allocation

When determining the size of a StS sample $$\mathcal{Y}$$, one must also consider the problem of allocating the number of units $$n_i$$ in each stratum $$\mathcal{Y}_i$$. If $$|\mathcal{Y}_i|=n_i$$, $$1\leq i\leq M$$, then $$n=n_1+\cdots+n_M.$$ But how are the $$n_i$$ determined?

In a StS, the sampling variance of the estimator $$\overline{y}_{\text{StS}}$$ is $\text{V}(\overline{y}_{\text{StS}})=\frac{1}{N^2}\sum_{i=1}^M N_i^2\cdot \frac{\sigma_i^2}{n_i}\Big(\frac{N_i-n_i}{N_i-1}\Big).$

When $$N_i\gg 1$$, then $$N_i\approx N_i-1$$ and $\text{V}(\overline{y}_{\text{StS}})\approx {\frac{1}{N^2}\sum_{i=1}^M N_i^2\cdot \frac{\sigma_i^2}{n_i}\Big(\frac{N_i-n_i}{N_i}\Big)=\frac{1}{N^2}\sum_{i=1}^M N_i^2\cdot\frac{\sigma_i^2}{n_i}-\frac{1}{N^2}\sum_{i=1}^M N_i\sigma_i^2}.$ Since the sampling variance $$\text{V}(\overline{y}_{\text{StS}})$$ determines the bound on the error of estimation $$\hat{B}_{\mu;\text{StS}}$$, we can minimize the bound (and thus the error) by minimizing the sampling variance. The quantities $$N$$, $$N_i$$, $$\sigma_i^2$$, are fixed for $$1\leq i\leq M$$; what we minimize against is the sample size $$n$$ and the allocation $$n_i$$ in each stratum.

The total cost of the survey $$\tilde{C}$$ can also affect the allocation. The survey budget includes the overhead cost (indirect costs) $$c_0$$ and the cost per response $$c_i$$ in each stratum $$\mathcal{U}_i$$, $$1\leq i\leq M$$. The total cost is thus $\tilde{C}=c_0+\sum_{i=1}^Mc_in_i,$ which must remain below than available survey budget $$C$$.

The allocation problem is an optimization problem: we seek to solve $\arg_{(n,n_1,\ldots,n_M)}\min \text{V}(\overline{y}_{\text{StS}}),\quad \text{subject to } \tilde{C}\leq C.$ We use the method of Lagrange multipliers. The objective function becomes \begin{aligned} f(n_1,\ldots,n_M,\lambda)&=\text{V}(\overline{y}_{\text{StS}})+\lambda (\tilde{C}-C)\\ &={\frac{1}{N^2}\sum_{k=1}^M N_i^2\cdot\frac{\sigma_k^2}{n_k}-\frac{1}{N^2}\sum_{k=1}^M N_k\sigma_k^2+\lambda(c_0+\sum_{k=1}^Mc_kn_k-C)}.\end{aligned}

Its critical points solve \begin{aligned} 0&=\frac{\partial f(n_1,\ldots,n_M,\lambda)}{\partial n_i}= {\frac{1}{N^2}\sum_{k=1}^M N_k^2\sigma_k^2\frac{\partial (1/n_k)}{\partial n_i}+\lambda\sum_{k=1}^Mc_k\frac{\partial (n_k)}{\partial n_i}}\\ &={-\frac{N_i^2\sigma_i^2}{N^2n_i^2}+\lambda c_i},\quad 1\leq i\leq M,\end{aligned} which is to say that $n_i={\frac{N_i\sigma_i}{N\sqrt{\lambda}\sqrt{c_i}}},\quad 1\leq i\leq M.$

The strata sampling weights $$w_i$$ are $w_{i}={\frac{n_i}{n_1+\cdots+n_M}},\quad 1\leq i\leq M.$ The general optimal allocation is thus $w_{i}={\frac{n_i}{n}=\frac{\displaystyle{\frac{N_i\sigma_i}{N\sqrt{\lambda}\sqrt{c_i}}}}{\displaystyle{\sum_{k=1}^M\frac{N_k\sigma_k}{N\sqrt{\lambda}\sqrt{c_k}}}}=\frac{\displaystyle{\frac{N_i\sigma_i}{\sqrt{c_i}}}}{\displaystyle{\sum_{k=1}^M\frac{N_k\sigma_k}{\sqrt{c_k}}}}},\quad 1\leq i\leq M.$

Once we have determined the size $$n$$ of the sample $$\mathcal{Y}$$, we compute the size of the sample $$n_i$$ in each $$\mathcal{Y}_i$$ using $$w_i \cdot n$$, $$1\leq i\leq M$$. Since the product $$w_i\cdot n$$ is not typically an integer, we allocate $$[w_i\cdot n]$$ units to each $$\mathcal{Y}_i$$, and distribute the remaining $n-[w_1\cdot n]-\cdots-[w_M\cdot n]$ units using “common sense” (while ensuring that $$\tilde{C}\leq C$$).

If the cost per response in each stratum is constant, $$c_1=\cdots=c_M$$, Neyman allocation yields the following stratum sampling weights: $w_i=\frac{n_i}{n}={\frac{N_i\sigma_i}{\displaystyle{N_1\sigma_1+\cdots+N_M\sigma_M}}},\quad 1\leq i\leq M.$

If moreover the variance is the same in each stratum, $$\sigma_1^2=\cdots=\sigma_M^2$$, proportional allocation yields the following stratum sampling weights: $w_i=\frac{n_i}{n}={\frac{N_i}{N_1+\cdots+N_M}=\frac{N_i}{N}},\quad 1\leq i\leq M.$

Once the sample size and allocation have been selected, the methods in the previous section can be used to provide confidence intervals for the mean $$\mu$$, for the total $$\tau$$, or for a proportion $$p$$. When the variances are unknown, the usual approximations can be used.

We may at times use allocation schemes that are not necessarily ideal from a technical perspective, but which facilitate the preparation of reports or the dissemination of results: $w_i=\frac{n_i}{n}={\frac{f(N_i)}{f(N_1)+\cdots+f(N_M)}},\quad 1\leq i\leq M, \ f\ \text{a random function}.$

For intance, when studying Canadian populations, we often stratify according to the provinces and use $$f(x)=\sqrt{x}$$; the proportional allocation and square root allocation sampling weights for the 13 Canadian jurisdictions (based on 2022 population data) are shown below.

Example: consider a finite population $$\mathcal{U}$$ of size $$N=37,444$$, separated in two disjoint strata $$\mathcal{U}_1$$ and $$\mathcal{U}_2$$, of respective sizes $$N_1=21,123$$ and $$N_2=16,321$$. We seek to estimate the mean $$\mu$$ of $$\mathcal{U}$$ using a StS. The survey budget allows for a sample size $$n=132$$. In a preliminary study, we estimated $$\sigma_1\approx 20$$ and $$\sigma_2\approx 15$$. If the cost of a response in the first stratum is four times that of the cost of a response in the second stratum, find the general optimal allocation. If the response cost per stratum is constant, determine the Neyman and the proportional allocations.

Solution: in the general case, we have $$c_1=4c_2$$, $\frac{N_1\sigma_1}{\sqrt{c_1}}={\frac{21123(20)}{\sqrt{4c_2}}=\frac{211230}{\sqrt{c_2}}}, \quad \frac{N_2\sigma_2}{\sqrt{c_2}}={\frac{16321(15)}{\sqrt{c_2}}=\frac{244815}{\sqrt{c_2}}},$ and $\frac{N_1\sigma_1}{\sqrt{c_1}}+\frac{N_2\sigma_2}{\sqrt{c_2}}={\frac{211230}{\sqrt{c_2}}+ \frac{244815}{\sqrt{c_2}}=\frac{456045}{\sqrt{c_2}}},$ from which we conclude that $n_1={132\left(\frac{211230}{456045}\right)=61.13}\quad \text{and}\quad n_2={132\left(\frac{244815}{456045}\right)=70.87};$ the general optimal allocation is thus $$n_1={61}$$ and $$n_2={71}$$.

If the cost for a response is the same in both strata, $$c_1=c_2$$, then we have $N_1\sigma_1={21123(20)=422460}, \quad N_2\sigma_2={16321(15)=244815},$ and $N_1\sigma_1+N_2\sigma_2={422460+ 244815=667275},$ from which we conclude that $n_1={132\left(\frac{422460}{667275}\right)=83.57}\quad \text{and}\quad n_2={132\left(\frac{244815}{667275}\right)=48.43};$ the Neyman allocation is thus $$n_1={84}$$ and $$n_2={48}$$.

If we do not trust the study conducted beforehand, and we assume that the variance is constant in each stratum, $$\sigma_1=\sigma_2$$, then we have $N_1={21123}, \quad N_2={16321},$ and $N_1+N_2={21123+16321=37444},$ from which we conclude that $n_1={132\left(\frac{21123}{37444}\right)=74.46}\quad \text{and}\quad n_2={132\left(\frac{16321}{37444}\right)=57.54};$ la proportional allocation is thus $$n_1={74}$$ and $$n_2={58}$$. $$\blacksquare$$

#### Sample Size, Given a Bound on the Error of Estimation

In theory, only analytical considerations should influence the choice of sample size.

Recall that in a StS of size $$n$$, the sampling weight corresponding to the stratum $$\mathcal{U}_i$$ is $$w_i=frac{n_i}{n}$$, for $$1\leq i\leq M$$. When we estimate $$\mu$$ via $$\overline{y}_{\text{StS}}$$, the bound on the error of estimation can be written $B_{\mu;\text{StS}}={2\sqrt{\frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot \frac{\sigma_i^2}{w_i\cdot n}\Big(\frac{N_i-w_i\cdot n}{N_i-1}\Big)}}.$ We seek to express $$n$$ in terms of the parameters $$N_i$$, $$\sigma_i$$, $$w_i$$, and $$B_{\mu;\text{StS}}$$.

If $$N_i \gg 1$$ (what is hopefully the casein practice), then $$N_i\approx N_i-1$$ and so \begin{aligned} {\underbrace{\strut \frac{B^2_{\mu;\text{StS}}}{4}}_{=D_{\mu;\text{StS}}}}&{\approx \frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot \frac{\sigma_i^2}{w_i\cdot n}\Big(\frac{N_i-w_i\cdot n}{N_i}\Big)} \\ & \Longleftrightarrow {N^2D_{\mu;\text{StS}}\approx\frac{1}{n}\left\{\sum_{i=1}^M\frac{N_i^2\sigma_i^2}{w_i}\right\}-\sum_{i=1}^M\frac{N_i^2\sigma_i^2}{w_i}\cdot \frac{w_i}{N_i}} \\ & \Longleftrightarrow {\frac{N^2D_{\mu;\text{StS}}+\displaystyle{\sum_{i=1}^M N_i\sigma_i^2}}{\displaystyle{\sum_{i=1}^M\frac{N_i^2\sigma_i^2}{w_i}}}\approx \frac{1}{n}} \Longleftrightarrow n_{\mu;\text{StS}}\approx \frac{\displaystyle{\sum_{i=1}^M\frac{N_i^2\sigma_i^2}{w_i}}}{N^2D_{\mu;\text{StS}}+\displaystyle{\sum_{i=1}^M N_i\sigma_i^2}}.\end{aligned}

Under general optimal allocation, the stratum sampling weights are given by $w_i= \displaystyle{\frac{N_i\sigma_i}{\sqrt{c_i}}}\left(\displaystyle{\sum_{k=1}^M\frac{N_k\sigma_k}{\sqrt{c_k}}}\right)^{-1}\!\!\!\!\!\!\! , \quad 1\leq i\leq M,$ and the sample size is then \begin{aligned} n_{\mu;\text{StS}}&\approx{\frac{\displaystyle{\left(\sum_{i=1}^M\frac{N_i^2\sigma_i^2}{N_i\sigma_i/\sqrt{c_i}} \right) \div \left(\sum_{k=1}^M\frac{N_k\sigma_k}{\sqrt{c_k}}\right)^{-1}}}{N^2D_{\mu;\text{StS}}+\displaystyle{\sum_{i=1}^M N_i\sigma_i^2}}} = \frac{\displaystyle{\left(\sum_{i=1}^MN_i\sigma_i\sqrt{c_i}\right) \left(\sum_{i=1}^M\frac{N_i\sigma_i}{\sqrt{c_i}}\right)}}{{N^2D_{\mu;\text{StS}}+\displaystyle{\sum_{i=1}^M N_i\sigma_i^2}}}\end{aligned}

Under Neyman allocation, the stratum sampling weights are given by $w_i= \displaystyle{N_i\sigma_i}\left(\displaystyle{\sum_{k=1}^MN_k\sigma_k}\right)^{-1}\!\!\!\!\!\!\! , \quad 1\leq i\leq M,$ and the sample size is then \begin{aligned} n_{\mu;\text{StS}}&\approx{\frac{\displaystyle{\left(\sum_{i=1}^M\frac{N_i^2\sigma_i^2}{N_i\sigma_i} \right) \div \left(\sum_{k=1}^MN_k\sigma_k\right)^{-1}}}{N^2D_{\mu;\text{StS}}+\displaystyle{\sum_{i=1}^M N_i\sigma_i^2}}} = \frac{\displaystyle{\Big(\sum_{i=1}^MN_i\sigma_i\Big)^2}}{{N^2D_{\mu;\text{StS}}+\displaystyle{\sum_{i=1}^M N_i\sigma_i^2}}}\end{aligned}

In a proportional allocation scenario, the stratum sampling weights are given by $w_i= \displaystyle{N_i}\left(\displaystyle{\sum_{k=1}^MN_k}\right)^{-1}\!\!\!\!\!\!\! , \quad 1\leq i\leq M,$ and the sample size is then \begin{aligned} n_{\mu;\text{StS}}&\approx{\frac{\displaystyle{\left(\sum_{i=1}^M\frac{N_i^2\sigma_i^2}{N_i} \right) \div \left(\sum_{k=1}^MN_k\right)^{-1}}}{N^2D_{\mu;\text{StS}}+\displaystyle{\sum_{i=1}^M N_i\sigma_i^2}}} = \frac{\displaystyle{\sum_{i=1}^MN_i\sigma_i^2}}{{ND_{\mu;\text{StS}}+\displaystyle{\frac{1}{N}\sum_{i=1}^M N_i\sigma_i^2}}}\end{aligned}

When we try to estimate the total $$\tau$$ using the estimator $$\hat{\tau}_{\text{StS}}$$, we must substitute $D_{\mu;\text{StS}}=\frac{B^2_{\mu;\text{StS}}}{4}\quad\text{by} \quad D_{\tau;\text{StS}}=\frac{B^2_{\tau;\text{StS}}}{4N^2}.$

When we want to estimate a proportion $$p$$ using the estimator $$\hat{p}_{\text{StS}}$$, the bound remains $D_{p;\text{StS}}=\frac{B^2_{p;\text{StS}}}{4},$ but we have to substitute the stratum variances $$\sigma_i^2$$ by $$p_i(1-p_i)$$. The proportions $$p_i$$ can be estimated with the help of a previous study, or, conservatively, by using $$p_i=0.5$$.

Example: consider a finite population $$\mathcal{U}$$ of size $$N=37,444$$, separated in two disjoint strata $$\mathcal{U}_1$$ and $$\mathcal{U}_2$$, of respective sizes $$N_1=21,123$$ and $$N_2=16,321$$. We seek to estimate the mean $$\mu$$ of $$\mathcal{U}$$ using a StS, with a bound on the error of estimation of $$B_{\mu;\text{StS}}=5$$. The response costs by stratum are $$c_1=400\$$ and $$c_2=100\$$. In a preliminary study, we estimated $$\sigma_1\approx 20$$ and $$\sigma_2\approx 15$$. Determine the sample size and allocation in each of the three scenarios: general optimal allocation, Neyman allocation, and proportional allocation (in the last two cases, use $$c_1=c_2=100\$$).

Solution: in the general case, we have \begin{aligned} \frac{N_1\sigma_1}{\sqrt{c_1}}&={\frac{21123(20)}{\sqrt{400}}=21123,} \quad \frac{N_2\sigma_2}{\sqrt{c_2}}={\frac{16321(15)}{\sqrt{100}}=24481.5,} \\ N_1\sigma_1\sqrt{c_1}&={21123(20)\sqrt{400}=8449200,}\quad N_2\sigma_2\sqrt{c_2}={16321(15)\sqrt{100}=2448150}\\ N_1\sigma_1^2&={21123(20)^2=8449200,} \quad N_2\sigma_2^2={16321(15)^2=3672225,} \\ \sum_{i=1}^2\frac{N_i\sigma_i}{\sqrt{c_i}}&={45604.5,} \quad \sum_{i=1}^2N_i\sigma_i\sqrt{c_i}={10897350,} \quad \sum_{i=1}^2N_i\sigma_i^2={12121425,}\\ D_{\mu;\text{StS}}&={\frac{5^2}{4}=6.25,}\quad n={\frac{(10897350)(45604.5)}{(37444)^2(6.25)+12121425}=56.63\approx 57}\\ n_1&={57\left(\frac{21123}{45604.5}\right)=26.4\approx 26},\quad n_2={57\left(\frac{24481.5}{45604.5}\right)=30.6\approx 31.}\end{aligned}

If instead the response cost per stratum is constant ($$c_1=c_2=100$$), we have: \begin{aligned} N_1\sigma_1&={21123(20)=422460,} \quad N_2\sigma_2={16321(15)=244815,} \\ N_1\sigma_1^2&={21123(20)^2=8449200,} \quad N_2\sigma_2^2={16321(15)^2=3672225,} \\ \sum_{i=1}^2N_i\sigma_i&={667275,} \quad \sum_{i=1}^2N_i\sigma_i^2={12121425,}\\ D_{\mu;\text{StS}}&={\frac{5^2}{4}=6.25,}\quad n={\frac{(667275)^2}{(37444)^2(6.25)+12121425}=50.74\approx 51}\\ n_1&={51\left(\frac{422460}{667275}\right)=32.30\approx 32},\quad n_2={51\left(\frac{244815}{667275}\right)=18.71\approx 19.}\end{aligned} It turns out that the exact value of $$c_1=c_2$$ does not come into play.

If we look for a proportional allocation, we still have \begin{aligned} N_1\sigma_1&={21123(20)=422460,} \quad N_2\sigma_2={16321(15)=244815,} \\ N_1\sigma_1^2&={21123(20)^2=8449200,} \quad N_2\sigma_2^2={16321(15)^2=3672225,} \\ \sum_{i=1}^2N_i\sigma_i&={667275,} \quad \sum_{i=1}^2N_i\sigma_i^2={12121425,}\\ D_{\mu;\text{StS}}&={\frac{5^2}{4}=6.25,}\quad n={\frac{12121425}{37444(6.25)+\frac{12121425}{37444}}=51.72\approx 52}\\ n_1&={52\left(\frac{21123}{37444}\right)=29.33\approx 29},\quad n_2={52\left(\frac{16321}{37444}\right)=22.67\approx 23.}\end{aligned} The exact value of $$c_1=c_2$$ still does not come into play. $$\blacksquare$$

#### Sample Size, Given a Budget

In practice, however, it is often budgetary considerations that play the most important role in sample size selection.

In a StS of size $$n$$, the stratum sampling weights are $$w_i=\frac{n_i}{n}$$, for $$1\leq i\leq M$$. In this case, we seek to maximize the size $$n$$ allowed by the survey budget $$C$$: $C=c_0+\sum_{i=1}^Mc_in_i=c_0+n\sum_{i=1}^Mc_iw_i \implies n={\frac{C-c_0}{\displaystyle{\sum_{i=1}^Mc_iw_i}}}.$

In a general optimal allocation scenario, we have $w_i= \displaystyle{\frac{N_i\sigma_i}{\sqrt{c_i}}}\left(\displaystyle{\sum_{k=1}^M\frac{N_k\sigma_k}{\sqrt{c_k}}}\right)^{-1}\!\!\!\!\!\!\! , \quad 1\leq i\leq M,$ from which we see that $c_iw_i=c_i\cdot \frac{N_i\sigma_i}{\sqrt{c_i}}\left(\displaystyle{\sum_{k=1}^M\frac{N_k\sigma_k}{\sqrt{c_k}}}\right)^{-1}\!\!\!\!\!\!\! =N_i\sigma_i\sqrt{c_i}\left(\displaystyle{\sum_{k=1}^M\frac{N_k\sigma_k}{\sqrt{c_k}}}\right)^{-1}\!\!\!\!\!\!\! , \quad 1\leq i\leq M;$ the sample size is then \begin{aligned} n_{\text{StS}}&={(C-c_0)\left(\displaystyle{\sum_{i=1}^M\frac{N_i\sigma_i}{\sqrt{c_i}}}\right)\left(\displaystyle{\sum_{i=1}^MN_i\sigma_i\sqrt{c_i}}\right)^{-1}}\!\!\!\!\!\! .\end{aligned}

In a Neyman allocation or proportional allocation scenario, the sample weights are $w_i= \displaystyle{N_i\sigma_i}\Big(\displaystyle{\sum_{k=1}^MN_k\sigma_k}\Big)^{-1}\!\!\!\!\!\!\! , \quad 1\leq i\leq M,$ from which we see that $c_iw_i=c\cdot{N_i\sigma_i}\Big(\displaystyle{\sum_{k=1}^M{N_k\sigma_k}}\Big)^{-1}\!\!\!\!\!\!\! , \quad 1\leq i\leq M;$ the sample size is then \begin{aligned} n_{\text{StS}}&={(C-c_0)\left(\displaystyle{\sum_{i=1}^MN_i\sigma_i}\right)\left(c\displaystyle{\sum_{i=1}^MN_i\sigma_i}\right)^{-1}\!\!\!\!\!\! =\frac{C-c_0}{c}}.\end{aligned}

Example: consider a finite population $$\mathcal{U}$$ of size $$N=37,444$$, separated in two disjoint strata $$\mathcal{U}_1$$ and $$\mathcal{U}_2$$, of respective sizes $$N_1=21,123$$ and $$N_2=16,321$$. We seek to estimate the mean $$\mu$$ of $$\mathcal{U}$$ using a StS. The budget for the study is $$C=20,000\$$, minus $$c_0=4,000\$$ for overhead costs. The cost of a response in each stratum are $$c_1=400\$$ and $$c_2=100\$$, respectively. In a preliminary study, we estimate $$\sigma_1=20$$ and $$\sigma_2=15$$. Determine the sample size and allocation in each of the three scenarios: general optimal allocation, Neyman allocation, and proportional allocation (in the last two cases, use $$c_1=c_2=100\$$).

Solution: in the general case, we have \begin{aligned} \frac{N_1\sigma_1}{\sqrt{c_1}}&={\frac{21123(20)}{\sqrt{400}}=21123,} \quad \frac{N_2\sigma_2}{\sqrt{c_2}}={\frac{16321(15)}{\sqrt{100}}=24481.5,} \\ N_1\sigma_1\sqrt{c_1}&={21123(20)\sqrt{400}=8449200, }\\ N_2\sigma_2\sqrt{c_2}&={16321(15)\sqrt{100}=2448150}\\ \frac{N_1\sigma_1}{\sqrt{c_1}}+\frac{N_2\sigma_2}{\sqrt{c_2}}&={21123+ 24481.5=45604.5,} \\ N_1\sigma_1\sqrt{c_1}+N_2\sigma_2\sqrt{c_2}&={8449200+2448150=10897350,} \\ n&={(20000-4000)\Big(\frac{45604.5}{10897350}\Big)=66.96\approx 66,}\\ n_1={66\left(\frac{21123}{45604.5}\right)}&{=30.56\approx 31},\quad n_2={66\left(\frac{24481.5}{45604.5}\right)=35.43\approx 35.}\end{aligned}

If the response cost per stratum is constant ($$c_1=c_2=100$$): \begin{aligned} N_1\sigma_1&={21123(20)=422460,} \quad N_2\sigma_2={16321(15)=244815,} \\ N_1\sigma_1+N_2\sigma_2&={422460+ 244815=667275,} \\ n&={\frac{20000-4000}{100}=160,}\\ n_1={160\left(\frac{422460}{667275}\right)}&{=101.3\approx 101},\quad n_2={160\left(\frac{244815}{667275}\right)=58.7\approx 59.}\end{aligned}

If we also assume that the variances are equal in the 2 strata, the sample size remains $$n={160}$$, but the proportional allocation yields \begin{aligned} n_1&={160\left(\frac{21123}{37444}\right)=90.25\approx 90}\quad \text{and}\quad n_2={160\left(\frac{16321}{37444}\right)=69.74\approx 70.}\quad \blacksquare\end{aligned}

### 5.4.3 Comparison Between SRS and StS

Let $$\mathcal{U}=\{u_1,\ldots,u_N\}$$ have mean $$\mu$$ and variance $$\sigma^2$$.

Using a SRS of size $$n$$, we can construct the estimator $$\overline{y}_{\text{SRS}}$$, with sampling variance $\text{V}(\overline{y}_{\text{SRS}})={\frac{\sigma^2}{n}\Big(\frac{N-n}{N-1}\Big)}.$ We have studied the properties of such estimators in section 5.3.

If $$\mathcal{U}$$ can be split into $$M$$ strata \begin{aligned} \mathcal{U}_1&=\{u_{1,1},\ldots, u_{1,N_1}\}, \ \cdots \ , \ \mathcal{U}_M=\{u_{M,1},\ldots, u_{M,N_M}\},\end{aligned} with mean and variance $$\mu_i$$ and $$\sigma_i^2$$, respectively, for $$1\leq i\leq M$$.

Using a StS of size $$n=(n_1,\ldots,n_M)$$, we can construct the estimator $$\overline{y}_{\text{StS}}$$, with sampling variance $\text{V}(\overline{y}_{\text{StS}})={\frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot \frac{\sigma_i^2}{n_i}\Big(\frac{N_i-n_i}{N_i-1}\Big)}.$

Both samples have the same size; is there any way to determine which of the two approaches is preferable before computing the confidence intervals? In general, the sample design for which the sampling variance of the corresponding estimator is smallest is preferred.62

If $$N\gg n$$ and $$N_i\gg n_i$$ for all $$1\leq i\leq M$$, then $${N-n\approx N-1}$$ and $$N_i-n_1\approx N_i-1$$ for all $$1\leq i\leq M$$. Consequently, $\text{V}(\overline{y}_{\text{SRS}})\approx {\frac{\sigma^2}{n}=\frac{1}{nN}\sum_{i=1}^M\sum_{j=1}^{N_i}(u_{i,j}-\mu)^2}\quad \text{and}\quad \text{V}(\overline{y}_{\text{StS}})\approx {\frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot \frac{\sigma_i^2}{n_i}}.$

In a proportional allocation scenario, $$n_i={n\cdot \frac{N_i}{N}}$$ for all $$1\leq i\leq M$$, from which we see that $\text{V}(\overline{y}_{\text{StS}})_{\text{Prop}}\approx{\frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot \frac{\sigma_i^2\cdot N}{nN_i}=\frac{1}{nN}\sum_{i=1}^MN_i\sigma_i^2}.$

In a Neyman allocation scenario, $$n_i={n\cdot \frac{N_i\sigma_i}{N_1\sigma_1+\cdots+N_M\sigma_M}}$$ for all $$1\leq i \leq M$$, from which we see that $\text{V}(\overline{y}_{\text{StS}})_{\text{Neyman}}\approx{\frac{1}{N^2}\sum_{i=1}^MN_i^2\cdot \frac{\sigma_i^2 \left(\sum_{k=1}^MN_{k}\sigma_k\right)}{nN_i\sigma_i}=\frac{1}{nN^2}\left(\sum_{i=1}^MN_i\sigma_i\right)^2}.$

But \begin{aligned} \text{V}(\overline{y}_{\text{SRS}})&\approx {\frac{1}{nN}\sum_{i=1}^M\sum_{j=1}^{N_i}(u_{i,j}-\mu)^2=\frac{1}{nN}\sum_{i=1}^M\sum_{j=1}^{N_i}(u_{i,j}-\mu_i+\mu_i-\mu)^2} \\ &={\frac{1}{nN}\sum_{i=1}^M\sum_{j=1}^{N_i}\left\{(u_{i,j}-\mu_i)^2+2(u_{i,j}-\mu_i)(\mu_i-\mu)+(\mu_i-\mu)^2\right\}}\\ &={\frac{1}{nN}\left\{\sum_{i=1}^M\underbrace{\strut \sum_{j=1}^{N_i}(u_{i,j}-\mu_i)^2}_{N_i\sigma_i^2}+2\sum_{i=1}^M(\mu_i-\mu)\underbrace{\strut \sum_{j=1}^{N_i}(u_{i,j}-\mu_i)}_{N_i\mu_i-N_i\mu_i=0}+\sum_{i=1}^M(\mu_i-\mu)^2\underbrace{\strut \sum_{j=1}^{N_i}1}_{N_i}\right\}} \\ &={\frac{1}{nN}\left\{\sum_{i=1}^MN_i\sigma_i^2+\sum_{i=1}^MN_i(\mu_i-\mu)^2\right\}=\text{V}(\overline{y}_{\text{StS}})_{\text{Prop}}+\frac{1}{nN}\sum_{i=1}^MN_i(\mu_i-\mu)^2}.\end{aligned}

As such, $\text{V}(\overline{y}_{\text{SRS}})\gg \text{V}(\overline{y}_{\text{StS}})_{\text{Prop}}, \quad \text{whenever } {\frac{1}{nN}\sum_{i=1}^MN_i(\mu_i-\mu)^2\gg 0};$ a StS under proportional allocation is substantially preferable to a SRS when the variance of the stratum means is high.

Similarly, set $\overline{\sigma}=\frac{1}{N}\sum_{i=1}^MN_i\sigma_i={\sqrt{n\text{V}(\overline{y}_{\text{StS}})_{\text{Neyman}}}}.$ As such, \begin{aligned} \text{V}(\overline{y}_{\text{StS}})_{\text{Prop}}-\text{V}(\overline{y}_{\text{StS}})_{\text{Neyman}}&={\frac{1}{nN}\sum_{i=1}^MN_i\sigma_i^2-\frac{\overline{\sigma}^2}{n}=\frac{1}{nN}\left\{\sum_{i=1}^MN_i\sigma_i^2-N\overline{\sigma}^2\right\}}\\ &={\frac{1}{nN}\sum_{i=1}^MN_i(\sigma_i^2-2\sigma_i\overline{\sigma}+\overline{\sigma}^2)=\frac{1}{nN}\sum_{i=1}^MN_i(\sigma_i-\overline{\sigma})^2\geq 0;} \end{aligned} a StS under Neyman allocation is substantially preferable to a StS under proportional allocation when the variance of the stratum standard deviations is high.

Combining these, we can conclude that a StS under Neyman allocation is substantially preferable to a SRS when stratum means and standard deviations vary greatly across strata.

Since in practice there are other considerations at play (sampling cost, etc.), one may still decide in favor of a SRS or a StS under proportional allocation, especially if the difference in the corresponding variances is (relatively) small.

format: plain


text:
### GameDev Marketplace

$20 ### Image of the Day Submit IOTD | Top Screenshots ### The latest, straight to your Inbox. Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content. Sign up now ## How much do you use your IDE? Old topic! Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic. 90 replies to this topic ### Poll: How much do you use your IDE? (96 member(s) have cast votes) #### What tasks do you use your IDE (Integrated Development Environment) for? 1. I do everything from within the IDE (edit code, compiling, debugging, etc.) (83 votes [86.46%]) Percentage of vote: 86.46% 2. I only use the IDE for specific tasks I can not do elsewhere (2 votes [2.08%]) Percentage of vote: 2.08% 3. I don't use the IDE for anything (9 votes [9.38%]) Percentage of vote: 9.38% 4. The development tools I use don't have an IDE (2 votes [2.08%]) Percentage of vote: 2.08% Vote Guests cannot vote ### #1Dragonion Members Posted 17 August 2011 - 03:34 AM Just curious :) ### #2Hodgman Moderators Posted 17 August 2011 - 04:01 AM POPULAR Why would you not use an IDE? Are you chuck norris? ### #3szecs Members Posted 17 August 2011 - 04:03 AM Any programmer worth a damn works with a hex editor directly with the .exe ### #4Dragonion Members Posted 17 August 2011 - 04:16 AM Why would you not use an IDE? Are you chuck norris? Chuck Norris doesn't even need to code; he simply creates a binary beam from his forehead connecting with the computer and makes whatever program he wants instantly appear on the hard-drive ;) ### #5Tachikoma Members Posted 17 August 2011 - 04:57 AM No. Chuck Norris makes code write itself. Latest project: Sideways Racing on the iPad ### #60Circle0 Members Posted 17 August 2011 - 05:47 AM My IDE is Notepad, for my java programs I create a batch file that compiles, jars, and signs my applet javac SprCre.java IF NOT EXIST SprCre.jar ( jar cvf SprCre.jar SprCre.class Sprites ) ELSE ( jar uf SprCre.jar SprCre.class Sprites ) < response.txt keytool -genkey -keyalg rsa -alias YourSign echo NotAPass| keytool -certreq -alias YourSign echo NotAPass| jarsigner SprCre.jar YourSign IF EXIST index.html echo Y | DEL index.html echo ^<applet width=755 height=508 code="SprCre.class" archive="SprCre.jar"^> ^</applet^> >> index.html  I find an IDE tedious to use, especially Java ones(I tried using a few) where there are certain options you just cannot turn off. Some were so annoying I just went back to using Notepad.exe. I did like the format feature in Eclipse though, but is not needed unless looking at code that is not my own. I do like Dev Bloodshed for doing C/C++, but I am mainly doing Java atm. Sprite Creator 3 VX & XP WARNING: I edit my posts constantly. ### #7Antheus Members Posted 17 August 2011 - 06:32 AM It's 2011. - Continuous integration toolkit - Issue tracker - Source repository - staging/testing server/machine - Release/deployment hosting - An IDE - Office/productivity suite The bare minimums, all of which are available for free as well ### #8XXChester Members Posted 17 August 2011 - 06:50 AM My IDE is Notepad, for my java programs I create a batch file that compiles, jars, and signs my applet javac SprCre.java IF NOT EXIST SprCre.jar ( jar cvf SprCre.jar SprCre.class Sprites ) ELSE ( jar uf SprCre.jar SprCre.class Sprites ) < response.txt keytool -genkey -keyalg rsa -alias YourSign echo NotAPass| keytool -certreq -alias YourSign echo NotAPass| jarsigner SprCre.jar YourSign IF EXIST index.html echo Y | DEL index.html echo ^<applet width=755 height=508 code="SprCre.class" archive="SprCre.jar"^> ^</applet^> >> index.html  I find an IDE tedious to use, especially Java ones(I tried using a few) where there are certain options you just cannot turn off. Some were so annoying I just went back to using Notepad.exe. I did like the format feature in Eclipse though, but is not needed unless looking at code that is not my own. I do like Dev Bloodshed for doing C/C++, but I am mainly doing Java atm. Eeep just plain old notepad? Not even Notepad++ (free download). I couldn't imagine going back to not using an IDE, I use RAD 7.5.5 at work all day and I use Visual Studio 2010 for game development at home. Remember to mark someones post as helpful if you found it so. Journal: http://www.gamedev.net/blog/908-xxchesters-blog/ Portfolio: http://www.BrandonMcCulligh.ca Company: ### #9SimonForsman Members Posted 17 August 2011 - 06:57 AM Any programmer worth a damn works with a hex editor directly with the .exe http://xkcd.com/378/ For me it really depends on what i'm doing, the bigger the project the more useful the IDE becomes, for writing short scripts or modifying existing ones a good but lightweight text editor is a much better tool (i prefer vim for editing files) I don't suffer from insanity, I'm enjoying every minute of it. The voices in my head may not be real, but they have some good ideas! ### #10Telastyn Members Posted 17 August 2011 - 07:03 AM I will use vi in unix machines when I need to do c or c++ or perl there. Otherwise I'll use visual studio or netbeans (for java). While I occasionally don't heed my own advice; programmers should use any tool available to them to create better things faster. ### #110Circle0 Members Posted 17 August 2011 - 07:42 AM My IDE is Notepad, for my java programs I create a batch file that compiles, jars, and signs my applet javac SprCre.java IF NOT EXIST SprCre.jar ( jar cvf SprCre.jar SprCre.class Sprites ) ELSE ( jar uf SprCre.jar SprCre.class Sprites ) < response.txt keytool -genkey -keyalg rsa -alias YourSign echo NotAPass| keytool -certreq -alias YourSign echo NotAPass| jarsigner SprCre.jar YourSign IF EXIST index.html echo Y | DEL index.html echo ^<applet width=755 height=508 code="SprCre.class" archive="SprCre.jar"^> ^</applet^> >> index.html  I find an IDE tedious to use, especially Java ones(I tried using a few) where there are certain options you just cannot turn off. Some were so annoying I just went back to using Notepad.exe. I did like the format feature in Eclipse though, but is not needed unless looking at code that is not my own. I do like Dev Bloodshed for doing C/C++, but I am mainly doing Java atm. Eeep just plain old notepad? Not even Notepad++ (free download). I couldn't imagine going back to not using an IDE, I use RAD 7.5.5 at work all day and I use Visual Studio 2010 for game development at home. Nope just regular old Notepad.exe unless I am doing C/C++ Sprite Creator 3 VX & XP WARNING: I edit my posts constantly. ### #12Dragonion Members Posted 17 August 2011 - 07:54 AM It's 2011. - Continuous integration toolkit - Issue tracker - Source repository - staging/testing server/machine - Release/deployment hosting - An IDE - Office/productivity suite The bare minimums, all of which are available for free as well Or -still being in 2011- if you have that semi-autistic need to have 100% control of every single byte in your projects (both the binary and ASCII ones), you have a collection of scripts and manage everything from a console. Mmm ... just seing the screen get flooded with text as every lille component is processed individually like a large clockwork being assembled in perfect harmony. What beauty! Not saying that I am that type, of course ;D ### #13Bregma Members Posted 17 August 2011 - 07:56 AM Nobody has ever demonstrated to me what possible advantage I could gain by using an IDE. I have encountered many disadvantages. Stephen M. Webb Professional Free Software Developer ### #14Hodgman Moderators Posted 17 August 2011 - 08:10 AM POPULAR Nobody has ever demonstrated to me what possible advantage I could gain by using an IDE. That's because they're too scared to come down to the basement Seriously though, the features I appreciate the most would be: * easy maintenance of your 'makefile': 3 clicks to add a new source file, two clicks to exclude a file from a particular build config, etc... * working on multiple files at once via ctrl+tabbing, split window, etc... * quick shortcuts for things like: -- find text in project -- find files by name (show me...?) -- find symbol in project (where is...?) -- find code that references a symbol (who uses...?) -- go to symbol (alt+g how I love you) * debugging, srlsly. -- watch window to inspect and modify variables, including complex structs and arrays. -- mouse-hover to inspect and modify variables, including complex structs and arrays. -- watch window to execute/evaluatie arbitrary code statements (ability to interactively type C++ into a dialog while on a breakpoint and see the result) -- ability to edit/recompile the program's code while it's running. -- memory view to hex/float/decimal/etc inspect RAM/registers during debugging. -- ability to drag the program counter to a specific line of code. -- button for switching from viewing source, asm and mixed. -- window for view multiple threads and ability to easily debug more than one at once. -- ^having all of that on screen at once. ### #15Dragonion Members Posted 17 August 2011 - 08:28 AM I have encountered many disadvantages. I know what you mean. Some time ago I decided to try out the Visual C++ 2010 IDE and made a simple Hello World program. Then, after having spend half an hour getting the project to compile because it was missing some files ("export/symbol definition files" or something like that), when I looked at the size of the project folder I was honestly shocked -- 50 MEGABYTES for a program writing one line in a console!! It turned out to be some Intelli-thingy that apparently created some very large files, which, after all, can be disabled. But still; waaay to much junk in that folder compared to a single makefile ;) ### #16Oberon_Command Members Posted 17 August 2011 - 08:36 AM POPULAR I have encountered many disadvantages. I know what you mean. Some time ago I decided to try out the Visual C++ 2010 IDE and made a simple Hello World program. Then, after having spend half an hour getting the project to compile because it was missing some files ("export/symbol definition files" or something like that), when I looked at the size of the project folder I was honestly shocked -- 50 MEGABYTES for a program writing one line in a console!! It turned out to be some Intelli-thingy that apparently created some very large files, which, after all, can be disabled. But still; waaay to much junk in that folder compared to a single makefile ;) Sounds like you messed something up. I can create and compile a hello world program in VC++ 2010 in less than two minutes. - File->Project->New - Select Empty Project - Type name - Click OK - Right click on the project in the solution explorer, select Add->New Item - Type in name - Click OK - Type in code - Press F7 - Press Ctrl-F5 to run it. In fact, if your machine isn't slow, that should take less than ONE minute, and most of the time would be spent typing in the code. ### #17Dragonion Members Posted 17 August 2011 - 08:58 AM I can do it in less than 30 seconds from my editor: - Ctrl+N (make new file) - Type code - Ctrl+S (save file) - Type file name - F5 (compile) - F7 (link) - F8 (run) Plus the only file created on my hard-drive is "hello.cpp" :P However, for me development time is more or less irrelevant ... EDIT: And another great advantage: Unlike the Visual C++ IDE my editor has no boot-time :) (Even though development time is irrelevant, having fast and reliable tools certainly isn't) EDIT2: Also I have another dev tool installed (Open Watcom) I use every once in a while for testing various compatibility issues, and if I want to build the file with this instead I simply use Shift+F5 and Shift+F7 instead :) ### #18Bregma Members Posted 17 August 2011 - 11:27 AM stephenw@ariel:~/cv$ date
Wed Aug 17 13:18:29 EDT 2011
stephenw@ariel:~/cv$cat >hello.c #include <stdio.h> int main() { printf("hello world!\n"); return 0; } ^D stephenw@ariel:~/cv$ make hello
cc hello.c -o hello
stephenw@ariel:~/cv$date Wed Aug 17 13:19:07 EDT 2011 stephenw@ariel:~/cv$ ./hello
hello world!
stephenw@ariel:~/cv$date Wed Aug 17 13:19:13 EDT 2011 stephenw@ariel:~/cv$

If course, if I hadn't made some many typos it would have been faster. IDEs can only do so much in that respect, too.

Yeah, one wouldn't use cat for a real project. Why in the deep dark damp underworld would you use an IDE for a hello world project? Would you use a bazooka to kill a mosquito?
Stephen M. Webb
Professional Free Software Developer

### #19A Brain in a Vat  Members

Posted 17 August 2011 - 11:41 AM

Nobody has ever demonstrated to me what possible advantage I could gain by using an IDE. I have encountered many disadvantages.

This is like saying "As a bike rider, nobody has ever demonstrated to me what possible advantage I could gain by using a car."

I'm not saying you should use an IDE. I often don't. I also don't own a car. But, although I can get anywhere by bike that I could by car, and although I detest cars and don't think their positives make up for their negatives, I can admit that there are positives.

Without an IDE you don't have the integration between your source and the debugger. Is this necessary? No, but it's nice. I use gdb all the time, but on certain projects it's nice to be able to visually place breakpoints while looking at my code.

Without an IDE you don't have automatic refactoring tools. Are these necessarY? No, but they're nice. They save a lot of time and headache, and let you focus on writing logic.

Without an IDE you don't have useful autocompletion, "go to definition", call hierarchy, etc.

Without an IDE you don't have a class-level view of your program that is integrated with your source.

Without an IDE you have to remember the locations of each of your files. This may not sound like a big deal, but those of us working in giant codebases don't want to spend lots of time searching through directories.

etc.

I respect your decision not to use an IDE, and I don't think it's a strange one, but you're intentionally closing your eyes if you don't realize that there are advantages (along with the disadvantages) to using an IDE.

### #20Bregma  Members

Posted 17 August 2011 - 12:18 PM

Nobody has ever demonstrated to me what possible advantage I could gain by using an IDE. I have encountered many disadvantages.

Without an IDE you don't have the integration between your source and the debugger. Is this necessary? No, but it's nice. I use gdb all the time, but on certain projects it's nice to be able to visually place breakpoints while looking at my code.

Without an IDE you don't have automatic refactoring tools. Are these necessarY? No, but they're nice. They save a lot of time and headache, and let you focus on writing logic.

Without an IDE you don't have useful autocompletion, "go to definition", call hierarchy, etc.

Without an IDE you don't have a class-level view of your program that is integrated with your source.

Without an IDE you have to remember the locations of each of your files. This may not sound like a big deal, but those of us working in giant codebases don't want to spend lots of time searching through directories.

Not a single one of those points require an IDE, unless you rephrase them to say "with an IDE, you cant ... in an IDE." So, I guess an IDE is kinda like a tautology. I can also create tautologies with an IDE, so again that's not an argument for their use.

I have tools that do all of the above. I do do all of the above. Well, not autocompletion, I don't like it, but my tools do it. And none of my tools are integrated with my source, because my source is in text files. An IDE is also not integrated with the source.
Stephen M. Webb
Professional Free Software Developer

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


text:
×
Back to all chapters

# Functions

Functions map an input to an output. For example, the function f(x) = 2x takes an input, x, and multiplies it by two. An input of x = 2 gives you an output of 4. Learn all about functions.

# Functions: Level 2 Challenges

Consider a function $$f$$ satisfying

$f\big(\sqrt{x}\big)=x^2.$

What is the value of $$f(2) ?$$

Suppose $$f$$ is a real function satisfying $$f(x+f(x)) = 4f(x)$$ and $$f(1)=4$$. What is $$f(21)$$?

Given that $$f(2^x)+xf(2^{-x})=1$$, find the value of $$f(2)$$.

$x * y = \frac{1}{x} + \frac{1}{y}, \quad x \# y = \frac{x+y}{x-y}$

Let the operations $$\#$$ and $$*$$ be defined as described above.

Find the value of $$k$$ such that

$(22 * k) \# (k * 33) = 27.$

If $$f$$ is a function such that $$f(f(x)) = x^2 - 1$$, what is the value of $$f(f(f(f(3))))$$?

×


text:
## Algebra: A Combined Approach (4th Edition)

$5\times3$
$15=5\times3$ 5 and 3 are both prime numbers


text:
# Why is a subscript set in roman font placed differently

Consider the following MWE:

\documentclass{article}
\RequirePackage{fontspec,unicode-math}
\setmainfont{STIX Two Text}
\setmathfont{STIX Two Math}
\begin{document}
\showboxdepth\maxdimen
$\gamma_{e}\ne\gamma_{\mathrm{e}}\showlists$\showlists
\end{document}

It produces this output with LuaLaTeX:

As you can see, the two subscripts are placed differently.

The first \showlists contains no surprises:

### math mode entered at line 8
\mathord
.\fam0 𝛾
_\fam0 𝑒
\mathrel
.\fam0 ≠
\mathord
.\fam0 𝛾
_\fam4 e

But the second one does:

\mathon
\TU/STIXTwoMath(1)/m/n/10 𝛾
\kern-1.5
\hbox(3.6254+0.09818)x3.85008, shifted 2.09998, direction TLT
.\TU/STIXTwoMath(1)/m/n/7.01236 𝑒
\glue(\thickmuskip) 2.77771 plus 2.77771
\TU/STIXTwoMath(1)/m/n/10 ≠
\penalty 500
\glue(\thickmuskip) 2.77771 plus 2.77771
\TU/STIXTwoMath(1)/m/n/10 𝛾
\hbox(3.401+0.07013)x3.65373, shifted 2.09998, direction TLT
.\TU/STIXTwoText(1)/m/n/7.01236 e
\mathoff

Note the \kern-1.5, which tucks the subscript in under the gamma character on the left side, and the absence of a similar kern on the right side.

Why is this happening?

Edit: As egreg notes, this appears to be related to fonts – i.e., that the subscript comes from the text font and not the math font. Replacing \mathrm{e} by \symrm{e} cures it, in this case. However, if the subscript is a word, like “ess” or “disc”, this is not a good option, as the interletter spacing in the subscript is then wrong. Here is a workaround for that:

\Umathchardef\zwspace="0"0"200B
...
$\gamma_{\zwspace\mathrm{ess}}$

which adds a zero-width space from the math font as an ordinary math atom at the beginning of the subscript, allowing the normal subscript placement to take place. This has one shortcoming: If the next character is tall, that is not taken into account, and the subscript could be too far to the left.

I have reported this problem to the luatex list, and will report back here if I have some news from them.

• You should ask on the luatex list; if I compile with XeLaTeX, the kern is added also in the second case. Apr 10 '18 at 12:13
• On the other hand, if you use \symrm{e}, the kern is added also with LuaLaTeX. I guess it has to do with different fonts used. Apr 10 '18 at 12:16
• I get no kern at all. Which tex system and which version of the fonts are you using? OK: I see it with TL17 but not TL18. Apr 10 '18 at 12:21
• @UlrikeFischer I am on the latest (frozen) TL2017 on a mac. The STIX Math font is Version 2.00 b137 (according to otfinfo). Apr 10 '18 at 12:24
• I just edited my comment: I see it on TL17 but not on TL18. Apr 10 '18 at 12:25


text:
# Measure Theory and Differentiation (Part 1)

### 21 Feb 2021 -

So I had an analysis exam yesterday last week a while ago (this post took a bit of time to finish writing). It roughly covered the material in chapter 3 of Folland’s “Real Analysis: Modern Techniques and Their Applications”. I’m decently comfortable with the material, but a lot of it has always felt kind of unmotivated. For example, why is the Lebesgue Differentiation Theorem called that? It doesn’t look like a derivative… At least not at first glance.

A big part of my studying process is fitting together the various theorems into a coherent narrative. It doesn’t have to be linear (in fact, it typically isn’t!), but it should feel like the theorems share some purpose, and fit together neatly. I also struggle to care about theorems before I know what they do. This is part of why I care so much about examples – it’s nice to know what problems a given theorem solves.

After a fair amount of reading and thinking1, I think I’ve finally fit the puzzle pieces together in a way that works for me. Since I wrote it all down for myself as part of my studying, I figured I would post it here as well in case other people find it useful. Keep in mind this is probably obvious to anyone with an analytic mind, but it certainly wasn’t obvious to me!

Let’s get started!

To start, we need to remember how to relate functions and measures. Everything we say here will be in $\mathbb{R}$, and $m$ will be the ($1$-dimensional) Lebesgue Measure.

If $F$ is increasing and continuous from the right, then there is a (unique!) regular borel measure $\mu_F$ (called the Lebesgue-Stieltjes Measure associated to $F$) so that

$\mu_F((a,b]) = F(b) - F(a)$

Moreover, given any regular borel measure $\mu$ on $\mathbb{R}$, the function

$F_\mu \triangleq \begin{cases} \mu((0,x]) & x \gt 0 \\ 0 & x = 0 \\ -\mu((x,0]) & x \lt 0 \end{cases}$

is increasing and right continuous.

This is more or less the content of the Carathéodory Extension Theorem. It’s worth taking a second to think where we use the assumptions on $F$. The fact that $F$ is increasing means our measure is positive. Continuity from the right is a bit more subtle, though. Since $F_\mu$ is always right continuous, we need to assume our starting function is right continuous in order to guarantee $F_{\mu_F} = F$.

This is not a big deal, though. A monotone function is automatically continuous except at a countable set (see here for a proof) and at its countably many discontinuities, we can force right-continuity by defining

$\tilde{F}(x_0) \triangleq \lim_{x \to x_0^+} F(x)$

which agrees with $F$ wherever $F$ is continuous. If we put our probabilist hat on, we say that $F_\mu$ is the Cumulative Distribution Function of $\mu$. Here $F_\mu(x)$ represents the total (cumulative) mass we’ve seen so far.

It turns out that Lebesgue-Stieltjes measures are extremely concrete, and a lot of this post is going to talk about computing with them2. After all, it’s entirely unclear which (if any!) techniques from a calculus class carry over when we try to actually integrate against some $\mu_F$. Before we can talk about computation, though, we have to recall another (a priori unrelated) way to relate functions to measures:

Given a positive, locally $L^1$ function $f$, we can define the regular measure $m_f$ by

$m_f(E) \triangleq \int_E f dm$

Moreover, if $m_f = m_g$, then $f=g$ almost everywhere.

The locally $L^1$ conditions says that $\int_E f dm$ is finite whenever $E$ is bounded. It’s not hard to show that this is equivalent to the regularity of $m_f$, which we’ll need shortly.

Something is missing from the above theorem, though. We know sending $F \rightsquigarrow \mu_F$ is faithful, in the sense that $F = F_{\mu_F}$ and $\mu_{F_\mu} = \mu$. We’ve now introduced the measure $m_f$, but we didn’t say how to recover $f$ from $m_f$… Is it even possible? The answer is yes, as a corollary of a much more powerful result:

Every measure $\mu$ decomposes (uniquely!) as

$\mu = \lambda + m_f$

for some measure $\lambda \perp m$ and some function $f$.

Moreover, we can recover $f$ from $\mu$ as3

$f(x) = \lim_{r \to 0} \frac{\mu(B_r(x))}{m(B_r(x))}$

for almost every $x$. Here, as usual $B_r(x) = (x-r,x+r)$ is the ball of radius $r$ about $x$.

People often write $f = \frac{d \mu}{dm}$, and call it the Radon-Nikodym Derivative. Let’s see why.

In the case $\mu = m_f$, then this shows us how to recover $f$ (uniquely) from $m_f$, and life is good:

$\frac{d m_f}{dm} = f$

The converse needs a ~bonus condition~. In order to say $\mu = m_{\frac{d\mu}{dm}}$, we need to know that $\mu$ is absolutely continuous with respect to $m$, written $\mu \ll m$.

As an exercise, do you see why this condition is necessary? If $\mu \not \ll m$, why don’t we have a chance of writing $\mu = m_f$ for any $f$?

In the case of Lebesgue-Stieltjes measures, Lebesgue-Radon-Nikodym buys us something almost magical. For almost every $x$, we see:

\begin{aligned} \frac{d\mu_F}{dm} &= \lim_{r \to 0} \frac{\mu_F(B_r(x))}{m(B_r(x))} \\ &= \lim_{r \to 0} \frac{F(x+r) - F(x-r)}{x+r - (x-r)} \\ &= \lim_{r \to 0} \frac{F(x+r) - F(x-r)}{2r} \\ &= F'(x) \end{aligned}

Now we see why we might call this $f$ the Radon-Nikodym derivative. In the special case of Lebesgue-Stieltjes measures, it literally is the derivative. We saw earlier that $F = F_{m_f}$ acts like an antiderivative of $f$, and now we see $f = \frac{d \mu_F}{dm}$ works as a derivative of $F$ as well!

In fact, yet more analogies are true! Let’s take a look at the Lebesgue Differentiation Theorem

For almost every $x$, we have:

$$\lim_{r \to 0} \frac{1}{m B_r(x)} \int_{B_r(x)} f(t) dm = f(x)$$

Why is this called the differentiation theorem? Let’s look at $F_{m_f}$, which you should remember is a kind of antiderivative for $f$.

For $x > 0$ (for simplicity), we have $F_{m_f}(x) = m_f((0,x]) = \int_{(0,x]} f dm$. If we rewrite the theorem in terms of $F_{m_f}$, what do we see?

\begin{aligned} f(x) &= \lim_{r \to 0} \frac{1}{m B_r(x)} \int_{B_r(x)} f dm \\ &= \lim_{r \to 0} \frac{1}{(x+r) - (x-r)} \int_{x-r}^{x+r} f dm \\ &= \lim_{r \to 0} \frac{1}{2r} \left ( \int_{0}^{x+r} f dm - \int_{0}^{x-r} f dm \right )\\ &= \lim_{r \to 0} \frac{F_{m_f}(x+r) - F_{m_f}(x-r)}{2r} \\ &= F_{m_f}'(x) \end{aligned}

So this is giving us part of the fundamental theorem of calculus4! This theorem (in the case of Lebesgue-Stieltjes measures) says exactly that (for almost every $x$)

$\left ( x \mapsto \int_0^x f dm \right )' = f(x)$

Let’s take a moment to summarize the relationships we’ve seen. Then we’ll use these relationships to actually compute with Lebesgue-Stieltjes integrals.

$\bigg \{ \text{increasing, right-continuous functions F} \bigg \} \leftrightarrow \bigg \{ \text{regular borel measures \mu_F} \bigg \}$ $\bigg \{ \text{positive locally L^1 functions f} \bigg \} \leftrightarrow \bigg \{ \text{regular borel measures m_f \ll m} \bigg \}$

Moreover:

• By considering $F_{m_f}$ we see functions of the first kind are antiderivatives of functions of the second kind.

• By considering $\frac{d \mu_F}{dm}$, we see functions of the second kind are (almost everywhere) derivatives of functions of the first kind.

• Indeed, $\frac{d \mu_F}{dm} = F’$ almost everywhere.

• And $F_{m_f}’ = f$ almost everywhere.

Why should we care about these theorems? Well, Lebesgue-Stieltjes integrals arise fairly regularly in the wild, and these theorems let us actually compute them! It’s easy to integrate against $m_f$, since monotone convergence gives us $\int g dm_f = \int g f dm$.

Then this buys us the (very memorable) formula:

$\int g d \mu_F = \int g \frac{d \mu_F}{dm} dm = \int g F' dm$

and now we’re integrating against lebesgue measure, and all our years of calculus experience is applicable!

Of course, I’ve left out an important detail: Whatever happened to that measure $\lambda$? The above formula is true exactly when $F$ is continuous everywhere. At points where it is discontinuous we need to change it slightly by using $\lambda$. These are called singular measures, and they can be pretty pathological. A good first intuition, though, is to think of them like dirac measures, and that’s the case that we’ll focus on in this post5.

Let’s write $$H = \begin{cases} 0 & x \lt 0 \\ 1 & 0 \leq x \end{cases}$$. This us usually called the heaviside function.

Recall our interpretation of this function: $H(x)$ is supposed to represent the mass of $(-\infty, x]$. So as we scan from left to right, we see the mass is constantly $0$ until we hit the point $0$. Then suddenly we jump up to mass $1$. But once we get there, our mass stays constant again.

So $H$ thinks that $0$ has mass $1$ all by itself, and thinks that there’s no other mass at all!

Indeed, we see that

$\mu_H((a,b]) = H(b) - H(a) = \begin{cases} 1 & 0 \in (a,b] \\ 0 & 0 \not \in (a,b] \end{cases}$

So $\mu_H$ is just the dirac measure at $0$ (or $\delta_0$ to its friends)! Notice this lets us say the “derivative” of $H$ is $\delta_0$, by analogy with the Lebesgue-Stieltjes case. Or conversely, that $H$ is the “antiderivative” of $\delta_0$. This shows us that recasting calculus in this language actually buys us something new, since there’s no way to make sense of $\delta_0$ as a traditional function.

It’s finally computation time! Since we know $\int g d\delta_0 = g(0)$, and (discrete) singular measures look like (possibly infinite) linear combinations of dirac measures, this lets us compute all increasing right-continuous Lebesgue-Stieltjes measures that are likely to arise in practice. Let’s see some examples! If you want to see more, you really should look into Carter and van Brunt’s “The Lebesgue-Stieltjes Integral: A Practical Introduction”. I mentioned it in a footnote earlier, but it really deserves a spotlight. It’s full of concrete examples, and is extremely readable!

Let’s start with a continuous example. Say $$F = \begin{cases} 0 & x \leq 0 \\ x^2 & x \geq 0 \end{cases}$$.

So $\mu_F$ should think that everything is massless until we hit $0$. From then on, we start gaining mass faster and faster as we move to the right. If you like, larger points are “more dense” than smaller ones, and thus contribute more mass in the same amount of space.

Say we want to compute

$\int_{-\pi}^\pi \sin(x) d \mu_F = \int_{-\pi}^\pi \sin(x) \cdot F' dm$

We can compute $$F' = \begin{cases} 0 & x \leq 0 \\ 2x & x \geq 0 \end{cases}$$, so we split up our integral as

$\int_{-\pi}^0 \sin(x) \cdot 0 dm + \int_0^\pi \sin(x) \cdot 2x dm$

But both of these are integrals against lebesgue measure $m$! So these are just “classical” integrals, and we can use all our favorite tools. So the first integral is $0$, and the second integral is $2\pi$ (integrating by parts). This gives

$\int_{-\pi}^\pi \sin(x) d \mu_F = 2\pi$

Let’s see another, slightly trickier one. Let’s look at $$F = \begin{cases} x & x \lt 0 \\ e^x & x \geq 0 \end{cases}$$

You should think through the intuition for what $\mu_F$ looks like. You can then test your intuition against a computation:

$\mu_F = \lambda + m_f$

In the previous example, $\lambda$ was the $0$ measure since our function was differentiable everywhere. Now, though, we aren’t as lucky. Our function $F$ is not differentiable at $0$, so we will have to work with some nontrivial $\lambda$.

Let’s start with the places $F$ is differentiable. This gives us the density function $$f = F' = \begin{cases} 1 & x \lt 0 \\ e^x & x \gt 0 \end{cases}$$.

We can also see the point $0$ has mass $1$. In this case we can more or less read this off the graph (since we have a discontinuity where we jump up by $1$), but in more complex examples we would compute this by using $\mu_F({ 0 }) = \lim_{r \to 0^+} F(r) - F(-r)$. You can see that this does give us $1$ in this case, as expected. So we see (for $f$ as before)

$\mu_F = \delta_0 + m_f$

So to compute

$\int_{-1}^1 4 - x^2 d\mu_F = \int_{-1}^1 4 - x^2 d(\delta_0 + m_f) = \int_{-1}^1 4 - x^2 d \delta_0 + \int_{-1}^1 (4 - x^2)f dm$

we can handle the $\delta_0$ part and the $f dm$ part separately!

We know how to handle dirac measures:

$\int_{-1}^1 4 - x^2 d \delta_0 = \left . (4 - x^2) \right |_{x = 0} = 4$

And we also know how to handle “classical” integrals:

$\int_{-1}^1 (4 - x^2) f dm = \int_{-1}^0 (4 - x^2) dm + \int_0^1 (4 - x^2) e^x dm = \frac{11}{3} + (3e-2)$

So all together, we get $$\int_{-1}^1 4 - x^2 d\mu_F = 4 + \frac{11}{3} + (3e-2)$$.

As an exercise, say $$F = \begin{cases} e^{3x} & x \lt 0 \\ 2 & 0 \leq x \lt 1 \\ 2x+1 & 1 \leq x \end{cases}$$

Can you intuitively see how $\mu_F$ distributes mass?

Can you compute

$$\int_{-\infty}^2 e^{-2x} d\mu_F$$

As another exercise, can you intuit how $\mu_F$ distributes mass when $F(x) = \lfloor x \rfloor$ is the floor function?

What is $\int_1^\infty \frac{1}{x^2} d\mu_F$? What about $\int_1^\infty \frac{1}{x} d\mu_F$?

Ok, I hear you saying. There’s a really tight connection between increasing (right-)continuous functions $F$ on $\mathbb{R}$ and positive integrable functions $f$. This connection is at its tightest wherever $F$ is actually continuous, as then the measures $\mu_F$ and $m_f$ have a derivative relationship, which is reflected in the same derivative relationship of functions $F’ = f$. Not only does this give us a way to generalize the notion of derivative to functions that might not normally have one (as in the case of the heaviside function and the dirac delta), it gives us a concrete way of evaluating Lebesgue-Stieltjes integrals.

But doesn’t this feel restrictive? There are lots of functions $F$ which aren’t (right-)continuous or increasing that we might be interested in differentiating. There are also lots of nonpositive functions $f$ which we might be interested in integrating. Since we got a kind of “fundamental theorem of calculus” from these measure theoretic techniques, if we can show how to apply these techniques to a broader class of functions, we might be able to get a more general fundamental theorem of calculus.

Of course, to talk about more general functions $F$, we’ll need to allow our measures to assign negative mass to certain sets. That’s ok, though, and we can even go so far as to allow complex valued measures! In fact, from what I can tell, this really is the raison d’être for signed and complex measures. I was always a bit confused why we might care about these objects, but it’s beginning to make more sense.

This post is getting pretty long, though, so we’ll talk about the signed case in a (much shorter, hopefully) part 2!

1. I was mainly reading Folland (Ch. 3), since it’s the book for the course. I’ve also been spending time with Terry Tao’s lecture notes on the subject (see here, and here), as well as this PDF from Eugenia Malinnikova’s measure theory course at Stanford. I read parts of Axler’s new book, and while I meant to read some of Royden too, I didn’t get around to it.

2. As an aside, I really can’t recommend Carter and van Brunt’s “The Lebesgue-Stieltjes Integral: A Practical Introduction” enough. It spends a lot of time on concrete examples of computation, which is exactly what many measure theory courses are regrettably missing. Chapter 6 in particular is great for this, but the whole book is excellent.

3. We can actually relax this from balls $B_r(x)$ to a family ${E_r}$ that “shrinks nicely” to $x$, though it’s still a bit unclear to me what that means and what it buys us. It seems like one important feature is that the $E_r$ don’t have to contain $x$ itself. It’s enough to take up a (uniformly) positive fraction of space near $x$.

4. There’s another way of viewing this theorem which is quite nice. I think I saw it on Terry Tao’s blog, but now that I’m looking for it I can’t find it… Regardless, once we put on our nullset goggles, we can no longer evaluate functions. After all, for any particular point of interest, I can change the value of my function there without changing its equivalence class modulo nullsets. However, even with our nullset goggles on, the integral $\frac{1}{m B_r(x)} \int_{B_r(x)} f dm$ is well defined! So for almost every $x$, we can “evaluate” $f$ through this (rather roundabout) approach. The benefit is that this notion of evaluation does not depend on your choice of representative!

5. In no small part because I’m not sure how you would actually integrate against a singular continuous measure in the wild…


text:
# Consider the following linear program.Maximize 30X + 10YSubject to:3X + Y â‰¤ 300X + Y â‰¤ 200X â‰¤ 100Y â‰¥

###### Question:

Consider the following linear program. Maximize 30X + 10Y Subject to: 3X + Y â‰¤ 300 X + Y â‰¤ 200 X â‰¤ 100 Y â‰¥ 50 X,Y â‰¥ 0 Which of these is NOT a corner point of the feasible region? A) (50,50) B) (50,150) C) (0,50) D) (75,50)

#### Similar Solved Questions

The long-term liabilities section of CPS Transportation’s December 31, 2017, balance sheet included the following: (FV of $1, PV of$1, FVA of $1, PVA of$1, FVAD of $1 and PVAD of$1) (Use appropriate factor(s) from the tables provided.) TABLE 5 Future Value of an Annuity Due of $1 FVAD = (1... 1 answer ##### Mobility Partners makes wheelchairs and other assistive devices. For years it has made the rear wheel... Mobility Partners makes wheelchairs and other assistive devices. For years it has made the rear wheel assembly for its wheelchairs. A local bicycle manufacturing firm, Trailblazers, Inc., offered to sell these rear wheel assemblies to Mobility. If Mobility makes the assembly, its cost per rear wheel... 5 answers ##### Problemn 6 (18 pts._ Set-up but do not evaluate the following integrals:dV,where V is the solid between the spheres :2 +y? + 22 = 36 and 2 +y2 + 22 = above the plane Problemn 6 (18 pts._ Set-up but do not evaluate the following integrals: dV, where V is the solid between the spheres :2 +y? + 22 = 36 and 2 +y2 + 22 = above the plane... 1 answer ##### Issued 2,650 shares of its common stock to Jeremy after$25,070 in cash and computer equipment...
Issued 2,650 shares of its common stock to Jeremy after $25,070 in cash and computer equipment with a fair market value of$35,880 were received no additional info available. i need you to provide a journal transaction....
##### Table 11.1 Siandard Reduclion Polentals 25-C (298 K) lor Many Common Half-reac: onsHalf-rexctionHali rection2H,o40H0A 0.54 0,27 0,22 0.20Hg,Cl; A;Cl2Hg 2C1Io: 2H"2H,0HiSO, HjoPbo_ 4H" 504' PbSOa 2H,o MnO IH" Mno , 20 [Q4 2M4" IO, Hzo MnO Mn" 4H,o0.0 0.036 ~0; ~ud ~0 076 =0,40360Pb?PbOz 4H" Pb? = 2H,O 2CI Cn0 14H" ZCr' + 711,0 2H,o MnOz Mn? ' 2H,o IO , 6H 3 3HL;O 2Br 2H" Vo"' H,o AuCh 4CI NO; 4H` NO 2H,0 CIO_ CIOz ZHc HpzFbSoSOuM0.7
Table 11.1 Siandard Reduclion Polentals 25-C (298 K) lor Many Common Half-reac: ons Half-rexction Hali rection 2H,o 40H 0A 0.54 0,27 0,22 0.20 Hg,Cl; A;Cl 2Hg 2C1 Io: 2H" 2H,0 HiSO, Hjo Pbo_ 4H" 504' PbSOa 2H,o MnO IH" Mno , 20 [Q4 2M4" IO, Hzo MnO Mn" 4H,o 0.0 0.036 ~0...
##### ConstantsPeriodic TablePart A2.50 mol of calcium chlorite is dissolved in enough water t0 produce 3.50 L of solution. Ka 2.9 X 10-8 for HCIO , and Ka 1.1X 10-2 for HC1Oz.Compute the pH of the solution. Express your answer using one decimal placeAzdpH =SubmitRequest Answer
Constants Periodic Table Part A 2.50 mol of calcium chlorite is dissolved in enough water t0 produce 3.50 L of solution. Ka 2.9 X 10-8 for HCIO , and Ka 1.1X 10-2 for HC1Oz. Compute the pH of the solution. Express your answer using one decimal place Azd pH = Submit Request Answer...
##### The table summarizes results from 981 pedestrian deaths that were caused by automobile accidents_Driver Pedestrian Intoxicated? Intoxicated? YesYes231609If one of the pedestrian deaths is randomly selected, find the probability that the pedestrian was not intoxicated or the driver was intoxicatedReport the answer as percent rounded to one decimal place accuracy: You need not enter the "%" symbol, prob
The table summarizes results from 981 pedestrian deaths that were caused by automobile accidents_ Driver Pedestrian Intoxicated? Intoxicated? Yes Yes 231 609 If one of the pedestrian deaths is randomly selected, find the probability that the pedestrian was not intoxicated or the driver was intoxicat...
##### 5) Let the matrix 4 be given by A =1| Find ifpossible, a diagonal matrixsimilar to A (20 points)
5) Let the matrix 4 be given by A = 1| Find ifpossible, a diagonal matrix similar to A (20 points)...
##### Several factors people considered before investing in any financial instrument
several factors people considered before investing in any financial instrument...
##### Evaluate each logarithm. See Examples 2 and 3. $\log _{64}(64)$
Evaluate each logarithm. See Examples 2 and 3. $\log _{64}(64)$...
##### Mechanism of the reaction: Reduction of ketone with NaBH- Reduction of aldehyde with LiAIH Reaction of 'organolithium with aldehyde or ketone followed by acidic work-up Oxidation of alcohol: With CrO:
Mechanism of the reaction: Reduction of ketone with NaBH- Reduction of aldehyde with LiAIH Reaction of 'organolithium with aldehyde or ketone followed by acidic work-up Oxidation of alcohol: With CrO:...
##### When Fe_2O_3(s) reacts with Al(s) to form Al_2O_3(s) and Fer(s).204 kcal of energy are evolved for...
When Fe_2O_3(s) reacts with Al(s) to form Al_2O_3(s) and Fer(s).204 kcal of energy are evolved for each mole of Fe_2O_39s) that reaction Write a balanced equation the reaction with an energy term in local as part of the equation. Use the SMALLEST INTEGER coefficients possible and put the energy term...
##### Two firms, DeSoto Cab (D) and Uber (U), sell taxi cab rides in San Francisco. Suppose...
Two firms, DeSoto Cab (D) and Uber (U), sell taxi cab rides in San Francisco. Suppose the demand curve for DeSoto is Dp = 60 - PD + 0.5pu while the demand curve for Uber is given by Du = 60 - Pu + 0.5pd. Suppose DeSoto has marginal cost of $25 and Uber has a marginal cost of$35. The two firms compe...
##### The University of Dental Health (UDH) is a state-run university focusing on the education and training...
The University of Dental Health (UDH) is a state-run university focusing on the education and training of dentists, dental assistants, dental hygienists, and other dental professionals. The university provides both traditional undergraduate courses to 7,150 students and continuing professional educa...
##### QUESTION 10 Aging of Receivables Problem: For Reggie Company you have the following data for accounts...
QUESTION 10 Aging of Receivables Problem: For Reggie Company you have the following data for accounts receivable at 12/31/Y9: Allowance Reguired 1.0 % 3.0 % 10.0 % Amount Age Category 0-30 days 31-80 days Over 80 days $200,000 100,000 10,000 Total$ 260,000 Reggie uses aging of receivables method to...
##### Suppose that X ∼ U(-5.0, 9.8). Find the P(0 ≤ X ≤ 8) Round your answer...
Suppose that X ∼ U(-5.0, 9.8). Find the P(0 ≤ X ≤ 8) Round your answer to the nearest ten thousandth....
##### Lulcch prouide Insocls co-evolved with endosymbiotic bacteria Gabenu hoirhasi False (circle correct chaice)PartComprehensive (90 Pts)Energy, Nutrients, Blono @cmes (18 pts)answer lhe following this trophic diagram Goucher s rain garden- questiansGecondanFdnntumaee Knalas1c405Priman Crnsumam abbitsInsnztPnmary DfoqiucansWhat = the ultimate_source oi energy for this ecosystem? (Draw it in the diagram) Pts)Consider the Prmary producer level of the diagram. What process used by Ihese organisms provi
Lulcch prouide Insocls co-evolved with endosymbiotic bacteria Gabenu hoirhasi False (circle correct chaice) Part Comprehensive (90 Pts) Energy, Nutrients, Blono @cmes (18 pts) answer lhe following this trophic diagram Goucher s rain garden- questians Gecondan Fdnntumaee Knalas 1c405 Priman Crnsumam ...
##### Player X is meeting with his opponent in badminton match_ If player X scores the points ahead of his opponent, he has the probability of 0.3 to win the game, otherwise deuce will happen If player X scures far behind, he either lose with probability ends up with deuce When deuce has occurred, player has the opportunity t0 Ecore ahead of his opponent with probability 0 .4, otherwise he will far behind sSume Ahead (State Far Behind (State 2), Deuce (State 3) . Win (State 4) and Lose ( State 5) are
Player X is meeting with his opponent in badminton match_ If player X scores the points ahead of his opponent, he has the probability of 0.3 to win the game, otherwise deuce will happen If player X scures far behind, he either lose with probability ends up with deuce When deuce has occurred, player ...
##### (a) To test independence of perceived mental health and sex, we want t0 use chi-square model withdegree(s) of freedom:(b) Compute the chi-square statistic used to test independence of perceived mental health and sex. Round your answer t0 decimal places: For all intermediate steps; keep at least decimal places Answer:(c) Which of the following statements correct based on the result of the Chi-square test?A At a 5% significance level, we reject the null hypothesis. There is strong evidence that pe
(a) To test independence of perceived mental health and sex, we want t0 use chi-square model with degree(s) of freedom: (b) Compute the chi-square statistic used to test independence of perceived mental health and sex. Round your answer t0 decimal places: For all intermediate steps; keep at least de...
##### Constants Part A Point charge 2.5 μC is located at z-0 y-0.30 m. point charge-25 μC...
Constants Part A Point charge 2.5 μC is located at z-0 y-0.30 m. point charge-25 μC is located at z-0 y -0.30 m. What are (a)the magnitude and (b)direction of the total electric force that these charges exert on a third point charge Q = 45 μC at 0.40 m, y = 0? Express your answer using two ...
##### Problem 1-5A Preparing a balance sheet LO P2 As of December 31, 2017, Armani Company's financial...
Problem 1-5A Preparing a balance sheet LO P2 As of December 31, 2017, Armani Company's financial records show the following items and amounts. Cash Accounts receivable Supplies Equipment Accounts payable A. Armani, Capital, Dec. 31, 2016 A. Armani, Capital, Dec. 31, 2017 A. Armani, Withdrawals C...