• Complain

Baron Jonathan - Behavioral Research Data Analysis with R

Here you can read online Baron Jonathan - Behavioral Research Data Analysis with R full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. City: London;New York, year: 2012, publisher: Springer, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Baron Jonathan Behavioral Research Data Analysis with R

Behavioral Research Data Analysis with R: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Behavioral Research Data Analysis with R" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Baron Jonathan: author's other books


Who wrote Behavioral Research Data Analysis with R? Find out the surname, the name of the author of the book and a list of all author's works by series.

Behavioral Research Data Analysis with R — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Behavioral Research Data Analysis with R" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Yuelin Li and Jonathan Baron Use R! Behavioral Research Data Analysis with R 10.1007/978-1-4614-1238-0_1 Springer Science+Business Media, LLC 2012
1. Introduction
Yuelin Li 1
(1)
Department of Psychiatry and Behavioral Sciences, Memorial Sloan-Kettering Cancer Center, 641 Lexington Ave. 7th Floor, New York, New York 10022-4503, USA
(2)
Department of Psychology, University of Pennsylvania, 3720 Walnut Street, Philadelphia, Pennsylvania 19104-6241, USA
Yuelin Li (Corresponding author)
Email:
Jonathan Baron
Email:
Abstract
R is more like a computer programming language than a typical statistical computer package. Some of R s features such as data frames are already familiar to behavioral scientists who are used to other statistical packages. Some other features like vectors, matrices, lists, and functions may first appear technical and strange. These features can help a behavioral scientist improve the efficiency and clarity of data analysis. But they also require a different thinking in data analysis. This chapter is an introduction to some of these advantages of using R , including the basic concepts in vectors, matrices, lists, and functions, how to quickly carry out simple statistical calculations, and how to define data types in a data frame. Some examples in this chapter will be revisited later in this book with more details.
1.1 An Example R Session
Here is a simple R session.
> help(sleep)
> x1 <- sleep$extra[sleep$group == 1]
> x2 <- sleep$extra[sleep$group == 2]
> t.test(x1, x2)
> sleep[c(1:3, 11:13), ]
> with(sleep, t.test(extra[group == 1],
+ extra[group == 2]))
> q()
The help() command prints documentation for the requested topic. The sleep dataset is a built-in dataset in R. It comes from William Sealey Gossets article under the pseudonym Student (1908). It contains the effects of two drugs, measured as the extra hours of sleep as compared to controls. The vectors x1 and x2 are assigned the values of the extra hours of sleep in drugs 1 and 2, respectively. (a less than sign followed by a minus sign, <- , represents assignment) Two equal signs, == , represent the logical equal operator. The t.test(x1, x2) carries out an independent sample t -test of the sleep time between the two groups. The same analysis can be done using with(sleep, t.test(extra[group == 1], extra[group == 2])) . sleep[c(1:3, 11:13), ] prints observations 1 through 3 and 11 through 13. To exit the R program, type q() . Typing q without the parentheses prints out the contents of the function to quit R. Most functions are visible to the user in this way. The advantage of using built-in datasets is that they have already been imported. The next example describes how to import data from a text file.
The sleep data can be entered into a text file, the variable names on the first row, and the variables are separated by spaces.
extra group ID
0.7 1 1
-1.6 1 2
-0.2 1 3
-1.2 1 4
-0.1 1 5
3.4 1 6
3.7 1 7
0.8 1 8
0.0 1 9
2.0 1 10
1.9 2 1
0.8 2 2
1.1 2 3
0.1 2 4
-0.1 2 5
4.4 2 6
5.5 2 7
1.6 2 8
4.6 2 9
3.4 2 10
Suppose the data entries are saved in a file named t1.dat in the directory C:\\Documents and Settings\\usr1\\My Documents , then this command imports the data and assigns it a name called sleep.df .
> sleep.df <- data.frame(read.table(file =
+"C:/Documents and Settings/usr1/My Documents/t1.dat",
+header = TRUE))
On a Windows platform, the double back slashes () in a path name can be replaced with one forward slash ( / ). On Unix/Linux and Mac OS, one forward slash works fine. The read.table() function reads the data in file . It uses the first line of the raw data file ( header = TRUE ) to assign variable names to the three columns. Blank spaces in the raw data file are ignored. The data.frame() function converts the imported data into a data frame. The sleep.df data is now available for analysis (type objects() to see it). The example above shows some of the unique features of R. Most data analytic tasks in R are done through functions, and functions have parameters such as the options of file and header in the read.table() function. Functions can be nested, the output of one function can be fed directly into another. Some other basic R features are covered in the next section. These features make R flexible but more challenging to learn for beginners.
Some things are more difficult with Respecially if you are used to using menus. With R, it helps to have a list of commands in front of you. There are lists in the on-line help and in the index of An introduction to R by the R Core Development Team, and in the reference cards listed in http://finzi.psych.upenn.edu/ .
Some things turn out to be easier in R. Although there are no menus, the on-line help files are very easy to use, and quite complete. The elegance of the language helps too, particularly those tasks involving the manipulation of data. The purpose of this book is to reduce the difficulty of the things that are more difficult at first. Next we will go over a few basic concepts in R. The remainder of this chapter covers a few examples on how to take advantage of Rs strengths.
1.2 A Few Useful Concepts and Commands
1.2.1 Concepts
In R, most commands are functions. The command is written as the name of the function, followed by parentheses, with the arguments (inputs) of the function in parentheses, separated by commas when there is more than one, e.g., plot(swiss) to plot a pairwise scatterplot of the swiss data. When there is no argument, the parentheses are still needed, e.g., q() to exit the program. A function is said to return its output when the output is printed or when we can set a variable equal to the output. For example, sqrt(4) returns (prints) 2 on the screen; and if we say v1 <- sqrt(4) , v1 is set equal to the output of the function, or 2.
Some basic concepts in R are surprising to beginners. For example, the square of Picture 1 is not 7.
> 7 == sqrt(7)^2
[1] FALSE
That is because floating point arithmetic is not exact.
> options(digits = 22)
> sqrt(7)^2
[1] 7.000000000000000888178
A solution is to compare all.equal(sqrt(7)^2, 7) .
In this book, we generally use names such as x1 or file1 , that is, names containing both letters and a digit, to indicate variable names that the user makes up. Really, these can be of any form. We use the number simply to clarify the distinction between a made up name and a key word with a predetermined meaning in R. R is case sensitive; for example, X and x can stand for different things. We generally use upper-case data objects like X , Y , and M to represent matrices or arrays; and lower-case objects to represent vectors. Although most commands are functions with the arguments in parentheses, some arguments require specification of a key word with an equal sign and a value for that key word, such as source("myfile1.R", echo = T) , which means read in myfile1.R and echo the commands on the screen. It helps to add spaces between input parameters, so that the extra spaces in echo = T make it easier to read than echo=T . But that is not necessary. Key words can be abbreviated (e.g., e = T ). In addition to the idea of a function, R has objects and modes. Objects are anything that you can give a name. There are many different classes of objects. The main classes of interest here are vector , matrix , factor , list , and data frame . The mode of an object tells what kind of things are in it. The main modes of interest here are logical , numeric , and character .
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Behavioral Research Data Analysis with R»

Look at similar books to Behavioral Research Data Analysis with R. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Behavioral Research Data Analysis with R»

Discussion, reviews of the book Behavioral Research Data Analysis with R and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.