R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Question 1

names(NCbirths)
##  [1] "Gender"       "Premie"       "weight"       "Apgar1"       "Fage"        
##  [6] "Mage"         "Feduc"        "Meduc"        "TotPreg"      "Visits"      
## [11] "Marital"      "Racemom"      "Racedad"      "Hispmom"      "Hispdad"     
## [16] "Gained"       "Habit"        "MomPriorCond" "BirthDef"     "DelivComp"   
## [21] "BirthComp"
# The variables that indicate whether or not the other smoked and the weight of the baby are "Habit" and "weight" respectively.

Question 2

# In addition to "Habit" and "Weight", an important numerical value could be the mother's age "Mage" and a categorical value could be premature birth "Premie," as the mother's age can affect birth outcomes, and premature births are typically suggestive of lower birth weights.

Question 3

NCbirths_subset <- NCbirths[, c("Habit", "weight", "Mage", "Premie")]
head(NCbirths_subset)
##       Habit weight Mage Premie
## 1 NonSmoker    124   25     No
## 2 NonSmoker    177   26     No
## 3 NonSmoker    107   16     No
## 4 NonSmoker    144   37     No
## 5 NonSmoker    117   33     No
## 6 NonSmoker     98   29     No

Question 4

head(NCbirths_subset)
##       Habit weight Mage Premie
## 1 NonSmoker    124   25     No
## 2 NonSmoker    177   26     No
## 3 NonSmoker    107   16     No
## 4 NonSmoker    144   37     No
## 5 NonSmoker    117   33     No
## 6 NonSmoker     98   29     No

Question 5

mean(NCbirths$weight, na.rm = TRUE) #weights of all babies
## [1] 116.0512
mean(NCbirths$weight[NCbirths$Habit == "Smoker"], na.rm = TRUE) #weights of those born to smoking mothers
## [1] 108.4225
mean(NCbirths$weight[NCbirths$Habit == "NonSmoker"], na.rm = TRUE) #weights of those born to non-smoking mothers
## [1] 116.8416

Question 6

sd(NCbirths$weight, na.rm = TRUE) #SD of all babies' weights
## [1] 20.40953
sd(NCbirths$weight[NCbirths$Habit == "Smoker"], na.rm = TRUE) #SD of babies' weights born to smoking mothers
## [1] 20.03352
sd(NCbirths$weight[NCbirths$Habit == "NonSmoker"], na.rm = TRUE) #SD of babies' weights born to non-smoking mothers
## [1] 20.29014

Question 7

Births <- NCbirths[NCbirths$Habit != "",]
names(Births)
##  [1] "Gender"       "Premie"       "weight"       "Apgar1"       "Fage"        
##  [6] "Mage"         "Feduc"        "Meduc"        "TotPreg"      "Visits"      
## [11] "Marital"      "Racemom"      "Racedad"      "Hispmom"      "Hispdad"     
## [16] "Gained"       "Habit"        "MomPriorCond" "BirthDef"     "DelivComp"   
## [21] "BirthComp"
histogram(~ weight | Habit,data = Births,layout = c(1, 2))

bwplot(weight ~ Habit, data = Births)

Question 7 Cont.

# Based on my graphs above, the overall distribution of birth weights seem similar; however, there is a lower median and higher amount of low-weight outliers within smoking mothers which can suggest that smoking can be associated with lower birth weights.

Question 8

mean_smoking <- mean(Births$weight[Births$Habit == "Smoker"], na.rm = TRUE) #mean of birth weights for smokers
sd_smoking <- sd(Births$weight[Births$Habit == "Smoker"], na.rm = TRUE) #SD of birth weights for smokers

mean_non_smoking <- mean(Births$weight[Births$Habit == "NonSmoker"], na.rm = TRUE) #mean of birth weights for non-smokers
sd_non_smoking <- sd(Births$weight[Births$Habit == "NonSmoker"], na.rm = TRUE) #SD of birth weights for non-smokers

mean_smoking
## [1] 108.4225
sd_smoking
## [1] 20.03352
mean_non_smoking
## [1] 116.8416
sd_non_smoking
## [1] 20.29014
# Based on the graphs, mean birth weights (below), and standard deviations (below) between smokers and non-smokers, the birth weight of babies indeed differ based on smoking habit. The means have a noticeable difference as those who are born to non-smoking mothers have a higher average birth weight. The boxplot showed that the median birth weight of non-smokers is higher than smokers as well. This evidence is suggestive that reduced birth weight is associated with mothers that smoke.
# The conclusion can be extended to populations that have a similar environment and smoking habits as the ones used in this dataset. Populations within a similar age group and smoking prevalence among pregnant women can be considered. It is also important to consider populations with similar genetic/biological factors as well as environments that account for similar pollution levels and lifestyle behaviors.
histogram(~Mage,data = Births, breaks = 5)

histogram(~ Mage, data = Births, breaks = seq(min(Births$Mage, na.rm = TRUE), max(Births$Mage, na.rm = TRUE), by = 2))

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.