Docsity

R Function for Data Distribution Analysis and Normal Approximations, Study Guides, Projects, Research of Mathematics

Toggle sidebar
bg1
Project5
TheCentralLimitTheorem
Problem1.WebeginthisprojectbywritinganRfunctionthatwillinputasetofdata,plotahistogramforthe
data,andoverlaythehistogrambyanormalapproximationandanonparametricsmoothedversionofthe
data.Moreover,itwillplotanormalquantileplotofthedata.TogethelponhowtowriteafunctionsinR,
refertoSection6.3of“RforBeginners”byPardis.Below hatyouwillwrite:arethedetailsofthefunctiont
Input:Avectorofdata,aparameterfor“breaks” forthehistogramwithdefault"Sturges",a
bandwidthparameterwithdefaultbw = “nrd0”.
Functionname:DataShape.R
Output:Meanandstandarddeviationofthedata.Also,twoseparategraphwindowsofsize5inchby5
inch,thatincludethegraphsdescribedin(a)‐(c)belowononewindowandthegraphdescribedin(d)on
thesecondwindow.Thecommandwindows(5,5)isuseful.
(a)Plotadensityhistogramofthedata.
(b)Overlaytheabovehistogrambyanormaldensitycurvewithmeanandstandarddeviationmatching
thoseofthehistogramdata.Usegreencolorforthiscurve.TheRcommandslinesanddnormare
useful.
(c)Overlaytheplotgeneratedin(a)and(b)withasmoothdensitycurve(useredcolorforthesmooth
densitycurve).RefertoSection3.5of“UsingRforDataAnalysisandGraphics”byMaindonald.The
commandsdensityandlinesareuseful.When
(d)Plotthenormalquantileplotforthesample.
WeUsethefollowingfive(population)sourcestotakesamplesfrom:
1. QuebecBirthData:NumberofdailybirthsinQuebecfromJanuary1,1977toDecember31,1990.
2. DataGeneratedfromanormalwithmean10andstandarddeviation2.
3. DatageneratedfromBinomialwithn=10,andp=0.1.
4. Datageneratedfromanexponentialrandomvariablewithmean1.
5. DatageneratedfromaCauchydis
Problem2:Takeasampleofsize1000fromeachoftheabovepopulations,andinputthesampleobtained
intoyourDataShapefunction,usingappropriatenumberofbreaksforthehistogram,andappropriate
bandwidthforthedensitycurve.Pastethegraphsobtainedintoyourreport,andforeachcasebriefly,discuss
theshapeofthedistributionofthesampleddata,ascomparedtoanormaldistribution,inlightofthered
curve,thegreencurve,andthenormalprobabilityplot.
Problem3(TheCentralLimitTheorematwork…ornot):Take1000samplesofsize3fromeachoftheabove
fivepopulations.Then,obtainthemeanofeachsampleofsize3andsaveittoavector.Inputtheobtained
vectorofmeansintoDataShape.R. Thenrepeatthisforsamplesofsizen=10,50,and100.(b)Foreach
casecomparethemeanandstandarddeviationofthesamplemeanstotheirtheoreticalcounterpart.(c)For
eachcasediscusstheshapeofthesamplemeansinlightofthecentrallimittheorem.
Followthefollowingproceduretoobtainthe1000sampleofthemeans:
Initialize a vector, say xbar
for (i in 1:1000) {
pf2

Partial preview of the text

Download R Function for Data Distribution Analysis and Normal Approximations and more Study Guides, Projects, Research Mathematics in PDF only on Docsity!

Project 5

The Central Limit Theorem Problem 1. We begin this project by writing an R function that will input a set of data, plot a histogram for the data, and overlay the histogram by a normal approximation and a nonparametric smoothed version of the data. Moreover, it will plot a normal quantile plot of the data. To get help on how to write a functions in R, refer to Section 6.3 of “R for Beginners” by Pardis. Below are the details of the function that you will write: Input: A vector of data, a parameter for “ breaks ” for the histogram with default " Sturges ", a bandwidth parameter with default bw = “nrd0”. Function name: DataShape.R Output: Mean and standard deviation of the data. Also, two separate graph windows of size 5 inch by 5 inch, that include the graphs described in (a)‐(c) below on one window and the graph described in (d) on the second window. The command windows(5,5) is useful. (a) Plot a density histogram of the data. (b) Overlay the above histogram by a normal density curve with mean and standard deviation matching those of the histogram data. Use green color for this curve. The R commands lines and dnorm are useful. (c) Overlay the plot generated in (a) and (b) with a smooth density curve (use red color for the smooth density curve). Refer to Section 3.5 of “Using R for Data Analysis and Graphics” by Maindonald. The commands density and lines are useful. When (d) Plot the normal quantile plot for the sample. We Use the following five (population) sources to take samples from:

  1. Quebec Birth Data: Number of daily births in Quebec from January 1, 1977 to December 31, 1990.
  2. Data Generated from a normal with mean 10 and standard deviation 2.
  3. Data generated from Binomial with n = 10, and p= 0.1.
  4. Data generated from an exponential random variable with mean 1.
  5. Data generated from a Cauchy dis Problem 2: Take a sample of size 1000 from each of the above populations, and input the sample obtained into your DataShape function, using appropriate number of breaks for the histogram, and appropriate bandwidth for the density curve. Paste the graphs obtained into your report, and for each case briefly, discuss the shape of the distribution of the sampled data, as compared to a normal distribution, in light of the red curve, the green curve, and the normal probability plot. Problem 3 (The Central Limit Theorem at work … or not): Take 1000 samples of size 3 from each of the above five populations. Then, obtain the mean of each sample of size 3 and save it to a vector. Input the obtained vector of means into DataShape.R. Then repeat this for samples of size n = 10, 50, and 100. (b) For each case compare the mean and standard deviation of the sample means to their theoretical counterpart. (c) For each case discuss the shape of the sample means in light of the central limit theorem. Follow the following procedure to obtain the 1000 sample of the means: Initialize a vector, say xbar for (i in 1:1000) {

i. Take a sample of size n from the population. ii. Calculate the mean of the sample, and retain it in xbar. } At this point you have the vector of 1000 means.