Introduction to Mplus7 -...

16
การใชโปรแกรมสําเร็จรูป Mplus ขั้นพื้นฐาน (Introduction to Mplus) ผศ.ดร.ธีรเดช ฉายอรุณ หลักสูตรบัณฑิตศึกษา สาขาวิชาประชากรศึกษา ภาควิชาศึกษาศึกษาศาสตร# คณะสังคมศาสตร#และมนุษยศาสตร# มหาวิทยาลัยมหิดล พัฒนาการของ Mplus เริ่มตนในช(วงทศวรรษที่ 90 ภายใตชื่อ LISCOMP ที่ทํางานบน DOS โดย ผูพัฒนาคือ Prof.Muthén จาก UCLA Version แรกของ Mplus เริ่มในปH ค.ศ.1998 Version ปKจจุบันคือ 7 (2012) ทํางาน ไดทั้ง 32 และ 64 bit บน ระบบปฏิบัติการ Windows, Mac, Linux Bengt Muthen & Linda Muthén (2004)

Transcript of Introduction to Mplus7 -...

Page 1: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

การใช�โปรแกรมสําเร็จรูป Mplus ข้ันพ้ืนฐาน(Introduction to Mplus)

ผศ.ดร.ธีรเดช ฉายอรุณ

หลักสูตรบัณฑิตศึกษา สาขาวิชาประชากรศึกษา ภาควิชาศึกษาศึกษาศาสตร#

คณะสังคมศาสตร#และมนุษยศาสตร# มหาวิทยาลัยมหิดล

พัฒนาการของ Mplus

� เริ่มต�นในช(วงทศวรรษท่ี 90 ภายใต�ช่ือ LISCOMP ท่ีทํางานบน DOS โดยผู�พัฒนาคือ Prof.Muthén จาก UCLA

� Version แรกของ Mplus เริ่มในปH ค.ศ.1998

� Version ปKจจุบันคือ 7 (2012) ทํางานได�ทั้ง 32 และ 64 bit บนระบบปฏิบัติการ Windows, Mac, Linux

Bengt Muthen & Linda Muthén (2004)

Page 2: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

Mplus General Description� Mplus is a statistical modeling program that provides researchers with a flexible

tool to analyze their data. Mplus offers researchers a wide choice of models, estimators, and algorithms in a program that has an easy-to-use interface and graphical displays of data and analysis results. Mplus allows the analysis of both cross-sectional and longitudinal data, single-level and multilevel data, data that come from different populations with either observed or unobserved heterogeneity, and data that contain missing values. Analyses can be carried out for observed variables that are continuous, censored, binary, ordered categorical (ordinal), unordered categorical (nominal), counts, or combinations of these variable types. In addition, Mplus has extensive capabilities for Monte Carlo simulation studies, where data can be generated and analyzed according to any of the models included in the program.

� The Mplus modeling framework draws on the unifying theme of latent variables. The generality of the Mplus modeling framework comes from the unique use of both continuous and categorical latent variables.

Mplus Framework (1)

Background var. Outcome var.

Continuous Latent var.

Continuous

Categorical Latent var.

Categorical

Page 3: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

Mplus Framework (2)

กลุ(มเทคนิคทางสถิติท่ีสามารถวิเคราะหlได�ด�วย Mplus

ที่มา: สารบัญของคู(มือการใช�งานโปรแกรม Mplus 7

Page 4: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

การเปลี่ยนแปลงท่ีน(าสนใจใน Mplus Version 7

�Mplus Diagrammer�Bayesian estimators�Improvement of multiple group SEM�Three-level modeling�Improvement of missing data modeling

การทํางานของ Mplus

�+�= �Data file (*.dat)

1.Raw data (individual)2.Summary data (CorrelationCovariance)

Input file 1.*.inp (Command)2.*.dgm (Diagram)

Output file1.*.out (Command)2.*.mdg (Diagram)3.*.gh5 (Plot)

Page 5: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

The Mplus Language

แต)ละ Command อาจมี Options ย)อยๆ ลงไปอีกเพ่ือให:ผู:ใช:เลือกตามความเหมาะสม ผู:ศึกษานอกจากจะศึกษาจากตัวอย)างการส่ังงานแล:ว ในบทท่ี 15 – 20 ของคู)มือจะรวมคําส่ังและวิธีส่ังงานท้ังหมดไว: (บทท่ี 20 จะเปQนสรุปคําส่ังท้ังหมด)

วิธีศึกษาการใช�คําส่ัง Mplus ในคู(มือ

command

Options Default ถ�าผู�ใช�ไม(กําหนด

ทางเลือกต(างๆ

Page 6: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

หลักการเขียนคําส่ัง � คําส่ัง Data Variable เปuนคําส่ังบังคับต�องมีทุกครั้ง

� ทุกคําส่ังต�องขึ้นต�นบรรทัดใหม( และต�องตามด�วย : แล�วจึงเริ่มด�วยรายละเอียดแต(ละ Option ซ่ึงจะต(อในบรรทัดเดียวกันหรือขึ้นบรรทัดใหม(ก็ได�

� เม่ือจบแต(ละ Option ให�ปwดด�วย ; และจะต(อด�วย Option ต(อไปในบรรทัดเดียวกัน หรือขึ้นบรรทัดใหม(ก็ได� (ยกเว�นคําส่ัง title จบได�โดยไม(ต�องมี ;)

� ในหน่ึงบรรทัด จะมีความยาวได�ไม(เกิน 90 Columns

� หมายเหตุ หรือ บันทึกช(วยจําต(างๆ (comments) สามารถใส(ไว�ในไฟลlคําส่ังได� โดยขึ้นต�นด�วย !

� คําว(า IS, ARE, = สามารถใช�แทนกันได� ยกเว�นคําส่ัง Define, Model Constraint, Model test ซ่ึงต�องใช� = อย(างเดียว

� เคร่ืองหมาย – (Hyphen) ใช:ในการกล)าวถึงตัวแปรหลายๆ ตัวต)อกัน เช)น x1-x4 หรืออาจใช: All ถ:าต:องการใช:ทุกตัวแปร

� ในกรณีท่ีอ:างถึงตัวแปรหลายชุด อาจใช: , หรือการเว:นวรรค เช)น x1-x4, y1-y5 หรือ x1-x4 y1-y5

�สามารถใช:ตัวพิมพ[ใหญ) หรือตัวพิมพ[เล็กก็ได: และสามารถเว:นช)องว)างโดยใช: Tab ได:ด:วย

หลักการเขียนคําสั่ง (ต)อ)

Page 7: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

ตัวอย)างชุดคําส่ังใน Mplus

ชุดคําส่ังจัดการไฟล[ข:อมูลใน Mplus

� ประกอบไปด�วยคําสั่ง Title, Data, Variable, Define� Mplus จะทํางานกับไฟลlข�อมูลท่ีแยกออกไปต(างหาก ดังนั้น คําสั่ง Data

จึงต�องมี Option: Files is เสมอ� ไฟลlข�อมูลนั้น อาจเปuน Raw data ท้ังในรูป Free format, Fixed

format หรืออ่ืนๆ รวมท้ังในรูปของ Summary data เช(น Correlation matrix หรือ Covariance matrix เปuนต�น

� คําสั่ง Variable เปuนรายละเอียดเก่ียวกับตัวแปรท้ังหมดในไฟลlข�อมูล เช(น ช่ือตัวแปร ชนิดตัวแปร การเลือกใช�ตัวแปร รหัสบอดของตัวแปร ฯลฯ

� คําสั่ง Define เปuนการสร�างตัวแปรข้ึนใหม( จากการนําตัวแปรเดิมมาคํานวณทางคณิตศาสตรl

Page 8: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

ตัวอย(างชุดคําส่ังจัดการไฟลlข�อมูล

กรณี Raw data, Free format

กรณี Summary Data

Notepad (*.*) � Mplus (*.dat)

Page 9: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

ชุดคําส่ังเพ่ือการวิเคราะห[ข:อมูล

�ประกอบไปด:วยคําส่ัง Analysis และ Model� คําส่ัง Analysis เปQนคําส่ังกําหนดรูปแบบและวิธีการ

วิเคราะห[ท่ีไม)เปQนการท่ัวไป (general) ซึ่งจะแตกต)างกันไปในแต)ละเทคนิค

� ในบางกรณี ท่ีไม)มีคําส่ัง Analysis หมายความว)าใช:ตามท่ีโปรแกรมต้ังไว: (general)

� คําส่ัง Model เปQนคําส่ังอธิบายความสัมพันธ[ระหว)างตัวแปร ท่ีต:องการวิเคราะห[

ตัวอย)างคําส่ัง Analysis และ Model

Page 10: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

ชุดคําส่ังเก่ียวกับผลการวิเคราะห[

�ประกอบไปด�วยคําส่ัง Output, Savedata, Plot�ผู�วิจัยจะร�องขอผลการวิเคราะหl ว(าต�องการอะไรบ�างได�

จากคําส่ัง Output�เม่ือต�องการนําผลการวิเคราะหlไปทําอะไรต(อ ให�บันทึกไว�

ด�วยคําส่ัง Savedata�Mplus มีกราฟให�ด�วย แม�จะไม(สวยงามมากนัก แต(ก็มี

จํานวนมากให�เลือก ภายใต�คําส่ัง Plot

ตัวอย)าง (Crime.sav)� ผู:วิจัยสนใจว)า อัตราการเกิดคดีฆาตกรรมของเมืองต)างๆ จะ

มากหรือน:อยน้ันข้ึนอยู)เหตุปdจจัยใดบ:าง เขาได:ทําการสํารวจอัตราการเกิดคดีฆาตกรรม (murder rate) ต)อประชากร 100,000 คน ในแต)ละรัฐของสหรัฐอเมริกา รวมกับตัวแปรอิสระอ่ืนได:แก) อัตราส)วนของประชากรในเขตเมืองต)อประชากร 100,000 คน (metropol) สัดส)วนของประชากรที่เปQนคนผิวขาว (white) สัดส)วนของประชากรที่จบการศึกษาภาคบังคับ (graduate) สัดส)วนของครัวเรือนที่มีรายได:ต่ํากว)าเส:นความยากจน (poverty) และ สัดส)วนของครอบครัวท่ีเลี้ยงดูบุตรโดยพ)อหรือแม) (single)

� เก็บข:อมูลมาทั้งส้ิน 50 รัฐ และทําการวิเคราะห[ด:วย Multiple regression analysis

Page 11: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

โครงสร:างข:อมูลในไฟล[ crime.sav

การแปลงไฟล[ข:อมูล SPSS มาเปQน .dat (1)

Page 12: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

การแปลงไฟล[ข:อมูล SPSS มาเปQน .dat (2)

เลือก Folder ท่ีจะบันทึกไฟล[ลงไป

เลือกชนิดของไฟล[เปQน Tab delimitted (*.dat)

ไม)ให:บันทึกช่ือตัวแปรลงในไฟล[

การแปลงไฟล[ข:อมูล SPSS มาเปQน .dat (3)

ไฟล[ข:อมูลใหม)ท่ีเปmดด:วย Notepad

Page 13: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

คําสั่งใน Mplus vs. SPSS

SPSS

Mplus

ผลการวิเคราะหl (1)

ค(าสถิติพื้นฐาน

Page 14: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

กราฟหลายชนดิจากคาํส ั"ง Plot

ผลการวิเคราะหl (2)

จากตารางพบว(า ท่ีระดับนัยสําคัญทางสถิติ .05 ผลการทดสอบ ปฏิเสธ Null Hypothesis สรุปว(า ตัวแปรอิสระท้ัง 5 ตัว ร(วมกันพยากรณlอัตราการเกิดคดีฆาตกรรมในรัฐต(างๆ ได�อย(างมีนัยสําคัญทางสถิติระดับ .05

SPSS

Mplus

Page 15: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

ผลการวิเคราะห[ (3)

จากตาราง พบว�าตัวแปรอิสระท้ัง 5 ตัว ร�วมกันพยากรณ�อัตราการเกิดคดีฆาตกรรมในรัฐต�างๆ ได$มากถึง 81%

SPSS

Mplus

ผลการวิเคราะห[ (4)

SPSS

Mplus

ผลการทดสอบพบว�า ตัวแปร metropol, white, poverty, single ท่ีมีอิทธิพลต�ออัตราการเกิดคดีฆาตกรรม (murder) อย�างมีนัยสําคัญทางสถิติท่ีระดับ .05 ส�วนตัวแปร graduate นั้นไม�มีอิทธิพลต�ออัตราการเกิดคดีฆาตกรรม

Page 16: Introduction to Mplus7 - ns2.ph.mahidol.ac.thns2.ph.mahidol.ac.th/phklb/knowledgefiles/Introduction_to_Mplus7.pdf · SPSS Mplus ผลการทดสอบพบวา ตัวแปร

แผนภาพจากคําส่ัง View Diagram