R basics Assignments, numbers, vectors Assign number 5 to variable - - PowerPoint PPT Presentation

r basics assignments numbers vectors
SMART_READER_LITE
LIVE PREVIEW

R basics Assignments, numbers, vectors Assign number 5 to variable - - PowerPoint PPT Presentation

R basics Assignments, numbers, vectors Assign number 5 to variable x > x <- 5 > x [1] 5 Calculate 5*x 2 +7 > 5*x^2+7 [1] 132 Create vector, assign > y <- c(1, 2, 3, 4, 5) to variable y > y [1] 1 2 3 4 5 Multiply


slide-1
SLIDE 1

R basics

slide-2
SLIDE 2

Assignments, numbers, vectors

> x <- 5 > x [1] 5 Assign number 5 to variable x > y <- c(1, 2, 3, 4, 5) > y [1] 1 2 3 4 5 Create vector, assign to variable y Calculate 5*x2+7 > 5*x^2+7 [1] 132 Multiply each element in y with the number in x > x*y [1] 5 10 15 20 25

slide-3
SLIDE 3

Strings

> name <- "Claus Wilke" > name [1] "Claus Wilke" A string contains text: A vector of strings: > animals <- c("cat", "mouse", "mouse", "cat", "rabbit") > animals [1] "cat" "mouse" "mouse" "cat" "rabbit"

slide-4
SLIDE 4

Factors

Factors keep track of distinct categories (levels) in a vector: > animals [1] "cat" "mouse" "mouse" "cat" "rabbit” > factor(animals) [1] cat mouse mouse cat rabbit Levels: cat mouse rabbit

slide-5
SLIDE 5

Data frames

> pets <- data.frame( family = c(1, 2, 3, 4, 5), pet = animals ) We use data frames to store data sets with multiple variables: > pets family pet 1 1 cat 2 2 mouse 3 3 mouse 4 4 cat

slide-6
SLIDE 6

Data frames

> pets$family [1] 1 2 3 4 5 We access individual columns in a data frame with $ + the column name: > pets$pet [1] cat mouse mouse cat rabbit Levels: cat mouse rabbit

slide-7
SLIDE 7

Data frames

> cars speed dist 1 4 2 2 4 10 3 7 4 4 7 22 5 8 16 6 9 10 7 10 18 8 10 26 9 10 34 10 11 17 R has many built-in data frames:

slide-8
SLIDE 8

Data frames

> head(cars) speed dist 1 4 2 2 4 10 3 7 4 4 7 22 5 8 16 6 9 10 > The head() function shows the first few lines of a data frame:

slide-9
SLIDE 9

Hypothesis testing: a quick review

slide-10
SLIDE 10

H0 and HA: Null and alternative hypothesis

H0: Null hypothesis, assumption that the data show no signal, that nothing has happened. HA: Alternative hypothesis, opposite of H0, assumption that something has happened.

slide-11
SLIDE 11

The P value tells us how unexpected the data are

P value: Probability to observe the given data under the assumption that H0 is true We generally reject H0 if P < 0.05 We never accept HA

slide-12
SLIDE 12

t test: Do two groups of numerical measurements have the same mean?

slide-13
SLIDE 13

Correlation: Do two numerical variables have a relationship with each other?

slide-14
SLIDE 14

Multivariate regression:Which predictors have an effect on the response variable?

Example: