MoDS MA5820 Intro to R online session

# ggplot(iris,aes(x=Petal.Length,y=Sepal.Length)) +geom_point()

data(iris)
P<-iris$Petal.Length
S<-iris$Sepal.Length

# Sepal,Petal
plot(S,P)
lm(S~P)
## 
## Call:
## lm(formula = S ~ P)
## 
## Coefficients:
## (Intercept)            P  
##      4.3066       0.4089
abline(4.3066,0.4089)

# doesn't align the plots

# Petal,Sepal
plot(P,S)
lm(P~S)
## 
## Call:
## lm(formula = P ~ S)
## 
## Coefficients:
## (Intercept)            S  
##      -7.101        1.858
abline(-7.101,1.858)

# Doesn't align the plots

# Sepal~Petal  NOTE the tilde in the plot() function
plot(S~P)
lm(S~P)
## 
## Call:
## lm(formula = S ~ P)
## 
## Coefficients:
## (Intercept)            P  
##      4.3066       0.4089
abline(4.3066,0.4089)

# aligns the plots

# Sepal,Petal
plot(S,P)
lm(P~S)
## 
## Call:
## lm(formula = P ~ S)
## 
## Coefficients:
## (Intercept)            S  
##      -7.101        1.858
abline(-7.101,1.858)

# aligns the plots

# Petal,Sepal
plot(P,S)
lm(S~P)
## 
## Call:
## lm(formula = S ~ P)
## 
## Coefficients:
## (Intercept)            P  
##      4.3066       0.4089
abline(4.3066,0.4089)

# aligns the plots

# Sepal~Petal  NOTE the tilde in the plot() function
plot(P~S)
lm(P~S)
## 
## Call:
## lm(formula = P ~ S)
## 
## Coefficients:
## (Intercept)            S  
##      -7.101        1.858
abline(-7.101,1.858)

# aligns the plots



# normal distribution
iqscore <- rnorm(100,100,15)  #generate data
hist(iqscore)                 #plot histogram of data

d <- density(iqscore)         #generate density data
plot(d)                       #plot density data

# Binomial distribution
coin_toss <- rbinom(14,100,0.5) #generate data
hist(coin_toss)                 #plot histogram data

d<-density(coin_toss)
plot(d)

pnorm(22,30,5)
## [1] 0.05479929
qnorm(0.90,mean=1000,sd=100)
## [1] 1128.155
dnorm(101,100,2)
## [1] 0.1760327
dbinom(10,12,0.6)
## [1] 0.06385228
jelly_arms<-rnorm(1000,14,2)
hist(jelly_arms)

d<-density(jelly_arms)
plot(d)

car_fix<-rbinom(30,150,0.5)
hist(car_fix)

week_sample<-sample(car_fix,7)
hist(week_sample)

# Tall_peeps<-1-pnorm(...)
# Ex 3
# calc prob 1 minus prob 2 because looking at a region between 2 values