I have tried to determine the validity of a normal distribution which I obtained in the following way:
xfit<-seq(min(x),max(x),length=1000)
yfit<-dnorm(xfit,mean=mean(x),sd=sd(x))
In this excerpt of my code x is an array with ~300 values between -15 and -5.
I evaluated the distribution by comparing it to a histogram and a Q-Q plot in the following way:
#Fitting in histogram with normal curve
x <- dataM31
h<-hist(x, breaks=10, col="red", xlab="Absolute Magnitude", prob = TRUE)
xfit<-seq(min(x),max(x),length=1000)
yfit<-dnorm(xfit,mean=mean(x),sd=sd(x))
lines(xfit, yfit, col="blue", lwd=2)
#Create a normality test plot (qq-plot)
x_norm <- (x - mean(x))/sd(x)
qqnorm(x_norm); abline(0,1)
I have tried to perform any kind of quantitative test for the validity of this normal distribution, but I cannot find a function that does this for a 1D array of data vs. a 2D normal distribution. Is there any function that could do this for me with relative ease or should I completely rewrite my code to get this to work?
These functions provide the solutions for normality test and density estimation, run that in the console and see examples:
?shapiro.test()
?ks.test()
?density()