HINWEIS: Die IDRE Statistical Consulting Group wird die Migration der Website auf das WordPress CMS im Februar, um die Wartung und Erstellung neuer Inhalte zu erleichtern. Einige unserer älteren Seiten werden entfernt oder archiviert, so dass sie nicht länger erhalten bleiben. Wir werden versuchen, die Weiterleitungen so zu halten, dass die alten URLs weiterhin so gut funktionieren, wie wir können. Willkommen im Institut für Digitale Forschung und Bildung Helfen Sie der Stat Consulting Group durch ein Geschenk Regression mit Stata Kapitel 3 - Regression mit kategorischen Prädiktoren Kapitelübersicht 3.0 Regression mit kategorialen Prädiktoren 3.1 Regression mit einer 01 Variablen 3.2 Regression mit 12 Variablen 3.3 Regression mit Eine 123-Variable 3.4 Regression mit mehreren kategorialen Prädiktoren 3.5 Kategorialer Prädiktor mit Interaktionen 3.6 Kontinuierliche und kategoriale Variablen 3.7 Interaktionen von Continuous bis 01 Kategoriale Variablen 3.8 Kontinuierliche und kategoriale Variablen, Interaktion mit 123 Variablen 3.9 Zusammenfassung 3.10 Selbsteinstufung 3.11 Für weitere Informationen Bitte beachten Sie: Dies Seite verwendet das Programm xi3 welches nicht mehr gepflegt wird und aus unserem Archiv stammt. Verweise auf xi3 bleiben auf dieser Seite, da sie spezifische Prinzipien der Codierung kategorischer Variablen veranschaulichen. In den beiden vorangegangenen Kapiteln haben wir uns auf Regressionsanalysen mit kontinuierlichen Variablen konzentriert. Allerdings ist es möglich, kategoriale Prädiktoren in eine Regressionsanalyse einzubeziehen, aber es erfordert einige zusätzliche Arbeit bei der Durchführung der Analyse und zusätzliche Arbeit bei der richtigen Interpretation der Ergebnisse. In diesem Kapitel wird gezeigt, wie Sie Stata zur Einbeziehung kategorialer Prädiktoren in Ihre Analyse verwenden und beschreiben können, wie die Ergebnisse dieser Analysen interpretiert werden können. Stata hat einige großartige Tools, die den Prozess der Einbeziehung kategorialer Variablen in Ihre Regressionsanalyse wirklich erleichtern, und wir werden die Verwendung dieser zeitsparenden Tools betonen. In diesem Kapitel werden die elemapi2-Daten verwendet, die Sie in den vorangegangenen Kapiteln gesehen haben. Wir konzentrieren uns auf vier Variablen api00. Etwas kol. Yrrnd und mealcat. Die Mahlzeiten nimmt und bricht es in 3 Kategorien. Werfen wir einen kurzen Blick auf diese Variablen. Die Variable api00 ist ein Maß für die Leistungsfähigkeit der Schulen. Unten sehen wir die Codebuch-Informationen für api00 Die Variable somecol ist eine kontinuierliche Variable, die den Prozentsatz der Eltern in der Schule misst, die das College besucht haben, und die Codebuch-Informationen sind unten gezeigt. Die Variable yrrnd ist eine kategoriale Variable, die codiert wird, wenn die Schule nicht das ganze Jahr ist und 1, wenn das ganze Jahr über, siehe unten. Die Variable Mahlzeiten ist der Prozentsatz der Studenten, die staatlich geförderte kostenlose Mahlzeiten erhalten und kann als Indikator für die Armut verwendet werden. Dies war in 3 Kategorien (um gleich große Gruppen) die Schaffung der variablen Mahlzeit gebrochen. Die Codebuch-Informationen für mealcat sind unten gezeigt. 3.1 Regression mit einer 01-Variablen Das einfachste Beispiel eines kategorischen Prädiktors in einer Regressionsanalyse ist eine 01-Variable, auch Dummy-Variable genannt. Die Variable yrrnd kann als Beispiel für eine Dummy-Variable verwendet werden. Wir können eine Dummy-Variable als Prädiktor in einer Regressionsanalyse einschließen, wie unten gezeigt. Dies mag zunächst seltsam erscheinen, aber das ist eine legitime Analyse. Aber was bedeutet dies Lets gehen zurück zu Grundlagen und schreiben Sie die Regressionsgleichung, dass dieses Modell impliziert. Wobei cons der Intercept (oder die Konstante) ist, und wir verwenden Byrrnd, um den Koeffizienten für die Variable yrrnd darzustellen. Wenn wir die Werte aus der Regressionsgleichung ausfüllen, erhalten wir Wenn eine Schule kein ganzjähriges Schuljahr ist (dh yrrnd 0 ist), würde die Regressionsgleichung vereinfachen, wenn eine Schule eine ganzjährige Schule ist, würde die Regressionsgleichung für We vereinfachen Kann die beobachteten Werte und die vorhergesagten Werte mit dem Scatter-Befehl wie unten gezeigt grafisch darstellen. Obwohl yrrnd nur 2 Werte hat, können wir noch eine Regressionslinie zeichnen, die die Beziehung zwischen yrrnd und api00 zeigt. Basierend auf den obigen Ergebnissen sehen wir, dass der vorhergesagte Wert für Nicht-Jahr-Schulen 684.539 und der prognostizierte Wert für das ganze Jahr über Schulen 524.032 ist und die Steigung der Linie negativ ist, was sinnvoll ist, da der Koeffizient für yrrnd war Negativ (-160.5064). Lets vergleichen Sie diese vorhergesagten Werte mit den durchschnittlichen api00 Scores für die ganzjährige und nicht-ganzjährige Schulen. Wie Sie sehen, sagt die Regressionsgleichung vor, dass der Wert von api00 der Mittelwert sein wird, je nachdem, ob eine Schule ein ganzes Jahr oder eine Schuljahrsausbildung ist. Wir können diese vorhergesagten Werte wieder auf die Regressionsgleichung zurückführen. Für die nicht-ganzjährigen Schulen ist ihr Mittel das gleiche wie das Intercept (684.539). Der Koeffizient für yrrnd ist der Betrag, den wir addieren müssen, um den Mittelwert für die ganzjährigen Schulen zu erhalten, d. h. wir müssen -160.5064 addieren, um 524.0326 zu erhalten, der Mittelwert für die nicht ganzjährigen Schulen. Mit anderen Worten, Byrrnd ist die durchschnittliche api00 Punktzahl für die ganzjährigen Schulen minus der durchschnittlichen api00 Punktzahl für die nicht ganzjährig Schulen, d. H. Mittel (ganzjährig) - Mittel (nicht ganzjährig). Es kann überraschend sein, dass diese Regressionsanalyse mit einer einzigen Dummy-Variable dieselbe ist wie ein t-Test, der die mittlere api00 für die ganzjährigen Schulen mit den nicht ganzjährigen Schulen vergleicht (siehe unten). Sie können sehen, dass der t-Wert unten der gleiche ist wie der t-Wert für yrrnd in der Regression oben. Dies liegt daran, dass Byrrnd die Jahresrunden und die Nichtjahresrunden vergleicht (da der Koeffizient Mittelwert (ganzjährig) - Mittel (nicht ganzjährig) ist. Da ein t-Test das gleiche wie ein Anova ist. Können wir die gleichen Ergebnisse auch mit dem Befehl anova erhalten. Wenn wir den t-Wert aus dem t-Test quadrieren, erhalten wir den gleichen Wert wie der F-Wert aus der anova. 3.2 Regression mit einer 12 Variablen Eine kategoriale Prädiktorvariable muss nicht kodiert werden, um in einem Regressionsmodell verwendet zu werden. Es ist leichter zu verstehen und interpretieren die Ergebnisse aus einem Modell mit Dummy-Variablen, aber die Ergebnisse aus einer variablen codierten 12 liefern im Wesentlichen die gleichen Ergebnisse. Machen wir eine Kopie der Variablen yrrnd mit dem Namen yrrnd2, die 12, 1non ganzjährig und 2year-round codiert ist. Wir können eine Regression vorhersagen api00 von yrrnd2. Beachten Sie, dass der Koeffizient für yrrnd derselbe ist wie yrrnd2. So können Sie sehen, dass, wenn Sie yrrnd als 01 oder als 12 Code, der Regressionskoeffizient arbeitet, um die gleiche sein. Allerdings ist der Intercept (cons) etwas weniger intuitiv. Als wir yrrnd benutzten. Der Schnittpunkt war der Mittelwert für die Nichtjahresrunden. Bei Verwendung von yrrnd2. Ist der Intercept der Mittelwert für die Nichtjahresrunden minus Byrrnd2. D. h. 684.539 - (-160.506) 845.045 Beachten Sie, dass Sie 01 oder 12 Kodierung verwenden können und die Ergebnisse für den Koeffizienten gleich kommen, aber die Interpretation der Konstanten in der Regressionsgleichung ist unterschiedlich. Es ist oft einfacher, die Schätzungen für die 01-Codierung zu interpretieren. Zusammenfassend lassen diese Ergebnisse darauf schließen, dass die api00-Werte für die Schulen je nach Schulart, Ganzjahresschule und Nichtjahresschule deutlich unterschiedlich sind. Nicht ganzjährig Schulen haben deutlich höhere API-Werte als ganzjährig Schulen. Basierend auf den Regressionsergebnissen haben nicht ganzjährige Schulen Punkte, die 160,5 Punkte höher sind als die ganzjährigen Schulen. 3.3 Regression mit einer 123-Variablen 3.3.1 Manuelles Erstellen von Dummy-Variablen Sagen wir, dass wir die Beziehung zwischen dem Betrag der Armut und den AIP-Scores untersuchen möchten. Wir haben nicht ein Maß der Armut, aber wir können mealcat als Proxy für ein Maß von Armut verwenden. Im folgenden wiederholen wir die Codebuch-Info für mealcat mit den Werten für die drei Kategorien. Sie könnten versucht sein, versuchen, einschließlich mealcat in einer Regression wie diese. Aber dies ist der Blick auf die lineare Wirkung von mealcat mit api00. Aber mealcat ist keine Intervallvariable. Stattdessen möchten Sie die Variable kodieren, so dass alle Informationen über die drei Ebenen berücksichtigt werden. Sie können Dummy-Code Mealcat wie folgt. Wir haben jetzt mealcat1 erstellt, das ist 1, wenn mealcat 1 ist und 0 sonst. Ebenso ist mealcat2 1, wenn mealcat 2 ist und 0 sonst und ebenfalls mealcat3 erstellt wurde. Wir können das unten sehen. Wir können nun zwei dieser Dummy-Variablen (mealcat2 und mealcat3) in der Regressionsanalyse verwenden. Wir können die Gesamtunterschiede zwischen den drei Gruppen testen, indem wir den Testbefehl wie unten gezeigt verwenden. Dies zeigt, dass die Gesamtunterschiede zwischen den drei Gruppen signifikant sind. Die Interpretation der Koeffizienten ist ähnlich wie bei den binären Variablen. Gruppe 1 ist die weggelassene Gruppe, so dass cons der Mittelwert für Gruppe 1 ist. Der Koeffizient für mealcat2 ist der Mittelwert für Gruppe 2 minus Mittelwert der weggelassenen Gruppe (Gruppe 1). Und der Koeffizient für mealcat3 ist der Mittelwert der Gruppe 3 minus dem Mittelwert der Gruppe 1. Sie können dies überprüfen, indem man die Koeffizienten mit den Mitteln der Gruppen vergleicht. Basierend auf diesen Ergebnissen können wir sagen, dass sich die drei Gruppen in ihren api00-Scores unterscheiden und dass insbesondere die Gruppe 2 signifikant von der Gruppe 1 (weil Mealcat2 signifikant war) und die Gruppe 3 signifikant von der Gruppe 1 unterscheiden (da Mealcat3 signifikant war). 3.3.2 Verwenden des Befehls xi Mit dem Befehl xi können wir die Arbeit für uns erstellen, um die Indikatorvariablen zu erstellen und die Regression in einem einzigen Befehl auszuführen (siehe unten). Wenn wir xi verwenden und den Begriff i. mealcat in das Modell aufnehmen, erzeugt Stata die Variablen Imealcat2 und Imealcat3, die Dummy-Variablen wie mealcat2 und mealcat3 sind, die wir zuvor erstellt haben. Es gibt wirklich keinen Unterschied zwischen mealcat2 und Imealcat2. Wie Sie sehen können, sind die Ergebnisse die gleichen wie in der vorherigen Analyse. Wenn wir den Gesamteffekt von mealcat testen wollen, verwenden wir den Testbefehl wie unten gezeigt, der uns auch die gleichen Ergebnisse liefert, wie wir die Dummy-Variablen mealcat2 und mealcat3 gefunden haben. Beachten Sie, dass wenn Sie dies in Stata Version 6 tun, die Variablen Imealc2 und Imealc3 anstelle von Imealcat2 und Imealcat3 benannt werden. Eine der Verbesserungen in Stata 7 ist, dass Variablennamen länger als 8 Zeichen sein können, sodass die Namen der Variablen, die mit dem Befehl xi erstellt wurden, einfacher zu verstehen sind als in Version 6. Von diesem Zeitpunkt an werden wir die Variablennamen verwenden Würde in Version 7 erstellt werden. Was wäre, wenn wir eine andere Gruppe als Referenzgruppe wünschen. Wenn wir Dummy-Variablen über tabulate erstellen. Wenn wir die Gruppe 3 weggelassen haben, ist die Konstante nun der Mittelwert der Gruppe 3 und mealcat1 ist Gruppe1-gruppe3 und mealcat2 ist gruppe2-gruppe3 . Wir sehen, dass beide Koeffizienten signifikant sind, was darauf hinweist, dass Gruppe 1 signifikant von Gruppe 3 und Gruppe 2 von Gruppe 3 signifikant verschieden ist. Wenn wir den Befehl xi verwenden, wie können wir wählen, welche Gruppe die weggelassene Gruppe ist. Die erste Gruppe weggelassen wird, aber sagen, wir wollen Gruppe 3 weggelassen werden. Wir können den char-Befehl wie unten gezeigt verwenden, um Stata mitzuteilen, dass wir die dritte Gruppe die ausgelassene Gruppe für die Variable mealcat sein wollen. Dann, wenn wir den Befehl xi mit mealcat verwenden, wird die mealcat3-Gruppe weggelassen. Wenn Sie die Datei speichern, wird sich Stata dies für zukünftige Stata-Sitzungen merken. Sie können vergleichen und sehen, dass diese Ergebnisse identisch sind mit denen, die mit mealcat1 und mealcat2 als Prädiktoren gefunden werden. 3.3.3 Anova-Befehl verwenden Wir können diese Analyse auch mit dem Befehl anova durchführen. Der Vorteil der anova-Befehl ist, dass es uns die Prüfung der Gesamteffekt von mealcat, ohne die Verwendung der Test-Befehl wie wir mit dem Regress-Befehl. Wir können sehen, der anova-Test der Wirkung von mealcat ist die gleiche wie die Test-Befehl aus dem Regress-Befehl. Wir können dies auch mit dem anova, regress Befehl verfolgen und die Parameterschätzungen mit denen vergleichen, die wir zuvor durchgeführt haben. Hinweis: Die Parameterschätzungen sind die gleichen, da mealcat im Regressbefehl und im anova-Befehl genauso kodiert ist, in beiden Fällen wird die letzte Kategorie (Kategorie 3) gelöscht. Während Sie steuern können, welche Kategorie die ausgelassene Kategorie ist, wenn Sie den Regress-Befehl verwenden, fällt der Befehl anova, regress immer die letzte Kategorie. 3.3.4 Andere Codierungsschemata Es ist allgemein sehr bequem, Dummy-Codierung zu verwenden, aber das ist nicht die einzige Art von Codierung, die verwendet werden kann. Wie Sie gesehen haben, wenn Sie eine Dummy-Codierung verwenden, wird eine der Gruppen zur Referenzgruppe, und alle anderen Gruppen werden mit dieser Gruppe verglichen. Dies kann nicht der interessanteste Satz von Vergleichen sein. Sagen Sie, dass Sie Gruppe 1 mit Gruppe 2 und 3 vergleichen möchten, und für einen zweiten Vergleich Vergleiche Gruppe 2 mit Gruppe 3. Sie müssen ein Codierschema erzeugen, das diese 2 Vergleiche bildet. Wir veranschaulichen dies mit einem Stata-Programm, xi3. (Eine erweiterte Version von xi), die die Variablen, die Sie für solche Vergleiche (sowie eine Vielzahl anderer allgemeiner Vergleiche) benötigen würden. Die Vergleiche, die wir beschrieben haben (Vergleich von Gruppe 1 mit 2 und 3 und dann Vergleich der Gruppen 2 und 3) entsprechen Helmert-Vergleichen (siehe Kapitel 5 für weitere Details). Wir verwenden die h. Präfix (anstelle des i. Präfix), um anzuzeigen, dass wir Helmert Vergleiche auf der variablen Mahlzeit wünschen. Ansonsten sehen Sie, dass xi3 sehr ähnlich dem Befehl xi funktioniert. Wenn Sie die Parameterschätzungen mit den Mitteln vergleichen (siehe unten), können Sie überprüfen, ob der Koeffizient für Imealcat1 der Mittelwert der Gruppe 1 minus dem Mittel der Gruppen 2 und 3 (805.71756 - (639.39394 504.37956) 2 233.83081) und des Koeffizienten für Imealcat2 ist Ist der Mittelwert der Gruppe 2 minus Gruppe 3 (639,39 - 504,37 135,01). Beide Vergleiche sind signifikant, was darauf hinweist, dass die Gruppe 1 sich signifikant von den Gruppen 2 und 3 unterscheidet und die Gruppe 2 sich signifikant von Gruppe 3 unterscheidet. Und der Wert von cons ist der ungewichtete Mittelwert der Mittel der 3 Gruppen. Verwenden des Codierschemas, das von xi3 zur Verfügung gestellt wird. Waren wir in der Lage, vielleicht noch interessantere Tests als die von Dummy-Codierung. Das Programm xi3 kann Variablen gemäß anderen Codierungsschemata sowie benutzerdefinierte Codierungsschemata erstellen, die Sie erstellen, siehe Hilfe xi3 und Kapitel 5 für weitere Informationen. 3.4 Regression mit zwei kategorialen Prädiktoren 3.4.1 Verwendung des Befehls xi: Bisher haben wir uns mit yrrnd beschäftigt, um api00 vorherzusagen. Und wir haben auch mealcat mit dem Befehl xi betrachtet. Wir können sowohl yrrnd als auch mealcat zusammen im gleichen Modell einschließen. Wir können den Gesamteffekt von mealcat mit dem Testbefehl testen, was signifikant ist. Da dieses Modell nur Haupteffekte hat (keine Interaktionen), können Sie Byrrnd als Differenz zwischen der Jahres - und der Nichtjahresgruppe interpretieren. Der Koeffizient für Imealcat1 (den wir BImealcat1 nennen) ist der Unterschied zwischen mealcat1 und mealcat3 und BImealcat2 als der Unterschied zwischen mealcat2 und mealcat3. Lässt graben unter der Oberfläche und sehen, wie die Koeffizienten beziehen sich auf die vorhergesagten Werte. Lets Ansicht die Zellen, die durch Kreuzung von yrrnd und mealcat und Anzahl der Zellen von cell1 zu cell6. In Bezug auf mealcat. Die Gruppe mealcat3 ist die Referenzkategorie, und in Bezug auf yrrnd ist die Gruppe yrrnd0 die Referenzkategorie. Als Ergebnis ist cell3 die Referenzzelle. Die Konstante ist der vorhergesagte Wert für diese Zelle. Der Koeffizient für yrrnd ist die Differenz zwischen cell3 und cell6. Da dieses Modell nur Hauptwirkungen hat, ist es auch der Unterschied zwischen cell2 und cell5, oder von cell1 und cell4. Mit anderen Worten, Byrrnd ist die Menge, die Sie zum vorhergesagten Wert hinzufügen, wenn Sie von nicht Jahr zu Jahr über Schulen gehen. Der Koeffizient für Imealcat1 ist der vorhergesagte Unterschied zwischen cell1 und cell3. Da dieses Modell nur Hauptwirkungen hat, ist es auch der vorhergesagte Unterschied zwischen cell4 und cell6. Ebenso ist BImealcat2 die vorhergesagte Differenz zwischen cell2 und cell3, und auch die vorhergesagte Differenz zwischen cell5 und cell6. Daher sollten die vorhergesagten Werte, bezogen auf die Koeffizienten, sein. Wir sollten beachten, dass, wenn Sie die vorhergesagten Werte für jede Zelle berechnet haben, sie nicht genau mit den Mitteln in den 6 Zellen übereinstimmen würden. Die vorhergesagten Mittel wären in der Nähe der beobachteten Mittel in den Zellen, aber nicht genau die gleichen. Denn unser Modell hat nur Haupteffekte und geht davon aus, dass der Unterschied zwischen Zelle1 und Zelle4 genau derselbe ist wie der Unterschied zwischen den Zellen 2 und 5, der der Differenz zwischen den Zellen 3 und 6 entspricht. Da die beobachteten Werte nicht folgen Gibt es eine gewisse Diskrepanz zwischen den vorhergesagten Mitteln und den beobachteten Mitteln. 3.4.2 Anova-Befehl verwenden Wir können die gleiche Analyse mit dem anova-Befehl mit nur Haupteffekten ausführen. Beachten Sie, dass wir die gleichen Informationen erhalten, die wir von der xi ausführen. Regress-Befehl, gefolgt von dem Test-Befehl. Der Befehl "anova" liefert automatisch die vom Testbefehl bereitgestellten Informationen. Wenn wir mögen, können wir die Parameterschätzungen auch später noch einmal anfordern. Anova zeigt die Parameterschätzungen des letzten Anova-Modells an. Jedoch ist der anova-Befehl in seiner Bestimmung starr, in welcher Gruppe die weggelassene Gruppe und die letzte Gruppe fallen gelassen wird. Da sich dies von der Codierung unterscheidet, die wir in den oben beschriebenen Regressionsbefehlen verwendet haben, unterscheiden sich die Parameterschätzungen von diesem anova-Befehl von dem oben beschriebenen Regressbefehl. Zusammenfassend lassen diese Ergebnisse darauf schließen, dass die Unterschiede zwischen dem ganzjährigen und nichtjährigen Schulen signifikant sind und die Unterschiede zwischen den drei Mahlzeitengruppen signifikant sind. 3.5 Kategorialer Prädiktor mit Interaktionen Wir können die gleiche Analyse durchführen, die wir oben durchgeführt haben, diesmal die Interaktion von mealcat mit yrrnd einschließen. Bei Verwendung von xi. Ist es einfach, einen Interaktionsbegriff einzuschließen, wie unten gezeigt. Wir können die Gesamtinteraktion mit dem Testbefehl testen. Dieser Wechselwirkungseffekt ist nicht signifikant. Es ist wichtig zu beachten, wie sich die Bedeutung der Koeffizienten in der Gegenwart dieser Interaktionsterme ändert. Zum Beispiel könnten wir im vorigen Modell mit nur Haupteffekten Byrrnd als den Unterschied zwischen dem ganzen Jahr und nicht ganzjährigen Schulen interpretieren. Doch nachdem wir den Interaktionsbegriff hinzugefügt haben, repräsentiert der Begriff Byrrnd den Unterschied zwischen Zelle3 und Zelle6 oder der Differenz zwischen dem ganzen Jahr und Nichtjahresschulen bei der Mahlzeit 3 (weil Mealcat 3 die weggelassene Gruppe war). Das Vorhandensein einer Interaktion würde bedeuten, dass die Differenz zwischen ganzjährig und nicht-jährigen Schulen hängt von der Höhe der mealcat. Die Wechselwirkungsterme BImeaXyrrn1 und BImeaXyrrn2 stellen das Ausmaß dar, in dem sich der Unterschied zwischen den Jahresrundschulen bei mealcat1 und bei mealcat2 (im Vergleich zur Referenzgruppe, mealcat3) ändert. Beispielsweise stellt der Begriff BImeaXyrrn1 die Differenz zwischen ganzjährig und nichtjährig für mealcat1 gegenüber der Differenz für mealcat3 dar. Mit anderen Worten, BImeaXyrrn1 in diesem Entwurf ist (cell1-cell4) - (cell3-cell6) oder es stellt dar, wie viel die Wirkung von yrrnd zwischen mealcat1 und mealcat3 unterscheidet. Im Folgenden haben wir die prognostizierten Werte für die sechs Zellen in Bezug auf die Koeffizienten im Modell gezeigt. Wenn Sie dies mit dem Haupteffektmodell vergleichen, werden Sie sehen, dass die vorhergesagten Werte die gleichen sind, mit Ausnahme der Addition von ImeaXyrrn1 (in Zelle 4) und ImeaXyrrn2 (in Zelle 5). Es kann sehr schwierig sein, diese Interaktionsbegriffe zu interpretieren, wenn Sie spezifische Vergleiche vornehmen möchten. Wenn Sie zum Beispiel einen Test der einfachen Hauptwirkung von yrrnd ausführen wollten, wenn Sie 1, dh einen Vergleich von cell1 mit cell4, durchführen, sollten Sie die BImealcat1-Bits und BImealcat1 BImeaXyrrn1 miteinander vergleichen und da die Nachteile von Imealcat1 ausfallen würden, Wir würden testen Dieser Test ist signifikant, was darauf hindeutet, dass die Wirkung von yrrnd ist signifikant für die mealcat 1 Gruppe. Wie wir sehen werden, können solche Tests leichter über anova durchgeführt werden. 3.5.2 Verwendung von anova Die Konstruktion dieser Interaktionen kann mit dem Befehl anova etwas einfacher sein. Wie Sie weiter unten sehen, gibt der anova-Befehl den Test der gesamten Hauptwirkungen und Interaktionen ohne die Notwendigkeit, nachfolgende Testbefehle auszuführen. Es ist einfach, Tests von einfachen Haupteffekten mit dem Befehl sme durchzuführen. Sie können sme aus dem Inneren von Stata herunterladen, indem Sie findit sme eingeben (siehe Wie kann ich den findit-Befehl verwenden, um nach Programmen zu suchen und zusätzliche Hilfe für weitere Informationen über die Verwendung von findit zu erhalten). Nun können wir die einfachen Haupteffekte von yrrnd auf jeder Ebene von mealcat testen. Die Ergebnisse von sme zeigen uns die Wirkung von yrrnd auf jeder der 3 Ebenen von mealcat. Wir können sehen, dass der Vergleich für mealcat 1 mit denen übereinstimmt, die wir oben mit der Testanweisung berechnet haben, jedoch war es viel einfacher und weniger fehleranfällig mit dem Befehl sme. Obwohl dieser Abschnitt konzentriert sich auf die Handhabung von Analysen mit Interaktionen, zeigen diese Ergebnisse keine Hinweise auf Interaktion. Wir konnten entscheiden, Wechselwirkungsterme von zukünftigen Analysen wegzulassen, die gefunden haben, dass die Wechselwirkungen nicht signifikant sind. Dies würde künftige Analysen vereinfachen, wobei jedoch der Interaktionsbegriff nützlich sein kann, um den Lesern zu gewährleisten, dass der Interaktionsterm nicht signifikant ist. 3.6 Kontinuierliche und kategoriale Variablen 3.6.1 Verwendung von regress Sagen wir, dass wir sowohl kontinuierliche als auch kategorische Variablen in einer Analyse analysieren wollen. Zum Beispiel können yrrnd und somecol in der gleichen Analyse. Wir können die vorhergesagten Werte mit dem Vorhersagebefehl erstellen. Ermöglicht die graphische Darstellung der vorhergesagten Werte durch somecol. Der Koeffizient für somecol zeigt an, dass für jeden Einheitsanstieg in somecol die api00-Punktzahl voraussichtlich um 2,23 Einheiten erhöht wird. Dies ist die Steigung der Zeilen, die in dem obigen Graphen gezeigt sind. Die Grafik hat zwei Zeilen, eine für die ganzjährigen Schulen und eine für die nicht-ganzjährigen Schulen. Der Koeffizient für yrrnd ist -149.16, was anzeigt, dass, wenn yrrnd um 1 Einheit zunimmt, die api00-Punktzahl um etwa 149 Einheiten sinken soll. Wie Sie in der Grafik sehen können, ist die obere Zeile etwa 150 Einheiten höher als die untere Zeile. Sie können sehen, dass der Schnittpunkt 637 ist und dass die obere Linie die Y-Achse kreuzt, wenn X 0 ist. Die untere Linie kreuzt die Linie um etwa 150 Einheiten niedriger bei etwa 487. 3.6.2 Anova verwenden Wir können diese Analyse mit dem Programm ausführen Anova Befehl. Der anova-Befehl geht davon aus, dass die Variablen kategorial sind, also müssen wir die continu () - Option (die als cont () abgekürzt werden kann, verwenden, um anzugeben, dass somecol eine kontinuierliche Variable ist. Wenn wir die t-Werte aus dem Regress-Befehl (oben) quadrieren, würden wir feststellen, dass sie mit denen des anova-Befehls übereinstimmen. 3.7 Interaktionen von Continuous durch 01 Kategorische Variablen Oben zeigten wir eine Analyse, die die Beziehung zwischen somecol und api00 betrachtete und auch yrrnd einschloß. Wir haben gesehen, dass dies ein Diagramm, wo wir sahen die Beziehung zwischen somecol und api00, aber es gab zwei Regressionsgeraden, eine höhere als die andere, aber mit gleichen Steigung. Ein solches Modell ging davon aus, dass die Steigung für beide Gruppen gleich war. Vielleicht kann die Steigung für diese Gruppen unterschiedlich sein. Lassen Sie die Regressionen getrennt für diese beiden Gruppen beginnend mit den nicht-ganzjährigen Schulen laufen. Ebenso können wir das ganze Jahr über Schulen betrachten. Beachten Sie, dass die Steigung der Regressionsgerade für die Schulen im ganzen Jahr viel steiler ausfällt als für die nichtjährigen Schulen. Dies wird durch die Regressionsgleichungen bestätigt, die zeigen, dass die Steigung für die ganzjährigen Schulen höher ist (7,4) als nichtjährige Schulen (1,3). Wir können diese vergleichen, um zu sehen, wenn diese signifikant voneinander verschieden sind, indem wir die Wechselwirkung von somecol durch yrrnd einschließen. Eine Wechselwirkung einer stetigen Variablen durch eine kategorische Variable. 3.7.1 Interaktionen manuell berechnen Wir beginnen mit der manuellen Berechnung der Interaktion von somecol durch yrrnd. Starten Sie neu und verwenden Sie die Datei elemapi2 mit der Option clear, um alle Variablen, die wir zuvor erstellt haben, zu löschen. Als nächstes können Sie eine Variable, die die Interaktion von einigen College (somecol) und ganzjährig Schulen (yrrnd) genannt yrXsome ist. Wir können nun die Regression durchführen, die testet, ob der Koeffizient für somecol bei Jahresrundschulen und Nichtjahresschulen signifikant unterschiedlich ist. Tatsächlich ist der Interaktionseffekt von yrXsome signifikant. Wir können einen Graphen mit den Regressionsgeraden für die beiden Schultypen erstellen, die zeigen, wie unterschiedlich ihre Regressionslinien sind. Zuerst erstellen wir den vorhergesagten Wert, wir nennen ihn yhata. Dann erstellen wir separate Variablen für die beiden Schultypen, die yhata0 für nichtjährige Schulen und yhata1 für ganzjährige Schulen genannt werden. Wir können dann die vorhergesagten Werte für die beiden Arten von Schulen durch somecol. Sie können sehen, wie die beiden Linien haben ganz unterschiedliche Hänge, im Einklang mit der Tatsache, dass die yrXsome-Interaktion war signifikant. Die Option c (ll) gibt an, dass yhata0 mit einer Linie verbunden werden soll und yhata1 mit gestrichelten Linien verbunden werden sollte (weil wir nach dem l eingeschlossen haben). Wenn wir l. Es hätte eine gepunktete Linie gemacht. Die Optionen für gestrichelte und gepunktete Linien sind neu für Stata 7 und Sie können weitere Informationen über die Hilfe grsym finden. Wir können denselben Graphen mit den Datenpunkten wieder aufzeichnen. Das Diagramm oben verwendet die gleiche Art von Punkten für die Datenpunkte für beide Arten von Schulen. Lets make separate Variablen für die api00 Scores für die beiden Arten von Schulen genannt api000 für die nicht-ganzjährigen Schulen und api001 für die ganzjährigen Schulen. Wir können dann den gleichen Graphen wie oben ausführen, nur die Punkte für die beiden Schularten unterschiedlich zeigen. Im folgenden verwenden wir kleine Kreise für die nicht-ganzjährigen Schulen und Dreiecke für das ganze Jahr über Schulen. Wir können schnell die Regressionen wieder ausführen, wo wir separate Regressionen für die beiden Gruppen durchgeführt haben Nun können wir die Regression für beide Arten von Schulen mit dem Interaktionsbegriff zeigen. Beachten Sie, dass der Koeffizient für somecol in der kombinierten Analyse derselbe ist wie der Koeffizient für somecol für die nichtjährigen Schulen. Dies liegt daran, dass nichtjährige Rundschulen die Referenzgruppe sind. Dann ist der Koeffizient für die yrXsome-Wechselwirkung in der kombinierten Analyse der Bsomecol für die ganzjährigen Schulen (7,4) minus Bsomecol für die nichtjährigen Schulen (1,41), was 5,99 ergibt. Diese Interaktion ist der Unterschied in den Hängen von somecol für die beiden Arten von Schulen, und deshalb ist dies nützlich für die Prüfung, ob die Regressionslinien für die beiden Arten von Schulen gleich sind. Wenn die beiden Schulformen den gleichen Regressionskoeffizienten für somecol hatten. Dann wäre der Koeffizient für die yrXsome-Wechselwirkung 0. In diesem Fall ist die Differenz signifikant, was anzeigt, daß die Regressionslinien signifikant verschieden sind. Wenn wir also den Graphen der beiden Regressionslinien betrachten, sehen wir den Unterschied in den Steigungen der Regressionslinien (siehe Grafik unten). In der Tat können wir sehen, dass die nichtjährigen Schulen (die durchgezogene Linie) eine geringere Steigung (1,4) als die Steigung für die ganzjährigen Schulen (7,4) haben. Der Unterschied zwischen diesen Steigungen ist 5,99, der Koeffizient für yrXsome. 3.7.2 Recheninteraktionen mit xi Wir können den Befehl xi auch für diese Art der Analyse verwenden. Starten Sie neu und verwenden Sie die Datei elemapi2. Wir können ein Modell ausführen, genau wie das Modell, das wir oben mit dem Befehl xi gezeigt haben. Sie können die Ergebnisse vergleichen, um die oben genannten und sehen, dass wir die gleichen Ergebnisse erhalten. Der Begriff i. yrrndsomecol schafft 3 Begriffe, somecol. Iyrrnd2 eine Indikatorvariable für yrrnd, die angibt, ob die Schule das ganze Jahr über ist und die Variable IyrXsome 2 die Interaktion von yrrnd durch somecol darstellt. Wie wir oben ausgeführt haben, können wir vorhergesagte Werte erstellen und Graphen erstellen, die die Regressionslinien für die beiden Schulformen zeigen. Wir verzichten auf diese Befehle. 3.7.3 Recheninteraktionen mit anova Wir können auch ein Modell wie das oben dargestellte Modell mit dem Befehl anova ausführen. Wir schließen die Begriffe yrrnd somecol und die Interaktion yrrnrsomecol ein. Wie wir oben dargestellt haben, können wir die vorhergesagten Werte mit dem Vorhersagebefehl berechnen und die einzelnen Regressionslinien grafisch darstellen. Diese Befehle werden weggelassen. In diesem Abschnitt haben wir festgestellt, dass die Beziehung zwischen somecol und api00 davon abhängt, ob die Schule ein ganzes Jahr Schule oder eine nichtjährige Schule ist. Für das ganze Jahr über Schulen, war die Beziehung zwischen somecol und api00 deutlich stärker als für nicht-jährige Rundschulen. Im Allgemeinen können Sie anhand dieser Analyse überprüfen, ob die Stärke der Beziehung zwischen zwei kontinuierlichen Variablen auf der Basis der kategorischen Variablen variiert. 3.8 Kontinuierliche und kategoriale Variablen, Interaktion mit 123 Variablen Die vorangegangenen Beispiele zeigten, wie Regressionen mit einer kontinuierlichen Variablen und einer kategorialen Variablen mit 2 Ebenen durchgeführt werden können. Diese Beispiele werden dies weiter durch eine kategorische Variable mit 3 Ebenen, mealcat. Wir können den Befehl xi verwenden, um ein Modell mit somecol auszuführen. Mealcat und die Interaktion dieser beiden Variablen. Die Interaktion hat nun zwei Begriffe (ImeaXsome 2 und ImeaXsome 3). Um einen Gesamttest dieser Interaktion zu erhalten, können wir den Testbefehl verwenden. Diese Ergebnisse zeigen, dass die Gesamtinteraktion tatsächlich signifikant ist. Das bedeutet, dass sich die Regressionslinien der 3 Gruppen signifikant unterscheiden. Wie wir vorher getan haben, können wir die vorhergesagten Werte berechnen und einen Graphen der vorhergesagten Werte bilden, damit wir sehen können, wie sich die Regressionslinien unterscheiden. Da wir drei Gruppen hatten, erhalten wir drei Regressionslinien, eine für jede Kategorie von Mealcat. Die durchgezogene Linie ist für Gruppe 1, die gestrichelte Linie für Gruppe 2 und die gepunktete Linie für Gruppe 3. Gruppe 1 war die weggelassene Gruppe, daher ist die Steigung der Linie für Gruppe 1 der Koeffizient für irgendeine Farbe, die -94 ist . Tatsächlich hat diese Linie eine Abwärtsneigung. Wenn wir den Koeffizienten für irgendeinen Kubus zu dem Koeffizienten für ImeaXsome 2 addieren, erhalten wir den Koeffizienten für die Gruppe 2, d. H. 3.14 -.94 ergibt 2,2, die Steigung für Gruppe 2. Tatsächlich zeigt Gruppe 2 eine Aufwärtssteigung. Wenn wir den Koeffizienten für einen bestimmten Koeffizienten für den Koeffizienten für ImeaXsome 3 addieren, erhalten wir den Koeffizienten für die Gruppe 3, dh 2,6 -.94 ergibt 1,66, die Steigung für die Gruppe 3. Die Steigungen für die 3 Gruppen sind also der Test der Koeffizient für ImeaXsome 2 überprüfte, ob sich der Koeffizient für Gruppe 2 von Gruppe 1 unterscheidet, und zwar war dies signifikant. Ebenso wurde bei der Prüfung des Koeffizienten für ImeaXsome 3 geprüft, ob sich der Koeffizient für Gruppe 3 von Gruppe 1 unterscheidet, und zwar signifikant. Was war der Test des Koeffizienten somecol-Test? Dieser Koeffizient repräsentiert den Koeffizienten für die Gruppe 1, so dass geprüft wurde, ob sich der Koeffizient für Gruppe 1 (-0,94) signifikant von 0 unterscheidet. Dies ist wahrscheinlich ein nicht interessanter Test. Die Vergleiche in den obigen Analysen scheinen nicht so interessant zu sein wie der Vergleich von Gruppe 1 vs 2 und dann Vergleich von Gruppe 2 vs 3. Diese sukzessiven Vergleiche scheinen viel interessanter. Wir können dies tun, indem wir Gruppe 2 die weggelassene Gruppe, und dann jede Gruppe würde mit der Gruppe 2 verglichen werden. Wie wir zuvor getan haben, werden wir den char Befehl verwenden, um anzuzeigen, dass wir Gruppe 2 die weggelassene Kategorie und dann wieder ausführen wollen Die Regression. Nun testet der Test von ImeaXsome 1, ob sich der Koeffizient für Gruppe 1 von Gruppe 2 unterscheidet, und das tut. Dann prüft der Test von ImeaXsome 3, ob der Koeffizient für Gruppe 3 signifikant von Gruppe 2 abweicht, und dies nicht. Dies ist angesichts des Graphen und der Schätzung der Koeffizienten, die wir haben, sinnvoll, dass -.94 signifikant von 2.2 abweicht, aber 2.2 nicht signifikant von 1.66 unterscheidet. 3.8.2 Anova verwenden Mit dem Befehl anova können Sie die gleiche Analyse durchführen, wie unten dargestellt. The anova command gives us somewhat less flexibility since we cannot choose which group is the omitted group. Because the anova command omits the 3rd category, and the analysis we showed above omitted the second category, the parameter estimates will not be the same. You can compare the results from below with the results above and see that the parameter estimates are not the same. Because group 3 is dropped, that is the reference category and all comparisons are made with group 3. These analyses showed that the relationship between somecol and api00 varied, depending on the level of mealcat . In comparing group 1 with group 2, the coefficient for somecol was significantly different, but there was no difference in the coefficient for somecol in comparing groups 2 and 3. This covered four techniques for analyzing data with categorical variables, 1) manually constructing indicator variables, 2) creating indicator variables using the xi command, 3) coding variables using xi3 . and 4) using the anova command. Each method has its advantages and disadvantages, as described below. Manually constructing indicator variables can be very tedious and even error prone. For very simple models, it is not very difficult to create your own indicator variables, but if you have categorical variables with many levels andor interactions of categorical variables, it can be laborious to manually create indicator variables. However, the advantage is that you can have quite a bit of control over how the variables are created and the terms that are entered into the model. The xi command can really ease the creation of indicator variables, and make it easier to include interactions in your models by allowing you to include interaction terms such as i. progfemale. The xi command also gives you the flexibility to decide which category would be the omitted category (unlike the anova command). The anova command eliminates the need to create indicator variables making it easy to include variables that have lots of categories, and making it easy to create interactions by allowing you to include terms like somecolmealcat . It can be easier to perform tests of simple main effects with the anova command. However, the anova command is not flexible in letting you choose which category is the omitted category (the last category is always the omitted category). As you will see in the next chapter, the regress command includes additional options like the robust option and the cluster option that allow you to perform analyses when you dont exactly meet the assumptions of ordinary least squares regression. In such cases, the regress command offers features not available in the anova command and may be more advantageous to use. See the Stata Topics: Regression page for more information and resources on regression with categorical predictors in Stata. 3.10 Self Assessment 1. Using the elemapi2 data file ( use ats. ucla. edustatstatawebbooksregelemapi2 ) convert the variable ell into 2 categories using the following coding, 0-25 on ell becomes 0, and 26-100 on ell becomes 1. Use this recoded version of ell to predict api00 and interpret the results. 2. Convert the variable ell into 3 categories coding those scoring 0-14 on ell as 1, and those 1541 as 2 and 42100 as 3. Do an analysis predicting api00 from the ell variable converted to a 123 variable. Interpret the results. 3. Do a regression analysis predicting api00 from yrrnd and the ell variable converted to a 01 variable. Then create an interaction term and run the analysis again. Interpret the results of these analyses. 4. Do a regression analysis predicting api00 from ell coded as 01 (from question 1) and somecol . and the interaction of these two variables. Interpret the results, including showing a graph of the results. 5. Use the variable ell converted into 3 categories (from question 2) and predict api00 from ell in 3 categories, from somecol and the interaction. of these two variables. Interpret the results, including showing a graph. Click here for our answers to these self assessment questions. 3.11 For more informationMultivariate Statistics: Concepts, Models, and Applications David W. Stockburger Multiple Regression with Categorical Variables When a researcher wishes to include a categorical variable with more than two level in a multiple regression prediction model, additional steps are needed to insure that the results are interpretable. These steps include recoding the categorical variable into a number of separate, dichotomous variables. This recoding is called dummy coding. In order for the rest of the chapter to make sense, some specific topics related to multiple regression will be reviewed at this time. The Multiple Regression Model Multiple regression is a linear transformation of the X variables such that the sum of squared deviations of the observed and predicted Y is minimumized. The prediction of Y is accomplished by the following equation: The b values are called regression weights and are computed in a way that minimizes the sum of squared deviations. Dichotomous Predictor Variables Categorical variables with two levels may be directly entered as predictor or predicted variables in a multiple regression model. Their use in multiple regression is a straightforward extension of their use in simple linear regression. When entered as predictor variables, interpretation of regression weights depends upon how the variable is coded. If the dichotomous variable is coded as 0 and 1, the regression weight is added or subtracted to the predicted value of Y depending upon whether it is positive or negative. If the dichotomous variable is coded as -1 and 1, then if the regression weight is positive, it is subtracted from the group coded as -1 and added to the group coded as 1. If the regression weight is negative, then addition and subtraction is reversed. Dichotomous variables can be included in hypothesis tests for R 2 change like any other variable. Testing for Blocks of Variables A block of variables can simultaneously be entered into an hierarchical regression analysis and tested as to whether as a whole they significantly increase R 2. given the variables already entered into the regression equation. The degrees of freedom for the R 2 change test corresponds to the number of variables entered in the block of variables. Correlated and Uncorrelated Predictor Variables Adding variables to a linear regression model will always increase the unadjusted R 2 value. If the additional predictor variables are correlated with the predictor variables already in the model, then the combined results are difficult to predict. In some cases, the combined result will provide only a slightly better prediction, while in other cases, a much better prediction than expected will be the outcome of combining two correlated variables. If the additional predictor variables are uncorrelated (r 0) with the predictor variables already in the model, then the result of adding additional variables to the regression model is easy to predict. Namely the R 2 change will be equal to the correlation coefficient squared between the added variable and predicted variable. In this case it makes no difference what order the predictor variables are entered into the prediction model. For example, if X 1 and X 2 were uncorrelated (r 12 0) and r 1y 2 .3 and r 2y 2 .4, then R 2 for X 1 and X 2 would equal .3 .4 .7. The value for R 2 change for X 2 given X 1 was in the model would be .4. The value for R 2 change for X 2 given no variable was in the model would be .4. It would make no difference at what stage X 2 was entered into the model, the value for R 2 change would always be .4. Similarly, the R 2 change value for X 1 would always be .3. Because of this relationship, uncorrelated predictor variables will be preferred, when possible. Example Data The following simulated data was generated using Example Student. It is available as a text file and an SPSSWIN sav file . Faculty Salary Simulated Data Salary Gender (0Male, 1Female) Rank (1Assistant, 2Associate, 3Full) Dept Department (1Family Studies, 2Biology, 3Business) Years since making Rank Average Merit Ranking It is fairly clear that Gender could be directly entered into a regression model predicting Salary , because it is dichotomous. The problem is how to deal with the two categorical predictor variables with more than two levels ( Rank and Dept ). Categorical Predictor Variables Dummy Coding - making many variables out of one Because categorical predictor variables cannot be entered directly into a regression model and be meaningfully interpreted, some other method of dealing with information of this type must be developed. In general, a categorical variable with k levels will be transformed into k-1 variables each with two levels. For example, if a categorical variable had six levels, then five dichotomous variables could be constructed that would contain the same information as the single categorical variable. Dichotomous variables have the advantage that they can be directly entered into the regression model. The process of creating dichotomous variables from categorical variables is called dummy coding . Depending upon how the dichotomous variables are constructed, additional information can be gleaned from the analysis. In addition, careful construction will result in uncorrelated dichotomous variables. As discussed earlier, these variables have the advantage of simplicity of interpretation and are preferred to correlated predictor variables. Dummy Coding with three levels The simplest case of dummy coding is when the categorical variable has three levels and is converted to two dichotomous variables. For example, Dept in the example data has three levels, 1Family Studies, 2Biology, and 3Business. This variable could be dummy coded into two variables, one called FamilyS and one called Biology . If Dept 1, then FamilyS would be coded with a 1 and Biology with a 0. If Dept 2, then FamilyS would be coded with a 0 and Biology would be coded with a 1. If Dept 3, then both FamilyS and Biology would be coded with a 0. The dummy coding is represented below. Using SPSSWIN to Dummy Code Variables The dummy coding can be done using SPSSWIN and the Transform, Recode, and Into different Variable options. The Dept variable is the Numeric Variable that is going to be transformed. In this case the FamilyS variable is going to be created. The window on the screen should appear as follows: Clicking on the Change button and then on the Old and New Values button will result in the following window: The Old Value is the level of the categorical variable to be changed, the New Value is the value on the transformed variable. In the example window above, a value of 3 on the Dept variable will be coded as a 0 on the FamilyS variable. The Add button must be pressed to add the recoding to the list. When all the recodings have been added, click on the Continue button and then the OK button. The recoding of the Biology is accomplished in the same manner. A listing of the data is presented below. The correlation matrix of the dummy variables and the Salary variable is presented below. Two things should be observed in the correlation matrix. The first is that the correlation between FamilyS and Biology is not zero, rather it is -.474. Second is that the correlation between the Salary variable and the two dummy variables is different from zero. The correlation between FamilyS and Salary is significantly different from zero. The results of predicting Salary from FamilyS and Biology using a multiple regression procedure are presented below. The first table enters FamilyS in the first block and Biology in the second. The second table reverses the order that the variables are entered into the regression equation. The model summary tables are presented below. In the first table above both FamilyS and Biology are significant. In the second, only FamilyS is statistically significant. Note that both orderings end up with the same value for multiple R (.604). It makes a difference what order the variables are entered into the regression equation in the hierarchical analysis. In the next tables, both FamilyS and Biology have been entered in the first block. The model summary table, ANOVA, and Coefficients tables are presented below. The ANOVA and model summary tables contain basically redundant information in this case. The Coefficients table can be interpreted as Biology making 8.886 thousand dollars less in salary per year relative to the Business department, while the Family Studies department make 12.350 thousand dollars less than the Business department. Note that the Sig. levels in the Coefficients table are the same as the significance levels of the model summary tables presented earlier when each of the dummy coded variables is entered into the regression equation last. Similarity of Regression analysis and ANOVA The results of the preceding analysis can be compared to the results of using the ANOVA procedure in SPSSWIN with Salary as the dependent measure and Dept as the independent. The following table presents the table of means and ANOVA table. Note first that the ANOVA tables produced using the ANOVA command and the LINEAR REGRESSION command are identical. ANOVA is a special case of linear regression when the variables have been dummy coded. The second notable comparison of the tables involves the regression weights and the actual differences between the means. Note that the regression weight for FamilyS in the regression procedure is -12.350 and the difference between the means of the Family Studies department (42.25) and the Business department (54.60) is -12.350. Dummy Coding into Independent Variables Selection of an appropriate set of dummy codes will result in new variables that are uncorrelated or independent of each other. In the case when the categorical variable has three levels this can be accomplished by creating a new variable where one level of the categorical variable is assigned the value of -2 and the other levels are assigned the value of 1. The signs are arbitrary and may be reversed, that is, values of 2 and -1 would work equally well. The second variable created as a dummy code will have the level of the categorical variable coded as -2 given the value of 0 and the other values recoded as 1 and -1. In all cases the sum of the dummy coded variable will be zero. Trust me, this is actually much easier than it sounds. Interpretation is straightforward. Each of the new dummy coded variables, called a contrast . compares levels coded with a positive number to levels coded with a negative number. Levels coded with a zero are not included in the interpretation. For example, Dept in the example data has three levels, 1Family Studies, 2Biology, and 3Business. This variable could be dummy coded into two variables, one called Business (comparing the Business Department with the other two departments) and one called FSvsBio (for Family Studies versus Biology.) The Business contrast would create a variable where all members of the Business Department would be given a value of -2 and all members of the other two departments would be given a value of 1. The FSvsBio contrast would assign a value of 0 to members of the Business Department, 1 divided by the number of members of the Family Studies Department to member of the Family Studies Department, and -1 divided by the number of members of the Biology Department to members of the Biology Department. The FSvsBio variable could be coded as 1 and -1 for Family Studies and Biology respectively, but the recoded variable would no longer be uncorrelated with the first dummy coded variable ( Business ). In most practical applications, it makes little difference whether the variables are correlated or not, so the simpler 1 and -1 coding is generally preferred. The contrasts are summarized in the following table. Dummy Coded Variables The data matrix with the dummy coded variables would appear as follows . The correlation matrix containing the two contrasts and the Salary variable is presented below. Note that the correlation coefficient between the two contrasts is zero. The correlation between the Business contrast and Salary is -.585 with a squared correlation coefficient of .342. This correlation coefficient has a significance level of .001. The correlation coefficient between the FSvsBio contrast and Salary is -.150 with a squared value of .023. In this case entering Business or FSvsBio first makes no difference in the results of the regression analysis. Entering both contrasts simultaneously into the regression equation produces the following ANOVA table. Note that this table is identical to the two ANOVA tables presented in the previous section. It may be concluded that it does not make a difference what set of contrasts are selected when only the overall test of significance is desired. It does make a difference how contrasts are selected, however, if it is desired to make a meaningful interpretation of each contrast. The coefficient table for the simultaneous entry of both contrasts is presented below. Note that the Sig. level is identical to the value when each contrast was entered last into the regression model. In this case the Business contrast was significant and the FSvsBio contrast was not. The interpretation of these results would be that the Business Department was paid significantly more than the Family Studies and Biology Departments, but that no significant differences in salary were found between the Family Studies and Biology Departments. By carefully selecting the set of contrasts to be used in the regression with categorical variables, it is possible to construct tests of specific hypotheses. The hypotheses to be tested are generated by the theory used when designing the study. Categorical Predictor Variables with Six Levels If a categorical variable had six levels, five dummy coded contrasts would be necessary to use the categorical variable in a regression analysis. For example, suppose that a researcher at a headache care center did a study with six groups of four patients each (N is being deliberately kept small). The dependent measure is subjective experience of pain. The six groups consisted of six different treatment conditions. Application of this dummy coding in a regression model entering all contrasts in a single block would result in an ANOVA table similar to the one obtained using Means, ANOVA, or General Linear Model programs in SPSSWIN. This solution would not be ideal, however, because there is considerable information available by setting the contrasts to test specific hypotheses. The levels of the categorical variable generally dictate the structure of the contrasts. In the example study, it makes sense to contrast the two control groups (1 and 2) with the other four experimental groups (3, 4, 5, and 6). Any two numbers would work, one assigned to groups 1 and 2 and the others assigned to the other four groups, but it is conventional to have the sum of the contrasts equal to zero. One contrast that meets this criterion would be (-2, -2, 1, 1, 1, 1). Generally it is easiest to set up contrasts within subgroups of the first contrast. For example, a second contrast might test whether there are differences between the two control groups. This contrast would appear as (1, -1, 0, 0, 0, 0). A third contrast might compare non-drug vs. rug treatment groups, groups 3 and 4 vs. groups 5 and 6 (0, 0, 1, 1, -1, -1). As can be seen, this would be a contrast within the experimental treatment groups. Within the non-drug treatment, a contrast comparing Group 3 with Group 4 might be appropriate (0, 0, 1, -1, 0, 0). Within the drug treatment conditions, a contrast comparing the two drug treatments would be the last contrast (0, 0, 0, 0, 1, -1). Combined, the contrasts are given in the following table. Dummy Coded Variables The following table presents example data and dummy coded contrasts for this hypothetical study. The correlation matrix of the five contrasts and the pain variable is presented below. Note that the correlation coefficients between the five contrasts are all zero. This occurs because all groups have an equal number of subjects. Using pain as the dependent variable and the five contrasts as the independent variables, the regression results tables entering all variables in block 1 are presented below. Of major interest is the Sig. column on the Coefficients table. Note that all contrasts are statistically significant except C5. This can be interpreted as: (1) The treatment conditions were more effective than the control conditions, (2) the two control conditions significantly differed from one another, with placebo more effective than control (3) The drug groups were more effective in reducing pain than the non-drug conditions (4) Acupuncture was significantly more effective than Psychotherapy (5) the two drug treatments were not significantly different from one another. The output from the General Linear Model, Simple Factorial program in SPSSWIN is presented below. Note that it is for practical purposes identical to the ANOVA table produced using the multiple regression program with the dummy coded contrasts. In effect what the General Linear Model program does is to automatically select a set of contrasts and then perform a regression analysis with those contrasts. The General Linear Model program allows the user to specify a special set of contrasts so that an analysis like the one done with dummy coding of contrasts in multiple regression might be performed. It is left for the reader to explore SPSSWIN for this ability. Combinations of Categorical Predictor Variables In the original example data set for this chapter there were three obvious categorical variables, Gender . Rang. and Dept . Gender could be directly entered into the regression model. After dummy coding into two contrasts each, Rank and Dept could be directly entered into the regression model. Difficulties arise, however, when combinations of these categorical variables must be considered. For example, consider Gender and Dept . Rather than two groups and three groups, this combination of categorical variables must be considered as six groups, Male Family Studies, Female Family Studies, Male Biology, Female Biology, Male Business, and Female Business. Dummy coding these data would require five dummy coded contrasts. Three exist, one for Gender and two for Dept . but there is no accounting for the two additional contrasts. They will be the focus of the next topics , interaction effects . EQUAL SAMPLE SIZE Because everything works out much cleaner when equal sample sizes are assumed, this case will be presented first. The example data set has been reduced to twelve subjects, two for each combination of Gender and Dept . The reduced data set is presented below. The situation is now analogous to the earlier case when the categorical variable had six levels. Main Effects A categorical variable with six levels can be dummy coded into five contrasts. The first three contrasts have already been discussed. The first of these contrasts will compare males with females and will comprise the Gender Main Effect . The next two will compare the salaries of the three departments over levels of gender and will be called the Department Main Effect . The dummy codes for these main effects are presented below. Gender Main Effect Department Main Effect This is basically the same coding as discussed earlier, except it is simplified because of the equal number of subjects in each cell. It will later be demonstrated that the correlation coefficients between these dummy coded variables is zero. Interaction Effects Two additional dummy coded variables are needed to account for the categorical variable. These contrasts will comprise the Interaction Effect . In this case the easiest way to find the needed contrasts is to multiply the dummy coded contrast for gender times the dummy coded contrasts for Department. This has the result of changing the sign of the department contrasts for one gender but not the other. The results of this operation appear below. Gender Main Effect Department Main Effect The correlation matrix for this data set is presented below. Note that the contrasts all have a correlation coefficient of zero among themselves. The contrasts will be entered into the regression equation predicting salary in three blocks. The first block will contain C1, the second will contain C2 and C3, while the third will contain C4 and C5. The results of this analysis are presented below. Entering the contrasts in the opposite order has no effect on R Square Change. The value for F Change and Sig. F change is different, however, because different error terms are employed in each case. In this subset of the data, none of the contrasts are significant. The interpretation of the main effects and interaction effects will be the topic of discussion of the next chapter. UNEQUAL SAMPLE SIZE Equal sample size is seldom achieved in the real world, even in the best-designed experiments. Unequal sample size makes the effects no longer independent. This implies that it makes difference in hypothesis testing when the effects are added into the model, first, middle, or last. The same dummy coding that was applied to equal sample sizes will now be applied to the original data with unequal sample sizes. The simplest way to do this is to recode GENDER into C. DEPARTMENT into C2 and C3, and compute C4 and C5 by multiplying corresponding contrasts into the new contrast. For example, C4 could be created by multiplying C1 C2 and C5 could be created by multiplying C1 C3. The data and dummy coded contrasts appear below. The correlation matrix of the contrasts is presented below. Note that the correlation coefficients between the contrasts are not zero. This has the effect of changing the value of R 2 Change for a term depending upon when that term was entered into the model. This is illustrated by entering the two contrasts associated with Dept (C2 and C3) first, second, and last. Main Effects of Dept Entered First Main Effects of Dept Entered Second There are two different ways in which the main effect of Dep t may be entered second in the regression model. The first is after Gender and is presented below. As can be seen, the value of R 2 change for adding C2 and C3 changes only slightly from .379 to .376. A slightly greater change in R 2 change value is observed if the interaction contrasts (C4 and C5) are entered before the main effect of department. Note that the value of R 2 change is greater for Gender (C1) if it is entered last, rather than first. Main Effects of Dept Entered Third Note that the value of R 2 change is only changed slightly depending upon when it was entered into the model. The pattern of results of the significance tests would not change. Main Effect of Gender Given Rank, Dept, Gender X Rank, Gender X Dept, Years, Merit The dummy coded contrasts can be used like any other variables in a multiple regression analysis. In order to find the significance of the effect of Gender given Rank . Dept . Gender X Rank . Gender X Dept . Years . and Merit . the Rank and Gender X Rank effects must be created as dummy coded contrasts. In the following data file the Rank main effect consists of two contrasts: C2a contrasting Full professors with Assistant and Associate professors and C3a contrasting Assistant with Associate professors. The Gender X Rank interaction contrasts (C4a and C5a) are constructed by multiplying the Gender contrast (C1) times the two contrasts for the main effect for Rank. The additional dummy coded variables are added to the data file in the following. Salary is predicted in six blocks (only two are really needed) in the following multiple regression analysis. In a simplified analysis, the first block would contain all variables except Gender (C1) and the second would contain only Gender (C1). As can be seen, the R 2 change for Gender has increased to a value of .120 which is significant. The value of multiple R is not really 1.000, but very high, close to 1.000. For that reason the error variance is extremely small, resulting in significant effects. This illustrates the problem of fitting too few data points with too many parameters. If all the effects mentioned above are entered into the model in a single block, the coefficients table appears as follows. A has been described earlier, the Sig. column is the significance level of that variable if it is entered last in the regression model. Since t 2 F, it is noted that 77.205 2 is equal to 5960.619, within rounding error. In this case, every variable except C4 and Years is statistically significant. The alert reader has probably noted that other interaction terms could be created and entered into the regression model. For example, four dummy coded contrasts could be created such that a Rank X Dept interaction could be found. Multiplying this by the Gender contrast (C1) would result in a three-way Gender X Rank X Dept interaction. ANOVA using General Linear Model in SPSSWIN Although the dummy coding of variables in multiple regression results in considerable flexibility in the analysis of categorical variables, it can also be tedious to program. For this reason most statistical packages have made a program available that automatically creates dummy coded variables and performs the appropriate statistical analysis. In most cases the user is unaware of the calculations being performed in the computer program. This is the case with the General Linear Model program in SPSSWIN. This program is selected in SPSSWIN by Statistics, General Linear Model, and GLM - General Factorial. To perform the Gender by Department analysis discussed earlier in this section, enter Salary as the dependent measure and Gender and Dept as fixed factors. The screen should appear as follows. Click OK and the results are as follows. Note that the F column and Sig. column is identical to the results of the R 2 change analysis presented earlier in this chapter if each of the effects is entered last. This is the meaning of the default Type III Sum of Squares. The interpretation of effects, the result of the dummy coding of categorical variables, is the subject of the next chapter.
No comments:
Post a Comment