**Problem of the Week**

**Number Theory Conf.**

**Zassenhaus Conference**

**Hilton Memorial Lecture**

You are here: Homepage » People » Ganggang Xu » (Archive) Solution for Math 448 Computing Homework (Fall 2015)

people:gang:cp_sol

####Set the R working directory### setwd("C:/") ###read in the data file, make sure your data file is under the working directory## dat = read.csv('data_6.csv',header=FALSE) ### 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## dat = read.csv('data_5.csv',header=FALSE) ### 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)

####Set the R working directory### setwd("C:/") ###read in the data file, make sure your data file is under the working directory## dat = read.csv('data_4.csv',header=FALSE) ### 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)

####Set the R working directory### setwd("C:/") ###read in the data file, make sure your data file is under the working directory## dat = read.csv('data_3.csv',header=FALSE) ### 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))

####Set the R working directory### setwd("C:/") ###read in the data file, make sure your data file is under the working directory## dat = read.csv('data_2.csv',header=FALSE) ### 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)

#####Set the R working directory### setwd("C:/") ###read in the data file, make sure your data file is under the working directory## dat = read.csv('data_1a.txt',header=FALSE) ### 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()"###

setwd("C:/") dat = read.csv('data_1b.txt',header=FALSE) dat <- as.matrix(dat) x <- dat[1,] mean(x) hist(x)

people/gang/cp_sol.txt · Last modified: 2016/01/24 18:44 by qiao

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported