7 views

Uploaded by Anoop Chakkingal

txt

- Formelblad, Ekonometri I
- Rplot01
- rqd
- 4818-Formula sheet-1.pdf
- 4818-Formula sheet-1.pdf
- New Microsoft Office Excel Worksheet
- Deriving Ols
- 4818 Formula Sheet 3
- PDEng Process and Product Design Office
- SampleQs Solutions
- s2
- New Microsoft Office Word Document (4)
- qqtest.pdf
- qqtest.pdf
- R
- MPRA Paper 79060
- Final
- The Python Mega Course_ Build 10 Real World Applications _ Udemy
- 4
- Graph Theory Chp 7

You are on page 1of 1

The following code takes 100 samples of size 100 from the gamma distribution with

parameters 5 and 1, and then estimates the parameters from those samples and plots

the sampling distribution.

alphas = rep(0,100)

lambdas = rep(0,100)

for (i in c(1:100)) {s <- rgamma(100,5,1); mu1 <- sum(s)/100; mu2 <-

sum(s^2)/100; lambdas[i] = mu1/(mu2-mu1^2); alphas[i] =

lambdas[i]*mu1}

hist(alphas)

hist(lambdas)

plot(alphas, lambdas)

This is similar code for the Rayleigh distribution. (To generate a random Rayleigh-

distributed random variable I generate two independent normals and then take the

square root of the sum of their squares; this is easier to write than loading in

the package which contains the Rayleigh distribution.) For each sample two

estimators are generated: meanest[i] is the estimator based on the mean, varest[i]

is the estimator based on the second moment. You can experiment with this data to

see that the estimator "varest" has slightly lower standard error, as discussed in

class.

r = 1000; #number of samples

meanest = rep(0,r); varest = rep(0,r);

for (i in (1:r)) {S = sqrt(rnorm(n)^2+rnorm(n)^2); meanest[i] =

mean(S)*sqrt(2/pi); varest[i] = sqrt(mean(S^2)/2)}

What does 576 draws from a Poisson with parameter 0.9323 look like?

S = rpois(576,.9323)

hist(S, breaks=seq(-0.5,6.5,1)) #might have to change upper limit of 6.5

lambda = mean(S)

Now once we have a sample like this, we estimate its lambda, and then we can take

many samples of the same size from Poissons with that new lambda, which will be

near 0.9323 but probably not exactly that. We make a histogram of the sampling

distribution.

lambdas = rep(0,1000)

for (i in (1:1000)) {T = rpois(576,lambda); lambdas[i] = mean(T)}

hist(lambdas)

Finally we can find the mean and standard deviation, and a 95 percent confidence

interval for lambda based on this particular sample.

mean(lambdas); sd(lambdas);

mean(lambdas)+qnorm(.025)*sd(lambdas); mean(lambdas)+qnorm(.975)*sd(lambdas)

- Formelblad, Ekonometri IUploaded byAnoop Chakkingal
- Rplot01Uploaded byAnoop Chakkingal
- rqdUploaded byAnoop Chakkingal
- 4818-Formula sheet-1.pdfUploaded byAnoop Chakkingal
- 4818-Formula sheet-1.pdfUploaded byAnoop Chakkingal
- New Microsoft Office Excel WorksheetUploaded byAnoop Chakkingal
- Deriving OlsUploaded byAnoop Chakkingal
- 4818 Formula Sheet 3Uploaded byAnoop Chakkingal
- PDEng Process and Product Design OfficeUploaded byAnoop Chakkingal
- SampleQs SolutionsUploaded byAnoop Chakkingal
- s2Uploaded byAnoop Chakkingal
- New Microsoft Office Word Document (4)Uploaded byAnoop Chakkingal
- qqtest.pdfUploaded byAnoop Chakkingal
- qqtest.pdfUploaded byAnoop Chakkingal
- RUploaded byAnoop Chakkingal
- MPRA Paper 79060Uploaded byAnoop Chakkingal
- FinalUploaded bySuhailUmar
- The Python Mega Course_ Build 10 Real World Applications _ UdemyUploaded byAnoop Chakkingal
- 4Uploaded byAnoop Chakkingal
- Graph Theory Chp 7Uploaded byAnoop Chakkingal
- FD AskarianUploaded byAnoop Chakkingal
- 2.xlsxUploaded byAnoop Chakkingal
- ABCUploaded byAnoop Chakkingal
- 20_S_Suppiah_AECLUploaded byAnoop Chakkingal
- 3Uploaded byAnoop Chakkingal
- Python_Bokeh_Cheat_Sheet.pdfUploaded byrakesharumalla
- % Lattice 2D VibUploaded byAnoop Chakkingal
- 5Uploaded byAnoop Chakkingal
- 2Uploaded byAnoop Chakkingal