forked from rdpeng/RepData_PeerAssessment1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
237 lines (237 loc) · 8.64 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
install.packages('np', dependencies = TRUE)
mydata <- read.dta("E:\\Dropbox\\book\\economics\\548\\paper\\data\\mysurvey_z_st2011.dta")
library(foreign)
mydata <- read.dta("E:\\Dropbox\\book\\economics\\548\\paper\\data\\mysurvey_z_st2011.dta")
header(mydata)
hist(mydata$_zlen)
View(mydata)
head(mydata)
zlen<-mydata$_zlen
mydata <- read.dta("E:\\Dropbox\\book\\economics\\548\\paper\\data\\mysurvey_z_st2011.dta")
mydata <- read.dta("E:\\Dropbox\\book\\economics\\548\\paper\\data\\mysurvey_z_st2011.dta")
zhei<-mydata$zhei
hist(zhei)
zwei<-mydata$zwei
hist(zwei)
zwfl<-mydata$zwfl
hist(zwfh)
mydata <- read.dta("E:\\Dropbox\\book\\economics\\548\\paper\\data\\mysurvey_z_st2011.dta")
hist(zwfl)
name(mydata)
names(mydata)
cdf(zlen)
install.packages("heR.Misc")
install.packages("CDFt")
help cdf
Czlen=ecdf(zlen)
mydata <- read.dta("E:\\Dropbox\\book\\economics\\548\\paper\\data\\mysurvey_z_st2011.dta")
zlen<-mydata$zlen
Czlen=ecdf(zlen)
Czlen(0.0)
plot(Czlen)
czwfl<-ecdf(zwfl)
plot(czwfl)
girl<-subset(mydata,gender==2)
boy<-subset(mydata,gender==1)
zleng<-girl$zlen
zlenb<-boy$zlen
fzleng<-ecdf(zleng)
Fzleng<-ecdf(zleng)
Fzlenb<-ecdf(zlenb)
dFzlen<-Fzleng-Fzlenb
plot(dFzlen)
summary Fzleng
plot(dFzleng)
plot(Fzleng)
install.packages("reldist")
reldist(Fzleng, Fzlenb)
library(reldist)
reldist(Fzleng, Fzlenb)
theta<- seq(0.68 , 0.93, 0.00001)
loss<-exp(theta)-theta-1
plot(theta,loss)
theta<- seq(-10.0 , 10.0, 0.00001)
loss<-exp(theta)-theta-1
plot(theta,loss)
plot(theta,loss,type="l", lwd=2, col="blue",xlim=(-10.0,10.0),xlab="Theta head", ylab="Loss function",main="ECON546 ASS3 Q3 LINEX")
loss<-exp(theta)-theta-1
theta<- seq(-10.0 , 10.0, 0.00001)
loss<-exp(theta)-theta-1
plot(theta,loss,type="l", lwd=2, col="blue",xlim=(-10.0,10.0),xlab="Theta head", ylab="Loss function",main="ECON546 ASS3 Q3 LINEX")
plot(theta,loss,type="l", lwd=2, col="blue",xlim=(-10.0,10.0),xlab="Theta head", ylab="Loss function",main="ECON546 ASS3 Q3 LINEX")
theta<- seq(-1.0 , 1.0, 0.00001)
loss<- exp(theta)-theta-1
plot(theta, loss, type="l", lwd=2, col="blue",xlab="Theta head/ theta normalized to 0", ylab="LINEX loss function", main="ECON546 ASS3 Q3")
theta<- seq(-10.0 , 10.0, 0.01)
loss<- exp(theta)-theta-1
plot(theta, loss, type="l", lwd=2, col="blue",xlab="Theta head/ theta normalized to 0", ylab="LINEX loss function", main="ECON546 ASS3 Q3")
theta<- seq(-5.0 , 10.0, 0.01)
loss<- exp(theta)-theta-1
plot(theta, loss, type="l", lwd=2, col="blue",xlab="Theta head/ theta normalized to 0", ylab="LINEX loss function", main="ECON546 ASS3 Q3")
theta<- seq(-5.0 , 5.0, 0.01)
loss<- exp(theta)-theta-1
plot(theta, loss, type="l", lwd=2, col="blue",xlab="Theta head/ theta normalized to 0", ylab="LINEX loss function", main="ECON546 ASS3 Q3")
theta<- seq(-2.0 , 2.0, 0.01)
loss<- exp(theta)-theta-1
plot(theta, loss, type="l", lwd=2, col="blue",xlab="Theta head/ theta normalized to 0", ylab="LINEX loss function", main="ECON546 ASS3 Q3")
install.packages("islr")
install.packages("ISLR")
library(ISLR)
attach(auto)
attach(Auto)
attach(Auto)
model = glm(mpg~horsepower, data = Auto)
MSE_LOOCV = cv.glm(Auto, model)
library(boot)
MSE_LOOCV = cv.glm(Auto, model)
MSE_LOOCV = cv.glm(Auto, model)
MSE_LOOCV$delta[1]
MSE_LOOCV = NULL
for(i in 1:10){
model = glm(mpg~poly(horsepower, i), data = Auto)
MSE_LOOCV[i] = cv.glm(Auto, model)$delta[1]
}
MSE_LOOCV
MSE_10_fold_cv = NULL
for(i in 1:10){
model = glm(mpg~poly(horsepower, i), data = Auto)
MSE_10_fold_cv[i] = cv.glm(Auto, model, K=10)$delta[1]
}
MSE_10_fold_cv
install.packages("knitr")
install.packages("KernSmooth")
library(kernsmooth)
library(KernSmooth)
find.package("devtools")
install.packages("devtools")
library(devtools)
library(devtools)
find_rtools()
find_rtools()
library(devtools)
install.packages("markdown")
install.packages("slidify")
install.packages("knitr")
install.packages("xtable")
setwd("~/GitHub/RepData_PeerAssessment1")
myData <- read.csv("activity.zip")
myData <- read.csv(unz("activity.zip","activity.txt"),)
myData <- read.table(unz("activity.zip","activity.txt"),header=T, sep=";")
myData <- read.table(unz("activity.zip","activity.txt"),header=T, sep=";")
myData <- read.table(unz("activity.zip","activity.csv"),header=T, sep=";")
head(myData)
myData <- read.table(unz("activity.zip","activity.csv"),header=T, sep=".")
head(myData)
myData <- read.table(unz("activity.zip","activity.csv"),header=T, sep=".")
head(myData)
myData <- read.csv(unz("activity.zip","activity.csv"),header=T, sep=".")
head(myData)
myData <- read.csv("activity.csv",header=T, sep=".")
head(myData)
myData <- read.csv("activity.csv",header=T)
head(myData)
# load data
myData <- read.csv(unz("activity.zip","activity.csv"),header=T)
myData1 <- read.csv(unz("activity.zip","activity.csv"),header=T)
head(myData1)
head(myData)
myData$date <- as.Date(myData$date, "%Y-%m-%d")
head(myData)
myData$steps <- as.numeric(myData$steps)
myData1<- read.csv(unz("activity.zip","activity.csv"),header=T, sep=",")
head(myData1)
myData$interval <- as.numeric(myData$interval)
head(myData)
hist(myData$steps)
myData<-na.omit(myData)
hist(myData$steps | myData$date)
hist(mean(myData$steps),myData$date)
mean(myData$steps,myData$date)
mean(myData$steps| myData$date)
mean(myData$steps by myData$date)
? mean
aggregate(myData$steps, by=list(myData$date),mean)
hist(aggregate(myData$steps, by=list(myData$date),mean))
myData$stepsperday <- aggregate(myData$steps, by=list(myData$date),mean)
mean(myData$steps, by=list(myData$date))
stepsperday <- aggregate(myData$steps, by=list(myData$date),mean)
View(stepsperday)
hist(stepsperday$x)
mean(stepsperday$x)
median(stepsperday$x)
myData$interval
stepsperinterval <- aggregate(myData$steps, by=list(myData$interval),mean)
View(stepsperinterval)
plot(stepsperinterval$group.1,stepsperinterval$x ,type = "l")
View(stepsperinterval)
plot(stepsperinterval$Group.1,stepsperinterval$x ,type = "l")
maximam(stepsperinterval$x)
maximan(stepsperinterval$x)
maximum(stepsperinterval$x)
max(stepsperinterval$x)
stepsperinterval$Group.1[max(stepsperinterval$x)]
stepsperinterval$Group.1[stepsperinterval$x==max(stepsperinterval$x)]
is.na(myData1$steps)
sum(is.na(myData1$steps))
steps_per_interval <- aggregate(myData$steps, by=list(myData$interval),mean)
steps_per_day <- aggregate(myData$steps, by=list(myData$date),mean)
myData[is.na(myData1$steps)] <- steps_per_day$x[myData$date==steps_per_day$Group.1]
myData$steps[is.na(myData1$steps)] <- steps_per_day$x[myData$date==steps_per_day$Group.1]
myData$steps[is.na(myData1$steps)]
is.na(myData1$steps)
myData$steps[is.na(myData1$steps)]
sum(is.na(myData1$steps))
myData1$steps[is.na(myData1$steps)] <- steps_per_day$x[myData1$date==steps_per_day$Group.1]
is.na(myData1$steps)
myData1$steps[is.na(myData1$steps)]
steps_per_day$date <- steps_per_day$Group.1
name(mydata1)
names(mydata1)
names(myData1)
steps_per_interval$interval <- steps_per_interval$Group.1
merge(myData1,steps_per_day,by="date",all=TRUE)
myData1<- read.csv(unz("activity.zip","activity.csv"),header=T, sep=",")
myData1$steps <- as.numeric(myData$steps)
myData1$date <- as.Date(myData$date, "%Y-%m-%d")
myData1$interval <- as.numeric(myData$interval)
myData1<- read.csv(unz("activity.zip","activity.csv"),header=T, sep=",")
myData1$steps <- as.numeric(myData1$steps)
myData1$date <- as.Date(myData1$date, "%Y-%m-%d")
myData1$interval <- as.numeric(myData1$interval)
merge(myData1,steps_per_day,by="date",all=TRUE)
head(myData1)
head(steps_per_day)
colnames(steps_per_day)[2] <- "steps_per_day"
colnames(steps_per_interval)[2] <- "steps_per_interval"
myData2 <- merge(myData1,steps_per_day,by="date",all=TRUE)
head(myData2)
head(steps_per_day)
colnames(steps_per_day)[1] <- "date"
head(steps_per_day)
colnames(steps_per_interval)[1] <- "interval"
myData2 <- merge(myData1,steps_per_day,by="date",all=TRUE)
View(steps_per_day)
colnames(steps_per_day)[1] <- "date1"
colnames(steps_per_interval)[1] <- "interval1"
myData2 <- merge(myData1,steps_per_day,by="date",all=TRUE)
head(myData2)
myData3 <- merge(myData1,steps_per_interval,by="date",all=TRUE)
colnames(steps_per_interval)[1] <- "interval1"
myData3 <- merge(myData1,steps_per_interval,by="interval",all=TRUE)
head(myData3)
myData3$steps[is.na(myData3$steps)] <- myData3$steps_per_interval
myData3$steps[is.na(myData3$steps)] <- myData3$steps_per_interval[is.na(myData3$steps)]
head(myData3)
steps_per_day3 <- aggregate(myData3$steps, by=list(myData3$date),mean)
View(stepsperinterval)
View(steps_per_interval)
View(steps_per_day3)
mean(steps_per_day3$x)
median(steps_per_day3$x)
hist(steps_per_day3$Group.1,steps_per_day3$x,xlab="number of steps taken each day")
hist(steps_per_day3$x,xlab="number of steps taken each day")
hist(steps_per_day3$x,xlab="number of steps taken each day",main="")
myData3$weekday <- weekdays(myData3$date)
head(myData3)
myData3$weekday <- weekdays(myData3$date)
head(myData3)