# ### Sidebar

people:gang:cp_sol

### (Archive) Solution for Math 448 Computing Homework (Fall 2015)

#### Computing Homework 6 solution


####Set the R working directory###
setwd("C:/")
###read in the data file, make sure your data file is under the working directory##
### the "dat" you just read into R is a data frame, need to convert it into a matrix
dat <- as.matrix(dat) ##dat now is a 2x31 matrix
x1 <- dat[1,]  ##take the first row of this matrix as your sample from population 1
x2 <- dat[2,]  ##take the second row of this matrix as your sample from population 2

---At this point, you have loaded the data into your R program, whose name is "y1" and "y2". You can start manipulating the data--

===Computing Homework 5 solution===
<code>
####Set the R working directory###
setwd("C:/")
###read in the data file, make sure your data file is under the working directory##
### the "dat" you just read into R is a data frame, need to convert it into a matrix
dat <- as.matrix(dat) ##dat now is a 1x20 matrix
x <- dat[1,]  ##take the first row of this matrix as your sample

---At this point, you have loaded the data into your R program, whose name is "x". You can start manipulating the data--

######## Part 1#########
mean(x)

######## Part 2#########
sqrt(mean(x^2)/2)

######## Part 3#########
mean(x)

######## Part 4#########
(mean(x))^2

######## Part 5#########
mean(x^2)/2

######## Part 6#########
(mean(x))^2*n/(n+1)


#### Computing Homework 4 solution


####Set the R working directory###
setwd("C:/")
###read in the data file, make sure your data file is under the working directory##
### the "dat" you just read into R is a data frame, need to convert it into a matrix
dat <- as.matrix(dat) ##dat now is a 1x100 matrix
x <- dat[1,]  ##take the first row of this matrix as your sample

---At this point, you have loaded the data into your R program, whose name is "x". You can start manipulating the data--

######## Part 1#########
var(x[1:10])

######## Part 2a#########
mean(x[1:10])-qnorm(0.95)*sd(x[1:10])/sqrt(10)

######## Part 2b#########
mean(x[1:10])+qnorm(0.95)*sd(x[1:10])/sqrt(10)

######## Part 3#########
nsize <- (qnorm(0.995)/0.5*sd(x[1:10]))^2
nsize <- floor(nsize)+1
cost <- nsize*12
cost

######## Part 4#########
mean(x[1:nsize])

######## Part 5a#########
mean(x[1:nsize])-qnorm(0.95)*sd(x[1:nsize])/sqrt(nsize)

######## Part 5b#########
mean(x[1:nsize])+qnorm(0.95)*sd(x[1:nsize])/sqrt(nsize)


#### Computing Homework 3 solution


####Set the R working directory###
setwd("C:/")
###read in the data file, make sure your data file is under the working directory##
### the "dat" you just read into R is a data frame, need to convert it into a matrix
dat <- as.matrix(dat) ##dat now is a 1000x1 matrix
x <- dat[1,]  ##take the first row of this matrix as your sample

---At this point, you have loaded the data into your R program, whose name is "x". You can start manipulating the data--

######## Part 1#########
max(x)

######## Part 2#########
n <- length(x)
max(x)*(n+1)/n

######## Part 3#########
mean(x)

######## Part 4#########
2*mean(x)

######## Part 5(a)#########
n <- length(x)
max(x)/(0.975^(1/n))

######## Part 5(b)#########
n <- length(x)
max(x)/(0.025^(1/n))

#### Computing Homework 2 solution


####Set the R working directory###
setwd("C:/")
###read in the data file, make sure your data file is under the working directory##
### the "dat" you just read into R is a data frame, need to convert it into a matrix
dat <- as.matrix(dat) ##dat now is a 1000x1 matrix
x <- dat[1,]  ##take the first row of this matrix as your sample

---At this point, you have loaded the data into your R program, whose name is "x". You can start manipulating the data--

######## Part 1#########
mean(x^2)

######## Part 2#########
xbar <- mean(x)
mean((x-xbar)^2)

######## Part 3#########
n <- length(x)
mean(x^2)
mean(x^2)-n*xbar^2

######## Part 4#########
(n-1)*var(x)

######## Part 5(a)#########
xbar <- mean(x)

######## Part 5(b)#########
std <- sqrt(var(x)/n)


#### Homework 1 Part (a)


#####Set the R working directory###
setwd("C:/")

###read in the data file, make sure your data file is under the working directory##

### the "dat" you just read into R is a data frame, need to convert it into a matrix

dat <- as.matrix(dat) ##dat now is a 25x1 matrix

x <- dat[1,]  ##take the first row of this matrix as your sample

##compute the average of all elements in the vector "x"
mean(x)

###PS: if you want to know how does your data set look like, you can create a histogram ###

hist(x)   #####type in ?hist to learn more about function "hist()"###

#### Homework 1 Part (b)


setwd("C:/")
hist(x) 