การแจกแจงแบบเกาส์เซียน

Mixture Models ใน R

Victor Medina

Researcher at The University of Edinburgh

Mixture model กับชุดข้อมูลเพศ

Mixture Models ใน R

แพ็กเกจสำหรับ fitting mixture models

  • mixtools
    • ไม่รองรับการแจกแจงแบบ Poisson
  • bayesmix
    • Bayesian inference อยู่นอกขอบเขตของคอร์สนี้
  • EMCluster
    • รองรับเฉพาะการแจกแจงแบบเกาส์เซียน
  • flexmix
    • ครอบคลุมทุกการแจกแจงที่ต้องการ และยืดหยุ่นพอสำหรับโมเดลที่ซับซ้อนยิ่งขึ้น
Mixture Models ใน R

คุณสมบัติของการแจกแจงแบบเกาส์เซียน

ค่าเฉลี่ย

ค่าเบี่ยงเบนมาตรฐาน

Mixture Models ใน R

การสุ่มตัวอย่างจากการแจกแจงแบบเกาส์เซียน

การสุ่มตัวอย่างจากการแจกแจงแบบเกาส์เซียน:

  • rnorm(n, mean, sd)

ตัวอย่าง: สุ่ม 100 ค่าจากการแจกแจงแบบเกาส์เซียนที่มีค่าเฉลี่ย 10 และค่าเบี่ยงเบนมาตรฐาน 5

 

> population_sample <- rnorm(n = 100, mean = 10, sd = 5)
> head(population_sample)
[1]  6.248874  9.564190 16.006521  9.139647 10.114969 16.423538
Mixture Models ใน R

การประมาณค่าเฉลี่ย

  • ไม่ทราบค่าเฉลี่ยและค่าเบี่ยงเบนมาตรฐาน มีเพียงข้อมูลที่สังเกตได้
    • จำเป็นต้องประมาณค่าจากข้อมูลที่สังเกตได้
  • ประมาณค่าเฉลี่ยได้โดยคำนวณค่าเฉลี่ยของตัวอย่าง

 

> mean_estimate <- mean(population_sample)
10.35759
Mixture Models ใน R

การประมาณค่า sd ทำตามขั้นตอนดังนี้

$$value_i\rightarrow (. -mean\_estimate)\rightarrow (.)^2\rightarrow mean (.)\rightarrow \sqrt{(.)}$$

> population_sample %>%  
+   subtract(mean_estimate) %>%
+   raise_to_power(2) %>% mean() %>% sqrt()
5.318641
  • ใช้ฟังก์ชัน sd
> standard_deviation_estimate <- sd(population_sample)
> standard_deviation_estimate
5.345435
Mixture Models ใน R

การแสดงภาพการแจกแจงแบบเกาส์เซียนที่ประมาณค่าได้

# Transform the sample into a data frame
population_sample <- data.frame(x = population_sample)

# Plot the histogram
ggplot(data = population_sample) + 
   geom_histogram(aes(x = x, y = ..density..)) +
   stat_function(geom = "line", 
                 fun = dnorm, 
                 args = list(mean = mean_estimate, 
                             sd = standard_deviation_estimate))
Mixture Models ใน R

Mixture Models ใน R

มาฝึกกันเถอะ!

Mixture Models ใน R

Preparing Video For Download...