#Problem 1
conv1 <- function(centimeters) {
    return (centimeters/2.54)
}

#Problem 2  
conv2 <- function(centimeters) {
    return (centimeters/2.54)
    return (centimeters/30.48)
    return (centimeters/100)
}

#Problem 3
conv3 <- function(centimeters) {
    if (centimeters > 0) {
        return (centimeters/2.54)
    }
    else {
        print("Error: No negative numbers")
    }
}       

#Problem 4
mat1 <- function(myMatrix) {
    s <- 0
    for(i in 1:length(myMatrix[,1])) {
        for(j in 1:length(myMatrix[1,])) {
            s <- s + myMatrix[i,j]
        }
    }
    pMT <- (myMatrix %*% t(myMatrix))
    inverse_pMT <- solve(pMT)
    out <- list(s,pMT,inverse_pMT)
    return(out)
}

#Problem 5
mat2 <- function(myMatrix) {
    if(is.matrix(myMatrix)) {
        s <- 0
        for(i in 1:length(myMatrix[,1])) {
            for(j in 1:length(myMatrix[1,])) {
                s <- s + myMatrix[i,j]
            }
        }
        pMT <- (myMatrix %*% t(myMatrix))
        inverse_pMT <- solve(pMT)
        out <- list(s,pMT,inverse_pMT)
        return(out)
    }
    else {
        return("Error, input is not a matrix")
    }
}

#Problem 6
library("readxl")
dataset1 <- read_xls("/Users/KathyOchoa/Documents/STAT classes/STAT 432/Project1data.xls")

#Problem 7
mean(dataset1$BMI)
## [1] 22.01838
median(dataset1$BMI)
## [1] 21
sd(dataset1$BMI)
## [1] 2.112982
mean(dataset1$Age)
## [1] 50.09559
median(dataset1$Age)
## [1] 50
sd(dataset1$Age)
## [1] 5.819635
mean(dataset1$Exercise_minutes_a_day)
## [1] 41.43382
median(dataset1$Exercise_minutes_a_day)
## [1] 30
sd(dataset1$Exercise_minutes_a_day)
## [1] 27.29463
#Problem 8
OW <- c(1:816)
for (i in 1:nrow(dataset1)) {
  if (dataset1[i,]$BMI >= 24) {
    OW[i] <- 1
  }
  else {
    OW[i] <- 0
  }
}

#Problem 9
dataset2 <- cbind(dataset1,OW)

#Problem 10 
set.seed(1)
group1 <- rnorm(100, mean = 20, sd = 5)

#Problem 11
set.seed(1)
group2 <- rnorm(100, mean = 25, sd = 5)

#Problem 12
hg1 <- hist(group1, plot = FALSE)
hg2 <- hist(group2, plot = TRUE)

c1 <- rgb(173,216,230,max = 255, alpha = 80, names = "lt.blue")
c2 <- rgb(255,192,203, max = 255, alpha = 80, names = "lt.pink")
plot(hg1, col = c1, main = "Histograms for group 1 and group 2", xlab = "Groups")
plot(hg2, col = c2, add = TRUE)
legend("topleft", inset=.02, legend = c("Group 1", "Group 2"), col = c(c1,c2), fill = c(c2,c1), cex=0.8)

#Problem 13
par(mfrow = c(2,2))
plot(hg1, col = 'grey')
plot(hg2, col = 'lightblue')

#Problem 14
hist(group1, probability = T, col = 'grey', lwd = 2, ylim = c(0.0,0.1))
lines(density(group1), lwd = 2, col = 'red')

#Problem 15
t.test(group1, group2, alternative = c("two.sided"), mu = 0, paired = F, var.equal = F)
## 
##  Welch Two Sample t-test
## 
## data:  group1 and group2
## t = -7.8725, df = 198, p-value = 2.234e-13
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -6.252473 -3.747527
## sample estimates:
## mean of x mean of y 
##  20.54444  25.54444

```