Make anova table rmarkdown11/10/2023 ![]() ![]() We then add a + which tells ggplot to include the next line of code. To break down what we are doing, we need to call ggplot, tell it what data to use, and use the aes or aesthetic call to assign the x coordinate. We will use our first ggplot2call to create a graph showing the distribution of age. Thus we can look at age, but we will not use it as a factor in our ANOVA. We also have age, but importantly it is recorded as a discrete number instead of as a factor (eg as 85 years, instead of old). Namely, we have our 3 categorical/factor variables: sex, health_status, and drug_treatment and 1 dependent variable (DV): mmse. We can collect some information about the dataset now. $ drug_treatment "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", … $ health_status "Healthy", "Healthy", "Healthy", "Healthy", "Healthy", … By using the glimpse function from dplyr we can see how the variables were imported, as well as the first few rows. Alternatively, you could convert your Excel sheet into. As such we must either load readxl like any other package or call both the package and the name as in readxl::read_xlsx. Readxl is unfortunately a funny case, as installing the tidyverse installs readxl, but readxl is not loaded when loading the tidyverse via a library call. As such, we can clarify from which package we want R to call our function from, so package::function ! To read more about the concept of “namespace” when calling functions, please look here. ![]() The concept of calling a function with the use of :: is important as some packages have conflicts in functions, for example multiple packages include the function select and summarize. While I am calling readxl::read_xlsx you could also simply use read_xlsx, but in the interest of transparency, I will be using the full call to begin. This will output some message about the packages being loaded and any conflicts of function calls. # Load libraries library ( tidyverse ) library ( broom ) library ( knitr ) library ( readxl ) Lastly we will load knitr for making nice html tables via knitr::kable, but not necessary for simply saving the outputs to Excel. ![]() This package includes ggplot2 (graphs), dplyr/ tidyr (summary statistics, data manipulation), and readxl (reading excel files) as well as the pipe %>%which will make our code much more readable! We will also load the broom package to tidy up some of our statistical outputs. If you have never installed it before you can also use the install.packages("tidyverse") call to install it for the first time. Using the library function we will load the tidyverse. You could think of it like being able to write R code inside a basic Word document (but it can do a lot more than that!).Īlthough you may not be interested in the dataset I have provided, this hopefully provides a clear workflow for you to swap in your data of interest and accomplish a basic analysis! Load the tidyverse, broom, and knitr R Markdown is a document created inside R that allows you to write code, execute it inline, and write comments/notes as you go. If you would rather see the entire workflow in an R-Markdown document, please see here. You can simply copy-paste the code seen here and it will run in R. I will use knitr::kable to generate some html tables for a markdown document, but it is not necessary for the workflow.Īdditionally, I will be uploading the Excel Sheet used in this example, so that you can re-create the workflow on your own. While other stats-heavy packages provide additional statistical testing, base R has a decent ability to perform statistical analyses out of the box. These two packages dramatically improve the data analysis workflow in my opinion. We will limit dependence to two packages: tidyverse and broomwhile using base R for the rest. We will be working through loading, plotting, analyzing, and saving the outputs of our analysis through the tidyverse, an “opinionated collection of R packages” designed for data analysis. Source: Folstein et al, 1975, J Psychiatr Res 12:189–198 ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |