Friday, June 28, 2013

Calculate Normal Distribution Using R



#:************************************************************************
#: Author: Alex Madriaga
#: Date: 06/06/2013
#: Time: 11:11:11
#: File: dnorm.r
#: Status: Working using the data in C:/workspace/ecdf/d176m.csv
#: Version: 0.98
#: Description: Latest version of the normal distribution for R scripting
#: Revision history:
#:
#:************************************************************************

# load the csv file, ignoring the header
mainDir <- "C:/workspace/ecdf"
setwd(mainDir)
mainDir <- getwd()
rawCSVFile <- "d176m.csv"
rsm <- read.csv(rawCSVFile,header=TRUE)

# check structure and convert vector values to numeric
str(rsm)
rsm$HEAP <- as.numeric(rsm$HEAP)

# calculate the mean and standard deviation
mean <- mean(rsm$HEAP)
sd <- sd(rsm$HEAP)

#plotting the density function of a normal distribution
heap <- rsm$HEAP

# plot the data
plot(heap, dnorm(heap, mean, sd), type="l")


No comments:

Post a Comment