Multinomial Logistic Regression | Stata Data Analysis Examples
文章推薦指數: 80 %
Multinomial logistic regression is used to model nominal outcome variables, in which the log odds of the outcomes are modeled as a linear combination of the ... SkiptoprimarynavigationSkiptomaincontentSkiptoprimarysidebar Versioninfo:CodeforthispagewastestedinStata12. Multinomiallogisticregressionisusedtomodelnominal outcomevariables,inwhichthelogoddsoftheoutcomesaremodeledasalinear combinationofthepredictorvariables. Pleasenote:Thepurposeofthispageistoshowhowtousevariousdataanalysiscommands. Itdoesnotcoverallaspectsoftheresearchprocesswhichresearchersareexpectedtodo.In particular,itdoesnotcoverdatacleaningandchecking,verificationofassumptions,model diagnosticsandpotentialfollow-upanalyses. Examplesofmultinomiallogisticregression Example1.People’soccupationalchoicesmightbeinfluenced bytheirparents’occupationsandtheirowneducationlevel.Wecanstudythe relationshipof one’soccupationchoicewitheducationlevelandfather’s occupation. Theoccupationalchoiceswillbetheoutcomevariablewhich consistsofcategoriesofoccupations. Example2.Abiologistmaybe interestedinfoodchoicesthatalligatorsmake.Adultalligatorsmighthave differentpreferencesfromyoungones.Theoutcomevariableherewillbethe typesoffood,andthepredictorvariablesmightbesizeofthealligators andotherenvironmentalvariables. Example3.Enteringhighschoolstudentsmakeprogramchoicesamonggeneralprogram, vocationalprogramandacademicprogram.Theirchoicemightbemodeledusing theirwritingscoreandtheirsocialeconomicstatus. Descriptionofthedata Forourdataanalysisexample,wewillexpandthethirdexampleusingthe hsbdemodataset.Let’sfirstreadinthedata. usehttps://stats.idre.ucla.edu/stat/data/hsbdemo,clear Thedatasetcontainsvariableson 200students.Theoutcomevariableisprog,programtype.Thepredictorvariables aresocialeconomicstatus,ses, athree-levelcategoricalvariable andwritingscore,write,acontinuousvariable.Let’sstartwith gettingsomedescriptivestatisticsofthe variablesofinterest. tabprogses,chi2 typeof|ses program|lowmiddlehigh|Total -----------+---------------------------------+---------- general|16209|45 academic|194442|105 vocation|12317|50 -----------+---------------------------------+---------- Total|479558|200 Pearsonchi2(4)=16.6044Pr=0.002 tableprog,con(meanwritesdwrite) ------------------------------------ typeof| program|mean(write)sd(write) ----------+------------------------- general|51.333339.397776 academic|56.257147.943343 vocation|46.769.318754 ------------------------------------ Analysismethodsyoumightconsider Multinomiallogisticregression:thefocusofthispage. Multinomialprobitregression:similartomultinomiallogistic regressionbutwithindependentnormalerrorterms. Multiple-groupdiscriminantfunctionanalysis:Amultivariatemethodfor multinomialoutcomevariables Multiplelogisticregressionanalyses,oneforeachpairofoutcomes: Oneproblemwiththisapproachisthateachanalysisispotentiallyrunonadifferent sample.Theotherproblemisthatwithoutconstrainingthelogisticmodels, wecanendupwiththeprobabilityofchoosingallpossibleoutcomecategories greaterthan1. Collapsingnumberofcategoriestotwoandthendoingalogisticregression:Thisapproach suffersfromlossofinformationandchangestheoriginalresearchquestionsto verydifferentones. Ordinallogisticregression:Iftheoutcomevariableistrulyordered andifitalsosatisfiestheassumptionofproportional odds,thenswitchingtoordinallogisticregressionwillmakethemodelmore parsimonious. Alternative-specificmultinomialprobitregression:allows differenterrorstructuresthereforeallowstorelaxtheindependenceof irrelevantalternatives(IIA,seebelow“ThingstoConsider”)assumption. Thisrequiresthatthedatastructurebechoice-specific. Nestedlogitmodel:alsorelaxestheIIAassumption,also requiresthedatastructurebechoice-specific. Multinomiallogisticregression Belowweusethemlogitcommandtoestimateamultinomiallogisticregression model.Thei.beforesesindicatesthatsesisaindicator variable(i.e., categoricalvariable),andthatitshouldbeincludedinthemodel.We havealsousedtheoption“base”toindicatethecategorywewouldwant touseforthebaselinecomparisongroup.Inthemodelbelow,wehavechosento usetheacademicprogramtypeasthebaselinecategory. mlogitprogi.seswrite,base(2) Iteration0:loglikelihood=-204.09667 Iteration1:loglikelihood=-180.80105 Iteration2:loglikelihood=-179.98724 Iteration3:loglikelihood=-179.98173 Iteration4:loglikelihood=-179.98173 MultinomiallogisticregressionNumberofobs=200 LRchi2(6)=48.23 Prob>chi2=0.0000 Loglikelihood=-179.98173PseudoR2=0.1182 ------------------------------------------------------------------------------ prog|Coef.Std.Err.zP>|z|[95%Conf.Interval] -------------+---------------------------------------------------------------- general| ses| 2|-.533291.4437321-1.200.229-1.40299.336408 3|-1.162832.5142195-2.260.024-2.170684-.1549804 | write|-.0579284.0214109-2.710.007-.0998931-.0159637 _cons|2.8521861.1664392.450.014.56600755.138365 -------------+---------------------------------------------------------------- academic|(baseoutcome) -------------+---------------------------------------------------------------- vocation| ses| 2|.2913931.47637370.610.541-.64228221.225068 3|-.9826703.5955669-1.650.099-2.14996.1846195 | write|-.1136026.0222199-5.110.000-.1571528-.0700524 _cons|5.21821.1635494.480.0002.9376867.498714 ------------------------------------------------------------------------------ Intheoutputabove,wefirstseetheiterationlog,indicatinghowquickly themodelconverged.Theloglikelihood(-179.98173)canbeusedincomparisonsofnestedmodels,butwewon’tshowanexampleofcomparing modelshere Thelikelihoodratiochi-squareof48.23withap-value<0.0001tellsusthatourmodelasawholefits significantlybetterthananemptymodel(i.e.,amodelwithno predictors) Theoutputabovehastwoparts,labeledwiththecategoriesofthe outcomevariableprog.Theycorrespondtothetwoequationsbelow: $$ln\left(\frac{P(prog=general)}{P(prog=academic)}\right)=b_{10}+b_{11}(ses=2)+b_{12}(ses=3)+b_{13}write$$ $$ln\left(\frac{P(prog=vocation)}{P(prog=academic)}\right)=b_{20}+b_{21}(ses=2)+b_{22}(ses=3)+b_{23}write$$ where\(b\)’saretheregressioncoefficients. Aone-unitincreaseinthevariablewriteisassociatedwitha .058decreaseintherelativelogoddsofbeingingeneralprogramvs. academicprogram. Aone-unitincreaseinthevariablewriteisassociatedwitha .1136decreaseintherelativelogoddsofbeinginvocationprogramvs. academicprogram. Therelativelogoddsofbeingingeneralprogramvs.inacademicprogramwill decreaseby1.163ifmovingfromthelowestlevelofses(ses==1)tothe highestlevelofses(ses==3). Theratiooftheprobabilityofchoosingoneoutcomecategoryoverthe probabilityofchoosingthebaselinecategoryisoftenreferredtoasrelativerisk (anditisalsosometimesreferredtoasoddsaswehavejustusedtodescribedthe regressionparametersabove). Relativeriskcanbeobtainedby exponentiatingthelinearequationsabove,yielding regressioncoefficientsthatarerelativeriskratiosforaunitchangeinthe predictorvariable. Wecanusetherrroptionfor mlogitcommandtodisplaytheregressionresultsintermsofrelativerisk ratios. mlogit,rrr MultinomiallogisticregressionNumberofobs=200 LRchi2(6)=48.23 Prob>chi2=0.0000 Loglikelihood=-179.98173PseudoR2=0.1182 ------------------------------------------------------------------------------ prog|RRRStd.Err.zP>|z|[95%Conf.Interval] -------------+---------------------------------------------------------------- general| ses| 2|.586671.2603248-1.200.229.24586071.39991 3|.3125996.1607448-2.260.024.1140996.856432 | write|.9437175.0202059-2.710.007.9049342.984163 _cons|17.3256220.209282.450.0141.761221170.4369 -------------+---------------------------------------------------------------- academic|(baseoutcome) -------------+---------------------------------------------------------------- vocation| ses| 2|1.338291.63752640.610.541.52609043.404399 3|.3743103.2229268-1.650.099.11648881.202761 | write|.8926126.0198338-5.110.000.8545734.9323449 _cons|184.6016214.7934.480.00018.872131805.719 ------------------------------------------------------------------------------ Therelativeriskratioforaone-unitincreaseinthevariablewriteis .9437(exp(-.0579284)fromtheoutputofthefirstmlogitcommand above)forbeingingeneralprogramvs.academicprogram. Therelativeriskratioswitchingfromses=1to3is.3126forbeing ingeneralprogramvs.academicprogram.Inotherwords,theexpectedrisk ofstayinginthegeneralprogramislowerforsubjectswhoarehighin ses. Wecantestforanoveralleffectofses usingthetestcommand.Belowweseethattheoveralleffectofsesis statisticallysignificant. test2.ses3.ses (1)[general]2.ses=0 (2)[academic]2.ses=0 (3)[vocation]2.ses=0 (4)[general]3.ses=0 (5)[academic]3.ses=0 (6)[vocation]3.ses=0 Constraint2dropped Constraint5dropped chi2(4)=10.82 Prob>chi2=0.0287 Morespecifically,wecanalsotestiftheeffectof3.sesin predictinggeneralvs.academicequalstheeffectof3.sesin predictingvocationvs.academicusingthetestcommandagain.Thetest showsthattheeffectsarenotstatisticallydifferentfromeachother. test[general]3.ses=[vocation]3.ses (1)[general]3.ses-[vocation]3.ses=0 chi2(1)=0.08 Prob>chi2=0.7811 Youcanalsousepredictedprobabilitiestohelpyouunderstandthemodel. Youcancalculatepredictedprobabilitiesusingthemarginscommand.Belowweusethemarginscommandto calculatethepredictedprobabilityofchoosingeachprogramtypeateachlevel ofses,holdingallothervariablesinthemodelattheirmeans.Since therearethreepossibleoutcomes,wewillneedtousethemarginscommandthree times,oneforeachoutcomevalue. marginsses,atmeanspredict(outcome(1)) AdjustedpredictionsNumberofobs=200 ModelVCE:OIM Expression:Pr(prog==general),predict(outcome(1)) at:1.ses=.235(mean) 2.ses=.475(mean) 3.ses=.29(mean) write=52.775(mean) ------------------------------------------------------------------------------ |Delta-method |MarginStd.Err.zP>|z|[95%Conf.Interval] -------------+---------------------------------------------------------------- ses| 1|.3581927.07264234.930.000.2158163.500569 2|.2283338.04511625.060.000.1399075.31676 3|.1784932.05404863.300.001.0725598.2844266 ------------------------------------------------------------------------------ marginsses,atmeanspredict(outcome(2)) AdjustedpredictionsNumberofobs=200 ModelVCE:OIM Expression:Pr(prog==academic),predict(outcome(2)) at:1.ses=.235(mean) 2.ses=.475(mean) 3.ses=.29(mean) write=52.775(mean) ------------------------------------------------------------------------------ |Delta-method |MarginStd.Err.zP>|z|[95%Conf.Interval] -------------+---------------------------------------------------------------- ses| 1|.4396842.07799255.640.000.2868217.5925466 2|.4777488.05525938.650.000.3694426.586055 3|.7009021.066304210.570.000.5709483.8308559 ------------------------------------------------------------------------------ marginsses,atmeanspredict(outcome(3)) AdjustedpredictionsNumberofobs=200 ModelVCE:OIM Expression:Pr(prog==vocation),predict(outcome(3)) at:1.ses=.235(mean) 2.ses=.475(mean) 3.ses=.29(mean) write=52.775(mean) ------------------------------------------------------------------------------ |Delta-method |MarginStd.Err.zP>|z|[95%Conf.Interval] -------------+---------------------------------------------------------------- ses| 1|.2021232.05996473.370.001.0845945.3196519 2|.2939174.05036175.840.000.1952103.3926246 3|.1206047.046432.600.009.0296037.2116058 ------------------------------------------------------------------------------ Wecanusethemarginsplotcommandtoplotpredicted probabilitiesbysesforeachcategoryofprog.Plotscreated bymarginsplotarebasedonthelastmarginscommand run.Furthermore,wecancombinethethreemarginsplotsintoone graphtofacilitatecomparisonusingthegraphcombine command.Asitisgenerated,eachmarginsplotmustbegivenaname, whichwillbeusedbygraphcombine.Additionally,wewould likethey-axestohavethesamerange,soweusetheycommon optionwithgraphcombine. marginsses,atmeanspredict(outcome(1)) marginsplot,name(general) marginsses,atmeanspredict(outcome(2)) marginsplot,name(academic) marginsses,atmeanspredict(outcome(3)) marginsplot,name(vocational) graphcombinegeneralacademicvocational,ycommon Anotherwaytounderstandthemodelusingthepredictedprobabilitiesisto lookattheaveragedpredictedprobabilitiesfordifferentvaluesofthe continuouspredictorvariablewrite,averagingacrosslevelsofses. margins,at(write=(30(10)70))predict(outcome(1))vsquish PredictivemarginsNumberofobs=200 ModelVCE:OIM Expression:Pr(prog==general),predict(outcome(1)) 1._at:write=30 2._at:write=40 3._at:write=50 4._at:write=60 5._at:write=70 ------------------------------------------------------------------------------ |Delta-method |MarginStd.Err.zP>|z|[95%Conf.Interval] -------------+---------------------------------------------------------------- _at| 1|.2130954.07743272.750.006.0613302.3648606 2|.2569932.05297614.850.000.1531619.3608245 3|.2543008.03362977.560.000.1883878.3202138 4|.2057855.03715365.540.000.1329658.2786052 5|.1423089.04816832.950.003.0479007.2367172 ------------------------------------------------------------------------------ margins,at(write=(30(10)70))predict(outcome(2))vsquish PredictivemarginsNumberofobs=200 ModelVCE:OIM Expression:Pr(prog==academic),predict(outcome(2)) 1._at:write=30 2._at:write=40 3._at:write=50 4._at:write=60 5._at:write=70 ------------------------------------------------------------------------------ |Delta-method |MarginStd.Err.zP>|z|[95%Conf.Interval] -------------+---------------------------------------------------------------- _at| 1|.1348408.05259792.560.010.0317507.2379308 2|.2808143.05532135.080.000.1723867.389242 3|.4773283.039759112.010.000.399402.5552547 4|.6680752.043468915.370.000.5828776.7532727 5|.8075124.054550414.800.000.7005956.9144291 ------------------------------------------------------------------------------ margins,at(write=(30(10)70))predict(outcome(3))vsquish PredictivemarginsNumberofobs=200 ModelVCE:OIM Expression:Pr(prog==vocation),predict(outcome(3)) 1._at:write=30 2._at:write=40 3._at:write=50 4._at:write=60 5._at:write=70 ------------------------------------------------------------------------------ |Delta-method |MarginStd.Err.zP>|z|[95%Conf.Interval] -------------+---------------------------------------------------------------- _at| 1|.6520638.09440416.910.000.4670353.8370924 2|.4621925.06143887.520.000.3417747.5826102 3|.2683708.03429327.830.000.2011575.3355842 4|.1261393.030194.180.000.0669679.1853107 5|.0501787.02168632.310.021.0076744.092683 ------------------------------------------------------------------------------ Sometimes,acoupleofplotscanconveyagooddealamountofinformation. Below,weplotthepredictedprobabilitiesagainstthewritingscorebythe levelofsesfordifferentlevelsoftheoutcomevariable. predictp1p2p3 sortwrite twoway(linep1writeifses==1)(linep1writeifses==2)(linep1writeifses==3),/// legend(order(1"ses=1"2"ses=2"3"ses=3")ring(0)position(7)row(1)) twoway(linep2writeifses==1)(linep2writeifses==2)(linep2writeifses==3),/// legend(order(1"ses=1"2"ses=2"3"ses=3")ring(0)position(7)row(1)) twoway(linep3writeifses==1)(linep3writeifses==2)(linep3writeifses==3),/// legend(order(1"ses=1"2"ses=2"3"ses=3")ring(0)position(7)row(1)) Wemayalsowishtoseemeasuresofhowwellourmodelfits.Thiscanbeparticularlyusefulwhencomparing competingmodels.Theuser-writtencommandfitstatproducesa varietyoffitstatistics.Youcanfindmoreinformationonfitstatand downloadtheprogrambyusingcommand searchfitstatinStata(see HowcanIusethesearchcommandtosearchforprogramsandgetadditionalhelp? formoreinformationaboutusingsearch). fitstat MeasuresofFitformlogitofprog fit Log-LikInterceptOnly:-204.097Log-LikFullModel:-179.982 D(185):359.963LR(6):48.230 Prob>LR:0.000 McFadden'sR2:0.118McFadden'sAdjR2:0.045 ML(Cox-Snell)R2:0.214Cragg-Uhler(Nagelkerke)R2:0.246 CountR2:0.610AdjCountR2:0.179 AIC:1.950AIC*n:389.963 BIC:-620.225BIC':-16.440 BICusedbyStata:402.350AICusedbyStata:375.963 Thingstoconsider TheIndependenceofIrrelevantAlternatives(IIA)assumption:roughly, theIIAassumptionmeansthataddingordeletingalternativeoutcome categoriesdoesnotaffecttheoddsamongtheremainingoutcomes.Testof theIIAassumptioncanbeperformed byusingtheStatacommandmlogtest,iia.However,asof April23,2010,mlogtest,iiadoesnotworkwithfactorvariables.Therearealternativemodelingmethods thatrelaxtheIIAassumption, suchasalternative-specificmultinomialprobitmodelsornestedlogit models. Diagnosticsandmodelfit:unlikelogisticregressionwherethereare manystatisticsforperformingmodeldiagnostics,itisnotas straightforwardtododiagnosticswithmultinomiallogisticregression models.Modelfitstatisticscanbeobtainedviathefitstatcommand. Forthepurposeofdetectingoutliersorinfluentialdatapoints,onecan runseparatelogitmodelsandusethediagnosticstoolsoneachmodel. Pseudo-R-Squared:theR-squaredofferedintheoutputisbasicallythe changeintermsoflog-likelihoodfromtheintercept-onlymodeltothe currentmodel.ItdoesnotconveythesameinformationastheR-squarefor linearregression,eventhoughitisstill“thehigher,thebetter”. Samplesize:multinomialregressionusesamaximumlikelihoodestimation method,itrequiresalargesamplesize.Italsousesmultiple equations.Thisimpliesthatitrequiresanevenlargersamplesizethanordinalor binarylogisticregression. Completeorquasi-completeseparation:Completeseparationimpliesthat theoutcomevariableseparatesapredictorvariablecompletely,leading toperfectpredictionbythepredictorvariable.Unlikerunningalogitmodel, Statadoesnotofferawarningwhenthishappens.Insteaditcontinuesto computeiterativelyandrequiresamanualquittostoptheprocess. Perfectpredictionmeansthatonlyonevalueofapredictor variableisassociatedwithonlyonevalueoftheresponsevariable.Butyoucantellfromtheoutputofthe regressioncoefficientsthatsomethingiswrong.Youcanthendoatwo-waytabulationoftheoutcome variablewiththeproblematicvariabletoconfirmthisandthenrerunthemodel withouttheproblematicvariable. Emptycellsorsmallcells: Youshouldcheckforemptyorsmall cellsbydoingacross-tabulationbetweencategoricalpredictorsand theoutcomevariable. Ifacellhasveryfewcases(asmallcell),the modelmaybecomeunstableoritmightnotevenrunatall. Perhapsyourdatamaynotperfectlymeettheassumptionsandyour standarderrorsmightbeoffthemark.Youmightwishtoseeourpagethat showsalternativemethodsforcomputingstandard errorsthatStataoffers. Sometimesobservationsareclusteredintogroups(e.g.,peoplewithin families,studentswithinclassrooms).Insuchcases,youmaywanttosee ourpageonnon-independencewithinclusters. Seealso BeyondBinary LogisticRegressionwithStatawithmovies Annotatedoutputforthemlogit command References Long,J.S.andFreese,J.(2006) RegressionModelsforCategoricalandLimitedDependentVariablesUsingStata, SecondEdition.CollegeStation,Texas:StataPress. Hosmer,D.andLemeshow,S. (2000)AppliedLogisticRegression(Second Edition).NewYork:JohnWiley&Sons,Inc.. Agresti,A.(1996)AnIntroductiontoCategoricalData Analysis.NewYork:JohnWiley&Sons,Inc. PrimarySidebar Clickheretoreportanerroronthispageorleaveacomment YourName(required) YourEmail(mustbeavalidemailforustoreceivethereport!) Comment/ErrorReport(required) Δ Howtocitethispage UCLAOIT ©2021UCREGENTS HOME CONTACT
延伸文章資訊
- 1Multinomial Logistic Regression | Stata Data Analysis Examples
Multinomial logistic regression is used to model nominal outcome variables, in which the log odds...
- 2Multinomial Logit Models - Overview - University of Notre Dame
When categories are unordered, Multinomial Logistic regression is one often-used strategy. Mlogit...
- 3Multinomial logistic regression - Wikipedia
In statistics, multinomial logistic regression is a classification method that generalizes logist...
- 4Multinomial Response Models
If J = 2 the multinomial logit model reduces to the usual logistic regression model. Note that we...
- 5Multinomial Logistic Regression
Multinomial logistic regression is used to predict categorical placement in or the probability of...