Evaluasi model akhir

R untuk Pengguna SAS

Melinda Higgins, PhD

Research Professor/Senior Biostatistician Emory University

Latihan akhir

Penutup kursus

  • Jalankan model regresi

    • untuk prediktor berbeda
    • untuk kelompok berbeda
  • Pilih model terbaik

    • simpan hasil model
    • ekstrak dan tampilkan statistik kecocokan

Tunjukkan keterampilan Anda

  • Evaluasi dan bandingkan model

    • dengan visualisasi grafis
  • Laporkan asosiasi terbaik

    • antar variabel
    • keseluruhan dan per kelompok
R untuk Pengguna SAS

Membandingkan model

# Run lm() for diffht by bmi, save model
lmdiffhtbmi <- lm(diffht ~ bmi,
                  data = daviskeep)

# Run lm() for diffht by weight, save model
lmdiffhtwt <- lm(diffht ~ weight,
                 data = daviskeep)
# Run summary() for each model, save results
smrylmdiffhtbmi <- summary(lmdiffhtbmi)
smrylmdiffhtwt <- summary(lmdiffhtwt)
R untuk Pengguna SAS

Membandingkan model

# Display r.squared for weight model
smrylmdiffhtwt$r.squared
# Display r.squared for bmi model
smrylmdiffhtbmi$r.squared
# Compare AICs for both models
AIC(lmdiffhtbmi, lmdiffhtwt)

[1] 0.003281645

[1] 0.00121824
            df      AIC
lmdiffhtbmi  3 788.0816
lmdiffhtwt   3 787.7052
R untuk Pengguna SAS

Model per kelompok - pria vs wanita

# Plot diffht by weight by sex
ggplot(daviskeep,
       aes(diffht, weight)) +
  geom_point() +
  geom_smooth(method = "lm") +
  facet_wrap(vars(sex)) +
  ggtitle("Perbedaan tinggi
          diprediksi oleh berat,
          kecocokan model per jenis kelamin")

plot diffht menurut berat per jenis kelamin

R untuk Pengguna SAS

Regresi pada subset

opsi where SAS proc reg mirip opsi subset untuk fungsi R lm

R untuk Pengguna SAS

opsi where SAS proc reg mirip opsi subset untuk fungsi R lm

R untuk Pengguna SAS

Memasang model untuk subset

# lm() of diffht by weight for females
lmdiffhtwtF <- lm(diffht ~ weight,
                  subset = (sex == "F"),
                  data = daviskeep)

# lm() of diffht by weight for males
lmdiffhtwtM <- lm(diffht ~ weight,
                  subset = (sex == "M"),
                  data = daviskeep)
# Run summary() for each model save results
smrylmdiffhtwtF <- summary(lmdiffhtwtF)
smrylmdiffhtwtM <- summary(lmdiffhtwtM)
R untuk Pengguna SAS

Memasang model untuk subset

# r.squared for females only model
smrylmdiffhtwtF$r.squared
# r.squared for males only model
smrylmdiffhtwtM$r.squared

[1] 4.00807e-05

[1] 0.00804139
R untuk Pengguna SAS

Mari kita tutup dengan membuat beberapa model untuk memprediksi usia abalon!

R untuk Pengguna SAS

Preparing Video For Download...