التباين المتغيرات الفئوية في فوركس ستاتا


إشعار: ستقوم مجموعة الاستشارات الإحصائية إدر بترحيل الموقع إلى نظام إدارة المحتوى في وردبريس في فبراير لتسهيل الصيانة وإنشاء محتوى جديد. ستتم إزالة بعض صفحاتنا القديمة أو وضعها في الأرشيف بحيث لا يتم الاحتفاظ بها بعد الآن. سنحاول الحفاظ على عمليات إعادة التوجيه بحيث تستمر عناوين ورل القديمة في العمل بأفضل ما في وسعنا. مرحبا بكم في معهد للبحوث الرقمية والتعليم مساعدة مجموعة الاستشارات الاستشارية من خلال إعطاء هدية الانحدار مع ستاتا الفصل 5 - أنظمة الترميز إضافية للمتغيرات الفئوية في تحليل الانحدار الفصل المخطط 5.1 الترميز بسيط 5.2 إلى الأمام الفرق الترميز 5.3 إلى الوراء الفرق الترميز 5.4 هلميرت الترميز 5.5 عكس هلمرت الترميز 5.6 الانحراف الترميز 5.7 متعامد متعدد الحدود الترميز 5.8 من قبل المستخدم الترميز 5.9 ملخص يرجى ملاحظة: هذه الصفحة يجعل من استخدام xi3 البرنامج الذي لم يعد الحفاظ عليه، وكان من أرشيفنا. سوف تترك الإشارات إلى xi3 في هذه الصفحة لأنها توضح مبادئ محددة لتشفير المتغيرات الفئوية. وتتطلب المتغيرات الفئوية اهتماما خاصا في تحليل الانحدار لأنه، على عكس المتغيرات الثنائية أو المستمرة، فإنها لا يمكن إدخالها في معادلة الانحدار تماما كما هي. على سبيل المثال، إذا كان لديك متغير يسمى العرق الذي تم ترميزه 1 اسباني، 2 الآسيوية 3 أسود 4 الأبيض، ثم دخول السباق في الانحدار الخاص بك سوف ننظر إلى التأثير الخطي للسباق، وهو على الارجح ليس ما كنت تقصد. وبدلا من ذلك، فإن المتغيرات الفئوية مثل هذا تحتاج إلى أن تكون مشفرة في سلسلة من المتغيرات التي يمكن بعد ذلك إدخالها في نموذج الانحدار. هناك مجموعة متنوعة من أنظمة الترميز التي يمكن استخدامها عند ترميز المتغيرات الفئوية. من الناحية المثالية، يمكنك اختيار نظام الترميز الذي يعكس المقارنات التي تريد أن تجعل. في الفصل 3 من الانحدار مع كتاب الويب ستاتا غطينا استخدام المتغيرات الفئوية في تحليل الانحدار مع التركيز على استخدام المتغيرات وهمية، ولكن هذا ليس هو نظام الترميز الوحيد الذي يمكنك استخدامه. على سبيل المثال، قد ترغب في مقارنة كل مستوى إلى المستوى الأعلى التالي، وفي هذه الحالة كنت ترغب في استخدام كودفوروارد ديفورسكوت الترميز، أو قد ترغب في مقارنة كل مستوى إلى متوسط ​​المستويات اللاحقة للمتغير، في هذه الحالة كنت ترغب في استخدام الترميز كوهلمرتكوت. عن طريق اختيار عمدا نظام الترميز، يمكنك الحصول على المقارنات التي هي الأكثر وضوحا لاختبار الفرضيات الخاصة بك. وبغض النظر عن نظام الترميز الذي تختاره، سيظل اختبار التأثير الكلي للمتغير الفئوي (أي التأثير العام للعرق) كما هو. في ما يلي جدول يبين أنواع مختلفة من التناقضات والمقارنة التي تجريها. اسم التباين يقارن كل مستوى من المتغيرات إلى المستوى المرجعي المستويات المجاورة للمتغير (كل مستوى ناقص المستوى التالي) المستويات المتجاورة للمتغير (كل مستوى ناقص المستوى السابق) قارن مستويات المتغير بمتوسط ​​اللاحقة مستويات المتغير يقارن مستويات متغير بمتوسط ​​المستويات السابقة للمتغير يقارن الانحرافات عن متوسط ​​التباين المتعدد الحدود المتعامد الكبير هناك بضع ملاحظات ينبغي أن يتم إجراؤها حول أنظمة الترميز المذكورة أعلاه. الأول هو أنها تمثل المقارنات المخطط لها وليس المقارنات بعد. وبعبارة أخرى، فهي مقارنات تنوي القيام بها قبل البدء في تحليل البيانات الخاصة بك، وليس المقارنات التي تفكر بها بمجرد أن ترى نتائج التحليلات الأولية. أيضا، بعض أشكال الترميز أكثر منطقية مع المتغيرات الفئوية الترتيبية من مع المتغيرات الفئوية الاسمية. سنعرض فيما يلي أمثلة باستخدام السباق كمتغير فئوي، وهو متغير اسمي. ولأن تشفير التأثير البسيط يقارن متوسط ​​المتغير التابع لكل مستوى من المتغيرات الفئوية إلى متوسط ​​المتغير التابع في المستوى المرجعي، يكون من المنطقي وجود متغير اسمي. ومع ذلك، قد لا يجعل من المنطقي استخدام مخطط الترميز الذي يختبر التأثير الخطي للعرق. كما أننا تصف كل نوع من أنواع نظام الترميز، نلاحظ تلك النظم الترميز التي لا يجعل من المنطقي استخدام المتغير الاسمي. أيضا، قد تلاحظ أننا نتبع عدة قواعد عند إنشاء مخططات الترميز التباين. لمزيد من المعلومات حول هذه القواعد، يرجى الاطلاع على القسم المتعلق بتشفير المستخدم. ستوضح هذه الصفحة طريقتين يمكنك من خلالها إجراء التحليلات باستخدام مخططات الترميز هذه: 1) استخدام الأمر xi3 (إصدار موسع من الأمر إكسي) و 2) ترميز المتغيرات يدويا وإدخالها باستخدام الأمر ريجريس. عند استخدام التراجع للقيام التناقضات، تحتاج أولا إلى إنشاء k-1 المتغيرات الجديدة (حيث k هو عدد مستويات المتغير الفئوية) واستخدام هذه المتغيرات الجديدة كما التنبؤات في نموذج الانحدار الخاص بك. ملف بيانات مثال الأمثلة في هذه الصفحة سوف تستخدم مجموعة البيانات تسمى hsb2.dta التي يمكنك تحميل من داخل ستاتا مثل هذا. ضمن ملف البيانات هذا، سوف نركز على السباق المتغير الفئوية. التي لديها أربعة مستويات (1 الإسباني، 2 الآسيوية، 3 الأمريكيين الأفارقة و 4 الأبيض)، وسوف نستخدم الكتابة كمتغير التابع لدينا. على الرغم من أن مثالنا يستخدم متغيرا مع أربعة مستويات، تعمل أنظمة الترميز هذه مع المتغيرات التي تحتوي على فئات أكثر أو أقل. بغض النظر عن نظام الترميز الذي تحدده، سيكون لديك دائما متغيرات أقل مشفر واحد من مستويات المتغير الأصلي. في مثالنا، لدينا متغير فئوي أربعة مستويات لذلك سيكون لدينا ثلاثة متغيرات جديدة (متغير المقابلة للمستوى النهائي للمتغيرات الفئوية ستكون زائدة عن الحاجة، وبالتالي لا لزوم لها). قبل النظر في أي تحليلات، دعونا ننظر إلى متوسط ​​المتغير التابع، والكتابة. لكل مستوى من السباق. وهذا سوف يساعد في تفسير الناتج من التحليلات في وقت لاحق. وتتشابه نتائج التشفير البسيط جدا مع التشفير الوهمي في أن كل مستوى يقارن بالمستوى المرجعي. في المثال التالي، المستوى 1 هو المستوى المرجعي والمقارنة الأولى يقارن المستوى 2 إلى المستوى 1، المقارنة الثانية تقارن المستوى 3 إلى المستوى 1، والمقارنة الثالثة تقارن المستوى 4 إلى المستوى 1. الطريقة الأولى: استخدام xi3 عند استخدام xi3. يمكننا أن نشير إلى g. race للإشارة إلى أننا نود أن نسجل السباق باستخدام ترميز بسيط يقارن كل مجموعة بمجموعة مرجعية، كما هو مبين في المثال أدناه. يقارن معامل Irace2 متوسط ​​المتغير التابع، يكتب. بالنسبة للمستويين 2 و 1 التي تنتج 58-46.458 11.54 وهي ذات دلالة إحصائية (plt.000). يقارن معامل Irace3 متوسط ​​المتغير التابع، يكتب. بالنسبة للمستويين 3 و 1، مما يسفر عن 48.2 - 46.46 1.74، وهذا ليس ذو دلالة إحصائية. وأخيرا، يقارن معامل Irace4 متوسط ​​المتغير التابع، يكتب. بالنسبة للمستويين 4 و 1، مما يسفر عن 7.59، وهذا ذو دلالة إحصائية. الطريقة 2: الترميز اليدوي إذا كنا نتمنى، يمكننا يدويا رمز سباق بدلا من السماح xi3 للقيام الترميز بالنسبة لنا. ونرى أدناه الترميز الذي يكرر النتائج التي شاهدناها في المثال أعلاه. وفي التشفير أدناه، يكون المستوى 1 هو المستوى المرجعي ويقارن x1 بين المستوى 2 والمستوى 1، ويقارن x2 بين المستوى 3 والمستوى 1، ويقارن x3 بين المستوى 4 والمستوى 1. وبالنسبة إلى x1، يكون التشفير 34 بالنسبة للمستوى 2، و 14 لجميع المستويات الأخرى. وبالمثل، بالنسبة إلى x2، يكون التشفير 34 بالنسبة للمستوى 2، و -14 لجميع المستويات الأخرى، وبالنسبة إلى x3، يكون التشفير 34 للمستوى 3، و -14 لجميع المستويات الأخرى. ليس من البديهي أن هذا المخطط الترميز الانحدار ينتج هذه المقارنات ومع ذلك، إذا كنت ترغب في مقارنات بسيطة، يمكنك اتباع هذه القاعدة العامة للحصول على هذه المقارنات. سيمبل ريبرسيون كودينغ متغير جديد 1 (x1) متغير جديد 2 (x2) نوضح أدناه كيفية إنشاء x1. x2 و x3 وأدخل هذه المتغيرات الجديدة في نموذج الانحدار باستخدام الأمر الانحدار. كما ترون، فإن النتائج أدناه تطابق تلك عندما استخدمنا الأمر xi3 أعلاه. وفي نظام الترميز هذا، يقارن متوسط ​​المتغير التابع لمستوى واحد من المتغير الفاصل مع متوسط ​​المتغير التابع للمستوى التالي (المجاور). في المثال التالي، تقارن المقارنة الأولى متوسط ​​الكتابة للمستوى 1 مع متوسط ​​الكتابة للمستوى 2 من السباق (الإسبانيون ناقص الآسيويين). المقارنة الثانية تقارن متوسط ​​الكتابة للمستوى 2 ناقص المستوى 3، والمقارنة الثالثة تقارن متوسط ​​الكتابة للمستوى 3 ناقص المستوى 4. وقد يكون هذا النوع من الترميز مفيدا إما بمتغير اسمي أو متغير. الطريقة 1: استخدام xi3 يمكننا أن نشير إلى أننا نريد إلى الأمام الاختلاف المجاورة الترميز للسباق عن طريق تحديد a. race كما هو مبين أدناه. مع هذا النظام الترميز، تتم مقارنة المستويات المجاورة للمتغير الفئوية. وبالتالي، يقارن متوسط ​​المتغير التابع في المستوى 1 بمتوسط ​​المتغير التابع عند المستوى 2: 46.4583 - 58 -11.542، وهو ذو دلالة إحصائية. وللمقارنة بين المستويين 2 و 3، يكون حساب معامل التباين 58 - 48.2 9.8، وهو أيضا ذو دلالة إحصائية. وأخيرا، مقارنة مستويات 3 و 4، 48.2 - 54.0552 -5.855، وهو فرق ذو دلالة إحصائية. ويستنتج المرء أن كل مستوى متجانس من العرق يختلف إحصائيا اختلافا كبيرا. الطريقة 2: الترميز اليدوي للمقارنة الأولى، حيث تتم مقارنة المستويين الأول والثاني، يتم ترميز x1 34 للمستوى 1 ويتم ترميز المستويات الأخرى -14. للمقارنة الثانية حيث يتم مقارنة المستوى 2 مع المستوى 3، يتم ترميز x2 12 12 -12 -12، وللمقارنة الثالثة حيث يتم مقارنة المستوى 3 مع المستوى 4، يتم ترميز x3 14 14 14 -34. فواروارد ديفيرانس ريفرسيون كودينغ متغير جديد 1 (x1) متغير جديد 2 (x2) يمكنك ان ترى معامل الانحدار ل x1 هو متوسط ​​الكتابة للمستوى 1 (اسباني) ناقص متوسط ​​الكتابة للمستوى 2 (آسيوي). وبالمثل، فإن معامل الانحدار ل x2 هو متوسط ​​الكتابة للمستوى 2 (آسيوي) مطروحا منه متوسط ​​الكتابة للمستوى 3 (أمريكان أفريكان)، ومعامل الانحدار ل x3 هو متوسط ​​الكتابة للمستوى 3 (أفريكان أمريكان) ناقص متوسط ​​الكتابة للمستوى 4 (أبيض). وفي نظام التشفير هذا، يقارن متوسط ​​المتغير التابع لمستوى واحد من المتغير الفئوي بمتوسط ​​المتغير التابع للمستوى المجاور السابق. في المثال التالي، تقارن المقارنة الأولى متوسط ​​الكتابة للمستوى 2 بمتوسط ​​الكتابة للمستوى 1 من السباق (من أصل إسباني ناقص الآسيويين). تقارن المقارنة الثانية متوسط ​​الكتابة للمستوى 3 ناقص المستوى 2، والمقارنة الثالثة تقارن متوسط ​​الكتابة للمستوى 4 ناقص المستوى 3. وقد يكون هذا النوع من الترميز مفيدا إما بتغير اسمي أو متغير. الأسلوب 1: استخدام xi3 يمكننا أن نشير إلى أننا نريد الاختلاف الفرق إلى الخلف للسباق عن طريق تحديد b. race كما هو مبين أدناه. مع هذا النظام الترميز، تتم مقارنة المستويات المجاورة للمتغير الفئوية، مع كل مستوى مقارنة مع المستوى السابق. وبالتالي، يقارن متوسط ​​المتغير التابع في المستوى 2 بمتوسط ​​المتغير التابع عند المستوى 1: 58-46.4583 11.542، وهو ذو دلالة إحصائية. للمقارنة بين المستويات 3 و 2، نحسب 48.2 - 58 -9.8، وهو أيضا ذو دلالة إحصائية. وأخيرا، مقارنة مستويات 4 و 3، 54.0552 - 48.2 5.855، وهو فرق ذو دلالة إحصائية. ويستنتج المرء أن كل مستوى متجانس من العرق يختلف إحصائيا اختلافا كبيرا. الطريقة 2: الترميز اليدوي للمقارنة الأولى، حيث تتم مقارنة المستويين الأول والثاني، يتم ترميز x1 34 للمستوى 1 بينما يتم ترميز المستويات الأخرى -14. للمقارنة الثانية حيث يتم مقارنة المستوى 2 مع المستوى 3، يتم ترميز x2 12 12 -12 -12، وللمقارنة الثالثة حيث يتم مقارنة المستوى 3 مع المستوى 4، يتم ترميز x3 14 14 14 -34. تشفير الانحدار الخلفي الاختلاف متغير جديد 1 (x1) متغير جديد 2 (x2) في المثال أعلاه، معامل الانحدار لل x1 هو متوسط ​​الكتابة للمستوى 2 ناقص متوسط ​​الكتابة للمستوى 1 (58- 46.4583 11.542). وبالمثل، فإن معامل الانحدار ل x2 هو متوسط ​​الكتابة للمستوى 3 ناقص متوسط ​​الكتابة للمستوى 2، ومعامل الانحدار ل x3 هو متوسط ​​الكتابة للمستوى 4 ناقص متوسط ​​الكتابة للمستوى 3. يقارن ترميز هلميرت كل مستوى من المتغيرات الفئوية إلى متوسط ​​المستويات اللاحقة. وبالتالي، يقارن التباين الأول متوسط ​​المتغير التابع للمستوى 1 من العرق مع متوسط ​​كل المستويات اللاحقة للعرق (المستويات 2 و 3 و 4)، ويقارن التباين الثاني متوسط ​​المتغير التابع للمستوى 2 من السباق بمتوسط ​​كل المستويات اللاحقة من السباق (المستويين 3 و 4)، ويقارن التباين الثالث متوسط ​​المتغير التابع للمستوى 3 من السباق بمتوسط ​​كل المستويات اللاحقة للعرق (المستوى 4). في حين أن هذا النوع من نظام الترميز لا معنى له مع متغير اسمي مثل العرق. فإنه من المفيد في الحالات التي يتم فيها ترتيب مستويات المتغير الفئوية، من الأدنى إلى الأعلى، أو الأصغر إلى الأكبر، إلخ. الأسلوب 1: استخدام xi3 يمكننا تحديد الترميز هلميرت للسباق باستخدام h. race كما هو موضح أدناه. ويحسب معامل الانحدار للمقارنة بين المستوى 1 والمستويات المتبقية بأخذ متوسط ​​المتغير التابع للمستوى 1 وطرح متوسط ​​المتغير التابع للمستويات 2 و 3 و 4: 46.4583 - (58 48.2 54.0552) 3 -6.960، وهو ذو دلالة إحصائية. وهذا يعني أن متوسط ​​الكتابة للمستوى 1 من السباق يختلف إحصائيا عن متوسط ​​الكتابة للمستويات من 2 إلى 4. وكما ذكر أعلاه، فإن هذه المقارنة ربما لا تكون ذات معنى لأن السباق المتغير إسمي. هذا النوع من المقارنة سيكون أكثر وضوحا إذا كان المتغير الفئوي ترتيبي. لحساب معامل التباين للمقارنة بين المستوى 2 والمستويات اللاحقة، تطرح متوسط ​​المتغير التابع للمستويين 3 و 4 من متوسط ​​المتغير التابع للمستوى 2: 58 - (48.2 54.0552) 2 6.872، ذو دلالة إحصائية. معامل الانحدار للمقارنة بين المستوى 3 والمستوى 4 هو الفرق بين متوسط ​​المتغير التابع للمستويين: 48.2 - 54.0552 -5.855، وهو أيضا ذو دلالة إحصائية. الطريقة 2: الترميز اليدوي أدناه نرى مثالا على ترميز الانحدار هيلميرت. للمقارنة الأولى (مقارنة المستوى 1 مع المستويات 2 و 3 و 4) الرموز هي 34 و -14 -14 -14. المقارنة الثانية تقارن المستوى 2 مع المستويين 3 و 4 ويتم ترميزها 0 23 -13 -13. المقارنة الثالثة يقارن المستوى 3 إلى المستوى 4 ويتم ترميزه 0 0 12 -12. هلمرت الانحدار الترميز جديد متغير 1 (x1) متغير جديد 2 (x2) أدناه نحن توضيح كيفية إنشاء x1. x2 و x3 وأدخل هذه المتغيرات الجديدة في نموذج الانحدار باستخدام الأمر الانحدار. كما ترى أعلاه، معامل الانحدار ل x1 هو متوسط ​​الكتابة للمستوى 1 (الإسباني) مقابل جميع المستويات اللاحقة (المستويات 2 و 3 و 4). وبالمثل، معامل الانحدار ل x2 هو متوسط ​​الكتابة للمستوى 2 ناقص متوسط ​​الكتابة للمستويين 3 و 4. وأخيرا، معامل الانحدار ل x3 هو متوسط ​​الكتابة للمستوى 3 ناقص متوسط ​​الكتابة للمستوى 4. عكس ترميز هلمرت (يعرف أيضا بتشفير الفرق) هو عكس عكس ترميز هلميرت: بدلا من مقارنة كل مستوى من المتغيرات الفئوية إلى متوسط ​​المستوى (المستويات) اللاحقة، يقارن كل منها بمتوسط ​​المستوى السابق (المستويات) . في مثالنا، فإن التباين الأول يقارن المقارنة بين متوسط ​​المتغير التابع للمستوى 2 من السباق إلى متوسط ​​المتغير التابع للمستوى 1 من السباق. المقارنة الثانية تقارن متوسط ​​مستوى المتغير التابع 3 للعرق مع المستويين 1 و 2 من السباق. والمقارنة الثالثة تقارن متوسط ​​المتغير التابع للمستوى 4 من السباق مع المستويات 1 و 2 و 3. ومن الواضح أن نظام الترميز هذا لا يكون له معنى كبير مع مثالنا للعرق لأنه متغير اسمي. ومع ذلك، فإن هذا النظام مفيد عندما يتم ترتيب مستويات المتغير الفئوية بطريقة هادفة. على سبيل المثال، إذا كان لدينا متغير فئوي حيث تم ترميز الإجهاد المرتبط بالعمل على أنه منخفض أو متوسط ​​أو مرتفع، فإن مقارنة وسائل المستويات السابقة للمتغير ستكون أكثر منطقية. الأسلوب 1: استخدام xi3 يمكننا تحديد هلميرت الترميز للسباق باستخدام r. race كما هو مبين أدناه. وقد تم حساب معامل الانحدار للمقارنة الأولى المبينة في هذا الإنتاج بطرح متوسط ​​المتغير التابع للمستوى 2 للمتغير الفاصل من متوسط ​​المتغير التابع للمستوى 1: 58 - 46.4583 11.542. هذه النتيجة ذات دلالة إحصائية. تم حساب معامل الانحدار للمقارنة الثانية (بين المستوى 3 والمستويات السابقة) بطرح متوسط ​​المتغير التابع للمستويين 1 و 2 من المستوى 3: 48.2 - (46.4583 58) 2 -4.029. هذه النتيجة ليست ذات دلالة إحصائية، وهذا يعني أنه لا يوجد فرق يمكن الاعتماد عليه بين متوسط ​​الكتابة للمستوى 3 من السباق مقارنة بمتوسط ​​الكتابة للمستويين 1 و 2 (من أصل هسباني وآسيوي). وكما ذكر أعلاه، فإن هذا النوع من نظام التشفير لا يكون له معنى كبير لمتغير اسمي مثل العرق. لمقارنة المستوى 4 والمستويات السابقة، تأخذ متوسط ​​المتغير التابع لتلك المستويات وطرحه من متوسط ​​المتغير التابع للمستوى 4: 54.0552 - (46.4583 58 48.2) 3 3.169. هذه النتيجة ذات دلالة إحصائية. الطريقة 2: الترميز اليدوي يبين التشفير الانحداري لترميز هلميرت العكسي أدناه. للمقارنة الأولى، حيث يتم مقارنة المستوى الأول والثاني، يتم ترميز x1 -12 و 12 و 0 خلاف ذلك. للمقارنة الثانية، يتم تشفير قيم x2 -13 -13 23 و 0. وأخيرا، للمقارنة الثالثة، يتم ترميز قيم x3 -14 -14 -14 و 34. ريفيرز هلمرت الانحدار الترميز متغير جديد 1 (x1 ) جديد متغير 2 (x2) أدناه نحن توضيح كيفية إنشاء x1. x2 و x3 وأدخل هذه المتغيرات الجديدة في نموذج الانحدار باستخدام الأمر ريجريس. في المثال أعلاه، معامل الانحدار ل x1 هو متوسط ​​الكتابة للمستوى 1 (اسباني) ناقص متوسط ​​الكتابة للمستوى 2 (آسيوي). وبالمثل، معامل الانحدار ل x2 هو متوسط ​​الكتابة للمستويين 1 و 2 مجتمعة ناقص متوسط ​​الكتابة للمستوى 3. وأخيرا، معامل الانحدار ل x3 هو متوسط ​​الكتابة للمستويات 1 و 2 و 3 مجتمعة ناقص المتوسط من الكتابة للمستوى 4. يقارن نظام الترميز هذا متوسط ​​المتغير التابع لمستوى معين لمتوسط ​​المتغير التابع لكل مستويات المتغير. في المثال التالي، تقارن المقارنة الأولى المستوى الثاني (الآسيويين) بجميع مستويات العرق. والثاني يقارن المستوى 3 (الأمريكيين الأفارقة) على جميع مستويات العرق. والمقارنة الثالثة يقارن المستوى 4 (الأبيض) إلى جميع مستويات العرق. الطريقة 1: استخدام xi3 نوضح أننا نود أن يتم ترميز السباق باستخدام الترميز تأثير الانحراف باستخدام e. race كما هو مبين أدناه. معامل الانحدار ل Irace2 هو متوسط ​​للمستوى 2 ناقص المتوسط ​​الكبير. ومع ذلك، فإن هذا المتوسط ​​الكبير ليس المتوسط ​​العام للمتغير التابع الذي ستحصل عليه من الأمر الموجز. بدلا من ذلك، هو متوسط ​​وسائل المتغير التابع في كل مستوى من المتغيرات الفئوية: (46.4583 58 48.2 54.0552) 4 51.678375. هذا معامل الانحدار هو ثم 58 - 51.678375 6.32. وبالمثل، فإن معامل Irace3 هو متوسط ​​المستوى 3 للعرق ناقص المتوسط ​​العام، أي 48.2 - 51.678 -3.47، و Irace4 هو متوسط ​​المستوى 4 للعرق ناقص المتوسط ​​العام، 54.055 - 51.678 2.37. الطريقة 2: الترميز اليدوي كما تراه في المثال أدناه، يتم إنجاز تشفير الانحدار بتخصيص 1 إلى المستوى 2 للمقارنة الأولى (لأن المستوى 2 هو المستوى الذي ينبغي مقارنته بكل ذلك)، والمستوى 1 إلى المستوى 3 للثانية (لأن المستوى 3 يجب مقارنته بالكل)، و 1 إلى المستوى 4 للمقارنة الثالثة (لأن المستوى 4 يجب مقارنته بكل شيء). وتجدر الإشارة إلى أن القيمة -1 تعين للمستوى 1 بالنسبة إلى المقارنات الثلاثة (لأنها المستوى الذي لا يقارن أبدا بالمستويات الأخرى) وتخصص جميع القيم الأخرى 0. ويؤدي مخطط تشفير الانحدار إلى إجراء المقارنات الموصوفة أعلاه. تشفير الانحدار بالانقسام متغير جديد 1 (x1) متغير جديد 2 (x2) الطريقة 1: استخدام xi3 نشير إلى أننا نود أن يتم ترميز السباق باستخدام متعددو الحدود المتعامدة باستخدام o. race كما هو موضح أدناه. المتغيرات الثلاثة المشفرة، Irace1. Irace2 و Irace3. تمثل الاتجاهات الخطية، التربيعية والمكعبة على التوالي. وبطبيعة الحال، فإن مصطلح الاتجاه لا معنى له إذا كان المتغير الاسمي، مثل العرق. ولكن إذا كنا ندعي أن السباق هو ترتيبي من أن يكون هناك اتجاه خطي ومكعب كبير. كما أنه من السهل لاختبار الاتجاه غير الخطية. اختبار الاتجاه غير الخطية ذو دلالة إحصائية. هذا المثال عملت بخير لإظهار كيفية استخدام xi3 ولكن نحن بحاجة إلى مثال أمر يمكن تفسيرها. سنقوم بإنشاء متغير الفئوية الخاصة بنا، ريادكات. من المتغير المستمر قراءة. الآن يمكننا تشغيل الانحدار مع xi3. ونحن نرى من Ireadcat1 كبير أن الاتجاه الخطي كبير بينما لا الاتجاهات التربيعية ولا مكعب (Ireadcat2 أمبير Ireadcat3) كبيرة. اختبار الاتجاه غير الخطية هو أيضا غير هام. الطريقة 2: الترميز اليدوي يمكنك استخدام الأمر xi3 لإنشاء نظام الترميز الانحدار الخاص بك. على سبيل المثال، سنقوم بإجراء المقارنات الثلاثة التالية: 1) المستوى 1 إلى المستوى 3 2) المستوى 2 إلى المستويين 1 و 4 3) المستويات 1 و 2 إلى المستويين 3 و 4. من أجل المقارنة بين المستوى 1 والمستوى 3، فإننا نستخدم معاملات التباين 1 0 -1 0. وللمقارنة بين المستوى 2 والمستويين 1 و 4 نستخدم معاملات التباين -12 1 0 -12 وأخيرا، وللمقارنة بين المستويين 1 و 2 مع المستويين 3 و 4 نستخدم المعامل 12 12 -12 -12. قبل الشروع في رمز ستاتا اللازمة لإجراء هذه التحليلات، دعونا نأخذ لحظة لشرح كامل المنطق وراء اختيار هذه المعاملات التباين. بالنسبة إلى التباين الأول، فإننا نقارن المستوى 1 إلى المستوى 3، وتكون معاملات التباين 1 0 -1 0. وهذا يعني أن المستويات المرتبطة بمعاملات التباين مع العلامات المعاكسة يجري مقارنتها. في الواقع، يتم ضرب متوسط ​​المتغير التابع في معامل التباين. وبالتالي، لا تشارك المستويات 2 و 4 في المقارنة: يتم ضربها بالصفر و كوتدروبد out. quot ستلاحظ أيضا أن معاملات التباين مجموع إلى الصفر. هذا مهم. إذا كانت معاملات التباين لا تصل إلى الصفر، فإن التباين غير قابل للتقدير وستصدر ستاتا رسالة خطأ. أي مستوى من المتغير الفئوي يتم تعيين قيمة موجبة أو سالبة ليست مهمة بشكل كبير: 1 0 -1 0 هو نفس -1 0 1 0 في أن كلا من هذه الترميزات مقارنة المستويين الأول والثالث للمتغير. ومع ذلك، فإن علامة معامل الانحدار ستتغير. الآن دعونا ننظر إلى معاملات التباين للمقارنات الثانية والثالثة. ستلاحظ أنه في كلتا الحالتين نستخدم الكسور التي مجموع واحد (أو ناقص واحد). ليس لديهم لتلخيص واحد (أو ناقص واحد). قد تتساءل لماذا نستخدم الكسور مثل -12 1 0 -12 بدلا من الأرقام الكاملة مثل -1 2 0 -1. في حين أن -12 1 0 -12 و -1 2 0 -1 على حد سواء مقارنة المستوى 2 مع المستويات 1 و 4 وكلاهما سوف تعطيك نفس القيمة t و p - قيمة لمعامل الانحدار، معاملات الانحدار نفسها ستكون مختلفة، وكذلك تفسيرها. معامل التباين -12 1 0 -12 هو متوسط ​​المستوى 2 ناقص متوسط ​​وسائل المستويات 1 و 4: 58 - (46.4583 54.0552) 2 7.74325. (بدلا من ذلك، يمكنك مضاعفة التناقضات بمتوسط ​​المتغير التابع لكل مستوى من المتغيرات الفئوية: -1246.4583 158.00 048.20 -1254.0552 7.74325. ومن الواضح أن هذه طرق مماثلة للتفكير في كيفية حساب معامل التباين). وبالمقارنة، فإن معامل التباين -1 2 0 -1 يكون مرتين في المتوسط ​​بالنسبة للمستوى 2 مطروحا منه متغير المتغير التابع للمستويين 1 و 4: 258 - (46.4583 54.0552) 15.4865، وهو نفس الرقم -146.4583 258 048.20 - 154.0552 15.4865. لاحظ أن معامل الانحدار باستخدام معاملات التباين -1 2 0 -1 هو ضعف معامل الانحدار الذي تم الحصول عليه عند -12 1 0 -12 يستخدم. الطريقة الأولى: استخدام xi3 نستخدم الأمر شار للإشارة إلى معاملات التباين التي سيتم استخدامها للسباق كما هو موضح أدناه. من أجل مقارنة المستوى 1 إلى المستوى 3، نستخدم معاملات التباين 1 0 -1 0. لمقارنة المستوى 2 إلى المستويين 1 و 4 نستخدم معاملات التباين -12 1 0 -12 وأخيرا، لمقارنة المستويات 1 و 2 مع مستويات 3 و 4، ونحن نستخدم معاملات 12 12 -12 -12. يتم استخدام هذه المعاملات في الأمر شار سبيسيوسر أدناه. وهذا يدل على أنه بالنسبة للعرق الذي يعرفه التباين الذي يعرفه المستخدم بأنه يحتوي على ثلاثة تباينات (لأن السباق له أربعة مستويات) (1 0 -1 0 -،5 1 0 -5 .5 .5 -5 -5). معامل Irace1 يتوافق مع التباين الأول مقارنة المستوى 1 إلى المستوى 3 من السباق. والمعامل هو متوسط ​​المستوى 1 من الكتابة ناقص المتوسط ​​للمستوى 3 من الكتابة. وأهمية هذا هو .525، أي ليست كبيرة. معامل Irace2 هو 7.743، وهو متوسط ​​المستوى 2 ناقص متوسط ​​المستوى 1 والمستوى 4، وهذا الفرق كبير، p 0.008. معامل الانحدار النهائي هو 1.1 وهو متوسط ​​المستويين 1 و 2 مطروحا منه متوسط ​​المستويين 3 و 4، وهذا التباين غير ذو دلالة إحصائية، p. 576. الطريقة 2: الترميز اليدوي كما في الأمثلة السابقة، سنقوم بإجراء المقارنات الثلاثة التالية: 1) المستوى 1 إلى المستوى 3، 2) من المستوى 2 إلى المستويين 1 و 4 و 3) المستويات 1 و 2 إلى المستويين 3 و 4. xi3 تحويل الترميز التباين في الترميز الانحدار بالنسبة لنا. ومع ذلك، يمكننا أن نفعل هذه العملية يدويا أيضا. بالنسبة للطرق 1 و 2 كان من السهل جدا ترجمة المقارنات التي أردنا أن نجعلها في الترميزات المتباينة، ولكن ليس من السهل ترجمة المقارنات التي نريدها في نظام ترميز الانحدار. إذا كنا نعرف نظام الترميز التباين، ثم يمكننا تحويل ذلك إلى نظام الترميز الانحدار باستخدام برنامج ستاتا هو مبين أدناه. كما ترون، نضع الترميزات التباين الثلاثة نريد في المصفوفة ج ثم تنفيذ مجموعة من عمليات المصفوفة على ج، مما أسفر عن المصفوفة س. ثم نعرض x باستخدام أمر الطباعة. هذا تحويل الترميز التباين في الترميز الانحدار التي نحتاجها لتشغيل هذا التحليل مع القيادة ريجريس. أدناه، نستخدم أوامر توليد واستبدال لإنشاء X1. x2 و x3 وفقا للترميز الموضح أعلاه ثم إدخالها في تحليل الانحدار. كما ترون، نتائج هذا التحليل تطابق تلك المنتجة باستخدام xi3. 5.9 ملخص وصفت هذه الصفحة عددا من أنظمة الترميز المختلفة التي يمكنك استخدامها للبيانات الفئوية، واستراتيجيتين مختلفتين يمكنك استخدامهما لإجراء التحليلات. يمكنك اختيار نظام الترميز الذي يعطي المقارنات التي هي الأكثر منطقية لاختبار الفرضيات الخاصة بك. بين الاستراتيجيتين (xi3 والترميز اليدوي)، يمكنك أن ترى أن xi3 بأتمتة عملية إنشاء الترميز، ولكن هذا يتخلى عن قدر معين من السيطرة. إذا أردت، يمكنك استخدام الترميز اليدوي الذي يمنحك المزيد من السيطرة على خلق الترميز للمتغيرات، ولكن قد تكون أكثر شاقة ومملة. بشكل عام، نوصي باستخدام أسهل طريقة لتحقيق أهدافك. 5.10 معلومات إضافیة فیما یلي بعض الموارد الإضافیة. ملاحظة: ستقوم مجموعة إدر للاستشارات الإحصائیة بترحیل الموقع الإلکتروني إلی نظام ووردبريس كمس في فبرایر لتسھیل الصیانة وإنشاء محتوى جدید. ستتم إزالة بعض صفحاتنا القديمة أو وضعها في الأرشيف بحيث لا يتم الاحتفاظ بها بعد الآن. سنحاول الحفاظ على عمليات إعادة التوجيه بحيث تستمر عناوين ورل القديمة في العمل بأفضل ما في وسعنا. مرحبا بكم في معهد للبحوث الرقمية والتعليم مساعدة المجموعة الاستشارية الاستشارية من خلال إعطاء هدية الانحدار مع ساس الفصل 5: أنظمة الترميز إضافية للمتغيرات الفئوية في تحليل الانحدار الفصل المخطط 5.1 الترميز بسيط 5.2 إلى الأمام الفرق الترميز 5.3 إلى الوراء الفرق الترميز 5.4 هيلمير الترميز 5.5 عكس هلمرت الترميز 5.6 الانحراف الترميز 5.7 ترميز متعدد الحدود متعامد 5.8 ترميز المعرفة من قبل المستخدم 5.9 ملخص تتطلب المتغيرات الفئوية اهتماما خاصا في تحليل الانحدار لأنه، على عكس المتغيرات ثنائية التفرع أو المستمر، فإنها لا يمكن إدخالها في معادلة الانحدار تماما كما هي. على سبيل المثال، إذا كان لديك متغير يسمى العرق الذي تم ترميزه 1 اسباني، 2 الآسيوية 3 أسود 4 الأبيض، ثم دخول السباق في الانحدار الخاص بك سوف ننظر إلى التأثير الخطي للسباق، وهو على الارجح ليس ما كنت تقصد. وبدلا من ذلك، فإن المتغيرات الفئوية مثل هذا تحتاج إلى أن تكون مشفرة في سلسلة من المتغيرات التي يمكن بعد ذلك إدخالها في نموذج الانحدار. هناك مجموعة متنوعة من أنظمة الترميز التي يمكن استخدامها عند ترميز المتغيرات الفئوية. من الناحية المثالية، يمكنك اختيار نظام الترميز الذي يعكس المقارنات التي تريد أن تجعل. في الفصل 3 من الانحدار مع ساس ويب بوك غطينا استخدام المتغيرات الفئوية في تحليل الانحدار مع التركيز على استخدام المتغيرات وهمية، ولكن هذا ليس هو نظام الترميز الوحيد الذي يمكنك استخدامه. على سبيل المثال، قد ترغب في مقارنة كل مستوى إلى المستوى الأعلى التالي، وفي هذه الحالة كنت ترغب في استخدام كودفوروارد ديفورسكوت الترميز، أو قد ترغب في مقارنة كل مستوى إلى متوسط ​​المستويات اللاحقة للمتغير، في هذه الحالة كنت ترغب في استخدام الترميز كوهلمرتكوت. عن طريق اختيار عمدا نظام الترميز، يمكنك الحصول على المقارنات التي هي الأكثر وضوحا لاختبار الفرضيات الخاصة بك. وبغض النظر عن نظام الترميز الذي تختاره، سيظل اختبار التأثير الكلي للمتغير الفئوي (أي التأثير العام للعرق) كما هو. في ما يلي جدول يبين أنواع مختلفة من التناقضات والمقارنة التي تجريها. اسم التباين يقارن كل مستوى من المتغيرات إلى المستوى المرجعي المستويات المجاورة للمتغير (كل مستوى ناقص المستوى التالي) المستويات المتجاورة للمتغير (كل مستوى ناقص المستوى السابق) قارن مستويات المتغير بمتوسط ​​اللاحقة مستويات المتغير يقارن مستويات متغير بمتوسط ​​المستويات السابقة للمتغير يقارن الانحرافات عن متوسط ​​التباين المتعدد الحدود المتعامد الكبير هناك بضع ملاحظات ينبغي أن يتم إجراؤها حول أنظمة الترميز المذكورة أعلاه. الأول هو أنها تمثل المقارنات المخطط لها وليس المقارنات بعد. وبعبارة أخرى، فهي مقارنات تنوي القيام بها قبل البدء في تحليل البيانات الخاصة بك، وليس المقارنات التي تفكر بها بمجرد أن ترى نتائج التحليلات الأولية. أيضا، بعض أشكال الترميز أكثر منطقية مع المتغيرات الفئوية الترتيبية من مع المتغيرات الفئوية الاسمية. سنعرض فيما يلي أمثلة باستخدام السباق كمتغير فئوي، وهو متغير اسمي. ولأن تشفير التأثير البسيط يقارن متوسط ​​المتغير التابع لكل مستوى من المتغيرات الفئوية إلى متوسط ​​المتغير التابع في المستوى المرجعي، يكون من المنطقي وجود متغير اسمي. ومع ذلك، قد لا يجعل من المنطقي استخدام مخطط الترميز الذي يختبر التأثير الخطي للعرق. كما أننا تصف كل نوع من أنواع نظام الترميز، نلاحظ تلك النظم الترميز التي لا يجعل من المنطقي استخدام المتغير الاسمي. أيضا، قد تلاحظ أننا نتبع عدة قواعد عند إنشاء مخططات الترميز التباين. لمزيد من المعلومات حول هذه القواعد، يرجى الاطلاع على القسم المتعلق بتشفير المستخدم. This page will illustrate two ways that you can conduct analyses using these coding schemes: 1) using proc glm with estimate statements to define quotcontrastquot coefficients that specify levels of the categorical variable that are to be compared , and 2) using proc reg . When using proc reg to do contrasts, you first need to create k-1 new variables (where k is the number of levels of the categorical variable) and use these new variables as predictors in your regression model. Method 1 uses a type of coding we will call quotcontrast codingquot while method 2 uses a type of coding we will call quotregression codingquot. The Example Data File The examples in this page will use dataset called hsb2.sas7bdat and we will focus on the categorical variable race . which has four levels (1 Hispanic, 2 Asian, 3 African American and 4 white) and we will use write as our dependent variable. Although our example uses a variable with four levels, these coding systems work with variables that have more or fewer categories. No matter which coding system you select, you will always have one fewer recoded variables than levels of the original variable. In our example, our categorical variable has four levels so we will have three new variables (a variable corresponding to the final level of the categorical variables would be redundant and therefore unnecessary). Before considering any analyses, lets look at the mean of the dependent variable, write . for each level of race . This will help in interpreting the output from later analyses. The results of simple coding are very similar to dummy coding in that each level is compared to the reference level. In the example below, level 4 is the reference level and the first comparison compares level 1 to level 4, the second comparison compares level 2 to level 4, and the third comparison compares level 3 to level 4. Method 1: PROC GLM The table below shows the simple coding making the comparisons described above. The first contrast compares level 1 to level 4, and level 1 is coded as 1 and level 4 is coded as -1. Likewise, the second contrast compares level 2 to level 4 by coding level 2 as 1 and level 4 as -1. As you can see with contrast coding, you can discern the meaning of the comparisons simply by inspecting the contrast coefficients. For example, looking at the contrast coefficients for c3, you can see that it compares level 3 to level 4. SIMPLE contrast coding New variable 1 (c1) New variable 2 (c2) Below we illustrate how to form these comparisons using proc glm . As you see, a separate estimate statement is used for each contrast. The contrast estimate for the first contrast compares the mean of the dependent variable, write . for levels 1 and 4 yielding -7.597 and is statistically significant (plt.000). The t-value associated with this test is -3.82. The results of the second contrast, comparing the mean of write for levels 2 and 4 is not statistically significant (t 1.40, p .1638), while the third contrast is statistically significant. Please note that while we have included the full SAS output for this example, we will only show the relevant output in later examples to conserve space. Method 2: Regression The regression coding is a bit more complex than contrast coding. In our example below, level 4 is the reference level and x1 compares level 1 to level 4, x2 compares level 2 to level 4, and x3 compares level 3 to level 4. For x1 the coding is 34 for level 1, and -14 for all other levels. Likewise, for x2 the coding is 34 for level 2, and -14 for all other levels, and for x3 the coding is 34 for level 3, and -14 for all other levels. It is not intuitive that this regression coding scheme yields these comparisons however, if you desire simple comparisons, you can follow this general rule to obtain these comparisons. SIMPLE regression coding New variable 1 (x1) New variable 2 (x2) New variable 3 (x3) 3 (African American) Below we show the more general rule for creating this kind of coding scheme using regression coding, where k is the number of levels of the categorical variable (in this instance, k 4). SIMPLE regression coding New variable 1 (x1) New variable 2 (x2) Below we illustrate how to create x1 . x2 and x3 and enter these new variables into the regression model using proc reg . You will notice that the regression coefficients in the table below are the same as the contrast coefficients that we saw using proc glm . Both the regression coefficient for x1 and the contrast estimate for c1 are the mean of write for level 1 of race (Hispanic) minus the mean of write for level 4 (white). Likewise, the regression coefficient for x2 and the contrast estimate for c2 are the mean of write for level 2 (Asian) minus the mean of write for level 4 (white). You also can see that the t values and significance levels are also the same as those from the proc glm output. Please note that while we have included the full SAS output for this example, we will only show the relevant output in later examples to conserve space. 5.2 Forward Difference Coding In this coding system, the mean of the dependent variable for one level of the categorical variable is compared to the mean of the dependent variable for the next (adjacent) level. In our example below, the first comparison compares the mean of write for level 1 with the mean of write for level 2 of race (Hispanics minus Asians). The second comparison compares the mean of write for level 2 minus level 3, and the third comparison compares the mean of write for level 3 minus level 4. This type of coding may be useful with either a nominal or an ordinal variable. Method 1: PROC GLM FORWARD DIFFERENCE contrast coding New variable 1 (c1) New variable 2 (c2) New variable 3 (c3) Level 1 v. Level 2 Level 2 v. Level 3 Level 3 v. Level 4 3 (African American) With this coding system, adjacent levels of the categorical variable are compared. Hence, the mean of the dependent variable at level 1 is compared to the mean of the dependent variable at level 2: 46.4583 - 58 -11.542, which is statistically significant. For the comparison between levels 2 and 3, the calculation of the contrast coefficient would be 58 - 48.2 9.8, which is also statistically significant. Finally, comparing levels 3 and 4, 48.2 - 54.0552 -5.855, a statistically significant difference. One would conclude from this that each adjacent level of race is statistically significantly different. Method 2: Regression For the first comparison, where the first and second levels are compared, x1 is coded 34 for level 1 and the other levels are coded -14. For the second comparison where level 2 is compared with level 3, x2 is coded 12 12 -12 -12, and for the third comparison where level 3 is compared with level 4, x3 is coded 14 14 14 -34. FORWARD DIFFERENCE regression coding New variable 1 (x1) New variable 2 (x2) New variable 3 (x3) Level 1 v. Level 2 Level 2 v. Level 3 Level 3 v. Level 4 3 (African American) The general rule for this regression coding scheme is shown below, where k is the number of levels of the categorical variable (in this case k 4). FORWARD DIFFERENCE regression coding New variable 1 (x1) New variable 2 (x2) You can see the regression coefficient for x1 is the mean of write for level 1 (Hispanic) minus the mean of write for level 2 (Asian). Likewise, the regression coefficient for x2 is the mean of write for level 2 (Asian) minus the mean of write for level 3 (African American), and the regression coefficient for x3 is the mean of write for level 3 (African American) minus the mean of write for level 4 (white). 5.3 Backward Difference Coding In this coding system, the mean of the dependent variable for one level of the categorical variable is compared to the mean of the dependent variable for the prior adjacent level. In our example below, the first comparison compares the mean of write for level 2 with the mean of write for level 1 of race (Hispanics minus Asians). The second comparison compares the mean of write for level 3 minus level 2, and the third comparison compares the mean of write for level 4 minus level 3. This type of coding may be useful with either a nominal or an ordinal variable. Method 1: PROC GLM BACKWARD DIFFERENCE contrast coding New variable 1 (c1) New variable 2 (c2) New variable 3 (c3) Level 1 v. Level 2 Level 2 v. Level 3 Level 3 v. Level 4 3 (African American) With this coding system, adjacent levels of the categorical variable are compared, with each level compared to the prior level. Hence, the mean of the dependent variable at level 2 is compared to the mean of the dependent variable at level 1: 58 - 46.4583 11.542, which is statistically significant. For the comparison between levels 3 and 2, the calculation of the contrast coefficient is 48.2 - 58 -9.8, which is also statistically significant. Finally, comparing levels 4 and 3, 54.0552 - 48.2 5.855, a statistically significant difference. One would conclude from this that each adjacent level of race is statistically significantly different. Method 2: Regression For the first comparison, where the first and second levels are compared, x1 is coded 34 for level 1 while the other levels are coded -14. For the second comparison where level 2 is compared with level 3, x2 is coded 12 12 -12 -12, and for the third comparison where level 3 is compared with level 4, x3 is coded 14 14 14 -34. BACKWARD DIFFERENCE regression coding New variable 1 (x1) New variable 2 (x2) New variable 3 (x3) Level 2 v. Level 1 Level 3 v. Level 2 Level 4 v. Level 3 3 (African American) The general rule for this regression coding scheme is shown below, where k is the number of levels of the categorical variable (in this case, k 4). BACKWARD DIFFERENCE regression coding New variable 1 (x1) New variable 2 (x2) In the above example, the regression coefficient for x1 is the mean of write for level 2 minus the mean of write for level 1 (58- 46.4583 11.542). Likewise, the regression coefficient for x2 is the mean of write for level 3 minus the mean of write for level 2, and the regression coefficient for x3 is the mean of write for level 4 minus the mean of write for level 3. 5.4 Helmert Coding Helmert coding compares each level of a categorical variable to the mean of the subsequent levels. Hence, the first contrast compares the mean of the dependent variable for level 1 of race with the mean of all of the subsequent levels of race (levels 2, 3, and 4), the second contrast compares the mean of the dependent variable for level 2 of race with the mean of all of the subsequent levels of race (levels 3 and 4), and the third contrast compares the mean of the dependent variable for level 3 of race with the mean of all of the subsequent levels of race (level 4). While this type of coding system does not make much sense with a nominal variable like race . it is useful in situations where the levels of the categorical variable are ordered say, from lowest to highest, or smallest to largest, etc. For Helmert coding, we see that the first comparison comparing level 1 with levels 2, 3 and 4 is coded 1, -13, -13 and -13, reflecting the comparison of level 1 with all other levels. The second comparison is coded 0, 1, -12 and -12, reflecting that it compares level 2 with levels 3 and 4. The third comparison is coded 0, 0, 1 and -1, reflecting that level 3 is compared to level 4. Method 1: PROC GLM HELMERT contrast coding New variable 1 (c1) New variable 2 (c2) New variable 3 (c3) Level 1 v. Later Level 2 v. Later Level 3 v. Later 3 (African American) Below we illustrate how to form these comparisons using proc glm with estimate statements. Note that on the first estimate statement we indicate -.33333 and not just -.33. We need to use this many decimals so the sum of all of the contrast coefficients (i. e. 1 -.333333 -.333333 -.333333) is sufficiently close to zero, otherwise SAS will say that the term cannot be estimated. The contrast estimate for the comparison between level 1 and the remaining levels is calculated by taking the mean of the dependent variable for level 1 and subtracting the mean of the dependent variable for levels 2, 3 and 4: 46.4583 - (58 48.2 54.0552) 3 -6.960, which is statistically significant. This means that the mean of write for level 1 of race is statistically significantly different from the mean of write for levels 2 through 4. As noted above, this comparison probably is not meaningful because the variable race is nominal. This type of comparison would be more meaningful if the categorical variable was ordinal. To calculate the contrast coefficient for the comparison between level 2 and the later levels, you subtract the mean of the dependent variable for levels 3 and 4 from the mean of the dependent variable for level 2: 58 - (48.2 54.0552) 2 6.872, which is statistically significant. The contrast estimate for the comparison between level 3 and level 4 is the difference between the mean of the dependent variable for the two levels: 48.2 - 54.0552 -5.855, which is also statistically significant. Method 2: Regression Below we see an example of Helmert regression coding. For the first comparison (comparing level 1 with levels 2, 3 and 4) the codes are 34 and -14 -14 -14. The second comparison compares level 2 with levels 3 and 4 and is coded 0 23 -13 -13. The third comparison compares level 3 to level 4 and is coded 0 0 12 -12. HELMERT regression coding New variable 1 (x1) New variable 2 (x2) New variable 3 (x3) Below we illustrate how to create x1 . x2 and x3 and enter these new variables into the regression model using porc reg . As you see below, the regression coefficient for x1 is the mean of write for level 1 (Hispanic) versus all subsequent levels (levels 2, 3 and 4). Likewise, the regression coefficient for x2 is the mean of write for level 2 minus the mean of write for levels 3 and 4. Finally, the regression coefficient for x3 is the mean of write for level 3 minus the mean of write for level 4. 5.5 Reverse Helmert Coding Reverse Helmert coding (also know as difference coding) is just the opposite of Helmert coding: instead of comparing each level of categorical variable to the mean of the subsequent level(s), each is compared to the mean of the previous level(s). In our example, the first contrast codes the comparison of the mean of the dependent variable for level 2 of race to the mean of the dependent variable for level 1 of race . The second comparison compares the mean of the dependent variable level 3 of race with both levels 1 and 2 of race . and the third comparison compares the mean of the dependent variable for level 4 of race with levels 1, 2 and 3. Clearly, this coding system does not make much sense with our example of race because it is a nominal variable. However, this system is useful when the levels of the categorical variable are ordered in a meaningful way. For example, if we had a categorical variable in which work-related stress was coded as low, medium or high, then comparing the means of the previous levels of the variable would make more sense. For reverse Helmert coding, we see that the first comparison comparing levels 1 and 2 are coded -1 and 1 to compare these levels, and 0 otherwise. The second comparison comparing levels 1, 2 with level 3 are coded -12, -12, 1 and 0, and the last comparison comparing levels 1, 2 and 3 with level 4 are coded -13, -13, -13 and 1. Method 1: PROC GLM REVERSE HELMERT contrast coding New variable 1 (c1) New variable 2 (c2) New variable 3 (c3) Below we illustrate how to form these comparisons using proc glm with estimate statements. Note that on the third estimate statement we indicate -.33333 and not just -.33. We need to use this many decimals so the sum of all of the contrast coefficients (i. e. -.333333 - .333333 - .333333 1) is sufficiently close to zero, otherwise SAS will say that the term cannot be estimated. An alternate way, which solves the problem of the repeating decimals, is shown below. Only one output is shown because the two outputs are identical. The contrast estimate for the first comparison shown in this output was calculated by subtracting the mean of the dependent variable for level 2 of the categorical variable from the mean of the dependent variable for level 1: 58 - 46.4583 11.542. This result is statistically significant. The contrast estimate for the second comparison (between level 3 and the previous levels) was calculated by subtracting the mean of the dependent variable for levels 1 and 2 from that of level 3: 48.2 - (46.4583 58) 2 -4.029. This result is not statistically significant, meaning that there is not a reliable difference between the mean of write for level 3 of race compared to the mean of write for levels 1 and 2 (Hispanics and Asians). As noted above, this type of coding system does not make much sense for a nominal variable such as race . For the comparison of level 4 and the previous levels, you take the mean of the dependent variable for the those levels and subtract it from the mean of the dependent variable for level 4: 54.0552 - (46.4583 58 48.2) 3 3.169. This result is statistically significant. Method 2: Regression The regression coding for reverse Helmert coding is shown below. For the first comparison, where the first and second level are compared, x1 is coded -12 and 12 and 0 otherwise. For the second comparison, the values of x2 are coded -13 -13 23 and 0. Finally, for the third comparison, the values of x3 are coded -14 -14 -14 and 34. REVERSE HELMERT regression coding New variable 1 (x1) New variable 2 (x2) New variable 3 (x3) Below we illustrate how to create x1 . x2 and x3 and enter these new variables into the regression model using proc reg . In the above examples, both the regression coefficient for x1 and the contrast estimate for c1 would be the mean of write for level 1 (Hispanic) minus the mean of write for level 2 (Asian). Likewise, the regression coefficient for x2 and the contrast estimate for c2 would be the mean of write for levels 1 and 2 combined minus the mean of write for level 3. Finally, the regression coefficient for x3 and the contrast estimate for c3 would be the mean of write for levels 1, 2 and 3 combined minus the mean of write for level 4. 5.6 Deviation Coding This coding system compares the mean of the dependent variable for a given level to the overall mean of the dependent variable. In our example below, the first comparison compares level 1 (Hispanics) to all levels of race . the second comparison compares level 2 (Asians) to all levels of race . and the third comparison compares level 3 (African Americans) to all levels of race . As you can see, the logic of the contrast coding is fairly straightforward. The first comparison compares level 1 to levels 2, 3 and 4. A value of 34 is assigned to level 1 and a value of -14 is assigned to levels 2, 3 and 4. Likewise, the second comparison compares level 2 to levels 1, 3 and 4. A value of 34 is assigned to level 2 and a value of -14 is assigned to levels 1, 3 and 4. A similar pattern is followed for assigning values for the third comparison. Note that you could substitute 3 for 34 and 1 for 14 and you would get the same test of significance, but the contrast coefficient would be different. Method 1: PROC GLM DEVIATION contrast coding New variable 1 (c1) New variable 2 (c2) New variable 3 (c3) Below we illustrate how to form these comparisons using proc glm . The contrast estimate is the mean for level 1 minus the grand mean. However, this grand mean is not the mean of the dependent variable that is listed in the output of the means command above. Rather it is the mean of means of the dependent variable at each level of the categorical variable: (46.4583 58 48.2 54.0552) 4 51.678375. This contrast estimate is then 46.4583 - 51.678375 -5.220. The difference between this value and zero (the null hypothesis that the contrast coefficient is zero) is statistically significant (p .0016), and the t-value for this test of -3.20. The results for the next two contrasts were computed in a similar manner. Method 2: Regression As you see in the example below, the regression coding is accomplished by assigning 1 to level 1 for the first comparison (because level 1 is the level to be compared to all others), a 1 to level 2 for the second comparison (because level 2 is to be compared to all others), and 1 to level 3 for the third comparison (because level 3 is to be compared to all others). Note that a -1 is assigned to level 4 for all three comparisons (because it is the level that is never compared to the other levels) and all other values are assigned a 0. This regression coding scheme yields the comparisons described above. DEVIATION regression coding New variable 1 (x1) New variable 2 (x2) New variable 3 (x3) 3 (African American) Below we illustrate how to create x1 . x2 and x3 and enter these new variables into the regression model using proc reg . In this example, both the regression coefficient for x1 is the mean of write for level 1 (Hispanic) minus the grand mean of write. Likewise, the regression coefficient for x2 is the mean write for level 2 (Asian) minus the grand mean of write . وما إلى ذلك وهلم جرا. As we saw in the previous analyses, all three contrasts are statistically significant. 5.7 Orthogonal Polynomial Coding Orthogonal polynomial coding is a form of trend analysis in that it is looking for the linear, quadratic and cubic trends in the categorical variable. This type of coding system should be used only with an ordinal variable in which the levels are equally spaced. Examples of such a variable might be income or education. The table below shows the contrast coefficients for the linear, quadratic and cubic trends for the four levels. These could be obtained from most statistics books on linear models. 3 (African American) Method 1: PROC GLM To calculate the contrast estimates for these comparisons, you need to multiply the code used in the new variable by the mean for the dependent variable for each level of the categorical variable, and then sum the values. For example, the code used in x1 for level 1 of race is -.671 and the mean of write for level 1 is 46.4583. Hence, you would multiply -.671 and 46.4583 and add that to the product of the code for level 2 of x1 and its mean, and so on. To obtain the contrast estimate for the linear contrast, you would do the following: -.67146.4583 -.22458 .22448.2 .67154.0552 2.905 (with rounding error). This result is not statistically significant at the .05 alpha level, but it is close. The quadratic component is also not statistically significant, but the cubic one is. This suggests that, if the mean of the dependent variable was plotted against race . the line would tend to have two bends. As noted earlier, this type of coding system does not make much sense with a nominal variable such as race . Method 2: Regression The regression coding for orthogonal polynomial coding is the same as the contrast coding. Below you can see the SAS code for creating x1 . x2 and x3 that correspond to the linear, quadratic and cubic trends for race . The regression coefficients obtained from this analysis are the same as the contrast coefficients obtained using proc glm . 5.8 User Defined Coding You can use SAS for any general kind of coding scheme. For our example, we would like to make the following three comparisons: 1) level 1 to level 3 2) level 2 to levels 1 and 4 3) levels 1 and 2 to levels 3 and 4. In order to compare level 1 to level 3, we use the contrast coefficients 1 0 -1 0. To compare level 2 to levels 1 and 4 we use the contrast coefficients -12 1 0 -12. Finally, to compare levels 1 and 2 with levels 3 and 4 we use the coefficients 12 12 -12 -12. Before proceeding to the SAS code necessary to conduct these analyses, lets take a moment to more fully explain the logic behind the selection of these contrast coefficients. For the first contrast, we are comparing level 1 to level 3, and the contrast coefficients are 1 0 -1 0. This means that the levels associated with the contrast coefficients with opposite signs are being compared. In fact, the mean of the dependent variable is multiplied by the contrast coefficient. Hence, levels 2 and 4 are not involved in the comparison: they are multiplied by zero and quotdropped out. quot You will also notice that the contrast coefficients sum to zero. This is necessary. If the contrast coefficients do not sum to zero, the contrast is not estimable and SAS will issue an error message. Which level of the categorical variable is assigned a positive or negative value is not terribly important: 1 0 -1 0 is the same as -1 0 1 0 in that both of these codings compare the first and the third levels of the variable. However, the sign of the regression coefficient would change. Now lets look at the contrast coefficients for the second and third comparisons. You will notice that in both cases we use fractions that sum to one (or minus one). They do not have to sum to one (or minus one). You may wonder why we would use fractions like -12 1 0 -12 instead of whole numbers such as -1 2 0 -1. While -12 1 0 -12 and -1 2 0 -1 both compare level 2 with levels 1 and 4 and both will give you the same t-value and p-value for the regression coefficient, the contrast estimatesregression coefficients themselves would be different, as would their interpretation. The coefficient for the -12 1 0 -12 contrast is the mean of level 2 minus the mean of the means for levels 1 and 4: 58 - (46.4583 54.0552)2 7.74325. (Alternatively, you can multiply the contrasts by the mean of the dependent variable for each level of the categorical variable: -1246.4583 158.00 048.20 -1254.0552 7.74325. Clearly these are equivalent ways of thinking about how the contrast coefficient is calculated.) By comparison, the coefficient for the -1 2 0 -1 contrast is two times the mean for level 2 minus the means of the dependent variable for levels 1 and 4: 258 - (46.4583 54.0552) 15.4865, which is the same as -146.4583 258 048.20 - 154.0552 15.4865. Note that the regression coefficient using the contrast coefficients -1 2 0 -1 is twice the regression coefficient obtained when -12 1 0 -12 is used. Method 1: PROC GLM In order to compare level 1 to level 3, we use the contrast coefficients 1 0 -1 0. To compare level 2 to levels 1 and 4 we use the contrast coefficients -12 1 0 -12. Finally, to compare levels 1 and 2 with levels 3 and 4, we use the coefficients 12 12 -12 -12. These coefficients are used in the estimate statements below. The contrast estimate for the first comparison is the mean of level 1 minus the mean for level 3, and the significance of this is .525, i. e. not significant. The second contrast estimate is 7.743, which is the mean of level 2 minus the mean of level 1 and level 4, and this difference is significant, p 0.008. The final contrast estimate is 1.1 which is the mean of levels 1 and 2 minus the mean of levels 3 and 4, and this contrast is not statistically significant, p .576. Method 2: Regression As in the prior example, we will make the following three comparisons: 1) level 1 to level 3, 2) level 2 to levels 1 and 4 and 3) levels 1 and 2 to levels 3 and 4. For methods 1 and 2 it was quite easy to translate the comparisons we wanted to make into contrast codings, but it is not as easy to translate the comparisons we want into a regression coding scheme. If we know the contrast coding system, then we can convert that into a regression coding system using the SAS program shown below. As you can see, we place the three contrast codings we want into the matrix c and then perform a set of matrix operations on c, yielding the matrix x . We then display x using the print command. Below we see the output from this program showing the regression coding scheme we would use. This converted the contrast coding into the regression coding that we need for running this analysis with proc reg . Below, we use if-then statements to create x1 . x2 and x3 according to the coding shown above and then enter them into the regression analysis. The first comparison of the mean of the dependent variable for level 1 to level 3 of the categorical variable was not statistically significant, while the comparison of the mean of the dependent variable for level 2 to that of levels 1 and 4 was. The comparison of the mean of the dependent variable for levels 1 and 2 to that of levels 3 and 4 also was not statistically significant. This page has described a number of different coding systems that you could use for categorical data, and two different strategies you could use for performing the analyses. You can choose a coding system that yields comparisons that make the most sense for testing your hypotheses. In general we would recommend using the easiest method that accomplishes your goals. 5.10 Additional Information Here are some additional resources. محتوى هذا الموقع لا ينبغي أن يفسر على أنه تأييد لأي موقع ويب معين، كتاب، أو منتج البرمجيات من قبل جامعة كاليفورنيا.

Comments