## ---------------------------------------------------------------------------- ## R scripts for Haerdle/Mueller/Sperlich/Werwatz: "Nonparametric and ## Semiparametric Modelling", Springer Series in Statistics, 2004 ## ---------------------------------------------------------------------------- ## Script SPMhistogram ## ---------------------------------------------------------------------------- ## Description computes a histogram for stock returns data ## ---------------------------------------------------------------------------- ## Author Marlene Mueller, 2008/11/21 ## ---------------------------------------------------------------------------- x <- read.csv("D:\\stockres.txt") x <- unlist(x) x0 <- 0.02 h <- 0.04 breaks <- function(x,x0,h){ b <- floor((min(x)-x0)/h) : ceiling((max(x)-x0)/h) b <- b*h+x0 return(b) } hist(x,freq=FALSE,breaks=breaks(x,x0,h), main="Histogram of Stock Returns",xlab="Data x",ylab="Histogram")