# Statistical modelling

I am pretty new to R. I have 2 general questions when it comes to modeling.

1. What statistical model would be best to test whether there is a difference in weight between male and female (sexual dimorphism)
2. What would be the best way to validate this?
• Hi Joanne. Stack Overflow is specifically for programming questions. Even if you intend to run the analysis in R, this is a statistical question, so is off topic here. There is a Stack Exchange site called CrossValidated where you will get better answers to statistical questions than you will here. I have therefore voted to migrate your question over there. For what it's worth, you're probably looking for t.test(male_weights, female_weights, paired = FALSE) if you have two separate variables. Nov 25, 2020 at 19:08
• The way to test whether there is a difference is to carry out a t-test. Nov 25, 2020 at 22:33

Ideally, you should have data from about 100 men and 100 women chosen at random from whatever population interests you. US? UK? EU? China? Or certain ethnic groups within countries?

Then you can do a two-sample t test to see if sample means differ "significantly" (implying that population means actually do differ). Or you can find a 95% confidence interval for the difference between weights of men and women in the target population. These procedures assume that weights are roughly normally distributed.

Model. If you know population means and standard deviations for men and women, and assume weights are normally distributed, you can use statistical software to provide simulated samples to use as examples for testing and making confidence intervals.

For example, suppose US men have weights distributed as $$\mathsf{Norm}(\mu = 190, \sigma=50)$$ and women $$\mathsf{Norm}(\mu= 170, \sigma = 50).$$ These are approximate values for the US in pounds (lbs.) from an internet site. These are not authoritative numbers, but they may be good enough for an illustration.

Below are graphs of corresponding normal density curves for women (red) and men.

curve(dnorm(x, 170, 50), 0,400, lwd=2, col="red", ylab="Density",
xlab="Weight (lbs.)", main = "Hypothetical Normal Weight Distributions")
curve(dnorm(x, 190, 50), add=T, lwd=2, col="blue")
abline(h=0, col="green2")


Simulated data and data description. Here is an illustration using R statistical software, for a sample of $$n_m = 100$$ men and $$n_w = 100$$ women.

set.seed(2020)  # for reproducibility of results
m = rnorm(100, 190, 50)          # random sample of 100 men
w = rnorm(100, 170, 50)          # random sample of 100 women

summary(m);  length(m);  sd(m)
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
38.06  161.90  196.00  195.44  226.97  350.08
[1] 100       # sample size
[1] 55.96459  # sample standard deviation

summary(w);  length(w);  sd(w)
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
17.17  119.77  167.14  164.22  204.14  303.11
[1] 100
[1] 56.67422


One way to display data is to use a stripchait. It has tick marks that show exact values of the 200 simulated weights--100 men at the bottom and 100 women at the top.) It seems to show that men tend to weigh more than women.

stripchart(list(m,w), ylim=c(.5, 2.5), pch="|")


• For men, notice that the sample mean $$\bar M = 195$$ is not far from the population mean $$\mu_M = 190$$ and the sample standard deviation $$S_M= 56$$ is not far from the population standard deviation $$\sigma_M = 50.$$

• Also, for women, the sample mean $$\bar W = 164$$ is not far from the population mean $$\mu_W = 170$$ and the sample standard deviation $$S_W = 57$$ is not far from the population standard deviation $$\sigma_W = 50.$$

These sample 'estimates' are certainly not perfect, but they are reasonably good for samples of only 100 randomly chosen people from large populations.

Here are histograms of the heights of the two groups:

par(mfrow=c(2,1))
hist(m, prob=T, col="skyblue2", xlim=c(0,400))
hist(w, prob=T, col="skyblue2", xlim=c(0,400))
par(mfrow=c(2,1))


Test and confidence interval for simulated data. Because the population standard deviations are equal, we can use a 'pooled' t test to check to see if the samples of 100 are good enough to show a convincing difference between weights of men and women. [For the test we need an estimate of the common population standard deviation $$\sigma_m = \sigma_W = 50.$$ We 'pool' variance information from both samples to get the variance estimate for the test.]

In R, the procedure t.test tests the null hypothesis that men and women have equal weights against the alternative that weights differ. It also provides a 95% confidence interval for the difference in weights. [The parameter var.eq=T selects the pooled test.]

t.test(m, w, var.eq=T)

Two Sample t-test

data:  m and w
t = 3.9206, df = 198, p-value = 0.0001217
alternative hypothesis:
true difference in means is not equal to 0
95 percent confidence interval:
15.52010 46.93404
sample estimates:
mean of x mean of y
195.4446  164.2175


The P-value is below $$0.05 = 5\%,$$ so we can reject the null hypothesis at the 5% level. (Actually, in this particular test, we can also reject at the 1% level of significance and even more stringent levels.)

The P-value is the probability of getting two such different samples if there were no real difference between population mean weights of men and women. Because the probability is so small we prefer to believe that the null hypothesis is false.

Also the 95% confidence interval says that difference if population mean weights is likely to be in the interval $$(15.52, 46.93).$$ Notice that the interval does not contain $$0,$$ another indication that there is a difference in height between men and women.

Because our data came from a known model, we know that the true difference is $$\mu_m - \mu_w = 190-170 = 20.$$ The confidence interval contains $$20,$$ as it should (95% of the time).

Designing a study. Above I mentioned it might be a good idea to have 100 men and 100 women for good results. There are 'power and sample size' procedures that help you know how much data you need. If I want to be 80% sure to detect a difference of 20 lbs. between population weights of men and women, I know that the standard deviations of weights in the two population are $$\sigma = 50,$$ and I will test at the 5% level of significance, then I can put this information into such a procedure in order to know what sample sizes to use. The answer from a recent release of Minitab statistical software is 100. If I want to be 90% sure to detect such a difference, then it would be best to use 133.

Power and Sample Size

2-Sample t Test

Testing mean 1 = mean 2 (versus ≠)
Calculating power for mean 1 = mean 2 + difference
α = 0.05  Assumed standard deviation = 50

Sample  Target
Difference    Size   Power  Actual Power
20     100     0.8      0.803648
20     133     0.9      0.901483

The sample size is for each group.