Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Exercise-1.

R
asus

2021-09-22
# Question 1
getwd()

## [1] "C:/Users/asus/OneDrive/Máy tính/Study/Fall 2021/SBE204 - Business


Statistics 2"

setwd("D:/R/RStudio/R-files/")
lbwi <- read.table ("lbwi.txt", header = TRUE)
toxemia = subset(lbwi, toxemia == 1)
toxemia0 = subset(lbwi, toxemia == 0)
infantlength = mean(toxemia$length)
infantlength0 = mean(toxemia0$length)
infantlength

## [1] 37.57143

infantlength0

## [1] 36.62025

# infants from group of moms having toxemia have greater average than infants
from the other group

#Question 2
data <- subset(lbwi, headcirc < 28 & momage <30)
meanheight = mean(data$length)
medianheight = median(data$length)
meanheight

## [1] 35

medianheight

## [1] 36

# Question 3
quantile(lbwi$height, c(.9))

## 90%
## NA

quantile(lbwi$length, c(.9))
## 90%
## 41

topheight <- subset(lbwi, length > 40)


meanweight = mean(topheight$birthwt)
sd = sd (topheight$birthwt)
MarginOfError <- 1.96*sd/sqrt(100)
upper = meanweight + MarginOfError
lower = meanweight - MarginOfError
upper

## [1] 1443.167

lower

## [1] 1421

# the 95% confident interval for the mean weight of infants in the group of
top 10% height is from 1421 to 1443.167

#Question 4
# 5 number summary
mean(lbwi$length)

## [1] 36.82

median(lbwi$length)

## [1] 38

max(lbwi$length)

## [1] 43

min(lbwi$length)

## [1] 20

quantile(lbwi$length, c(.25, .75))

## 25% 75%
## 35 39

boxplot(lbwi$length, horrzontal = TRUE)


#Question 5
meanheight = mean(toxemia$length)
meanweight = mean(toxemia$birthwt)
# mean height of infants whose moms having toxemia is
meanheight

## [1] 37.57143

# mean weight of infants whose moms having toxemia is


meanweight

## [1] 1105

meanheadcirc = mean (toxemia$headcirc, na.rm = TRUE )


# mean headcirc of infants whose moms having toxemia is
meanheadcirc

## [1] 27

save(data, file ="exercise 1")

You might also like