text:
# 5 How Many Experimental Units are Required to Compare Two Treatments?

Suppose that a company would like to compare two versions of a web page to see if one version leads to higher sales. How many people should visit the each version of the website? A pharmaceutical company is required to compare a novel treatment for cancer against the standard treatment to investigate if patient mortality decreases when receiving the novel treatment. To study how physical expression influences psychological processes such as risk taking subjects were randomized to two groups where one group was instructed to pose in a high-power position and the second group in a low-power position.

In each of these examples experimental units (e.g., human subjects) were randomly assigned to two groups to investigate the causal effects of a treatment. How many subjects should be assigned to each group?

## 5.1 Clinical Trials

Clinical trials are prospective intervention studies with human subjects to investigate experimental drugs, new treatments, medical devices, or clinical procedures (Yin (2013)).

There are typically fours phases of clinical trials.

### 5.1.1 Phases of clinical trials

The phases of clinical trials that might be involved in developing a new drug for a certain cancer are described below.

Preclinical studies: In vitro (e.g. slides, test tubes) and in vivo (living organism such as rodents) studies on wide range of doses of experimental agents. This stage of study provides preliminary toxicity and efficacy data including pharmacokinetics (PK) and pharmacodynamics (PD) information.

Phase I: Usually first study in humans to investigate the toxicity and side effects of the new agent. Identify MTD.

Phase II: Assess if drug has sufficient efficacy. The drug is usually administered around the MTD. If drug does not show efficacy or is too toxic then further testing is discontinued.

Phase III: If drug passes phase II testing then it is compared to the current standard of care or placebo. These are long-term, large scale randomized studies that may involve hundreds or thousands of patients.

If the drug is proven to be effective (e.g. two positive phase III trials required for FDA approval) the company will file an application with regulatory agencies to sell the drug. If approved then the drug will be available to the general population in the country where it was approved.

Phase IV: After approval a study might follow a large number of patients over a longer period of time to monitor side effects and drug interactions. For example, findings from these studies might add a warning label to the drug.

• The four phases are usually conducted sequentially and separately.
• Each trial requires an independent study design and a study protocol.
• Every aspect of trial design, monitoring, and data analysis call upon statistical methods.
• In randomized clinical trials a treatment group is often referred to as an arm.

According to the ClinicalTrials.gov an arm is defined as:

A group or subgroup of participants in a clinical trial that receives specific interventions, or no intervention, according to the study protocol. This is decided before the trial begins.

How can causation be assessed using a randomized design?

• Suppose that patients are randomized in a two arm clinical trial where one of the arms is the standard treatment and the other arm is an experimental treatment and there is a statistically significant difference in the outcome between the two arms showing the experimental treatment is more efficacious.

• The interpretation is that the experimental treatment caused patients to have a better outcome since the only difference between the two arms is the treatment. Randomization is supposed to ensure that the groups will be similar with respect to all the factors measured in the study and all the factors that are not measured.

#### 5.1.1.1 How many patients should be enrolled in a Phase III clinical trial?

If an experimental agent exhibits adequate short-term therapeutic effects in a phase II trial, the drug will be moved forward to a phase III study for confirmative testing of its long-term effectiveness. Phase III clinical trials are randomized and controlled studies that directly compare the investigational drug with the current “gold standard” treatment or a placebo when there is no standard of care. The sample size of a phase III trial is large, usually ranging from hundreds up to thousands of participants … Due to their enormous sizes, large scales, and long follow-ups, phase III trials are the most costly comparative studies to evaluate the drug’s efficacy. (pg. 159, Yin (2013))

• In a phase III trial sample size is the most critical component of the study design. The sample size has implications for how many subjects will be exposed to a drug that has no proven efficacy.
• The investigator needs to specify type I, II error rates, and the effect sizes.
• Standard practice is to compute the smallest sample size required to detect a clinically important/significant treatment difference with sufficient.
• If the sample size is too small then the trial might fail to discover a truly effective drug because the statistical test cannot reach the significance level (5%) due to a lack of power.
• If the sample size is overestimated then resources wasted and drug development delayed since patient enrollment is often the main factor in time to complete a trial.

## 5.2 Statistical Hypotheses and the Number of Experimental Units

Suppose that subjects are randomized to treatments A or B with equal probability. Let $$\mu_A$$ be the mean response in the group receiving drug A and $$\mu_B$$ be the mean response in the group receiving drug B. The null hypothesis is that there is no difference between A and B, the alternative claims there is a clinically meaningful difference between them.

$H_0:\mu_A=\mu_B \thinspace \text{ versus } \thinspace H_1:\mu_A \ne \mu_B$

The type I error rate is defined as:

\begin{aligned} \alpha &=P\left(\text{type I error}\right) \\ &=P\left(\text{Reject } H_0|H_0 \text{ is true}\right).\\ \end{aligned}

The type II error rate is defined as:

\begin{aligned} \beta&=P\left(\text{type II error}\right) \\ &=P\left(\text{Accept }H_0|H_1 \text{ is true}\right). \end{aligned}

Power is defined as: \begin{aligned} \text {power} &= 1-\beta \\ &= 1-P\left(\text{Accept }H_0|H_1 \text{ is true}\right) \\ &= P\left(\text{Reject } H_0|H_1 \text{ is true}\right). \end{aligned}

## 5.3 Power of the One Sample z-test

Let $$X_1,...,X_n$$ be a random sample from a $$N(\mu,\sigma^2)$$ distribution. A test of the hypothesis

$H_0:\mu=\mu_0 \thinspace \text{ versus } \thinspace H_1:\mu \ne \mu_0$

will reject at level $$\alpha$$ if and only if

$\left|\frac{{\bar X} - \mu_0}{\sigma/{\sqrt{n}}} \right| \ge z_{\alpha/2},$

or

$\left|{\bar X} -\mu_0 \right| \ge \frac{\sigma}{\sqrt{n}} z_{\alpha/2},$

where $$z_{\alpha/2}$$ is the $$100(1-\alpha/2)^{th}$$ percentile of the $$N(0,1)$$.

The power of the test at $$\mu=\mu_1$$ is

\begin{aligned} 1-\beta &= 1-P\left(\text{type II error}\right) \\ &= P\left(\text{Reject } H_0|H_1 \text{ is true}\right) \\ &= P\left(\text{Reject } H_0|\mu=\mu_1\right) \\ &= P\left(\left|{\bar X} -\mu_0 \right| \ge \frac{\sigma}{\sqrt{n}} z_{\alpha/2}|\mu=\mu_1\right) \\ &= P\left({\bar X} -\mu_0 \ge \frac{\sigma}{\sqrt{n}} z_{\alpha/2}|\mu=\mu_1\right) + P\left({\bar X} -\mu_0 < \frac{-\sigma}{\sqrt{n}} z_{\alpha/2}|\mu=\mu_1\right) \\ \end{aligned}

Subtract the mean $$\mu_1$$ and divide by $$\sigma/\sqrt{n}$$ to obtain:

$1-\beta = 1-\Phi\left( z_{\alpha/2}-\left(\frac{\mu_1-\mu_0}{\sigma/\sqrt{n}}\right) \right)+\Phi\left( -z_{\alpha/2}-\left(\frac{\mu_1-\mu_0}{\sigma/\sqrt{n}}\right) \right),$

where $$\Phi(\cdot)$$ is the $$N(0,1)$$ CDF.

### 5.3.1 Exercises

1. What is the limit of the power function as:
1. $$n \rightarrow \infty$$
2. $$\mu_1 \rightarrow \mu_0$$

Answers:(a) 1; (b) $$\alpha$$.

### 5.3.2 Calculating the Power of the One Sample z-test using R

The power function for a one-sample z-test can be calculated using R.

pow.z.test <- function(alpha,mu1,mu0,sigma,n){
arg1 <- qnorm(1-alpha/2)-(mu1-mu0)/(sigma/sqrt(n))
arg2 <- -1*qnorm(1-alpha/2)-(mu1-mu0)/(sigma/sqrt(n))
1-pnorm(arg1)+pnorm(arg2)
}

For example the power of the test

$H_0:\mu = 0 \thinspace \text{ versus } \thinspace H_1:\mu = 0.2$ with $$n = 30,\sigma = 0.2, \alpha = 0.05$$ can be calculated by calling the above function.

pow.z.test(.05,.15,0,.2,30)
[1] 0.9841413

This means that with $$n = 30$$ experimental units there is a 0.98 probability that the z-test will detect a mean of 0.2 when $$\sigma = 0.2, \alpha = 0.05$$.

## 5.4 Power of the one-sample t-test

Let $$X_1,...,X_n$$ be a random sample from a $$N(\mu,\sigma^2)$$ distribution. A test of the hypothesis

$H_0:\mu=\mu_0 \thinspace \text{ versus } \thinspace H_1:\mu \ne \mu_0$

will reject at level $$\alpha$$ if and only if

$\left|\frac{{\bar X} - \mu_0}{S/{\sqrt{n}}} \right| \ge t_{n-1, \alpha/2},$

where $$t_{n-1, \alpha/2}$$ is the $$100(1-\alpha/2)^{th}$$ percentile of the $$t_{n-1}$$.

It can be shown that

$\sqrt{n} \left[\frac{{\bar X}-\mu_0}{S}\right] = \frac{Z + \gamma}{\sqrt{V/(n-1)}},$

where,

\begin{aligned} Z &= \frac{\sqrt{n}({\bar X}-\mu_1)}{\sigma} \\ \gamma &= \frac{\sqrt{n}(\mu_1-\mu_0)}{\sigma} \\ V &= \frac{(n-1)}{\sigma^2} S^2. \end{aligned}

$$Z \sim N(0,1)$$ and $$V \sim \chi^2_{n-1}$$ and $$Z$$ is independent of $$V$$.

If $$\gamma = 0$$ then then $$\sqrt{n} \left[\frac{{\bar X}-\mu_0}{S}\right] \sim t_{n-1}$$. But, if $$\gamma \ne 0$$ then $$\sqrt{n} \left[\frac{{\bar X}-\mu_0}{S}\right] \sim t_{n-1, \gamma}$$, where $$t_{n-1, \gamma}$$ is the non-central t-distribution with non-centrality parameter $$\gamma$$. If $$\gamma = 0$$ this is sometimes called the central t-distribution.

A plot of the central ($$\gamma = 0$$) and non-central t are shown in the plot below.

#Plot of noncentral t and central t
x <- seq(-6,6,by = 0.01)
plot(x,dt(x,10,0),type = "l",ylab = "t-density",col = "black",
xlab = "x",main = "Noncentral t-distribution")
points(x,dt(x,10,1),type = "l",lty = 2,col = "blue")
points(x,dt(x,10,2),type = "l",lty = 3,col = "red")
legend("topleft",
legend = c(expression(gamma == 0),
expression(gamma == 1),expression(gamma==2)),
lty = c(1,2,3),col = c("black","blue","red"))

The power of the test at $$\mu=\mu_1$$ is

\begin{aligned} 1-\beta &= 1-P\left(\text{type II error}\right) \\ &= P\left(\text{Reject } H_0|H_1 \text{ is true}\right) \\ &= P\left(\text{Reject } H_0|\mu=\mu_1\right) \\ &= P\left(\left|\frac {{\bar X} -\mu_0} {\frac{S}{\sqrt{n}}} \right| \ge t_{n-1, \alpha/2}|\mu=\mu_1\right) \\ &= P\left(\frac {{\bar X} -\mu_0} {\frac{S}{\sqrt{n}}} \ge t_{n-1, \alpha/2}|\mu=\mu_1\right) + P\left(\frac {{\bar X} -\mu_0} {\frac{S}{\sqrt{n}}} < - t_{n-1, \alpha/2}|\mu=\mu_1\right) \\ &= P(t_{n-1,\gamma}\ge t_{n-1,\alpha/2})+P(t_{n-1,\gamma}< -t_{n-1,\alpha/2}) \end{aligned}

### 5.4.1 Calculating the Power of the One Sample t-test using R

#### 5.4.1.1 Write a Custom Function to Calculate Power

The following function calculates the power function for the one-sample t-test in R:

onesampttestpow <- function(alpha,n, mu0, mu1,sigma)
{delta <- mu1-mu0
t.crit <-qt(1-alpha/2,n-1)
t.gamma <- sqrt(n)*(delta/sigma)
t.power <- 1-pt(t.crit,n-1,ncp = t.gamma)+pt(-t.crit,n-1,ncp = t.gamma)
return(t.power)
}

For example the power of the t-test for testing

$H_0:\mu = 0 \thinspace \text{ versus } \thinspace H_1:\mu = 0.15$ with $$n = 10,\sigma = 0.2, \alpha = 0.05$$ can be calculated by calling the above function is

onesampttestpow(.05,10,0,.15,0.2)
[1] 0.5619533

#### 5.4.1.2 Use power.t.test() to Calculate Power

There is built-in function in R that can calculate the power of t-test power.t.test(). Using this function on the previous example we get

power.t.test(n = 10,delta = 0.15,sd = 0.2,sig.level = 0.05,type = "one.sample" )

One-sample t test power calculation

n = 10
delta = 0.15
sd = 0.2
sig.level = 0.05
power = 0.5619339
alternative = two.sided

Exactly one of the parameters n, delta, power, sd, and sig.level must be passed as NULL, and that parameter is determined from the others. In this example the function calculates power given the other parameters. If sample size is required for, say, 80% power then use

power.t.test(power = 0.8,delta = 0.15,sd = 0.2,sig.level = 0.05,type = "one.sample" )

One-sample t test power calculation

n = 15.98026
delta = 0.15
sd = 0.2
sig.level = 0.05
power = 0.8
alternative = two.sided

The calculation shows that the study requires sixteen experimental units to have 80% power.

## 5.5 Power of two sample t test

Statistical sample size calculations are calculated under the alternative hypothesis based on the type I error rate $$\alpha$$ and power $$1 - \beta$$. In other words, we assume that the alternative hypothesis is true! Specifying the alternative hypothesis is usually tantamount to specifying a difference between the two groups that will be scientifically or practically meaningful. If two web pages are being tested to see which leads to higher sales is a 2% increase in sales worth the cost of redesigning the web site? If two drugs are being compared in a phase III clinical trial is a 5% difference in mortality rates clinically meaningful?

Sample size estimation not only depends on the effect size [the clinically meaningful difference is often called an effect size], but also on the variance. The larger the variance, the harder it is to detect the difference and thus a larger sample size is needed.

To fix idea let’s suppose that a phase III clinical trials is being designed and a continuous outcome $$Y$$ is the primary outcome. Although, the methods below are valid for experimental contexts beyond clinical trials.

Consider a two-sample comparison with continuous outcomes. Let $$Y_{ik}$$ be the observed outcome for the $$i^{th}$$ subject in the $$kth$$ treatment group, for $$i = 1,...,n_k$$, and $$k= 1,2$$. The outcomes in the two groups are assumed to be independent and normally distributed with different means but an equal variance $$\sigma^2$$,

$Y_{ik} \sim N(\mu_k,\sigma^2).$

Let $$\theta=\mu_1-\mu_2$$, the difference in the mean between treatment 1 (the new therapy) and treatment 2 (the standard of care). To test whether the effects of the two treatments are the same, we formulate the null and alternative hypotheses as $$H_0:\theta =0$$ versus $$H_1:\theta \ne 0.$$

The two-sample t-statistic $$T_n$$ discriminates between $$H_0$$ and $$H_1$$. The p-value is calculated by gauging the observed value of $$T_n$$ against its distribution under $$H_0$$. The hypothesis testing procedure assesses the strength of evidence contained in the data against the null hypothesis. If the p-value is adequately small, say, less than 0.05 under a two-sided test, we reject the null hypothesis and claim that there is a significant difference between the two treatments; otherwise there is no significant difference and the study is inconclusive.

The sample mean for each group is given by $${\bar Y}_k = (1/n_k)\sum_{i = 1}^{n_k} Y_{ik}$$, $$k = 1,2$$, and the pooled sample variance is

$S^2_p= \frac{1}{n_1+n_2-2} \sum_{k = 1}^2 \sum_{i = 1}^{n_k} (Y_{ik}-{\bar Y}_k)^2.$

Then the two-sample t statistic is given by

$T_n=\frac {{\bar Y}_1 - {\bar Y}_2}{S_p \sqrt{(1/n_1+1/n_2)}} \sim t_{n_1+n_2-2}.$

$$T_n \sim t_{n_1+n_2-2}$$ under $$H_0$$ and $$t_{n_1+n_2-2,\gamma}$$ with non-centrality parameter

$\gamma = \frac {\theta}{\sigma\sqrt{1/n_1+1/n_2}},$

under $$H_1$$.

$$H_0$$ is rejected if $$\left| T_n \right| \ge t_{n_1+n_2-2,\alpha/2}$$ where $$t_{df,\alpha/2}$$ is the $$100(1-\alpha/2)th$$ percentile of the central t distribution with $$df$$ degrees of freedom.

The sample size can be determined by specifying the type I and type II error rates, the standard deviation, and the difference in treatment means that the clinical trial aims to detect.

The power of the test is

$1-\beta = P(t_{n_1+n_2-2, \gamma} \ge t_{n_1+n_2-2, \alpha/2})+P(t_{n_1+n_2-2, \gamma} < -t_{n_1+n_2-2, \alpha/2})$

The sample size can be solved from this equation which does not have a closed form (see Yin (2013)).

### 5.5.1 Calculating the Power of the Two Sample t-test using R

#### 5.5.1.1 Write a Custom Function to Calculate Power

This can be programmed in R.

twosampttestpow <- function(alpha,n1,n2, mu1, mu2,sigma){
delta <- mu1-mu2
t.crit <-qt(1-alpha/2,n1+n2-2)
t.gamma <- delta/(sigma*sqrt(1/n1+1/n2))
t.power <- 1-pt(t.crit,n1+n2-2,ncp = t.gamma)+pt(-t.crit,n1+n2-2,ncp = t.gamma)
return(t.power)
}

The power of a clinical trial to detect $$\theta = 1$$ with $$\sigma = 3,n_1 = n_2 = 50$$ is

twosampttestpow(.05,50,50,1,2,3)
[1] 0.3785749

#### 5.5.1.2 Use power.t.test() to Calculate Power

The built-in function power.t.test() can also be used and gives the same results.

power.t.test(n = 50,delta = 1,sd = 3,sig.level = 0.05)

Two-sample t test power calculation

n = 50
delta = 1
sd = 3
sig.level = 0.05
power = 0.3784221
alternative = two.sided

NOTE: n is number in *each* group

So the study would require 50 subjects per group to achieve 38% power to detect a difference of $$\theta = 1$$ at the 5% significance level assuming $$\sigma = 3$$. power.t.test() can also output the number of subjects required to achieve a certain power. Suppose the investigators want to know how many subjects per group would have to be enrolled in each group to achieve 80% power under the same conditions?

power.t.test(power = 0.8,delta = 1,sd = 3,sig.level = 0.05)

Two-sample t test power calculation

n = 142.2466
delta = 1
sd = 3
sig.level = 0.05
power = 0.8
alternative = two.sided

NOTE: n is number in *each* group

142 subjects would be required in each group to achieve 80% power.

The following plot shows power of the two-sample t-test as a function of the difference $$\theta$$ to be detected and equal sample size per group.

# Study power as a function of theta and sample size
pow <- power.t.test(n = 30,delta = seq(0.01,2,by = 0.1),sd = 1.5,power = NULL,
type = "two.sample",alternative = "two.sided",strict = T)
plot(pow$delta,pow$power,type = "l",main = "Power of Two-Sample T-Test",
xlab = "theta",ylab = "Power")
pow <- power.t.test(n = 20,delta = seq(0.01,2,by = 0.1),sd = 1.5,power = NULL,
type = "two.sample",alternative = "two.sided",strict = T)
points(pow$delta,pow$power,type = "l",lty = 2,col = "blue")
pow <- power.t.test(n = 10,delta = seq(0.01,2,by = 0.1),sd = 1.5,power = NULL,
type = "two.sample",alternative = "two.sided",strict = T)
points(pow$delta,pow$power,type = "l",lty = 3,col = "red")
abline(a = 0.8,b = 0)
legend("bottomright",legend = c("N = 30","N = 20","N = 10"),
lty = c(1,2,3),col = c("black","blue","red"))

This next plot shows power as a function of $$\sigma$$ and sample size per group.

# Power as a funtion of sample size and sd
pow <- power.t.test(n = 30,delta = 1,sd = seq(1,3,by = 0.1),power = NULL,
type = "two.sample",alternative = "two.sided",strict = T)
plot(pow$sd,pow$power,type = "l",main = "Power of Two-Sample T-Test",
xlab = "SD",ylab = "Power")
pow <- power.t.test(n = 20,delta = 1,sd = seq(1,3,by = 0.1),power = NULL,
type = "two.sample",alternative = "two.sided",strict = T)
points(pow$sd,pow$power,type = "l",lty = 2,col = "blue")
pow <- power.t.test(n = 10,delta = 1,sd = seq(1,3,by = 0.1),power = NULL,
type = "two.sample",alternative = "two.sided",strict = T)
points(pow$sd,pow$power,type = "l",lty = 3,col = "red")
abline(a = 0.8,b = 0)
legend("topright",legend = c("N = 30","N = 20","N = 10"),
lty = c(1,2,3),col = c("black","blue","red"))

## 5.6 Effect size

In some studies instead of specifying the difference in treatment means and standard deviation separately the ratio

$\frac{\mu_1-\mu_2}{\sigma}$

can be specified. This ratio is called the scaled effect size. Cohen (1992) suggests that effect sizes of 0.2, 0.5, 0.8 correspond to small, medium , and large effects. Cohen (1992) states that:

Researchers find specifying the ES the most difficult part of power analysis … To convey the meaning of any given ES index, it is necessary to have some idea of its scale … My intent was that medium ES represent an effect likely to be visible to the naked eye of a careful observer, (it has since been noted in effect- size surveys that it approximates the average size of observed effects in various fields.) I set small ES to be noticeably smaller than medium but not so small as to be trivial, and I set large ES to be the same distance above medium as small was below it. Although the definitions were made subjectively …

Power as a function of effect size can be investigated using R.

pow.t <- function(theta){
alpha <-0.05
nA <- 10
nB <- 10
t.crit <-qt(1-alpha/2,nA+nB-2)
t.gamma <- theta/(sqrt(1/nA+1/nB))
t.power <- 1-pt(t.crit,nA+nB-2,ncp = t.gamma)+pt(-t.crit,nA+nB-2,ncp = t.gamma)
return(t.power)
}

x <- seq(-3,3,by = 0.1)
plot(x,pow.t(x),type = "l",xlab="",ylab = "power",main = "Two-Sample T-Test Power and Effect Size, N = 10")
abline(v=+1.33,lty = 2,col = "red")
abline(v=-1.33,lty = 2,col = "red")
abline(h = 0.8,lty = 2,col = "blue")

The plot shows that for $$n_1 = n_2 = 10$$ the two-sample t-test has at least 80% power for detecting effect sizes that are at least 1.3.

## 5.7 Sample size - known variance and equal allocation

Consider a study where experimental units are randomized into two treatment groups and the investigator would like an equal number of experimental units in each group.

If the variance is known then the test statistic is

$Z=\frac {{\bar Y}_1 - {\bar Y}_2}{\sigma \sqrt{(1/n_1+1/n_2)}} \sim N(0,1).$

This is the known as the two-sample z-test.

The power at $$\theta=\theta_1$$ is given by

$1-\beta= P\left( Z \ge z_{\alpha/2} - \frac{\theta_1}{\sigma \sqrt{1/n_1+1/n_2}} \right) + P\left( Z < -z_{\alpha/2} - \frac{\theta_1}{\sigma \sqrt{1/n_1+1/n_2}} \right).$

Ignoring terms smaller than $$\alpha/2$$ and combining positive and negative $$\theta$$

$\beta \approx \Phi\left( z_{\alpha/2} - \frac{\left|\theta_1\right|}{\sigma \sqrt{1/n_1+1/n_2}} \right).$

The sample size is obtained by solving

$z_{\beta}+z_{\alpha/2} = \left( \frac{\left|\theta_1\right|}{\sigma \sqrt{1/n_1+1/n_2}} \right).$

If we assume that there will be an equal allocation of subjects to each group then $$n_1 = n_2 = n/2$$, the total sample size is

$n= \frac {4\sigma^2 \left(z_{\beta}+z_{\alpha/2}\right)^2}{\theta^2}.$

## 5.8 Sample size - known variance and unequal allocation

In many studies comparing two treatments it is desirable to put more experimental units into the experimental group to learn more about this treatment. In a phase III clinical trial if the patient allocation between the two groups is $$r = n_1/n_2$$ then $$n_1 = r\cdot n_2$$ and

$n_2=\frac {(1+1/r)\sigma^2 \left(z_{\beta}+z_{\alpha/2}\right)^2} {\theta^2}.$

An R function to compute the sample size in groups 1 and 2 for unequal allocation is

size2z.uneq.test <- function(theta,alpha,beta,sigma,r)
{
zalpha <- qnorm(1-alpha/2)
zbeta <- qnorm(1-beta)
n2 <- (1+1/r)*(sigma*(zalpha+zbeta)/theta)^2
n1 <- r*n2
return(c(n1,n2))
}

The sample size required for 90% power to detect $$\theta = 1$$ with $$\sigma = 2$$ at the 5% level in a trial where two patients will be enrolled in the experimental arm for every patient enrolled in the control arm is 126 in the control group and 63 in the experimental group. The total sample size is 189.

# sample size for theta =1, alpha = 0.05, beta = 0.1, sigma = 2, r = 2
size2z.uneq.test(1,.05,.1,2,2)[1] # group 1 sample size (experimental group)
[1] 126.0891
size2z.uneq.test(1,.05,.1,2,2)[2] # group 2 sample size (control group)
[1] 63.04454

The power of the two-sample z-test can be studied as a function of the allocation ratio $$r$$.

# power of z test as a function of allocation ratio r,
# total sample size n, alpha, theta, and sigma
pow.z.test <- function(r,n,alpha,theta,sigma)
{
n2 <- n/(r+1)
x <- qnorm(1-alpha/2)-abs(theta)/(sigma*sqrt(1/(r*n2)+1/n2))
pow <- 1-pnorm(x)
return(pow)
}

plot(x = seq(.1,5,by = 0.1),y = pow.z.test(seq(.1,5,by = 0.1),168,.05,1,2),type = "l",
xlab = "Allocation ratio",ylab = "Power",
main = "Power vs. allocation ratio with total sample size fixed at \n n = 168 alpha = 0.05")

The plot shows that imbalance typically leads to loss of power.

## 5.9 Comparing Proportions for Binary Outcomes

In this section we will consider studies where the primary endpoint is dichotomous. In a clinical trial the outcome could be whether a patient has responded to the treatment, or whether a patient has experienced toxicity. More specifically, consider a phase III clinical trial where patients are randomized to two groups and a binary outcome is measured as the outcome.

Let $$p_1$$ denote the response rate of the experimental drug, $$p_2$$ as that of the standard drug, and the difference is $$\theta= p_1—p_2$$. Let $$Y_{ik}$$ be the binary outcome for subject $$i$$ in arm $$k$$; that is,

$Y_{ik} = \left\{ \begin{array}{ll} 1 & \mbox{with probability } p_k \\ 0 & \mbox{with probability } 1-p_k, \end{array} \right.$

for $$i = 1,...,n_k$$ and $$k = 1,2$$. The sum of independent and identically distributed Bernoulli random variables has a binomial distribution,

$\sum_{i = 1}^{n_k} Y_{ik} \sim Bin(n_k,p_k), \thinspace k = 1,2.$

(see Yin (2013), pg. 173-174)

The sample proportion for group $$k$$ is

${\hat p}_k={\bar Y}_k = (1/n_k)\sum_{i = 1}^{n_k} Y_{ik}, \thinspace k = 1,2,$

and $$E\left( {\bar Y}_k\right)=p_k$$ and $$Var\left({\bar Y}_k \right)=\frac{p_k(1-p_k)}{n_k}$$.

The goal of the clinical trial is to determine if there is a difference between the two groups using a binary endpoint. That is we want to test $$H_0: \theta = 0$$ versus $$H_1: \theta \ne 0.$$

The test statistic (assuming that $$H_0$$ is true) is:

$T = \frac {{\hat p}_1-{\hat p}_2} {\sqrt{p_1(1-p_1)/n_1+p_2(1-p_2)/n_2}} \sim N(0,1),$

The test rejects at level $$\alpha$$ if and only if

$\left|T\right| \ge z_{\alpha/2}.$

Using the same argument as the case with continuous endpoints and ignoring terms smaller than $$\alpha/2$$ we can solve for $$\beta$$

$\beta \approx \Phi\left( z_{\alpha/2}- \frac{|\theta_1|}{\sqrt{p_1(1-p_1)/n_1+p_2(1-p_2)/n_2}} \right).$

Using this formula to solve for sample size. If $$n_1 = r \cdot n_2$$ then

$n_2= \frac {\left(z_{\alpha/2}+z_{\beta}\right)^2}{\theta^2} \left(p_1(1-p_1)/r+p_2(1-p_2) \right).$

The built-in R function power.prop.test() can be used to calculate sample size or power. For example suppose that the standard treatment for a disease has a response rate of 20%, and an experimental treatment is anticipated to have a response rate of 28%. The researchers want both arms to have an equal number of subjects. How many patients should be enrolled if the study will conduct a two-sided test at the 5% level with 80% power?

power.prop.test(p1 = 0.2,p2 = 0.25,power = 0.8)

Two-sample comparison of proportions power calculation

n = 1093.739
p1 = 0.2
p2 = 0.25
sig.level = 0.05
power = 0.8
alternative = two.sided

NOTE: n is number in *each* group

This means that 1094 should be enrolled in each group.

## 5.10 Calculating Power by simulation

If the test statistic and distribution of the test statistic are known then the power of the test can be calculated via simulation.

Consider a two-sample t-test with 30 subjects per group and the standard deviation of the clinical outcome is known to be 1. What is the power of the test $$H_0:\mu_1-\mu_2 = 0$$ versus $$H_1:\mu_1-\mu_2 = 0.5$$, at the 5% significance level?

The power is the proportion of times that the test correctly rejects the null hypothesis in repeated sampling.

We can simulate a single study using the rnorm() command. Let’s assume that $$n_1 = n_2 = 30, \mu_1 = 3.5, \mu_2 = 3, \sigma = 1, \alpha = 0.05$$.

set.seed(2301)
# simulate 1 study with two samples with 30 observations: one sample is N(3.5,1)
# the other is N(3,1) then do a two-sample t-test on each study
t.test(rnorm(30,mean = 3.5,sd = 1),rnorm(30,mean = 3,sd = 1),var.equal = T)

Two Sample t-test

data:  rnorm(30, mean = 3.5, sd = 1) and rnorm(30, mean = 3, sd = 1)
t = 2.1462, df = 58, p-value = 0.03605
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.03458122 0.99248595
sample estimates:
mean of x mean of y
3.339362  2.825828

We would reject the null hypothesis at the 5% level since the p-value is 0.0360489.

Suppose that 10 studies are simulated. What proportion of these 10 studies will reject the null hypothesis at the 5% level? To investigate how many times the two-sample t-test will reject at the 5% level the replicate() command will be used to generate 10 studies and calculate the p-value in each study. It will still be assumed that $$n_1 = n_2 = 30, \mu_1 = 3.5, \mu_2 = 3, \sigma = 1, \alpha = 0.05$$.

set.seed(2301)
# simulate 10 studies with two samples with 30 observations: one sample is N(3.5,1)
# the other is N(3,1) then do a two-sample t-test on each study
pvals <- replicate(10,t.test(rnorm(30,mean = 3.5,sd = 1),rnorm(30,mean = 3,sd = 1),
var.equal = T)$p.value) pvals # print out 10 p-values  [1] 0.03604893 0.15477655 0.01777959 0.40851999 0.34580930 0.11131007 [7] 0.14788381 0.00317709 0.09452230 0.39173723 sum(pvals<=0.05)/10 #power is the number of times the test rejects at the 5% level [1] 0.3 But, since we only simulated 10 studies the estimate of power will have a large standard error. So let’s try simulating 10,000 studies so that we can obtain a more precise estimate of power. set.seed(2301) pvals <- replicate(10000,t.test(rnorm(30,mean = 3.5,sd = 1),rnorm(30,mean = 3,sd = 1), var.equal = T)$p.value)
sum(pvals<=0.05)/10000
[1] 0.4881

This is much closer to the theoretical power obtained from power.t.test().

power.t.test(n = 30,delta = 0.5,sd = 1,sig.level = 0.05)

Two-sample t test power calculation

n = 30
delta = 0.5
sd = 1
sig.level = 0.05
power = 0.477841
alternative = two.sided

NOTE: n is number in *each* group

The built-in R functions power.t.test() and power.prop.test() don’t have an option for calculating power where the there is unequal allocation of subjects between groups. One option is to simulate power for the scenarios that are of interest. Another option is to write your own function using the formula derived above.

In the previous example the standard treatment for a disease has a response rate of 20%, and an experimental treatment is anticipated to have a response rate of 28%. The researchers want both arms to have an equal number of subjects. The power calculation above revealed that the study will require 1094 patients for 80% power. What would happen to the power if the researchers put 1500 patients in the experimental arm and 500 patients in the control arm?

The number of subjects in the experimental arm that have a positive response to treatment will be an observation from a $$Bin(1500,0.28)$$ and the number of subjects that have a positive response to the standard treatment will be an observation from a $$Bin(500,0.2)$$. We can obtain simulated responses from these distributions using the rbinom() command in R.

set.seed(2301)
rbinom(1,1500,0.28)
[1] 403
rbinom(1,500,0.20)
[1] 89

In this simulated clinical trial 431 of the 1500 patients in the experimental arm had a positive response to the experimental treatment and 101 of the 500 patients in the control arm had a positive response to the standard treatment. The p-value for this simulated study can be obtained using prop.test().

set.seed(2301)
prop.test(x = c(rbinom(1,1500,0.28),rbinom(1,500,0.20)),n = c(1500,500),correct = F)

2-sample test for equality of proportions without continuity
correction

data:  c(rbinom(1, 1500, 0.28), rbinom(1, 500, 0.2)) out of c(1500, 500)
X-squared = 16.62, df = 1, p-value = 4.568e-05
alternative hypothesis: two.sided
95 percent confidence interval:
0.05032654 0.13100680
sample estimates:
prop 1    prop 2
0.2686667 0.1780000

In this study the p-value is 0, which is less than 0.05 so there would be evidence that the new treatment is significantly better than the standard treatment. A power simulation repeats this process a large number of times. The repeat() command can be used for the repetition. In the example below we simulate 10,000 hypothetical studies to calculate power.

set.seed(2301)
pvals <- replicate(10000,prop.test(x = c(rbinom(n = 1,size = 1500,prob = 0.25),rbinom(n = 1,size = 500,prob = 0.20)),n = c(1500,500),correct = F)\$p.value)
sum(pvals<=0.05)/10000
[1] 0.6231

If the researchers decide to have a 3:1 allocation ratio of patients in the treatment to control arm then the power will decrease to approximately 62%.

## 5.11 Questions

1. The R function
# sample size for two-sample Z test equal allocation
size2z.test <- function(theta,alpha,beta,sigma)
{
zalpha <- qnorm(1-alpha/2)
zbeta <- qnorm(1-beta)
(2*sigma*(zalpha+zbeta)/theta)^2
}

implements the sample size formula for calculating the sample size for a test of $$H_0:\theta = 0$$ versus $$H_1:\theta \ne 0$$, where $$\theta=\mu_1-\mu_2$$.

$n=\left(\frac{2\sigma\left(z_{\alpha/2}+z_{\beta}\right)}{\theta}\right)^2$

1. What are the main assumptions behind this sample size formula? (see lecture slides)
2. Does the sample size increase or decrease as (assume that all the other parameters remain fixed):
• $$\sigma$$ decreases;
• $$\alpha$$ decreases;
• $$\theta$$ decreases.
1. A statistician is designing a phase III clinical trial comparing a continuous outcome in two groups (experimental versus standard therapy) with a total sample size of 168 patients. The team requires that the study have at least 80% power at the 5% significance level to detect a difference of 1 (the standard deviation of the outcome is 2). The design team would like to investigate if it’s possible to have four times as many patients in the experimental group versus the control group with out having to increase the sample size.

The statistician conducted the following analysis. What is the power if there are four times as many patients in the experimental group? What should the statistician recommend to the team in order for the study to have at least 80% power? For example, should the type I error rate be increased?

# sample size for two-sample z test unequal allocation
# r is the ratio of patients in the experimental arm to control arm
# e.g. r = 2 means that for every 2 patients in the experimental arm
# 1 pateint is in the control arm

size2z.uneq.test <- function(theta,alpha,beta,sigma,r)
{
zalpha <- qnorm(1-alpha/2)
zbeta <- qnorm(1-beta)
(1+1/r)*(sigma*(zalpha+zbeta)/theta)^2
}

# power of z test as a function of allocation ratio r,
# total sample size n, alpha, theta, and sigma
pow.z.test <- function(r,n,alpha,theta,sigma)
{
n2 <- n/(r+1)
x <- qnorm(1-alpha/2)-abs(theta)/(sigma*sqrt(1/(r*n2)+1/n2))
pow <- 1-pnorm(x)
return(pow)
}

plot(x = seq(.1,5,by = 0.1),y = pow.z.test(seq(.1,5,by = 0.1),168,.05,1,2),type = "l",
xlab = "Allocation ratio",ylab = "Power",
main = "Power vs. allocation ratio with total sample size fixed at \n n = 168 alpha = 0.05")

1. Let $$X_1, X_2, ..., X_n$$ be iid $$N\left(\mu,\sigma^2\right)$$.
1. Show that the power function of the test $$H_0:\mu = 0$$ versus $$H_1:\mu > 0$$ at $$\mu=1$$ is $1-\Phi\left(z_{\frac{\alpha}{2}}-\frac{\sqrt{n}}{\sigma}\right)$, where $$z_{\frac{\alpha}{2}},$$ is the $$100\left(1-\frac{\alpha}{2}\right)^{th}$$ percentile of the $$N\left(0,1\right)$$.

2. Use R to calculate the power when $$n = 10$$, $$\alpha = 0.01$$, and $$\sigma = 1$$.

## 5.12 Solutions to Questions

1. One sample is iid $$N\left(\mu_1,\sigma^2\right)$$ and one sample is iid $$N\left(\mu_2,\sigma^2\right)$$.
1. Does the sample size increase or decrease as (assume that all the other parameters remain fixed):
• $$\sigma$$ decreases;
# sample size for two-sample Z test equal allocation
size2z.test <- function(theta,alpha,beta,sigma)
{
zalpha <- qnorm(1-alpha/2)
zbeta <- qnorm(1-beta)
(2*sigma*(zalpha+zbeta)/theta)^2
}

#sigma=1
size2z.test(1,0.05,.1,1)
## [1] 42.02969
#sigma=2
size2z.test(1,0.05,.1,2)
## [1] 168.1188

$$n$$ decreases as $$\sigma$$ decreases.

• $$\alpha$$ decreases;
#alpha=0.05
size2z.test(1,0.05,.1,1)
## [1] 42.02969
#alpha=0.01
size2z.test(1,0.01,.1,1)
## [1] 59.51755

$$n$$ increases as $$\alpha$$ decreases.

• $$\theta$$ decreases.
#theta=1
size2z.test(1,0.05,.1,1)
## [1] 42.02969
#theta=2
size2z.test(2,0.05,.1,1)
## [1] 10.50742

$$n$$ increases as $$\theta$$ decreases.

1. If r=4 then the power is

pow.z.test <- function(r,n,alpha,theta,sigma)
{
n2 <- n/(r+1)
x <- qnorm(1-alpha/2)-abs(theta)/(sigma*sqrt(1/(r*n2)+1/n2))
pow <- 1-pnorm(x)
return(pow)
}

pow.z.test(4,168,0.05,1,2)
## [1] 0.7364151

The statistician can either increase $$n$$, $$\alpha$$, or $$\theta$$, or decrease $$\sigma$$. The statistician >should recommend increasing $$n$$. Most regulatory agencies have fixed $$\alpha=0.05$$. $$\theta=1$$ is the smallest meangingful clinical difference so it wouldn’t be rationale to increase $$\theta$$ since the study might miss detecting a clinically significant difference if $$\theta$$ is increased. Decreasing $$\sigma$$ is usually not possible since the variation of the outcome measure is difficult to change in practice.

1. The test rejects when

$\frac{\bar X}{\sigma/\sqrt{n}} \ge z_{\alpha/2}.$ The probability the test rejects when $$\mu=1$$ is:

\begin{aligned} P\left(\frac{\bar X}{\sigma/\sqrt{n}} \ge z_{\alpha/2}\right) &= P\left({\bar X} \ge z_{\alpha/2} \cdot \sigma/\sqrt{n} \right) \\ &= P\left(\frac{\bar X - 1}{\sigma/\sqrt{n}} \ge \frac{z_{\alpha/2} \cdot \sigma/\sqrt{n}-1}{\sigma/\sqrt{n}} \right) \\ &= P\left(Z \ge \frac{z_{\alpha/2} \cdot \sigma/\sqrt{n}-1}{\sigma/\sqrt{n}} \right) \\ &= 1-\Phi\left(\frac{z_{\alpha/2} \cdot \sigma/\sqrt{n}-1}{\sigma/\sqrt{n}} \right) \\ &= 1-\Phi\left(z_{\alpha/2} - \frac{\sqrt{n}}{\sigma} \right) \\ \end{aligned}

1. Use R to calculate the power when $$n=10$$, $$\alpha=0.01$$, and $$\sigma=1$$.
zalpha2 <- qnorm(1-0.01/2)
1-pnorm(zalpha2-sqrt(10))
## [1] 0.7212129

### References

Cohen, Jacob. 1992. “A Power Primer.” Psychological Bulletin 112 (1). American Psychological Association: 155.

Yin, Guosheng. 2013. Clinical Trial Design: Bayesian and Frequentist Adaptive Methods. Vol. 876. John Wiley; Sons.


text:
Course: Math Subtest II Lesson: Three-Dimensional Geometry Topic: Diagnostic Questions      Page 1 of 3

Diagnostic Question

1. What is the area of a circle whose equation is given by x^2 + 8x + y_2 + 12y + 3 = 0?

 A 98pi
 B 64pi
 C 49pi
 D 14pi

format: plain


text:
Meet students taking the same courses as you are!Join a Numerade study group on Discord

# Find the mode or modes for each list of numbers.$16,15,13,15,14,13,11,15,14$

## 15

#### Topics

Multivariable Optimization

### Discussion

You must be signed in to discuss.
##### Catherine R.

Missouri State University

##### Heather Z.

Oregon State University

##### Samuel H.

University of Nottingham

Lectures

Join Bootcamp

### Video Transcript

this question presents you with a list of numbers and ask you to find the me the mod. Excuse me. The numbers that are printed presents are 16 15 13 15 14 13 11 15 and 14. Now, we have a lot of numbers and several of them repeat. So the way that I like to do these is, um, set up a little table and sort of as I go through the list. Check off. Um, how maney of each value I see. So I know that 16 is my highest value here, and 11 is my lowest value. So I'm gonna just count them down 18 12 and 11 and I'll go through and check them off, as I see. So I get no, have won 16. That 1 15 I have 1 13 at another 15. Ah, 14. Another 13 and 11. Another 15 and another 14. So it's all of my data, and I could see that the one that I had the most of was 15. Now, the mode we know is that is the, uh, value that shows up the most in the data. And so here, 15 is our mode that your final answer

University of Oklahoma

#### Topics

Multivariable Optimization

##### Catherine R.

Missouri State University

##### Heather Z.

Oregon State University

##### Samuel H.

University of Nottingham

Lectures

Join Bootcamp


text:
Enroll in one of our FREE online STEM bootcamps. Join today and start acing your classes!View Bootcamps

by evaluating $f$ at $x$ -values near $0 .$ Sketc…

01:22
Westview High School
Problem 69

Estimating a Limit Consider the function$f(x)=(1+x)^{1 / x}$Estimate$$\lim _{x \rightarrow 0}(1+x)^{1 / x}$$by evaluating $f$ at $x$ -values near $0 .$ Sketch the graph of $f$

Discussion

You must be signed in to discuss.

Video Transcript

we're given the following limit as X approaches zero of the function one plus x two, the one over X power. And so we're asked to estimate this limit, Couldn't you waste so first of all, we are asked to created table to estimate it. So we have sex and effort backs and we know that approaches zero. So we need to create a values closer to zero. So we have neighbors 0.1 actual serving a good one negative. 0.1 No, ive is 0.1 Then we also do possible this around it. So we have 0.1 0.10 point one. And now the best way to estimate this is really just depressed. We figure this out is a punk thes rallies and your calculator. So you will get approximately achieve point six for Sorry. Two point 868 2.719 2.718 and then 2.716 She points 705 and she went for 94 Now, based off from this information, you can see that this is a spot where so This is a spot where zero is between and it seems to be approaching chill 0.717 So you can say that this limit is approximately 2.717 We want to check this race off photograph, so we graft dysfunction. And if we zoom in zero and we zoom in closer, we can see that it seems to be approaching around. There seems to be approaching 2.717 once again. So based off with this but based off of both our graph in her table when you say that limit as X approaches era of one plus x 2 to 1 over X power, it's approximately 2.717


text:
• I
Gold Member

## Main Question or Discussion Point

I have been reading D.E. Littlewood's book "The Skeleton Key of Mathematics", and near the beginning he says that if a projectile weighing one (long) ton were given a velocity of 44 miles a second, this would be "sufficient to raise it to a height of 1000 miles above the earth's surface."

Naturally, I wanted to reproduce this number for myself, so I started with conservation of energy:

$\frac{1}{2}M_P V^2 - \frac{GM_P M_E}{R_E} = -\frac{GM_P M_E}{R_E+h}$,

where $M_E$ is the mass of the Earth, $M_P$ that of the projectile, $h$ is the height of the projectile above the surface, $G$ is the gravitation constant, and $V$ is the projectile's speed. Solving for the height gives

$h = \frac{R_E}{\frac{2GM_E}{V^2 R_E}-1}$.

First, note that the mass of the projectile does not appear in this formula. It appears, then, irrelevant that the projectile weighs a ton. Second, as the denominator approaches zero, $h \rightarrow \infty$; setting the denominator to zero and solving for $V = V_{esc}$ yields

$V_{esc} = \sqrt{2G M_E / R} \approx 7 \frac{mi}{s}$.

Thus, 44 mi/s seems like way more than you would need to lift the projectile 1000 miles above the surface. I didn't account for energy lost to air resistance in these calculations, but launching an object through the atmosphere into space like that seems unfeasible - wouldn't it just burn up? Am I missing something or is Littlewood's calculation off?

Related Classical Physics News on Phys.org
Simon Bridge
Homework Helper
Well done - if you google "escape velocity in miles per second" what do you get?

Gold Member
Well, Google didn't give me what I expected, but Wolfram Alpha did - about 7 mi/s. For some reason, I always have a hard time believing that books could be wrong about things like this. I always think I must be missing something. Thanks!

Andy Resnick


text:
Balbharti Maharashtra State Board 11th Maths Book Solutions Pdf Chapter 3 Permutations and Combination Ex 3.2 Questions and Answers.

## Maharashtra State Board 11th Maths Solutions Chapter 3 Permutations and Combination Ex 3.2

Question 1.
Evaluate:
(i) 8!
Solution:
8!
= 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1
= 40320

(ii) 10!
Solution:
10!
= 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1
= 3628800

(iii) 10! – 6!
Solution:
10! – 6!
= 10 × 9 × 8 × 7 × 6! – 6!
= 6! (10 × 9 × 8 × 7 – 1)
= 6! (5040 – 1)
= 6 × 5 × 4 × 3 × 2 × 1 × 5039
= 3628080

(iv) (10 – 6)!
Solution:
(10 – 6)!
= 4!
= 4 × 3 × 2 × 1
= 24

Question 2.
Compute:
(i) $$\frac{12 !}{6 !}$$
Solution:
$$\frac{12 !}{6 !}=\frac{12 \times 11 \times 10 \times 9 \times 8 \times 7 \times 6 !}{6 !}$$
= 12 × 11 × 10 × 9 × 8 × 7
= 665280

(ii) $$\left(\frac{12}{6}\right) !$$
Solution:
$$\left(\frac{12}{6}\right) !$$
= 2!
= 2 × 1
= 2

(iii) (3 × 2)!
Solution:
(3 × 2)!
= 6!
= 6 × 5 × 4 × 3 × 2 × 1
= 720

(iv) 3! × 2!
Solution:
3! × 2!
= 3 × 2 × 1 × 2 × 1
= 12

(v) $$\frac{9 !}{3 ! 6 !}$$
Solution:
$$\frac{9 !}{3 ! 6 !}=\frac{9 \times 8 \times 7 \times 6 !}{(3 \times 2 \times 1) \times 6 !}=84$$

(vi) $$\frac{6 !-4 !}{4 !}$$
Solution:
$$\frac{6 !-4 !}{4 !}=\frac{6 \times 5 \times 4 !-4 !}{4 !}=\frac{4 !(6 \times 5-1)}{4 !}=29$$

(vii) $$\frac{8 !}{6 !-4 !}$$
Solution:
$$\frac{8 !}{6 !-4 !}=\frac{8 \times 7 \times 6 \times 5 \times 4 !}{6 \times 5 \times 4 !-4 !}$$
= $$\frac{8 \times 7 \times 6 \times 5 \times 4 !}{4 !(6 \times 5-1)}$$
= $$\frac{1680}{29}$$
= 57.93

(viii) $$\frac{8 !}{(6-4) !}$$
Solution:
$$\frac{8 !}{(6-4) !}=\frac{8 !}{2 !}$$
= $$\frac{8 \times 7 \times 6 \times 5 \times 4 \times 3 \times 2 !}{2 !}$$
= 20160

Question 3.
Write in terms of factorials
(i) 5 × 6 × 7 × 8 × 9 × 10
Solution:
5 × 6 × 7 × 8 × 9 × 10 = 10 × 9 × 8 × 7 × 6 × 5
Multiplying and dividing by 4!, we get
= $$\frac{10 \times 9 \times 8 \times 7 \times 6 \times 5 \times 4 !}{4 !}$$
= $$\frac{10 \times 9 \times 8 \times 7 \times 6 \times 5 \times 4 \times 3 \times 2 \times 1}{4 !}$$
= $$\frac{10 !}{4 !}$$

(ii) 3 × 6 × 9 × 12 × 15
Solution:
3 × 6 × 9 × 12 × 15
= 3 × (3 × 2) × (3 × 3) × (3 × 4) × (3 × 5)
= (35) (5 × 4 × 3 × 2 × 1)
= 35 (5!)

(iii) 6 × 7 × 8 × 9
Solution:
6 × 7 × 8 × 9 = 9 × 8 × 7 × 6
Multiplying and dividing by 5!, we get
= $$\frac{9 \times 8 \times 7 \times 6 \times 5 !}{5 !}$$
= $$\frac{9 \times 8 \times 7 \times 6 \times 5 \times 4 \times 3 \times 2 \times 1}{5 !}$$
= $$\frac{9 !}{5 !}$$

(iv) 5 × 10 × 15 × 20
Solution:
5 × 10 × 15 × 20
= (5 × 1) × (5 × 2) × (5 × 3) × (5 × 4)
= (54) (4 × 3 × 2 × 1)
= (54) (4!)

Question 4.
Evaluate: $$\frac{n !}{r !(n-r) !}$$ for
(i) n = 8, r = 6
(ii) n = 12, r = 12
(iii) n = 15, r = 10
(iv) n = 15, r = 8
Solution:

Question 5.
Find n, if
(i) $$\frac{n}{8 !}=\frac{3}{6 !}+\frac{1 !}{4 !}$$
Solution:

(ii) $$\frac{n}{6 !}=\frac{4}{8 !}+\frac{3}{6 !}$$
Solution:

(iii) $$\frac{1 !}{n !}=\frac{1 !}{4 !}-\frac{4}{5 !}$$
Solution:

(iv) (n + 1)! = 42 × (n -1)!
Solution:
(n + 1)! = 42(n – 1)!
∴ (n + 1) n (n – 1)! = 42(n – 1)!
∴ n2 + n = 42
∴ n2 + n – 42 = 0
∴ (n + 7)(n – 6) = 0
∴ n = -7 or n = 6
But n ≠ -7 as n ∈ N
∴ n = 6

(v) (n + 3)! = 110 × (n + 1)!
Solution:
(n + 3)! = (110) (n + 1)!
∴ (n + 3)(n + 2)(n + 1)! = 110(n + 1)!
∴ (n + 3) (n + 2) = (11) (10)
Comparing on both sides, we get
n + 3 = 11
∴ n = 8

Question 6.
Find n, if:
(i) $$\frac{(17-n) !}{(14-n) !}=5 !$$
Solution:

∴ (17 – n) (16 – n) (15 – n) = 6 × 5 × 4
Comparing on both sides, we get
17 – n = 6
∴ n = 11

(ii) $$\frac{(15-n) !}{(13-n) !}=12$$
Solution:
$$\frac{(15-n) !}{(13-n) !}=12$$
∴ $$\frac{(15-n)(14-n)(13-n) !}{(13-n) !}=12$$
∴ (15 – n) (14 – n) = 4 × 3
Comparing on both sides, we get
∴ 15 – n = 4
∴ n = 11

(iii) $$\frac{n !}{3 !(n-3) !}: \frac{n !}{5 !(n-5) !}=5: 3$$
Solution:

∴ 12 = (n – 3)(n – 4)
(n – 3)(n – 4) = 4 × 3
Comparing on both sides, we get
n – 3 = 4
∴ n = 7

(iv) $$\frac{n !}{3 !(n-3) !}: \frac{n !}{5 !(n-7) !}=1: 6$$
Solution:

∴ 120 = (n – 3)(n – 4) (n – 5)(n – 6)
∴ (n – 3)(n – 4) (n – 5)(n – 6) = 5 × 4 × 3 × 2
Comparing on both sides, we get
n – 3 = 5
∴ n = 8

(v) $$\frac{(2 n) !}{7 !(2 n-7) !}: \frac{n !}{4 !(n-4) !}=24: 1$$
Solution:

(2n – 1)(2n – 3)(2n – 5) = $$\frac{24 \times 7 \times 6 \times 5}{16}$$
∴ (2n – 1)(2n – 3)(2n – 5) = 9 × 7 × 5
Comparing on both sides. We get
∴ 2n – 1 = 9
∴ n = 5

Question 7.
Show that $$\frac{n !}{r !(n-r) !}+\frac{n !}{(r-1) !(n-r+1) !}=\frac{(n+1) !}{r !(n-r+1) !}$$
Solution:

Question 8.
Show that $$\frac{9 !}{3 ! 6 !}+\frac{9 !}{4 ! 5 !}=\frac{10 !}{4 ! 6 !}$$
Solution:

Question 9.
Show that $$\frac{(2 n) !}{n !}$$ = 2n (2n – 1)(2n – 3)…5.3.1
Solution:

Question 10.
Simplify
(i) $$\frac{(2 n+2) !}{(2 n) !}$$
Solution:

(ii) $$\frac{(n+3) !}{\left(n^{2}-4\right)(n+1) !}$$
Solution:

(iii) $$\frac{1}{n !}-\frac{1}{(n-1) !}-\frac{1}{(n-2) !}$$
Solution:

(iv) n[n! + (n – 1)!] + n2(n – 1)! + (n + 1)!
Solution:

(v) $$\frac{n+2}{n !}-\frac{3 n+1}{(n+1) !}$$
Solution:

(vi) $$\frac{1}{(n-1) !}+\frac{1-n}{(n+1) !}$$
Solution:

(vii) $$\frac{1}{n !}-\frac{3}{(n+1) !}-\frac{n^{2}-4}{(n+2) !}$$
Solution:

(viii) $$\frac{n^{2}-9}{(n+3) !}+\frac{6}{(n+2) !}-\frac{1}{(n+1) !}$$
Solution:


text:
# Complete miscibility between different crystallographic structures Monte Carlo simulations of Cu-Ag deposited on Cu(001)

* Corresponding author
Abstract : Monte Carlo simulations of an Ag$_c$Cu$_{1-c}$ monolayer deposited onto Cu(001) show that a complete solubility of two elements adopting different crystallographic structures can be observed in the surface, while experimental bulk phase diagrams preclude a similar phenomenon in the bulk. While the deposited pure Ag monolayer is pseudo-hexagonal and the pure Cu monolayer is square and pseudomorphic, for intermediate concentrations a disordered state appears in which square and hexagonal environments, respectively due to Cu and Ag coexist. As a result, the surface phase diagram does not present any miscibility gap at 650 K.
Keywords :
Document type :
Journal articles
Domain :

Cited literature [24 references]

https://hal-cea.archives-ouvertes.fr/cea-02356014
Contributor : amplexor amplexor Connect in order to contact the contributor
Submitted on : Monday, December 9, 2019 - 3:43:10 PM
Last modification on : Sunday, June 26, 2022 - 12:12:47 PM
Long-term archiving on: : Tuesday, March 10, 2020 - 1:14:14 PM

### File

200600004250.pdf
Files produced by the author(s)

### Citation

Isabelle Braems, F. Berthier, J. Creuze, R. Tetot, B. Legrand. Complete miscibility between different crystallographic structures Monte Carlo simulations of Cu-Ag deposited on Cu(001). Physical Review B: Condensed Matter and Materials Physics (1998-2015), American Physical Society, 2006, 74 (1-4), pp.113406. ⟨10.1103/PhysRevB.74.113406⟩. ⟨cea-02356014⟩

Record views


text:
Can a mathematically sound prediction interval have a negative lower bound?

I have used R to form a 95% prediction interval for the number of endemic species on an island.
My lower bound is negative – is that mathematically sound?

In the linear model used in the prediction interval, the data used are: Area Surface area of island, hectares DiscSC Distance from Santa Cruz, kilometres Elevation Elevation of higher point in metres and it is coded as such:

selected.model <- lm(ES ~ Area + Elevation + DistSC + I(Elevation^2)
+ (Elevation:DistSC) + (Area:Elevation))

and stepwise regression was performed to find this "best" model

I'm not exactly sure how a prediction interval works. I just want to make sure it is OK. Obviously a negative number of species is incorrect, but I know it takes into account the uncertainty of the mean as well as data scatter.

-
Can you explain more about your analysis? What kind of data is used for prediction - normal, counts, probabilities, categorical... ? How did you do the analysis - regression, anova - something more complicated? It is hard to know what to say without that kind of info. –  John Paul Apr 3 '14 at 18:08
In the linear model used in the prediction interval, the data used are: Area Surface area of island, hectares DiscSC Distance from Santa Cruz, kilometres Elevation Elevation of higher point in metres and it is coded as such: > selected.model<-lm(ES~Area+Elevation+DistSC+I(Elevation^2)+(Elevation:DistSC)+(Area:Elevation)) and stepwise regression was performed to find this "best" model –  user42835 Apr 3 '14 at 18:11
There's nothing problematic with a negative lower bound for a non-negative variable from a mathematical point of view. The important question is whether this is evidence that the prediction interval procedure in use might be a poor one in general or inappropriate for this phenomenon in particular. Have you performed the usual regression diagnostics, including goodness of fit and distributional evaluation of the residuals? –  whuber Apr 3 '14 at 18:12
The few seconds it takes to issue the command plot(selected.model) and look at the output will be well worth your time, then. –  whuber Apr 3 '14 at 18:54
You fitted a model that can be negative; if you do that you shouldn't be surprised when it generates an interval that does. Fitting a model more appropriate to your data/situation may help. –  Glen_b Apr 3 '14 at 23:03

Mathematics are reality-agnostic. So your negative lower prediction band can certainly be mathematically sound.

I would argue, however, that this is a good indication that you are using the wrong mathematics, e.g., Ordinary Least Squares (which assumes a normal distribution of errors) with count data (where a normal distribution makes no sense). I would suggest using Poisson regression or some similar method that is more suitable for count data.

-
I think applied scientists and statisticians would agree that allowing negative predicted counts is unsound in practice. –  AdamO Apr 4 '14 at 16:06

It suggests to me that you haven't used any analytic approach with an appropriate transformation of the outcome. With count data, for instance, popular linear models (Poisson Regression or Negative Binomial Regression in particular) model the log of the process as a linear function of predictors. Then, any predicted values resulting from such a model would have to be exponentiated and, thus, positive.

Similarly, when you use the predict.glm function with se.fit set to TRUE for these models, you calculate symmetric prediction intervals for counts on the log scale. Re-exponentiating those values ensures that you have intervals which do not include 0. You'll notice that the exponentiated predictions are the same as you would get from setting type='response' in the predict function. However, asking for both type='response', se.fit=TRUE will confuse R since the link transformation of the GLM means you'll have non-symmetric intervals (SE of FIT is calculated on the transformed outcome scale).

There are additive count models, just like there are additive risk models for binary endpoints, but I think the results can be difficult to interpret and they behave untenably for predictions near to the boundaries values of the support (0 for count data). As such, I'd be dubious about not only your negative predictions but all other predictions from your model.

-


text:
# How do you integrate int x^2e^x dx  using integration by parts?

Jan 27, 2016

$\int {x}^{2} {e}^{x} \mathrm{dx} = {x}^{2} {e}^{x} - 2 x {e}^{x} + 2 {e}^{x} + c$

#### Explanation:

The integration by parts formula say

$\int u \mathrm{dv} = u v - \int v \mathrm{du}$

So, if we pick $u = {x}^{2}$ and $\mathrm{dv} = {e}^{x}$ so we'll have $\mathrm{du} = 2 x$ and $v = {e}^{x}$

$\int {x}^{2} {e}^{x} \mathrm{dx} = {x}^{2} {e}^{x} - \int 2 x {e}^{x} \mathrm{dx}$

Now we pick $u = x$ and $\mathrm{dv} = {e}^{x}$, so $v = {e}^{x}$ and $\mathrm{du} = 1$

$\int {x}^{2} {e}^{x} \mathrm{dx} = {x}^{2} {e}^{x} - 2 \left(x {e}^{x} - \int {e}^{x} \mathrm{dx}\right)$

This last integral is tabled, so

$\int {x}^{2} {e}^{x} \mathrm{dx} = {x}^{2} {e}^{x} - 2 x {e}^{x} + 2 {e}^{x} + c$


text:
## View Blog | Read Bio

### When Feynman Diagrams Fail

We’ve gone pretty far with our series of posts about learning particle physics through Feynman diagrams. In our last post we summarized the Feynman rules for all of the known particles of the Standard Model. Now it’s time to fess up a little about the shortcomings of the Feynman diagram approach to calculations; in doing so, we’ll learn a little more about what Feynman diagrams actually represent as well as the kinds of physics that we must work with at a machine like the LHC.

## When one diagram isn’t enough

Recall that mesons are bound states of quarks and anti-quarks which are confined by the strong force. This binding force is very non-perturbative; in other words, the math behind our Feynman diagrams is not the right tool to analyze it. Let’s go into more detail about what this means. Consider the simplest Feynman diagram one might draw to describe the gluon-mediated interaction between a quark and an anti-quark:

Easy, right? Well, one thing that we have glossed over in our discussions of Feynman diagrams so far is that we can also draw much more complicated diagrams. For example, using the QCD Feynman rules we can draw something much uglier:

This is another physical contribution to the interaction between a quark and an anti-quark. It should be clear that one can draw arbitrarily many diagrams of this form, each more and more complicated than the last. What does this all mean?

Each Feynman diagram represents a term in a mathematical expression. The sum of these terms gives the complete probability amplitude for the process to occur. The really complicated diagrams usually give a much smaller contribution than the simple diagrams. For example, each photon vertex additional internal photon line (edit Dec 11, thanks ChriSp and Lubos) gives a factor of roughly α=1/137 to the diagram’s contribution to the overall probability. (There are some subtleties here that are mentioned in the comments.) Thus it is usually fine to just take the simplest diagrams and calculate those. The contribution from more complicated diagrams are then very small corrections that are only important to calculate when experiments reach that level of precision. For those with some calculus background, this should sound familiar: it is simply a Taylor expansion. (In fact, most of physics is about making the right Tayor expansion.)

However, QCD defies this approximation. It turns out that the simplest diagrams do not give the dominant contribution! It turns out that both the simple diagram and the complicated diagram above give roughly the same contribution. One has to include many complicated diagrams to obtain a good approximate calculation. And by “many,” I mean almost all of them… and “almost all” of an infinite number of diagrams is quite a lot.  For various reasons, these complicated diagrams are very difficult to calculate and at the moment our normal approach is useless.

There’s a lot of current research pushing this direction (e.g. so-called holographic techniques and recent progress on scattering amplitudes), but let’s move on to what we can do.

## QCD and the lattice

Surely,’ said I, surely that is something at my window lattice;
Let me see then, what thereat is, and this mystery explore –
— Edgar Allen Poe, “The Raven”

A different tool that we can use is called Lattice QCD. I can’t go into much detail about this since it’s rather far from my area of expertise, but the idea is that instead using Feynman diagrams to calculate processes perturbatively—i.e. only taking the simplest diagrams—we can use computers to numerically solve for a related quantity. This related quantity is called the partition function and is a mathematical object from which one can straightforwardly calculate probability amplitudes. (I only mention the fancy name because it is completely analogous to an object of the same name that one meets in thermodynamics.)

The point is that the lattice techniques are non-perturbative in the sense that we don’t calculate individual diagrams, we simultaneously calculate all diagrams. The trade-off is that one has to put spacetime on a lattice so that the calculations are actually done on a four-dimensional hyper-cube. The accuracy of this approximation depend on the lattice size and spacing relative to the physics that you want to study.  (Engineers will be familiar with this idea from the use of Fourier transforms.) As usual, a picture is worth a thousand words; suppose we wanted to study the Mona Lisa:

The first image is the original. The second image comes from putting the image on a lattice, you see that we lose details about small things. Because things with small wavelengths have high energies, we call this an ultraviolet (UV) cutoff. The third image comes from having a smaller canvas size so that we cannot see the big picture of the entire image. Because things with big wavelengths have low energies, we call this an IR cutoff. The final image is meant to convey the limitations imposed by the combination of the UV and IR cutoffs; in other words, the restrictions from using a lattice of finite size and finite lattice spacing.

If you’re interested in only the broad features the Mona Lisa’s face, then the lattice depiction above isn’t so bad. Of course, if you are a fine art critic, then the loss of small and large scale information is unforgiveable. Currently, lattice techniques have a UV cutoff of around 3 GeV and an IR cutoff of about 30 MeV; this makes them very useful for calculating information about transitions between charm (mass = 1.2 GeV) and strange quarks (mass = 100 MeV).

## Translating from theory to experiment (and back)

When I was an undergraduate, I always used to be flummoxed that theorists would always draw these deceptively simple looking Feynman diagrams on their chalkboards, while experimentalists had very complicated plots and graphs to represent the same physics. Indeed, you can tell whether a scientific paper or talk has been written by a theorist or an experimentalist based on whether it includes more Feynman diagrams or histograms. (This seems to be changing a bit as the theory community has made a concerted effort over the past decade to learn to the lingo of the LHC. As Seth pointed out, this is an ongoing process.)

There’s an reason for this: experimental data is very different from writing down new models of particle interactions. I encourage you to go check out the sample event displays from CMS and ATLAS on the Symmetry Breaking blog for a fantastic and accessible discussion of what it all means. I can imagine fellow bloggers Jim and Burton spending a lot of time looking at similar event displays! (Or maybe not; I suspect that an actual analysis focuses more on accumulated data over many events rather than individual events.) As a theorist, on the other hand, I seem to be left with my chalkboard connecting squiggly lines to one another. 🙂

Once again, part of the reason why we speak such different languages is non-perturbativity. One cannot take the straightforward Feynman diagram approach and use it when there is all sorts of strongly-coupled gunk flying around. For example, here’s a diagram for electron–positron scattering from Dieter Zeppenfeld’s PiTP 2005 lectures:

The part in black, which is labeled “hard scattering,” is what a theorist would draw. As a test of your Feynman diagram see if you can “read” the following: This diagram represents an electron and positron annihilating into a Z boson, which then decays into a top–anti-top pair. The brown lines also show the subsequent decay of each top into a W and (anti-)bottom quark.

Great, that much we’ve learned from our previous posts. The big question is: what’s all that other junk?! That, my friend, is the result of QCD. You can see that the pink lines are gluons which are emitted from the final state quarks. These gluons can sprout off other gluons or quark–anti-quark pairs. All of these quarks and gluons must then hadronize into color-neutral hadron states, mostly mesons. These are shown as the grey blobs. These hadrons can in turn decay into other hadrons, depicted by yellow blobs. Most of all of this happens before any of the particles reach the detector. Needless to say, there are many, many similar diagrams which should all be calculated to give an accurate prediction.

In fact, for the LHC it’s even more complicated since even the initial states are colored and so they also spit off gluons (“hadronic junk”). Here’s a picture just to show how ridiculous these process look at a particle-by-particle level:

Let me just remark that the two dark gray blobs are the incoming protons. The big red blob represents all of the gluons that these protons emit. Note that the actual “hard interaction,” i.e. the “core process” is gluon-gluon scattering. This is a bit of a subtle point, but at very high energies, the actual point-like objects which are interacting are gluons, not the quarks that make up the proton!

All of this hadronic junk ends up being sprayed through the experiments’ detectors. If the origin of some of the hadronic junk comes from a high-energy colored particle (e.g. a quark that came from the decay of a new heavy TeV-scale particle), then they are collimated into cones that are pointing in roughly the same direction called a jet, (image from Gavin Salam’s 2010 lectures at Cargese)

Some terminology: parton refers to either a quark or gluon, LO means “leading-order”, NLO means “next-to-leading order.” The parton shower is the stage in which partons can radiate more low-energy partons, which then confine into hadrons. Now one can start to see how to connect our simple Feynman diagrams to the neat looking event reconstructions at the LHC: (image from Gavin Salam’s lectures again)

Everything except for the black lines are examples of what one would actually read off of an event display. This is meant to be a cross-section of the interaction point of the beamline. The blue lines come from a tracking chamber, basically layers of silicon chips that detect the passage of charged particles. The yellow and pink bars are readings from the calorimeters, which tell how much energy is deposited into chunks of dense material. Note how ‘messy’ the event looks experimentally: all of those hadrons obscure the so-called hard scattering underlying event (edit Dec 11, thanks to ChriSp), which is what we draw with Feynman diagrams.

So here’s the situation: theorists can calculate the “hard scattering” or “underlying event” (black lines in the two diagrams above), but all of the QCD-induced stuff that happens after the hard scattering is beyond our Feynman diagram techniques and cannot be calculated from first principles. Fortunately, most of the non-peturbative effects can again be accounted for using computers. The real question is given an underlying event (a Feynman diagram), how many times will the final state particles turn into a range of different hadrons configurations. This time one uses Monte-Carlo techniques where instead of calculating the probabilities of each hadronic final state, the computer randomly generates these final states according to some pre-defined probability distribution. If we run such a simulation over and over again, then we end up with a simulated distribution of events which should match experiments relatively well.

One might wonder why this technique should work. It seems like we’re cheating—where did these “pre-defined” probability distributions come from? Aren’t these what we want to calculate in the first place? The answer is that these probability distributions come from experiments themselves. This isn’t cheating since the experiments reflect data about low-energy physics. This is well known territory that we really understand. In fact, everything in this business of hadronic junk is low-energy physics. The whole point is that the only missing information is the high-energy underlying event hard scattering (ed. Dec 11)—but fortunately that’s the part that we can calculate! The fact this works is a straightforward result of “decoupling,” or the idea that physics at different scales shouldn’t affect one another. (In this case physicists often say that the hadronic part of the calculation “factorizes.”)

To summarize: theorists can calculate the underlying event hard scattering (ed. Dec 11) for their favorite pet models of new physics. This is not the whole story, since it doesn’t reflect what’s actually observed at a hadron collider. It’s not possible to calculate what happens next from first principles, but fortunately this isn’t necessary, we can just use well-known probability distributions to simulate many events and predict what the model of new physics would predict in a large data set from an actual experiment. Now that we’re working our way into the LHC era, clever theorists and experimentalists are working on new ways to go the other way around and take the experimental signatures to try to recreate the underlying model.

As a kid I remember learning over and over again how a bill becomes a law. What we’ve shown here is how a model of physics (a bunch of Feynman rules) becomes a prediction at a hadron collider! (And along the way we’ve hopefully learned a lot about what Feynman diagrams are and how we deal with physics that can’t be described by them.)


text:
# Sovereign Individual

Forward thinking technological progressive and software engineer trying to be less wrong every day.

# Future-proof cryptographic hashes

I’d like to document my learnings as I’m diving into projects that catch my attention in the decentralization space, such as IPFS. If you aren’t familiar with IPFS or haven’t heard of it, it’s basically a stack of (networking) protocols that enables a fully distributed file storage system to creates a faster, safer and more reliable web.

Hashes play a big role in IPFS as they are used to address content in a distributed network, similar to how Git uses hashes to address commits, trees and binary objects inside a repository (yep, you probably use them on a daily basis, without noticing).

When a system relies on cryptographic hashes as fundamental building blocks, it’s pretty important to have an update strategy in mind in case the hash algorithms used are considered weak or insecure at some point. In this post I’d like to explore how the IPFS project takes advantage of “Multihashes” to ensure hashes are upgradable and can co-exist in the same application.

### What are hashes again?

Right, let’s get this out of our way quickly. A hash is actually less scary than it sounds. It is really just a function that takes some arbitrary input and returns a fixed-size alphanumeric string. What that alphanumeric string looks like depends on the given hash algorithm.

Let’s make up a simple hash function and say we have a message “abc” which is our input. Our custom hash function’s algorithm takes every character of the input message and moves it forward three letters in the alphabet. This will result in a hash digest “def”.

HASH('abc') // 'def'

There it is. A hash.

Now, if we look at some real world hash functions, they do exactly the same thing (just that the algorithm is more complex obviously). Git for example uses SHA-1, which produces a 160 bit hash, usually rendered as a hexadecimal number, 40 digits long. It hashes raw content (binary data), tree objects and commits.

If you have Git installed on your machine, try it yourself! Simply run the following command:

\$ echo "abc" | git hash-object --stdin

The returned digest is 8baef1b4abc478178b004d62031cf7fe6db6f903. And yes, a hash algorithm will always return the same hash for a given input. That’s how you can verify integrity when you receive data from a sender. However, it is impossible to derive the input from a hash. Super important characteristic.

To be accurate here, it turns out that Git doesn’t actually hash the raw input, but prepends the input with blob  followed by the size of the content before hashing. This isn’t important right now, but just in case you’re trying to verify the digest with e.g. OpenSSL’s SHA-1 implementation, you’ll notice it’ll return a different hash from ‘abc’.

Also, if you do want to dig deeper (like me), check out this StackOverflow answer.

The bottom line is:

• Hashes are the result of an algorithm transforming an input to a digest
• Algorithms return a fixed length (e.g. SHA1 returns 160 bit hashes)
• They always return the same hash value for a given input
• It is (or should be) impossible to derive the input from a hash

Okay, coming back to this “Multihashes” thing…

### The problem with hashes

Hashes are really great. Due to their characteristics, we can use them to verify the integrity of content and data, plus, they can be very compact as well. Unfortunately though, sometimes they turn out to be not secure or strong enough (I’m looking at you, MD5!), or attackers manage to break them. Not something that happens all the time, but it happened.

Imagine a simple, but common scenario in which user passwords are stored in some database. Obviously, we don’t want to store passwords in plain text, that’d be a disaster for many different reasons I don’t think I have to mention here. Perfect use case for hashes right? So let’s go ahead and assume we store those passwords as MD5 hashes. Wonderful, many problems solved with a simple fix.

Now let’s say, hypothetically, the next day, MD5 is considered insecure. What are are going to do? Well, we definitely have to upgrade our hash algorithm to something more secure. That turns out to be a challenge though, because we happen to deal with a large, maybe distributed, system and can only upgrade over time.

We need to find a way to slowly (but as fast as possible) upgrade to a different hash algorithm, while keeping the existing system in tact.

Another problem that shouldn’t get less attention, is that existing systems often rely on APIs that simply assume a certain type of hash and its length. Think about how many Git repositories are out there with every single object being a 160 bit hexadecimal hash (40 digits). Imagine what happens when Git switches to SHA-2, a 256 bit hash and how many tools and applications would break.

Turns out problems like those can be avoid by introducing a versioning system.

### Versioned hashes

The idea is quite simple: introduce some version as part of the hash so the system can easily figure out what hash it is dealing with.

Let’s take the ‘abc’ hash we calculated with Git earlier:

8baef1b4abc478178b004d62031cf7fe6db6f903

If this is a password hash and we’d have to verify whether it is the correct password or not, we’d just compare this computed hash with the one in our database. However, as mentioned earlier, we want to migrate to a different hash algorithm without breaking the system. The same input as SHA-256 for example, looks quite different:

BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD

In order to know up front that we’re in fact dealing with a different hash version, we ca introduce a version number like this:

1:BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD

This also works great for systems that already use unversioned hashes. Any hash without a colon must have been created before the version change. Any hash with a colon and version number can be handled in a respective way (stripping out the first two bytes (1:) and assume the hash is a SHA-256 hash in this case).

This solution can be scaled up and down in different ways depending on our needs. For example, if we’re in a scenario where we happen to deal with more than two hash types, we could introduce versions for each type like this:

sha1:0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae

In fact, this seems to be the way to go.

We can do better though. While the above is a decent way to approach this challenge, there are still some things can turn into problems:

• One obvious characteristic is that the version type might not be compatible with the rest of the hash type. For example s is not a valid hexadecimal digit. However, Most systems transfer hashes in hex (or base32, base64 etc). So there’s added complexity when building apps on top of those schemes.
• In case millions or billions of hashes have to be stored, long version types like blake2 might have a considerable impact in terms of byte costs. A shorter streamlined version syntax may be better here.

Okay, now it’s really time to dive into this Multihash thing.

### Multihashes

This is where Multihashes come into play. Multihash is a protocol (used by IPFS) for differentiating outputs from various well-established hash functions. It works very similar to what we’ve just done, just that it adds a little bit of extra information in a smart way.

A Multihash has the following pattern:

<hash-func-type><digest-length><digest-value>

Where

• the <hash-func-type> describes the hash function used - there’s a hash table to see how the codes are mapped
• the <digest-length> describes the length of the <digest-value> in bytes
• the <digest-value> is the actual hash value we’re interested in

Okay, let’s take the following Multihash as an example and try to demystify it

122041dd7b6443542e75701aa98a0c235951a28a0d851b11564d20022ab11d2589a8

Notice: In hexadecimal code, two digits are equal to one byte. In other words, the first two digits, 12, can be translated to 0001 0010. That’s why a 160 bit hash in hex code is a 40 digit number. Also, usually hex codes are prepended with 0x to indicate that it’s a hex code. In this case 0x12 and 12 are the same thing.

We’ve learned that the first byte identifies the hash function type. According to the Multihash table, that would be sha2-256 (take a look yourself, it’s in the seventh row).

Next up, the digest length (also in bytes). 0x20 is 32 in decimal, so at this point we already know the following hash value is 32 bytes (256 bits) long.

This is an important information to have. Remember the scenario where Git would switch from SHA-1 to SHA-256 ? Many apps and systems that work with Git hashes expect them to be 160 bit long. If Git used something like Multihash, apps could simply read out the length of the expected hash and keep it therefore variable.

Last but not least, the actual hash digest we’re dealing with 41dd7b6443542e75701aa98a0c235951a28a0d851b11564d20022ab11d2589a8.

We basically have a single hash that is completely self-describing and still addressable as it keeps the characteristics of any other cryptographic hash.

Using the Multihash protocol these days is very easy as well. There are implementations for several languages like Go, Java, Rust, JavaScript and more! If you want to learn about Multihashes and the IPFS protocol stack (yes, there’s so much more), here are some resources:


text:
# Math Help - Differentiating an integral

1. ## Differentiating an integral

d/dx( ∫ 3x to x^3 (t^3 + 1)^10 dt )

I am not sure how to do this, except I know that you are suppose to use chain rule

2. $h(x)=\int_{f(x)}^{g(x)}{\delta (t)\,dt}\implies h'(x)=\delta \left( g(x) \right)g'(x)-\delta \left( f(x) \right)f'(x).$

3. Makes sense, except I got to the part:

d/du( ∫ v to u (t^3 + 1)^10 dt )du/dx

but this doesnt make sense since my lower limit (v = 3x), isnt in terms of u

4. $\frac{d}{dx} \int^{x^{3}}_{3x} (t^{3}+1)^{10} \ dt = \frac{d}{dx} \Big( F(x^{3}) - F(3x) \Big)$ where F is an antiderivative of $(t^3+1)^{10}$

$= F'(x^{3}) \ \frac{d}{dx} (x^{3}) - F'(3x) \ \frac{d}{dx} (3x) = \Big((x^{3})^3+1\Big)^{10} * 3x^{2} - \Big((3x)^{3}+1\Big)^{10} *3$

$= 3x^{2} (x^9+1)^{10} - 3(27x^{3}+1)^{10}$

5. Thanks a lot. How would you do it in a form like this: d/du( ∫ v to u (t^3 + 1)^10 dt )du/dx, keeping the integral sign, and subbing in variables for the lower and upper limits?