 I'm going to be talking about how to do basic power analysis functions in R. So R can be extremely useful for running power analysis. It has the potential to do power analyses of many different types on many different types of statistical tests. One of the issues though is that these many different power calculation functions are distributed across many different R packages. There isn't really one package that will do all the different types of power analyses that are as capable of doing. However, there is one package that can be a good place to start for most of your basic functions. This is a package called power, and it'll do power analyses for things like t-tests, one-way novas, regressions, proportions, and correlations. So it has kind of all your basic statistical tests done. Documentation for the package can be found here. I'll also include a copy of the PDF along with these PowerPoint slides in an OSF project related to this, and I'll put a link at the end of the video to show you where you can find that. So the power package has many different functions in it, but all the functions share a couple of similar inputs. They'll all ask for the sample size and effect size. The exact type of effect size will depend upon the test that you're running. A significance level, also known as the alpha level that you want to test against, and the percent power that you want your test to attain. Most tests will also ask for something called an alternative, and this is really where you input whether you're going to be doing a one-tailed or a two-tailed test. So now I'm actually going to show you how to run some of these in R. So here's my RStudio window, and the first thing I have to do is install the package if I don't already have it installed. So I'll write install.packages, and it's called power, spelled P-W-R. I then have to load the package into R using the library command. I already have the package installed, so I'm not going to run this command, but I'll run this till loaded in, and I can now start writing my functions. So the first one I'll show is the power function for a t-test. So that's power.t.test, and as I mentioned, there are a couple of different inputs. There's going to be an input for the number of subjects. This is a t-test, so it's going to want to coincide for the effect size. It'll want a significance level, and it'll want a power level. As I mentioned, it'll also want what my alternative test is, which in this case is going to be two-sided. And it will also want to know the type of t-test that I'm running. So this function is valid for paired sample, one sample, and two sample t-tests. So I'm going to run a two-sample t-test. Now you'll notice I left these four inputs blank, and there's a reason for that. The reason is that this function, I have to specify what three of these are, and it will solve for the last one that I haven't put an input for. And that's because there are different types of power analyses I could run. The traditional power analysis that most people think of is where you input an effect size, a significance level, and the amount of power you want your study to have, and then you ask for the program to solve for the number of samples you're going to need. But that's not the only thing you can do. So I'll go ahead and start with that. So I want the number of samples, so I'm going to put null there, and then I'm going to fill in the other. So I'll have a medium effect size, which is a d of 0.5, a significance level of 0.05, and then I'll set power to 80%. And so now if I run this, you can see it outputs the number of people I need in each group. And it tells me that I need 63.7, so 64 people per group for a total of 128. Now as I mentioned, I could ask it for something else. So I can copy this code, and instead of asking for the n, let's say I know because of my grant that I can only run 100 people. But I think my effect size is going to be 0.5. So what I want to know is how much power will my study have to detect a effect size of 0.5 if I run 100 people. Now, I put in 100, really I should have put in 50 because this n is not the total n, it's the n per group. So I'm going to change this to 50, and I'll run this. And so it's telling me now that I would have 69.7% power. So I would have around about 70% power for this particular study. So I can also run something else. So I could run this exact same thing. But rather than having a two-sided test, maybe I want a one-sided test. So in R, there are two possibilities. There's a greater than or a less than. So you have to tell it the directionality of the test you want. Since my effect size is positive, I'm going to put greater. And this means that what I'm testing is whether my effect size is greater than 0. So if I run this, it's telling me now that to run a one-sided test, I would only need 50 people in each group. So just to show you that you'll get an error, if you write less, I can run this again. And you're going to get an error because the equation won't work. So if I just switch this to a negative sign, I should get the exact same number of people. It's just going in the different direction. And as you can see, I'm getting that same N of approximately 50 people per group. So I mentioned that all the materials for this video are posted online. They're posted at this OSF project, which will house all the online materials for all the different sets of videos we're going to do, as well as some how-tos and examples. So if you go to the index, you can see all the different materials we currently have uploaded. And for any particular one, if you click on it, the hyperlink will take you to the materials for that particular video. So here's this particular project, and there's the CRAN package, the PDFs of the PowerPoint slides, as well as the R code that will be fully annotated. So you can always go back and look at it. So hopefully this has been useful for you. If you have any questions about anything that we went over in the video, feel free to email us at stats-consulting at sos.io, and we'd be happy to answer any of your questions. You can also email us at contact at sos.io with questions, comments, or feedback, if you have any. Thanks.