woensdag 31 augustus 2011

Stata and graphics

Although the graphs aren't really flashy, Stata is quite good in generating graphical output and automatizing the proces. There is a vaste array of possible graphs to choose from. Below are some links.
For variations on the histogram command, try:
  • byhist
  • catplot
  • tabplot
  • spineplot
  • simple bar graphs, provided you bin and collapse variables first yourself

Stata, ranks and quantiles

I'm a huge fan of Stata, largely preferring the program over SPSS for almost everything, even graphics and tables. Yet ranks and quantiles are quite awkward. The commands needed are:

rank() - using egen, watch out for the order
xtile - basic program included in the software (Stata 11)
xtile2 - permits by-variables, to be installed

Office 2007, pdf's en algebra

Wanneer "vreemde en complexe" lettertypes niet geïnstalleerd zijn, zal de functie 'opslaan als pdf' in de Office-programma's niet werken. Oplossing: print met een pdf-printer (pdf995) of installeer de lettertypes.

httpBericht publiceren://help.lockergnome.com/office/Problems-equations-Word-2007--ftopict943892.html

Factoranalyse

Een zeer korte handleiding voor factoranalyse:

Waarom factoranalyse

Factoranalyse is een datareductiemethode, waarbij gezocht wordt naar latente variabelen die een set van variabelen samenvatten. Het vertrekt daarom van de correlatiematrix van deze geobserveerde variabelen.

Voorbeeld: leerlingen leggen op het eind van het jaar twaalf testen af. Een exploratieve factoranalyse zou aan het licht kunnen brengen dat dit eigenlijk slechts drie vaardigheden toetst.

  1. Taalvakken: Nederlands, Frans, Engels, Duits
  2. Analytische vakken: wiskunde, natuurkunde, scheikunde, logica
  3. Kennisvakken: geografie, biologie, geschiedenis, esthetica
Een confirmatorische factoranalyse werk op de omgekeerde manier: 

Let op!


  • Controleer eerst de correlatiematrix: enkel variabelen die een correlatie boven .30 met andere variabelen hebben dienen te worden weerhouden.
  • Gebruik geen factoranalyse als de correlatie tussen variabelen niet aan een latente factor te wijten is maar bijvoorbeeld aan de distributie van de populatie op irrelevante kenmerken.

Scree plot



Assumpties
Dezelfde als voor correlaties: normaal verdeelde, continue variabelen. Heb je ook of enkel ordinale of binaire data, dan moet je vluchten naar polychorische principale componentenanalyse (het trage en onoverzichtelijke polychoricpca in Stata of de complexe explorative factoranalyse in Mplus).

Eigenwaardes
Als een vuistregel gebruikt men Kaisers criterium (Kaiser's criterion) dat zegt dat eigenwaardes groter dan 1 moeten zijn. Alternatief kan je kijken naar relatieve sterke dalingen van de eigenwaarde, naar de cumulatieve voorspelde variantie, naar de factorsterkte (Mplus: > .9) of naar bepaalde significantiematen (Mplus: RMSE). 

Rotatie
Om de geobserveerde variabelen te scoren op een bepaalde matrix zijn er verschillende mogelijkheden. Orthogonale rotaties of oblique rotaties. Voor zover ik het begrijp zijn de dimensies in een orthogonale rotatie niet gecorreleerd (denk aan een kruis met rechte hoeken), terwijl dit in oblique rotaties wel het geval is (een kruis met scherpe en stompe hoeken). De vergelijking met kruisen gaat natuurlijk enkel op in twee- of driedimensionele omgevingen. De richting van de rotatie wordt bepaald door de te maximaliseren of minimaliseren afstand:
  • Varimax: maximaliseert per factor de variantie van de ladingen op deze factor
  • Quartimax (~oblimax): maximaliseert per variabele de variantie van de ladingen op de verschillende factoren
  • Geomin (Mplus), oblimin, equamax, ...
Er zijn slechts vuistregels omtrent de interpretatie van de factorladingen. Vanaf .400 en zeker vanaf .600 spreken we van hoge ladingen, al hangt het telkens af van de rotatiemethode.
Links
Yahoo Answers: What are difference between varimax, quartimax and equamax rotation in factor analysis? - http://answers.yahoo.com/question/index?qid=20080616044600AAnsCc4

maandag 22 augustus 2011

woensdag 25 mei 2011

Cluster analysis: yeah yeah yeah

Context
For a recent working paper, I did some cluster analyses. Plural, my friend, because there's not one way. Before reading further, please understand that cluster analysis is an explorative, non-inferential method.

Problem
The Stata manual says it all: "Some researchers claim that there are as many clustering methods as there are researchers. This is untrue, there are many more methods than researchers." The wording may not be exact, but I agree with the statement. In this post, I will address some difficulties.

Issues

  • Linkage method: there are five linkage methods, which define how cases get grouped: which distances to look after. There is no optimal method: single linkage causes linking patterns (one cases after another joining the same cluster), average linkage and ward's linkage are sensitive to outliers, ward's linkage distance measurement is not possible to interprete and centroid linkage will even refuse to return dendrograms.
  • Similarity distance measurement: there are many distance measurements: simple, Euclidian, city block, Mahalanobis, ... Which one to choose? There's no truth.
  • Cases: excluding cases may skew central values of clusters, resulting in wrongly added cases
  • Order: in two-step cluster analysis, some pre-clustering is done before tackling the full data set (because it may be too large). Shuffle your deck and you'll get different results.
  • Variables: ideally you cluster orthogonal factors, still, and in the general case, it doesn't mean that each variable/factor is equally important for clustering. They will all have the same a priori impact on clustering though.
  • Succes garanteed: you'll always get a result. Does that mean you found something? No. 
  • Stopping rules: there are many rules to determine the optimal number of clusters (see Mulligan, 1985). Calinski is default in Stata. There are some issues though, such as multiple optima or none at all. And does it make sense to choose a 23 cluster solution?
Conclusion

Cluster analysis is a wonderful way to reduce and explore data. However, I would recommend to experiment with different ways and keep my hands of it if they bear no similarity. Heck, a cluster analysis of outcomes would be useful!

Judgement: not to be trusted

maandag 2 mei 2011

Do people actually read them too?

Nick Cox is the incarnation of Stata. His view on table-machines, when asked to make more user friendly Stata tables:


http://www.stata.com/statalist/archive/2010-11/msg00071.html


I think that is a good summary of a widely held view. I have no axe to grind here as I am not a provider in the main territory that Thomas has in mind, but on behalf of fellow user-programmers I suggest that the descriptor "ad hoc" does not quite fit the situation.


Of the programs implied here, and that I know about, I'd say that they all have a clear vision of what they want to do which has been maintained throughout their development. It can seem ad hoc if you want to do something else, but that is a different matter. As I've already remarked in this thread, user-programmers tend to write programs for themselves, with no guarantee of meeting anyone else's needs.


The overall problem here is describable in two words "better tables" and lots of users want to second that. But some want more unified syntax for tables within Stata, some want more detailed control, some want greater support for export to their own favourite foreign programs, standard or otherwise, and some want two or three of those. All understandable enough, but don't complain if this all turns into a [T] manual several hundred pages long to meet not only your reasonable requests, but most other people's too!


Emphasis here varies depending on where you come from. Some people seem routinely to be producing tens or hundreds of tables in rigid formats full of coefficients, standard errors and P-values and those awful stars. Do people actually read them too?


Nick
n.j.cox@durham.ac.uk


P.S. On a key question of intellectual priority, I lay claim to "Some Alternative Software", as indeed could anyone else who came up with it earlier or later. But (with thanks to Maarten for the compliment) the joke about there being so many standards to choose from is certainly not mine. Andrew Tanenbaum got there much earlier.