- #1
_N3WTON_
- 351
- 3
Homework Statement
I have an upcoming assignment for a Statistics/Probability class that requires me to write a program in R. The assignment requires me to do the following:
1. Obtain the sample mean x and sample variance s2 of the sunspots data.
2. Provide a histogram of the data.
3. For 10000 replications, randomly sample n sunspots observations from the given dataset. For each replication, obtain the sample mean. That is, you will have 10000 sample means. Compute the sample variance of these sample means.
4. Repeat the above process with n=10, 20, 30, 40, 50, 60, 70, 80, 90, and 100.
5. Obtain juxtaposed plots of the histograms of the means corresponding to n=10 and n=100.
6. Plot the variances as the function of n. What are your observations?
Homework Equations
The Attempt at a Solution
This is the code I have come up with thus far:
Code:
filename <- "C://Users//Colin//Desktop//Project1Data.txt"
data <- read.table(filename)
colnames(data) <- c("id","x")
#Questions 1 and 2
x <- data$x
mean(x)
var(x)
summary(data)
hist(x)
#partial answer to Questions 3 and 4
p <- numeric()
for (i in 1:10000){
s <- data[sample(1:1053,10,replace=FALSE),]
x <- s$x
y[i] <- mean(x)
p[i] <- y[i]
assign(paste("sample",i,sep=""),s)
assign(paste("mean",i,sep=""),y)
}
Warning message:
In mean.default(x) : argument is not numeric or logical: returning NA". Any help or advice would be greatly appreciated, thanks.