## Learning Outcomes

By the end of this session, students will be able to:

- Continue practicing basic software commands
- Learn how to explore the dataset, identifying the different types of variable stored
- Calculate the different measures of location and spread
- Plot frequency distributions and histograms

You can download a copy of the slides here: A2.1 Key Concepts

**Video A2.1 Introduction to Power and Sample Size Calculation (11 minutes)**

## A2.1 PRACTICAL: R

**The power package**

We can estimate sample size and power using the R package â€˜pwrâ€™. First you need to install the package and load the library:

install.packages(“pwr”)

library(“pwr”)

Once this package is installed, we can start calculating our needed sample size to test hypotheses or we can estimate the amount of power a study had to detect a difference is one existed. The next sections will show you how to do this.

**Look at the help file for the function pwr.t.test. What is the default value for significance level? **

**What information do you need to conduct a sample size estimate for difference between means? **

**Answer**

The default value for significance level (denoted as ‘*sig.level*‘) in the function is 0.05. This is indicated by sig.level=0.05, and can be changed by specifying a different number in the function. So you can work out the sample size you would need for different significance levels.

To conduct a sample size estimate between means you need the power and alpha values you have decided on, the estimated mean of each group in the population, or the estimated difference between groups in the population, and the estimated population standard deviation.

## A2.1 PRACTICAL: Stata

**The **power **command**

Calculations for power and sample size in Stata can be performed using the power command. If you look at the help file, you will see that you can use this command to compute a sample size, the power or an effect size. You do not need to have a data set loaded.

Look at the setup of the power command:

power method …, n(numlist) [power_options …]

You need to choose the method you are calculating a power estimate for. To do this, ask yourself the following questions: do you have 1 sample, 2 independent samples or 2 paired samples? Additionally, do you want to compare means from continuous outcomes or proportions from binary/categorical outcomes? The practical today will explore the powerÂ command and the one on Session 28 will familiarise you with some of the other options of this command.

__Question A2.1:__**What are Stata’s default values for power and significance level in the power command? Can you see how to change them?**

**Answer**

The default is for 80% power and a 5% significance level (denoted as â€˜*alpha*â€™). You can change these using the options power() and alpha().

## A2.1 PRACTICAL: SPSS

Calculations for power and sample size in SPSS are performed using the ‘Power Analysis’ option under the ‘Analyze’ menu.

Take some time to have a look through the different test types which you can estimate power and sample size for.

You need to choose the method you are calculating a power estimate for. To do this, ask yourself the following questions: do you have 1 sample, 2 independent samples or 2 paired samples? Additionally, do you want to compare means from continuous outcomes or proportions from binary/categorical outcomes?

Take some time to open some of the power analysis tests in SPSS and have a look through them.

**What is the default value for significance level?Â **

**What information do you need to conduct a sample size estimate for difference between means?Â **

**Answer**

The default value for significance level (denoted as ‘*alpha*‘) in SPSS is 0.05. This is easily changed in the Power Analysis window once you have selected your test type. So you can work out the sample size you would need for different alpha values.

To conduct a sample size estimate between means you need the power and alpha values you have decided on, the estimated mean of each group in the population, or the estimated difference between groups in the population, and the estimated population standard deviation.