0% found this document useful (0 votes)
23 views9 pages

Practical 4

This document discusses maximum likelihood estimation for Poisson distributed data in R. It generates 100 random numbers from a Poisson distribution with parameter λ=5. It calculates the likelihood of a single data point for different λ values and plots the likelihood versus λ graph.

Uploaded by

Yuvika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views9 pages

Practical 4

This document discusses maximum likelihood estimation for Poisson distributed data in R. It generates 100 random numbers from a Poisson distribution with parameter λ=5. It calculates the likelihood of a single data point for different λ values and plots the likelihood versus λ graph.

Uploaded by

Yuvika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Practical Manual 4-MLE for Poisson data

Maximum Likelihood Estimation for data from Poisson Distribution

# Generating poisson distribution data

#In R, we can generate random numbers from a specific probability distribution easily.
To #generate numbers from poisson distribution, we can use rpois function. #We will
generate 100 data points from Poisson distribution with parameter lambda =5 #using
rpois function R

# generate data from Poisson distribution


# with the parameter lambda=5
data=rpois(n=100, lambda=5)
data
## [1] 5 6 7 11 3 3 4 3 3 7 5 5 4 2 6 8 7 6 6 3 2 3 5 6 2 ## [26] 8 5 6 7
5 4 7 3 3 6 3 3 8 4 7 1 6 1 4 4 2 3 5 4 8 ## [51] 9 3 4 6 7 6 5 6 4 3 3 2
6 8 7 5 8 2 3 4 4 6 0 4 4 ## [76] 5 5 5 5 6 7 8 3 3 8 7 5 8 3 5 1 6 5 5 2
65435
#Let us save the data into a data frame

# convert to data frame


df_Poisson <- data.frame(data=data)
df_Poisson
## data
## 1 5
## 2 6
## 3 7
## 4 11
## 5 3
## 6 3
## 7 4
## 8 3
## 9 3
## 10 7
## 11 5
## 12 5
## 13 4
## 14 2
## 15 6
## 16 8
## 17 7
## 18 6
## 19 6
## 20 3
## 21 2
## 22 3
## 23 5
## 24 6
## 25 2
## 26 8
## 27 5
## 28 6
## 29 7
## 30 5
## 31 4
## 32 7
## 33 3
## 34 3
## 35 6
## 36 3
## 37 3
## 38 8
## 39 4
## 40 7
## 41 1
## 42 6
## 43 1
## 44 4
## 45 4
## 46 2
## 47 3
## 48 5
## 49 4
## 50 8
## 51 9
## 52 3
## 53 4
## 54 6
## 55 7
## 56 6
## 57 5
## 58 6
## 59 4
## 60 3
## 61 3
## 62 2
## 63 6
## 64 8
## 65 7
## 66 5
## 67 8
## 68 2
## 69 3
## 70 4
## 71 4
## 72 6
## 73 0
## 74 4
## 75 4
## 76 5
## 77 5
## 78 5
## 79 5
## 80 6
## 81 7
## 82 8
## 83 3
## 84 3
## 85 8
## 86 7
## 87 5
## 88 8
## 89 3
## 90 5
## 91 1
## 92 6
## 93 5
## 94 5
## 95 2
## 96 6
## 97 5
## 98 4
## 99 3
## 100 5

hist(data,main=”Poisson distribution”,xlab=”value of r.V X”,col=rainbow(6),breaks = 10)


library(UsingR)
## Loading required package: MASS
## Warning: package ‘MASS’ was built under R version 3.6.3
## Loading required package: HistData
## Loading required package: Hmisc
## Warning: package ‘Hmisc’ was built under R version
3.6.3 ## Loading required package: lattice
## Warning: package ‘lattice’ was built under R version
3.6.3 ## Loading required package: survival

## Loading required package: Formula


## Loading required package: ggplot2
##
## Attaching package: ‘Hmisc’
## The following objects are masked from ‘package:base’:
##
## format.pval, units
##
## Attaching package: ‘UsingR’
## The following object is masked from ‘package:survival’:
##
## cancer

simple.freqpoly(data,main=”frequency polygon of poisson distribution data”,xlab=”value of r.V


X”,col=rainbow(6))
d=density(data)
plot(d)

#density plot for the above distribution


#Let us compute the likelihood of the single data point, but with multiple parameter values.

likelihood= dpois(data[1], lambda=seq(25))


likelihood
## [1] 3.065662e-03 3.608941e-02 1.008188e-01 1.562935e-01 1.754674e-01
## [6] 1.606231e-01 1.277167e-01 9.160366e-02 6.072688e-02 3.783327e-02
## [11] 2.241521e-02 1.274064e-02 6.993704e-03 3.726801e-03 1.935788e-03
## [16] 9.833474e-04 4.898433e-04 2.398174e-04 1.156090e-04 5.496410e-05
## [21] 2.580662e-05 1.197991e-05 5.504081e-06 2.504998e-06 1.130204e-06

dlike=data.frame(data=likelihood)
dlike #dataframe of likelihoods
## data
## 1 3.065662e-03
## 2 3.608941e-02
## 3 1.008188e-01
## 4 1.562935e-01
## 5 1.754674e-01
## 6 1.606231e-01
## 7 1.277167e-01
## 8 9.160366e-02
## 9 6.072688e-02
## 10 3.783327e-02
## 11 2.241521e-02
## 12 1.274064e-02
## 13 6.993704e-03
## 14 3.726801e-03
## 15 1.935788e-03
## 16 9.833474e-04
## 17 4.898433e-04
## 18 2.398174e-04
## 19 1.156090e-04
## 20 5.496410e-05
## 21 2.580662e-05
## 22 1.197991e-05
## 23 5.504081e-06
## 24 2.504998e-06
## 25 1.130204e-06
hist(likelihood,main=”likelihood of a single data point”,xlab=”likelihood(in class
intervals)”,col=rainbow(6))
simple.freqpoly(likelihood,main=”likelihood of a single data point”,xlab=”likelihood(in class
intervals)”,col=rainbow(6))
dens=density(likelihood)
plot(dens)

tab=data.frame(lamda=seq(1,25),likelihood)
tab
## lamda likelihood
## 1 1 3.065662e-03
## 2 2 3.608941e-02
## 3 3 1.008188e-01
## 4 4 1.562935e-01
## 5 5 1.754674e-01
## 6 6 1.606231e-01
## 7 7 1.277167e-01
## 8 8 9.160366e-02
## 9 9 6.072688e-02
## 10 10 3.783327e-02
## 11 11 2.241521e-02
## 12 12 1.274064e-02
## 13 13 6.993704e-03
## 14 14 3.726801e-03
## 15 15 1.935788e-03
## 16 16 9.833474e-04
## 17 17 4.898433e-04
## 18 18 2.398174e-04
## 19 19 1.156090e-04
## 20 20 5.496410e-05
## 21 21 2.580662e-05
## 22 22 1.197991e-05
## 23 23 5.504081e-06
## 24 24 2.504998e-06
## 25 25 1.130204e-06
plot(tab,col=”red”,main=”likelihood v/s lamda graph”)
#density plot of the likelihood of the first data point

You might also like