Research

multinomial logit in R

Monday, August 11th, 2008 -- By ET

# load the data
> nes96 <- read.table(”http://www.stat.washington.edu/quinn/classes/536/data/nes96r.dat”, header=TRUE)

# load the nnet library which has the multinom function
> library(nnet)
Loading required package: MASS

# let’s change the PID variable into a factor
> nes96$PID <- factor(nes96$PID, labels=c(”Strong Democrat”, “Weak
Democrat”, “Independent-Democrat”, “Independent-Independent”,
“Independent-Republican”, “Weak Republican”, “Strong Republican”))

# fit a multinomial logit model where PID is the response variable,
# and the predictors are: log(popul+.1), selfLR, age, educ, and income

> multinom.out <- multinom(PID~log(popul+.1)+selfLR+age+educ+income,
data=nes96)
# weights: 49 (36 variable)
initial value 1836.939181
iter 10 value 1691.507857
iter 20 value 1603.709441
iter 30 value 1523.540117
iter 40 value 1461.935703
final value 1461.922748
converged

# let’s take a look at the results
> summary(multinom.out, corr=FALSE)

Re-fitting to get Hessian

Call:
multinom(formula = PID ~ log(popul + 0.1) + selfLR + age + educ +
income, data = nes96)

Coefficients:
(Intercept) log(popul + 0.1) selfLR age
Weak Democrat -0.3733563 -0.01153736 0.2976980 -0.024944529
Independent-Democrat -2.2509348 -0.08875096 0.3916628 -0.022897526
Independent-Independent -3.6659051 -0.10596768 0.5735134 -0.014851243
Independent-Republican -7.6136944 -0.09155519 1.2787425 -0.008680754
Weak Republican -7.0604314 -0.09328575 1.3469400 -0.017903442
Strong Republican -12.1051935 -0.14087942 2.0699883 -0.009432601
educ income
Weak Democrat 0.082487696 0.005195818
Independent-Democrat 0.181044184 0.047874118
Independent-Independent -0.007131611 0.057577321
Independent-Republican 0.199828063 0.084495215
Weak Republican 0.216938699 0.080958623
Strong Republican 0.321923127 0.108890412

Std. Errors:
(Intercept) log(popul + 0.1) selfLR age
Weak Democrat 0.6298384 0.03428246 0.09362654 0.006524873
Independent-Democrat 0.7631917 0.03916169 0.10823837 0.007914493
Independent-Independent 1.1565170 0.05703689 0.15854307 0.011331040
Independent-Republican 0.9575695 0.04379006 0.12889466 0.008418690
Weak Republican 0.8443601 0.03935158 0.11718480 0.007611003
Strong Republican 1.0599179 0.04213748 0.14340364 0.008133748
educ income
Weak Democrat 0.07358680 0.01763372
Independent-Democrat 0.08528965 0.02228102
Independent-Independent 0.12628792 0.03361350
Independent-Republican 0.09412459 0.02619610
Weak Republican 0.08500687 0.02297606
Strong Republican 0.09109678 0.02530048

Residual Deviance: 2923.845
AIC: 2995.845

# the results above aren’t too surprising– for instance we see that
# more conservative respondents are more likely to be Republican identifiers
# than Democratic identifiers or independent identifiers. Income has a
# similar effect. Republican identifiers also tend to be better educated
# than other identifiers.
#

# let’s look at some fitted probabilities. To do this, we’ll set all of
# the covariates (except selfLR) equal to their median values and vary
# selfLR from its low value to it’s high value.

> beta <- coef(multinom.out)
> X <- cbind(1, 3.096, 1:7, 44, 4, 17)

> Xb1 <- X %*% beta[1,]
> Xb2 <- X %*% beta[2,]
> Xb3 <- X %*% beta[3,]
> Xb4 <- X %*% beta[4,]
> Xb5 <- X %*% beta[5,]
> Xb6 <- X %*% beta[6,]

> denomsum <- exp(Xb1) + exp(Xb2) + exp(Xb3) + exp(Xb4) + exp(Xb5) +
exp(Xb6)

> p0 <- 1/(1+denomsum)
> p1 <- exp(Xb1)/(1+denomsum)
> p2 <- exp(Xb2)/(1+denomsum)
> p3 <- exp(Xb3)/(1+denomsum)
> p4 <- exp(Xb4)/(1+denomsum)
> p5 <- exp(Xb5)/(1+denomsum)
> p6 <- exp(Xb6)/(1+denomsum)

> plot(0:6, p0, xlab=”Self LR Placement”, ylab=”", ylim=c(0,1), type=”l”,
col=1, pch=16)
> lines(0:6, p1, col=2)
> lines(0:6, p2, col=3)
> lines(0:6, p3, col=4)
> lines(0:6, p4, col=5)
> lines(0:6, p5, col=6)
> lines(0:6, p6, col=7)
> legend(0, 1, legend=c(”Strong Dem.”, “Weak Dem.”, “Ind. Dem.”, “Ind.
Ind.”, “Ind. Rep.”, “Weak Rep.”, “Strong Rep.”), col=1:7, lty=1)

Abstract Cloud

Wednesday, June 25th, 2008 -- By ET

screen-capture5

screen-capture-2

These pictures are based on words I used in an abstract of a paper. Bigger words have a larger voice.

Indeed, the paper is about pricing.

JIM Best Paper Award

Tuesday, June 17th, 2008 -- By ET

A pleasant surprise:

jim-best

Past winners:
2007 Award for Best Paper in 2006
Bundling, Unbundling and Pricing of Multiform Products: The Case of Magazine Content by R. Venkatesh and Rabikar Chatterjee (20/2)
Runners-up
A Field Experiment to Assess the Interruption Effect of Pop-Up Promotions by Wendy Moe (20/1)
Designing Marketplaces of the Artificial with Consumers in Mind: Four Approaches to Understanding Consumer Behavior in Electronic Environments by Steven Bellman, Eric Johnson, Gerald Lohse & Naomi Mandel (20/1)

2006 Award for Best Paper in 2005
Can We Predict Customer Lifetime Value by Edward Malthouse and Robert Blattberg (19/1)
Runners-up
Who Are the Multichannel Shoppers and How Do They Perform? Correlates of Multichannel Shopping Behavior by V. Kumar and Rajkumar Venkatesan (19/2)
Collaborating to Create: The Internet as Platform for Customer Engagement in Product Innovation by Mohanbir Sawhney, Gianmario Verona and Emanuela Prandelli (19/4)
Consumers in a Multichannel Environment: Product Utility, Process Utility and Channel Choice by Sridhar Balasubramanian, Rajagopal Raghunathan and Vijay Mahajan (19/2)

2005 Award for Best Paper in 2004
Capturing Evolving Visit Behavior in Clickstream Data by Wendy Moe and Peter Fader (18/1)

2004 Award for Best Paper in 2003
Customers as Assets by Sunil Gupta and Donald Lehmann (17/1)

2003 Award for Best Paper in 2002
Intentional Social Action in Virtual Communities by Richard Bagozzi and Utpal Dholakia (16/2)

Some Interesting Trends

Saturday, May 31st, 2008 -- By ET

Which segment are you in?

Looks like we should go to the creative class that represent less than 1/3 work force, but gets 1/2 the total money.

screen-capture2.png

MIT To Be Tuition-Free for 30% Students

Saturday, March 8th, 2008 -- By ET

Just received an email from MIT alumni office.  MIT will be tuition-free for nearly 30% students.

From the email:

MIT has long been a proponent of need-blind admissions and need-based
aid and this additional investment in our brilliant student body continues
to award aid based solely on need.

I’m very proud with this move.  I somehow have the impression that schools like Yale and Harvard are for rich kids. As a consequence, it means that some brilliant students can not go to those places due to financial constraints.  This artificial financial divide creates a feedback loop to discriminate kids from poorer families.  The free-tuition move at MIT will definitely help those smart and poor kids to fulfill their dreams, and more importantly help the society to benefit from better matching good education with smart kids.

I’m grateful to MIT for the support during my PhD study.   In addition to tuition waiver, I also got stipend to pay my rents, etc.  In return, I don’t know how to pay back this generosity.  Should I send my daughter to MIT in the future?  One thing for sure, her dad is richer than her dad’s dad.  If she needs to pay some tuition, I’d be happy to contribute.  The question is “Is MIT a good place for her?”

Back in Boston, we had some guests visiting,  one of them (G) asked Alantha (A),

G: Hey, Alantha, do you want to go to MIT or Harvard?
A: Hmm, I don’t want to go to either.
G: Oh, so where do you want to go?
A: Disneyland… (a sheepish smile)
Everyone else: (speechless)

The Pleasure of Finding Things Out

Friday, March 7th, 2008 -- By ET

I can categorize people I know into 4 groups. Well, at least theoretically, because I can’t really find an example in the (stupid,mean) domain.

smartnice.JPG

Richard Feynman, among many other people who I respect belongs to the first quadrant of (smart,nice). A good example of (smart,mean) is probably Lu Xun or an assistant professor I met at Wharton (he subsequently left Wharton and went to Europe). I’ve been listening to two of his audiobooks “Surely You’re Joking, Mr. Feynman”, and “What Do You Care What Other People Think”, and I feel very intellectually stimulated by his view of the world.

On my ipod, I have all sorts of audiobooks from Kung Fu novels by Jin Yong to bestsellers like “The World is Flat”, “The Devil Wears Prada” to non-fictions like one explaining E=MC^2, and a few of Stephen Hawking’s books on the universe. None of the these books can keep me awake at night. When I listen to Feynman’s audiobook, sometimes I get too excited to fall in sleep. For example, he described how he studied the process of people falling into sleep and how to examine the dreams. When I was young, I did almost exactly the same thing, and had some interesting findings such as “I can see color in dreams”, “I can control my motion consciously in my dreams”, and “I can create the situation in dream to explain the external sound I hear while I’m sleeping”.

The curiosity of finding how things work can be immensely rewarding. In the following video, Feynman explains how he appreciates the beauty of a flower. It’s amazing.

I Hear, I See, I Do

Saturday, December 15th, 2007 -- By ET

I hear, and I forget;

I see, and I remember;

I do, and I understand.

– Asian Proverb

Why My Daughters’ Names Start with A

Wednesday, November 28th, 2007 -- By ET

From this paper by Nelson and Simmons.

In five studies, we [Nelson and Simmons] found that people like their names enough to unconsciously pursue consciously avoided outcomes that resemble their names. Baseball players avoid strikeouts, but players whose names begin with the strikeout-signifying letter K strike out more than others (Study 1). All students want As, but students whose names begin with letters associated with poorer performance (C and D) achieve lower grade point averages (GPAs) than do students whose names begin with A and B (Study 2), especially if they like their initials (Study 3). Because lower GPAs lead to lesser graduate schools, students whose names begin with the letters C and D attend lower-ranked law schools than students whose names begin with A and B (Study 4). Finally, in an experimental study, we manipulated congruence between participants’ initials and the labels of prizes and found that participants solve fewer anagrams when a consolation prize shares their first initial than when it does not (Study 5). These findings provide striking evidence that unconsciously desiring negative name-resembling performance outcomes can insidiously undermine the more conscious pursuit of positive outcomes.

This figure on GPA says it all.

initials.png

Missuse of Statistics

Monday, November 12th, 2007 -- By ET

200604191943-pix1.gif

In Discovery Travel channel, there is a program called “Miami Ink”, it tells many stories about people getting tattoos.    Despite the way they tried to make it sound like fun and cool, I still don’t see any meaning of getting a tattoo.  I don’t think anyone I know has a tattoo, too.

 

The figure above is an ad for body piercing.  It shows that the risk of body piercing is very very low, compared to many other risks we face everyday.   That small number really is insignificant.  However, there is a fatal logical flaw in it. If you put the death as a result of body piercing on top of the human population as the denominator, you get such results.

 

Installing MATLAB in Mac OSX with CrossOver

Friday, November 9th, 2007 -- By ET

screen-capture-2.jpg

I have my MATLAB installed in Parallel Desktops for Mac. Since I do majority of my work in Mac now, I hate to open Parallel Desktops very often. So I’m thinking about porting some important packages to use in Mac OS natively.

CrossOver is a good package, I managed to port my BaKoMa TeX into Mac OS, it works fine. MATLAB turned out to be hard. When I install it within CrossOver, it gives an error:”Can not install OLE server”. It is related to Database, so I cleaned up all the extra toolboxes, and only install MATLAB itself. The error message still comes up.

Then I zipped the MATLAB from Parallel Desktop and unzipped the files to the “Drive_C” in CrossOver. Running MATLAB gives an error “License Manager Error -9.”. Checking MATLAB website, it seems that even if I have the serial number, I still need to reinstall, but in CrossOver, I simply can not install.

Here is the solution. Just open %CrossOver_Drive_C/MATLAB7/bin/win32/license.dat, and look for something like this: “HOSTID=DISK_SERIAL_NUM=d8682dc9 PLATFORMS=i86_n SN=0″.

Go to %CrossOver_Drive_C and create a file “.windows-serial” and “echo d8682dc9 > .windows-serial”.

Everything will be fine.

As soon as I can port SAS into CrossOver, I can delete Parallel Desktops and save me 30G hard drive space.

UPDATE: I forgot to mention that I installed the latest JRE in CrossOver before I copy MATLAB.

Full version of MATLAB 2006 for Windows. Java GUI included (_without_ -nojvm).

The new Java Runtime Environment Version 5.0 Update 6 for windows (jre-1_5_0_06-windows-i586-p.exe) must be downloaded from: http://www.java.com/en/download/windows_manual.jsp.

JRE must be installed either in windows or through wine.

Then the jre folder in matlab (../Program Files/MATLAB/R2006a/sys/java/jre/win32/jre) directory must replaced by the newly generated jre1.5.0_06 in ../Program Files/Java/.

After that the ../Program Files/MATLAB/R2006a/sys/java/jre/win32/jre.cfg file must be edited to contain a single line withe: 1.5.0_06

After that, MATLAB 2006a will be fully functional (as far as know). You can either use the windows installed version or copy the whole MATLAB folder to ~/.wine/drive_c/Program Files/ (that way you won’t need the windows partition anymore).


BlogTimer
You are visitor number several since September 1, 2001

Copyright Xiaoquan (Michael) Zhang, 2004-2007. All rights reserved.
All trademarks property of their owners.