RStudio Cloud shinyapps. RStudio Open source and enterprise-ready professional software for data science. Learn More. An integrated development environment for R, with a console, syntax-highlighting editor that supports direct code execution, and tools for plotting, history, debugging and workspace management. Publish and distribute data products across your organization. Control, organize, and govern your use of R packages to increase reproducibility and decrease the time you spend installing and troubleshooting. Learn more about RStudio Team. Latest News.

## Statistics and R

A few of our professional fans. Read our Customers' Stories. In the table below we show a few examples of such calculations where the first column gives a mathematical expression calculation , the second gives the equivalent of this expression in R and finally in the third column we can find the result that is output from R.

Probability distributions can be uniquely characterized by different functions such as, for example, their density or distribution functions. Based on these it is possible to compute theoretical quantiles and also randomly sample observations from them.

Replacing the R syntax for a given probability distribution with the general syntax name , all these functions and calculations are made available in R through the built-in functions:. Note that, when using these functions in practice, name is replaced with the syntax used in R to denote a specific probability distribution.

For example, if we wish to deal with a Uniform probability distribution, then the syntax name is replaced by unif and, furthering the example, to randomly generate observations from a uniform distribution the function to use will be therefore runif. R allows to make use of these functions for a wide variety of probability distributions that include, but are not limited to: Gaussian or Normal , Binomial, Chi-square, Exponential, F-distribution, Geometric, Poisson, Student-t and Uniform.

In order to get an idea of how these functions can be used, below is an example of a problem that can be solved using them. Assume that the test scores of a college entrance exam follows a Normal distribution. Furthermore, suppose that the mean test score is 70 and that the standard deviation is How would we find the percentage of students scoring 90 or more in this exam? To find this probability we need the distribution function pname for which we therefore replace name with the R syntax for the Normal distribution: norm.

The distribution function in R has various parameters to be specified in order to compute a probability which, at least for the Normal distribution, can be found by typing? Knowing these arguments, it is now possible to compute the probability we are interested in as follows:.

While the previous functions deal with theoretical distributions, it is also necessary to deal with real data from which we would like to extract information. The use of certain functions varies according to the nature of the inputs since these can be, for example, numerical or factors. A first step in analysing numerical inputs is given by computing summary statistics of the data which, in this section, we can generally denote as x we will discuss the structure of this data more in detail in the following chapters.

For central tendency or spread statistics of a numerical input, we can use the following R built-in functions:.

### An R Introduction to Statistics

If the data of interest is a factor with different categories or levels, then different summaries are more appropriate. For example, for a factor input we can extract counts and percentages to summarize the variable by using table. Using functions and data structures that will be described in the following chapters, below we create an example dataset with 90 observations of three different colors: 20 being Yellow , 10 being Green and 50 being Blue. We then apply the table function to it:. In many cases, when dealing with data we are actually dealing with datasets see Chapter 03 where variables of different nature are aligned together usually in columns.

For datasets there is another convenient way to get simple summary statistics which consists in applying the function summary to the dataset itself instead of simply a numerical input as seen earlier. As an example, let us explore the Iris flower dataset contained in the R built-in datasets package. The data set consists of 50 samples from each of three species of Iris Setosa, Virginica and Versicolor.

Four features were measured from each sample consisting in the length and the width in centimeters of the both sepals and petals. This dataset is widely used as an example since it was used by Fisher to develop a linear discriminant model based on which he intended to distinguish the three species from each other using combinations of these four features.

## R (programming language)

Using this dataset, let us use the summary function on it to output the minimum, first quartile and thrid quartile, median, mean and maximum statistics for the numerical variables in the dataset and frequency counts for factor inputs. This is not the first or the last book that has been written explaining and describing statistical programming in R. Indeed, this can be seen as a book that brings together and reorganizes information and material from other sources structuring and tailoring it to a course in basic statistical programming.

The main references which are far from being an exhaustive review of literature that can be used to have a more in-depth view of different aspects treated in this book are:. Wickham, Hadley. Advanced R. CRC Press. R Packages. Xie, Yihui. Dynamic Documents with R and Knitr. Statistical Programming Methods 1 Introduction 1. What is reproducible research? Defining the R Code in the backend of the Shiny app 7. This document is under development and it is therefore preferable to always access the text online to be sure you are using the most up-to-date version.

Due to its current development, you may encounter errors ranging from broken code to typos or poorly explained topics. If you do, please let us know! In addition, once you have learned RMarkdown and GitHub, feel free to make a pull request to offer bug fixes or corrections!

• Kill Switch (A Claire Waters Thriller);
• Nuns Without Cloister: Sisters of St. Joseph in the Seventeenth and Eighteenth Centuries;
• Live and Let Live?

Below is short video demonstrating a basic introduction of RStudio and some of its elements. This is a note that could be interesting or useful to the reader. This is a caution to help the reader avoid minor problems. This is a warning to help the reader avoid significant problems. For example, if you are interested in learning about the function log you could simply type:? You can often use the error message to search for answers about a problem you may have with a function. For example, if you want to install the package devtools you can simply write: install.

Please notice that although packages need to be loaded at each session if you want to use them, they need to be installed only once. The only exception to this rule is when you need to update the package or reinstall it for some reason.