Probability with R. Jane M. Horgan

Чтение книги онлайн.

Читать онлайн книгу Probability with R - Jane M. Horgan страница 17

Probability with R - Jane M. Horgan

Скачать книгу

a file containing the commands may be saved and loaded by clicking on Save History or Load History, and specifying its location. The commands are stored in a file with
attachment.

      A key feature of R it that it is a library of packages as much as it is a programming language. Packages are a collection of stored functions, data, and code that can be loaded for specific needs. The base installation of R contains a set of packages, which are sufficient for most users' needs. To see what packages are available with the base installation, type

      search()

      which gives

      [1] ".GlobalEnv" "package:stats" "package:graphics" [4] "package:grDevices" "package:utils" "package:datasets" [7] "package:methods" "Autoloads" "package:base"

      library(help = "stats")

      you will get a list of statistical procedures available in the “stats”package.

      By clicking on packages on the toolbar, you will be given a list of available packages. If you want to install a specific package, “Matrix” say, just click on “Matrix.”Alternatively, write

      install.packages("Matrix")

      in the command window.

      library(help = "Matrix")

      tells us what procedures are in the package “Matrix.”

      installed.packages()

      details all installed packages.

      Currently, there are thousands of packages available. It is unlikely that you will need any of these at this stage of your learning, as the packages available in the base package are usually adequate for the general users' needs.

      Over the last decade, many attempts have been made to develop interfaces for R to make it more user‐friendly. Some interfaces are enhanced code editors that interact with R in order to make it easier to use; RStudio and R tools for Visual Studio are two such examples, both of which provide an integrated development environment (IDE) for working with R.

      There are also full‐blown GUI such as R Commander (Rcmdr), Rattle and RKWard, all of which contain menus and dialog boxes with a point‐and‐click approach.

      We will look at two of the most popular of these interfaces, RStudio, and R Commander.

      1.12.1 RStudio

      RStudio is the most well known of the code editors currently available to interface with R. Written in C++, Version 1 was released in 2016, and since then many updates and revisions have been made. Like R, it is open source, and, after you have installed R, it can be downloaded from the RStudio website at http://www.rstudio.org by proceeding as follows:

       Click “Download RStudio”;

       Choose the Desktop version;

       Select the setup program suitable to your operating system;

       Press the option “Run”.

      RStudio is now installed, and you should see an icon on your screen. Clicking on this will start up and launch the RStudio interface. A screen divided into four windows will appear, each window representing a set of integrated tools designed to help you to be more productive in R.

       The top left quadrant is the Editor Window.

       The lower left quadrant is the Command Window where you write and execute commands after the prompt “>” similar to what you do in the main R. This is where you will first work, and when it is correct, copy it into the Editor Window.

       The top right quadrant is the Workspace and History Window. This keeps a record of the commands you have used.

       The lower right quadrant is referred to as the File/Plots/Packages Window. Here, you can open files, view plots and load packages. This window also contains the help function.

      To see for yourselves, click on the RStudio icon. Similar to R, RStudio can be run on a desktop using Windows, (Mac) OS X, and Linux or in a browser connected to RStudio.

      1.12.2 R Commander

      Of the GUI available, R Commander, also known as Rcmdr, is the most popular with a point‐and‐click interface to many statistical tasks. It is called “commander” because every time you make a selection from the menu, the R commands corresponding to the task is listed in the output window. You can save this code to be used again. Rcmdr is obtained by going into R, clicking on packages on the tool bar, and downloading Rcmdr.

      Exercises 1.1

      1 In a class of 50 students of computing, 23 are female and 27 are male. The results of their first‐year Java programming examination are given as follows:Females:57, 59, 78, 79, 60, 65, 68, 71, 75, 48, 51, 55, 56, 41, 43,44, 75, 78, 80, 81, 83, 83, 85Males:48, 49, 49, 30, 30, 31, 32, 35, 37, 41, 86, 42, 51, 53, 56,42, 44, 50, 51, 65, 67, 51, 56, 58, 64, 64, 75Read these data into R by storing them in the following ways:As two vectors, one for the females and one for the males;As one vector, with a factor vector designating the gender.If it was discovered that the mark for the 34th student was entered incorrectly and should have been 46 instead of 86, use an appropriate editing procedure to change this.Save the workspace in a file in a suitable directory for access later.

      Download RStudio and familiarize yourself with its workings, by using it to do Exercise 1. Decide, at this point, whether you prefer using RStudio for your data analysis rather than using R directly. Follow your preference throughout the rest of the book. It is up to you!

      1 Venables, W.N., Smith, D.M. and the R Core Team (2018), An Introduction to R, Notes on R: A Programming Environment for Data Analysis and Graphics, Version 3.6.1 (2019-07-05).

      Measures of central tendency are typical or central points in the data. The most

Скачать книгу