#Part 1

##Exercise 1

###1a

heights <- c(64, 62, 67)
print(heights)
## [1] 64 62 67

###1b

names <- c("Julie", "Lidya", "August")
print(names)
## [1] "Julie"  "Lidya"  "August"

##1c

a <-cbind(heights,names)
print(a)
##      heights names   
## [1,] "64"    "Julie" 
## [2,] "62"    "Lidya" 
## [3,] "67"    "August"
class(a)
## [1] "matrix" "array"

##Exercise 2

NCbirths <- read.csv("births.csv")
head(NCbirths)
##   Gender Premie weight Apgar1 Fage Mage Feduc Meduc TotPreg Visits   Marital
## 1   Male     No    124      8   31   25    13    14       1     13   Married
## 2 Female     No    177      8   36   26     9    12       2     11 Unmarried
## 3   Male     No    107      3   30   16    12     8       2     10 Unmarried
## 4 Female     No    144      6   33   37    12    14       2     12 Unmarried
## 5   Male     No    117      9   36   33    10    16       2     19   Married
## 6 Female     No     98      4   31   29    14    16       3     20   Married
##   Racemom Racedad Hispmom Hispdad Gained     Habit MomPriorCond BirthDef
## 1   White   White NotHisp NotHisp     40 NonSmoker         None     None
## 2   White   White Mexican Mexican     20 NonSmoker         None     None
## 3   White Unknown Mexican Unknown     70 NonSmoker At Least One     None
## 4   White   White NotHisp NotHisp     50 NonSmoker         None     None
## 5   White   Black NotHisp NotHisp     40 NonSmoker At Least One     None
## 6   White   White NotHisp NotHisp     21 NonSmoker         None     None
##      DelivComp BirthComp
## 1 At Least One      None
## 2 At Least One      None
## 3 At Least One      None
## 4 At Least One      None
## 5         None      None
## 6         None      None

##Exercise 3

find.package("maps")
## [1] "/home/juliecarrillo35@gmail.com/R/x86_64-pc-linux-gnu-library/4.4/maps"
library(maps)
map("state")

##Exercise 4

###4a

weights =NCbirths$weight

###4b

#I think the units are in ounces.

###4c

weights.in.pounds <- weights/16

###4d

weights.in.pounds[1:20]
##  [1]  7.7500 11.0625  6.6875  9.0000  7.3125  6.1250  9.1875  8.6250  6.5000
## [10]  7.6875  9.5625  8.0625  7.4375  6.7500  6.6250  7.8125  7.1875  8.0000
## [19]  8.2500  5.1875

#Exercise 5

mean(weights)
## [1] 116.0512

##5a

library(mosaic)
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## The 'mosaic' package masks several functions from core packages in order to add 
## additional features.  The original behavior of these functions should not be affected by this.
## 
## Attaching package: 'mosaic'
## The following objects are masked from 'package:dplyr':
## 
##     count, do, tally
## The following object is masked from 'package:Matrix':
## 
##     mean
## The following object is masked from 'package:ggplot2':
## 
##     stat
## The following objects are masked from 'package:stats':
## 
##     binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
##     quantile, sd, t.test, var
## The following objects are masked from 'package:base':
## 
##     max, mean, min, prod, range, sample, sum
tally(NCbirths$Habit)
## X
## NonSmoker    Smoker 
##      1805       187
tally(NCbirths$Habit, format='percent')
## X
## NonSmoker    Smoker 
##  90.61245   9.38755

##5b- In NC births, the percentage of smokers is about 12% lower than the CDC’s report

#Exercise 6

histogram(weights.in.pounds, breaks=3)

histogram(weights.in.pounds, breaks=20)

histogram(weights.in.pounds, breaks=100)

##The histogram with 100 weights gives the best visualization because it shows the most variability in between intergers

#Exercise 7

boxplot(NCbirths$Mage,NCbirths$Fage)

##Fathers tent to be older

#Exercise 8

histogram(~weight|Habit, data=NCbirths,layout=c(1,2))

####The baby weights from non-smoker moms appear to be higher on average than smoker moms

##Exercise 9

dotPlot(weights.in.pounds, cex=7)

##Exercise 10 ###I think smoking has a potitive correlation to birth defects

tally(~BirthDef|Habit, data=NCbirths)
##               Habit
## BirthDef       NonSmoker Smoker
##   At Least One        12      3
##   None              1793    184
library(pander)
pander(tally(~BirthDef|Habit, data=NCbirths, format= "proportion"),caption= "Birth Defects vs Mother;s Smoking Habit")
Birth Defects vs Mother;s Smoking Habit
  NonSmoker Smoker
At Least One 0.006648 0.01604
None 0.9934 0.984

###The graph does not support my hypothesis

##Exercise 11

plot(NCbirths$Mage,NCbirths$weight, col= "purple", cex=0.25)

#Part 2

##Exercise 1

###1a-

###1b-

###1c-

##Exercise 2

###2a-

###2b-

###2c-

##Exercise 3

##Exercise 4

###4a-

###4b-

##Exercise 5

###5a-

###5b-

##Exercise 6