Tuesday, September 20, 2011

Men's Calorie Calculator Results

Men's Calorie Calculator Results

  http://nutrition.about.com/od/changeyourdiet/a/calguide.htm         
These results will help determine the calorie count you need to maintain your current weight or to achieve your goal weight in a healthy and steady manner.
You need 2208.7 calories per day to maintain your current weight without exercise.
You need 2317.2 calories per day to reach your goal weight slowly and maintain that weight without exercise.
If you reduce your current caloric intake to 1708.7 calories per day you will lose one pound per week without exercise.
If you increase your current caloric intake to 2708.7 calories per day, you will gain one pound per week.
Exercise and Calorie Needs
If you exercise for 30 minutes each day, you may increase your caloric intake to 2408.2 calories per day and still maintain your current weight.
If you exercise for 60 minutes each day, you may increase your caloric intake to 2662.1 calories per day to maintain your current weight.
Macronutrients The United States Department of Agriculture suggests that approximately 50 percent of your calories come from carbohydrates, about 30 percent from fats, and approximately 20 percent from protein sources. One gram of protein has about four calories, one gram of fat has about nine calories, and one gram of carbohydrate has about four calories.

You need 276.1 grams of carbohydrates, 72.9 grams of fat, and 110.4 grams of protein per day for 2208.7 calories to maintain your weight of 120 pounds.

Friday, August 26, 2011

The MBA for Movie Watchers 看电影学MBA - 精髓课程 解析

The MBA for Movie Watchers
  
   1.  Wall Street DVD ~ Michael Douglas
The list author says: 
  "Corporate Finance" 

   2.  Barbarians at the Gate DVD ~ James Garner
The list author says: 
  "Mergers & Acquisitions" 

   3.  Rogue Trader DVD ~ Ewan McGregor
The list author says: 
  "Derivatives and Risk Management" 

   4.  Other People's Money [VHS] VHS Danny DeVito
The list author says: 
  "Corporate Restrucuring" 

   5.  The Godfather (Widescreen Edition) DVD ~ Marlon Brando
The list author says: 
  "Strategic Management" 

   6.  The Hudsucker Proxy DVD ~ Tim Robbins
The list author says: 
  "Marketing Management" 

   7.  Glengarry Glen Ross DVD ~ Al Pacino
The list author says: 
  "Human Resource Management" 
   8.  Lost in Translation DVD ~ Bill Murray
The list author says: 
  "International Business" 

   9.  Tucker--The Man and His Dream [VHS] VHS Jeff Bridges
The list author says: 
  "Operations Management" 

   10.  Wag the Dog (New Line Platinum Series) DVD ~ Dustin Hoffman
The list author says: 
  "Business Communication" 

   11.  Office Space [VHS] VHS Ron Livingston
The list author says: 
  "Organizational Behavior" 

   12.  Thirteen Days (Infinifilm Edition) DVD ~ Kevin Costner
The list author says: 
  "Business Negotiations" 
   13.  Citizen Kane (Two-Disc Special Edition) DVD ~ Orson Welles
The list author says: 
  "Power and Influence" 

   14.  Patton DVD ~ George C. Scott
The list author says: 
  "Leadership" 
   15.  Catch Me If You Can (Widescreen Two-Disc Special Edition) DVD ~ Leonardo DiCaprio
The list author says: 
  "Entrepreneurship"  

   16.  Pirates of Silicon Valley [VHS] VHS Noah Wyle
The list author says: 
  "Entrepreneurial Management" 

   17.  A Beautiful Mind (The Awards Edition) [VHS] VHS Russell Crowe
The list author says: 
  "Quantitative Methods" 

   18.  The Criterion Collection (3-Disc Boxed Set) DVD ~ Jonathan Pryce
The list author says: 
  "Information Systems Management" 
   19.  Roger & Me [VHS] VHS James Bond (IV)
The list author says: 
  "Managing Corporate Reputation" 

   20.  The Spanish Prisoner DVD ~ Campbell Scott
The list author says: 
  "Business Ethics" 

   21.  Enron: The Smartest Guys in the Room 
The list author says: 
  "Financial Accounting" 

Steve Jobs的十句金玉良言

“I think we’re having fun. I think our customers really like our products. And we’re always trying to do better.”
- Steve Jobs
His accomplishments and character helped define a generation and change the world. He is co-founder of the fairytale company we now know as Apple Computers. And he is the visionary of the personal computers world that led the entire computer hardware and software industry to restructure itself.
This man with boundless energy and charisma is also a master of hype, hyperbole and the catchy phrase. And even when he’s trying to talk normally, brilliant verbiage comes tumbling out.
Here’s a selection of some of the most insanely great things he said, golden lessons to help you succeed in life, Jobs-style:
1. Steve Jobs said: “Innovation distinguishes between a leader and a follower.”
Innovation has no limits. The only limit is your imagination. It’s time for you to begin thinking out of the box. If you are involved in a growing industry, think of ways to become more efficient; more customer friendly; and easier to do business with. If you are involved in a shrinking industry – get out of it quick and change before you become obsolete; out of work; or out of business. And remember that procrastination is not an option here. Start innovating now!
2. Steve Jobs said: “Be a yardstick of quality. Some people aren’t used to an environment where excellence is expected.”
There is no shortcut to excellence. You will have to make the commitment to make excellence your priority. Use your talents, abilities, and skills in the best way possible and get ahead of others by giving that little extra. Live by a higher standard and pay attention to the details that really do make the difference. Excellence is not difficult - simply decide right now to give it your best shot - and you will be amazed with what life gives you back.
3. Steve Jobs said: “The only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know when you find it.”
I’ve got it down to four words: “Do what you love.” Seek out an occupation that gives you a sense of meaning, direction and satisfaction in life. Having a sense of purpose and striving towards goals gives life meaning, direction and satisfaction. It not only contributes to health and longevity, but also makes you feel better in difficult times. Do you jump out of bed on Monday mornings and look forward to the work week? If the answer is ‘no’ keep looking, you’ll know when you find it.
4. Steve Jobs said: “You know, we don’t grow most of the food we eat. We wear clothes other people make. We speak a language that other people developed. We use a mathematics that other people evolved… I mean, we’re constantly taking things. It’s a wonderful, ecstatic feeling to create something that puts it back in the pool of human experience and knowledge.”
Live in a way that is ethically responsible. Try to make a difference in this world and contribute to the higher good. You’ll find it gives more meaning to your life and it’s a great antidote to boredom. There is always so much to be done. And talk to others about what you are doing. Don’t preach or be self-righteous, or fanatical about it, that just puts people off, but at the same time, don’t be shy about setting an example, and use opportunities that arise to let others know what you are doing.
5. Steve Jobs said: “There’s a phrase in Buddhism, ‘Beginner’s mind.’ It’s wonderful to have a beginner’s mind.”
It is the kind of mind that can see things as they are, which step by step and in a flash can realize the original nature of everything. Beginner’s mind is Zen practice in action. It is the mind that is innocent of preconceptions and expectations, judgements and prejudices. Think of beginner’s mind as the mind that faces life like a small child, full of curiosity and wonder and amazement.
6. Steve Jobs said: “We think basically you watch television to turn your brain off, and you work on your computer when you want to turn your brain on.”
Reams of academic studies over the decades have amply confirmed television’s pernicious mental and moral influences. And most TV watchers know that their habit is mind-numbing and wasteful, but still spend most of their time in front of that box. So turn your TV off and save some brain cells. But be cautious, you can turn your brain off by using a computer also. Try and have an intelligent conversation with someone who plays first person shooters for 8 hours a day. Or auto race games, or role-playing games.
7. Steve Jobs said: “I’m the only person I know that’s lost a quarter of a billion dollars in one year…. It’s very character-building.”
Don’t equate making mistakes with being a mistake. There is no such thing as a successful person who has not failed or made mistakes, there are successful people who made mistakes and changed their lives or performance in response to them, and so got it right the next time. They viewed mistakes as warnings rather than signs of hopeless inadequacy. Never making a mistake means never living life to the full.
8. Steve Jobs said: “I would trade all of my technology for an afternoon with Socrates.”
Over the last decade, numerous books featuring lessons from historical figures have appeared on the shelves of bookstores around the world. And Socrates stands with Leonardo da Vinci, Nicholas Copernicus, Charles Darwin and Albert Einstein as a beacon of inspiration for independent thinkers. But he came first. Cicero said of Socrates that, “He called philosophy down from the skies and into the lives of men.” So use Socrates’ principles in your life, your work, your learning, and your relationships. It’s not about Socrates, it’s really about you, and how you can bring more truth, beauty and goodness into your life everyday.
9. Steve Jobs said: “We’re here to put a dent in the universe. Otherwise why else even be here?”
Did you know that you have big things to accomplish in life? And did you know that those big things are getting rather dusty while you pour yourself another cup of coffee, and decide to mull things over rather than do them? We were all born with a gift to give in life, one which informs all of our desires, interests, passions and curiosities. This gift is, in fact, our purpose. And you don’t need permission to decide your own purpose. No boss, teacher, parent, priest or other authority can decide this for you. Just find that unique purpose.
10. Steve Jobs said: “Your time is limited, so don’t waste it living someone else’s life. Don’t be trapped by dogma - which is living with the results of other people’s thinking. Don’t let the noise of other’s opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.”
Are you tired of living someone else’s dream? No doubt, its your life and you have every right to spend it in your own individual way without any hurdles or barriers from others. Give yourself a chance to nurture your creative qualities in a fear-free and pressure-free climate. Live a life that YOU choose and be your own boss.
Each lesson might be difficult to integrate into your life at first, but if you ease your way into each lesson, one at a time, you’ll notice an immediate improvement in your overall performance. So go ahead, give them a try.
"I think we're having fun. I think our customers really like our products. And we're always trying to do better." - Steve Jobs.
他的成就和人格魅力影响了一代人和整个世界,他就是拥有梦幻般传奇经历的苹果电脑公司的创始人斯蒂夫乔布斯。这个个人电脑领域的梦想家引领并改变了整个计算机硬件和软件产业。
这个精力充沛魅力无限的家伙同时也是一个很会鼓动人心的激励大师,甚至在他的平常对话中,经典的语句也常常脱口而出。
这里摘取了一些他的经典语录,希望这些乔氏语录对你有所帮助:
“领袖和跟风者的区别就在于创新。”
创新无极限!只要敢想,没有什么不可能,立即跳出思维的框框吧。如果你正处于一个上升的朝阳行业,那么尝试去寻找更有效的解决方案:更招消费者喜爱、更简洁的商业模式。如果你处于一个日渐萎缩的行业,那么赶紧在自己变得跟不上时代之前抽身而出,去换个工作或者转换行业。不要拖延,立刻开始创新!
“成为卓越的代名词,很多人并不能适合需要杰出素质的环境。”
成功没有捷径。你必须把卓越转变成你身上的一个特质。最大限度的发挥你的天赋、才能、技巧,把其他所有人甩在你后面。高标准严格自己,把注意力集中在那些将会改变一切的细节上。变得卓越并不艰难 - 从现在开始尽自己最大能力去做 - 你会发现生活将给你惊人的回报。
“成就一番伟业的唯一途径就是热爱自己的事业。如果你还没能找到让自己热爱的事业,继续寻找,不要放弃。跟随自己的心,总有一天你会找到的。”
我把这段话浓缩为:“做我所爱”。去寻找一个能给你的生命带来意义、价值和让你感觉充实的事业。拥有使命感和目标感才能给生命带来意义、价值和充实。这不仅对你的健康和寿命有益处,而且即使在你处于困境的时候你也会感觉良好。在每周一的早上,你能不能利索的爬起来并且对工作日充满期待?如果不能,那么你得重新去寻找。你会感觉得到你是不是真的找到了。
“并不是每个人都需要种植自己的粮食,也不是每个人都需要做自己穿的衣服,我们说着别人发明的语言,使用别人发明的数学...我们一直在使用别人的成果。使用人类的已有经验和知识来进行发明创造是一件很了不起的事情。”
带着责任感生活,尝试为这个世界带来点有意义的事情,为更高尚的事情做点贡献。这样你会发现生活更加有意义,生命不再枯燥。需要我们去做的事情很多。告诉其他人你的计划,不要鼓吹,也不要自以为是,更不能盲目狂热,那样只会把人们吓跑,当然,你也不要害怕成为榜样,要抓住出头的机会让人们知道你的所作所为。
“佛教中有一句话:初学者的心态;拥有初学者的心态是件了不起的事情。”
不要迷惑于表象而要洞察事务的本质,初学者的心态是行动派的禅宗。所谓初学者的心态是指,不要无端猜测、不要期望、不要武断也不要偏见。初学者的心态正如一个新生儿面对这个世界一样,永远充满好奇、求知欲、赞叹。
“我们认为看电视的时候,人的大脑基本停止工作,打开电脑的时候,大脑才开始运转。”
过去十年中,大量的理论研究表明,电视对人的精神和心智是有害的。大多数电视观众都知道这个坏习惯会浪费时间并且使大脑变得迟钝,但是他们还是选择呆在电视机前面。关掉电视吧,给自己省点脑细胞。还有,电脑也会让你的大脑秀逗,不信的话你去跟那些一天花8小时玩第一视角设计游戏、汽车拉力游戏、角色扮演游戏的人聊聊看,你也会得出这个结论的。
“我是我所知唯一一个在一年中失去2.5亿美元的人...这对我的成长很有帮助。”
范错误不等于错误。从来没有哪个成功的人没有失败过或者犯过错误,相反,成功的人都是犯了错误之后,做出改正,然后下次就不会再错了,他们把错误当成一个警告而不是万劫不复的失败。从不犯错意味着从来没有真正活过。
“我愿意把我所有的科技去换取和苏格拉底相处的一个下午。”
十几年来,世界各地的书店里涌现出海量的关于历史人物的书籍。这些人物包括苏格拉底、达芬奇、哥白尼、达尔文以及爱因斯坦成为人们灵感的灯塔,而苏格拉底排在第一位。西塞罗评价苏格拉底说:“他把哲学从高山仰止高高在上的学科变得与人休戚相关。”把苏格拉底的原则运用到你的生活、工作、学习以及人及关系上吧,这不是关于苏格拉底,这是关于你自己,以及关于你如何给你每天的生活带来更多的真善美。
“活着就是为了改变世界,难道还有其他原因吗?”
你是否知道在你的生命中,有什么使命是一定要达成的?你知不知道在你喝一杯咖啡或者做些无意义事情的时候,这些使命又蒙上了一层灰尘?我们生来就随身带着一件东西,这件东西指示着我们的渴望、兴趣、热情以及好奇心,这就是使命。你不需要任何权威来评断你的使命,没有任何老板、老师、父母、牧师以及任何权威可以帮你来决定。你需要靠你自己来寻找这个独特的使命。
“你的时间有限,所以不要为别人而活。不要被教条所限,不要活在别人的观念里。不要让别人的意见左右自己内心的声音。最重要的是,勇敢的去追随自己的心灵和直觉,只有自己的心灵和直觉才知道你自己的真实想法,其他一切都是次要。”
你是否已经厌倦了为别人而活?不要犹豫,这是你的生活,你拥有绝对的自主权来决定如何生活,不要被其他人的所作所为所束缚。给自己一个培养自己创造力的机会,不要害怕,不要担心。过自己选择的生活,做自己的老板!

以上每句话,刚开始也许很难真正渗透入你的生活,但是如果你慢慢吸收这些教训,每次领悟一句话,慢慢的你将会发现一个全新的自我。不要踌躇不前,试试看。

What Are You Going to Do With That? 不要在不断的优秀里走向平庸

What Are You Going to Do With That?



By William Deresiewicz



The essay below is adapted from a talk delivered to a freshman class at Stanford University in May.
The question my title poses, of course, is the one that is classically aimed at humanities majors. What practical value could there possibly be in studying literature or art or philosophy? So you must be wondering why I'm bothering to raise it here, at Stanford, this renowned citadel of science and technology. What doubt can there be that the world will offer you many opportunities to use your degree?
But that's not the question I'm asking. By "do" I don't mean a job, and by "that" I don't mean your major. We are more than our jobs, and education is more than a major. Education is more than college, more even than the totality of your formal schooling, from kindergarten through graduate school. By "What are you going to do," I mean, what kind of life are you going to lead? And by "that," I mean everything in your training, formal and informal, that has brought you to be sitting here today, and everything you're going to be doing for the rest of the time that you're in school.
We should start by talking about how you did, in fact, get here. You got here by getting very good at a certain set of skills. Your parents pushed you to excel from the time you were very young. They sent you to good schools, where the encouragement of your teachers and the example of your peers helped push you even harder. Your natural aptitudes were nurtured so that, in addition to excelling in all your subjects, you developed a number of specific interests that you cultivated with particular vigor. You did extracurricular activities, went to afterschool programs, took private lessons. You spent summers doing advanced courses at a local college or attending skill-specific camps and workshops. You worked hard, you paid attention, and you tried your very best. And so you got very good at math, or piano, or lacrosse, or, indeed, several things at once.
Now there's nothing wrong with mastering skills, with wanting to do your best and to be the best. What's wrong is what the system leaves out: which is to say, everything else. I don't mean that by choosing to excel in math, say, you are failing to develop your verbal abilities to their fullest extent, or that in addition to focusing on geology, you should also focus on political science, or that while you're learning the piano, you should also be working on the flute. It is the nature of specialization, after all, to be specialized. No, the problem with specialization is that it narrows your attention to the point where all you know about and all you want to know about, and, indeed, all you can know about, is your specialty.
The problem with specialization is that it makes you into a specialist. It cuts you off, not only from everything else in the world, but also from everything else in yourself. And of course, as college freshmen, your specialization is only just beginning. In the journey toward the success that you all hope to achieve, you have completed, by getting into Stanford, only the first of many legs. Three more years of college, three or four or five years of law school or medical school or a Ph.D. program, then residencies or postdocs or years as a junior associate. In short, an ever-narrowing funnel of specialization. You go from being a political-science major to being a lawyer to being a corporate attorney to being a corporate attorney focusing on taxation issues in the consumer-products industry. You go from being a biochemistry major to being a doctor to being a cardiologist to being a cardiac surgeon who performs heart-valve replacements.
Again, there's nothing wrong with being those things. It's just that, as you get deeper and deeper into the funnel, into the tunnel, it becomes increasingly difficult to remember who you once were. You start to wonder what happened to that person who played piano and lacrosse and sat around with her friends having intense conversations about life and politics and all the things she was learning in her classes. The 19-year-old who could do so many things, and was interested in so many things, has become a 40-year-old who thinks about only one thing. That's why older people are so boring. "Hey, my dad's a smart guy, but all he talks about is money and livers."
And there's another problem. Maybe you never really wanted to be a cardiac surgeon in the first place. It just kind of happened. It's easy, the way the system works, to simply go with the flow. I don't mean the work is easy, but the choices are easy. Or rather, the choices sort of make themselves. You go to a place like Stanford because that's what smart kids do. You go to medical school because it's prestigious. You specialize in cardiology because it's lucrative. You do the things that reap the rewards, that make your parents proud, and your teachers pleased, and your friends impressed. From the time you started high school and maybe even junior high, your whole goal was to get into the best college you could, and so now you naturally think about your life in terms of "getting into" whatever's next. "Getting into" is validation; "getting into" is victory. Stanford, then Johns Hopkins medical school, then a residency at the University of San Francisco, and so forth. Or Michigan Law School, or Goldman Sachs, or Mc­Kinsey, or whatever. You take it one step at a time, and the next step always seems to be inevitable.
Or maybe you did always want to be a cardiac surgeon. You dreamed about it from the time you were 10 years old, even though you had no idea what it really meant, and you stayed on course for the entire time you were in school. You refused to be enticed from your path by that great experience you had in AP history, or that trip you took to Costa Rica the summer after your junior year in college, or that terrific feeling you got taking care of kids when you did your rotation in pediatrics during your fourth year in medical school.
But either way, either because you went with the flow or because you set your course very early, you wake up one day, maybe 20 years later, and you wonder what happened: how you got there, what it all means. Not what it means in the "big picture," whatever that is, but what it means to you. Why you're doing it, what it's all for. It sounds like a cliché, this "waking up one day," but it's called having a midlife crisis, and it happens to people all the time.
There is an alternative, however, and it may be one that hasn't occurred to you. Let me try to explain it by telling you a story about one of your peers, and the alternative that hadn't occurred to her. A couple of years ago, I participated in a panel discussion at Harvard that dealt with some of these same matters, and afterward I was contacted by one of the students who had come to the event, a young woman who was writing her senior thesis about Harvard itself, how it instills in its students what she called self-efficacy, the sense that you can do anything you want. Self-efficacy, or, in more familiar terms, self-esteem. There are some kids, she said, who get an A on a test and say, "I got it because it was easy." And there are other kids, the kind with self-efficacy or self-esteem, who get an A on a test and say, "I got it because I'm smart."
Again, there's nothing wrong with thinking that you got an A because you're smart. But what that Harvard student didn't realize—and it was really quite a shock to her when I suggested it—is that there is a third alternative. True self-esteem, I proposed, means not caring whether you get an A in the first place. True self-esteem means recognizing, despite everything that your upbringing has trained you to believe about yourself, that the grades you get—and the awards, and the test scores, and the trophies, and the acceptance letters—are not what defines who you are.
She also claimed, this young woman, that Harvard students take their sense of self-efficacy out into the world and become, as she put it, "innovative." But when I asked her what she meant by innovative, the only example she could come up with was "being CEO of a Fortune 500." That's not innovative, I told her, that's just successful, and successful according to a very narrow definition of success. True innovation means using your imagination, exercising the capacity to envision new possibilities.
But I'm not here to talk about technological innovation, I'm here to talk about a different kind. It's not about inventing a new machine or a new drug. It's about inventing your own life. Not following a path, but making your own path. The kind of imagination I'm talking about is moral imagination. "Moral" meaning not right or wrong, but having to do with making choices. Moral imagination means the capacity to envision new ways to live your life.
It means not just going with the flow. It means not just "getting into" whatever school or program comes next. It means figuring out what you want for yourself, not what your parents want, or your peers want, or your school wants, or your society wants. Originating your own values. Thinking your way toward your own definition of success. Not simply accepting the life that you've been handed. Not simply accepting the choices you've been handed. When you walk into Starbucks, you're offered a choice among a latte and a macchiato and an espresso and a few other things, but you can also make another choice. You can turn around and walk out. When you walk into college, you are offered a choice among law and medicine and investment banking and consulting and a few other things, but again, you can also do something else, something that no one has thought of before.
Let me give you another counterexample. I wrote an essay a couple of years ago that touched on some of these same points. I said, among other things, that kids at places like Yale or Stanford tend to play it safe and go for the conventional rewards. And one of the most common criticisms I got went like this: What about Teach for America? Lots of kids from elite colleges go and do TFA after they graduate, so therefore I was wrong. TFA, TFA—I heard that over and over again. And Teach for America is undoubtedly a very good thing. But to cite TFA in response to my argument is precisely to miss the point, and to miss it in a way that actually confirms what I'm saying. The problem with TFA—or rather, the problem with the way that TFA has become incorporated into the system—is that it's just become another thing to get into.
In terms of its content, Teach for America is completely different from Goldman Sachs or McKinsey or Harvard Medical School or Berkeley Law, but in terms of its place within the structure of elite expectations, of elite choices, it is exactly the same. It's prestigious, it's hard to get into, it's something that you and your parents can brag about, it looks good on your résumé, and most important, it represents a clearly marked path. You don't have to make it up yourself, you don't have to do anything but apply and do the work­—just like college or law school or McKinsey or whatever. It's the Stanford or Harvard of social engagement. It's another hurdle, another badge. It requires aptitude and diligence, but it does not require a single ounce of moral imagination.
Moral imagination is hard, and it's hard in a completely different way than the hard things you're used to doing. And not only that, it's not enough. If you're going to invent your own life, if you're going to be truly autonomous, you also need courage: moral courage. The courage to act on your values in the face of what everyone's going to say and do to try to make you change your mind. Because they're not going to like it. Morally courageous individuals tend to make the people around them very uncomfortable. They don't fit in with everybody else's ideas about the way the world is supposed to work, and still worse, they make them feel insecure about the choices that they themselves have made—or failed to make. People don't mind being in prison as long as no one else is free. But stage a jailbreak, and everybody else freaks out.
In A Portrait of the Artist as a Young Man, James Joyce has Stephen Dedalus famously say, about growing up in Ireland in the late 19th century, "When the soul of a man is born in this country there are nets flung at it to hold it back from flight. You talk to me of nationality, language, religion. I shall try to fly by those nets."
Today there are other nets. One of those nets is a term that I've heard again and again as I've talked with students about these things. That term is "self-indulgent." "Isn't it self-indulgent to try to live the life of the mind when there are so many other things I could be doing with my degree?" "Wouldn't it be self-indulgent to pursue painting after I graduate instead of getting a real job?"
These are the kinds of questions that young people find themselves being asked today if they even think about doing something a little bit different. Even worse, the kinds of questions they are made to feel compelled to ask themselves. Many students have spoken to me, as they navigated their senior years, about the pressure they felt from their peers—from their peers—to justify a creative or intellectual life. You're made to feel like you're crazy: crazy to forsake the sure thing, crazy to think it could work, crazy to imagine that you even have a right to try.
Think of what we've come to. It is one of the great testaments to the intellectual—and moral, and spiritual—poverty of American society that it makes its most intelligent young people feel like they're being self-indulgent if they pursue their curiosity. You are all told that you're supposed to go to college, but you're also told that you're being "self-indulgent" if you actually want to get an education. Or even worse, give yourself one. As opposed to what? Going into consulting isn't self-indulgent? Going into finance isn't self-indulgent? Going into law, like most of the people who do, in order to make yourself rich, isn't self-indulgent? It's not OK to play music, or write essays, because what good does that really do anyone, but it is OK to work for a hedge fund. It's selfish to pursue your passion, unless it's also going to make you a lot of money, in which case it's not selfish at all.
Do you see how absurd this is? But these are the nets that are flung at you, and this is what I mean by the need for courage. And it's a never-ending proc­ess. At that Harvard event two years ago, one person said, about my assertion that college students needed to keep rethinking the decisions they've made about their lives, "We already made our decisions, back in middle school, when we decided to be the kind of high achievers who get into Harvard." And I thought, who wants to live with the decisions that they made when they were 12? Let me put that another way. Who wants to let a 12-year-old decide what they're going to do for the rest of their lives? Or a 19-year-old, for that matter?
All you can decide is what you think now, and you need to be prepared to keep making revisions. Because let me be clear. I'm not trying to persuade you all to become writers or musicians. Being a doctor or a lawyer, a scientist or an engineer or an economist—these are all valid and admirable choices. All I'm saying is that you need to think about it, and think about it hard. All I'm asking is that you make your choices for the right reasons. All I'm urging is that you recognize and embrace your moral freedom.
And most of all, don't play it safe. Resist the seductions of the cowardly values our society has come to prize so highly: comfort, convenience, security, predictability, control. These, too, are nets. Above all, resist the fear of failure. Yes, you will make mistakes. But they will be your mistakes, not someone else's. And you will survive them, and you will know yourself better for having made them, and you will be a fuller and a stronger person.
It's been said—and I'm not sure I agree with this, but it's an idea that's worth taking seriously—that you guys belong to a "postemotional" generation. That you prefer to avoid messy and turbulent and powerful feelings. But I say, don't shy away from the challenging parts of yourself. Don't deny the desires and curiosities, the doubts and dissatisfactions, the joy and the darkness, that might knock you off the path that you have set for yourself. College is just beginning for you, adulthood is just beginning. Open yourself to the possibilities they represent. The world is much larger than you can imagine right now. Which means, you are much larger than you can imagine.


William Deresiewicz is a contributing writer for The Nation and a contributing editor at The New Republic. His next book, A Jane Austen Education, will be published next year by Penguin Press.


William Deresiewicz 2010年在斯坦福大学的演讲:

我的题目提出的问题,当然,是一个传统地面向人文科学的专业所提出的问题:学习文学、艺术或哲学能有什么实效价值(practical value)?你肯定纳闷,我为什么在以科技堡垒而闻名的斯坦福提出这个问题呢?大学学位给人带来众多机会,这还有什么需要质疑的吗?

但那不是我提出的问题。这里的“做(do)”并不是指工作(job),“那(that)”并不是指你的专业(major)。]我们不仅仅是我们的工作,教育的全部也不仅仅是一门主修专业。(We are more than our jobs, and education is more than a major.)教育也不仅仅是上大学,甚至也不仅是从幼儿园到研究生院的正规学校教育。我说的“你要做什么”的意思是你要过什么样的生活(what kind of life are you going to lead?)?我所说的“那”指的是你得到的正规或非正规的任何训练,那些把你送到这里来的东西,你在学校的剩余时间里将要做的任何事。

我们不妨先来讨论你是如何考入斯坦福的吧。

你能进入这所大学说明你在某些技能(skills)上非常出色。你的父母在你很小的时候就鼓励你追求卓越(excel)。他们送你到好学校,老师的鼓励和同伴的榜样激励你更努力地学习。除了在所有课程上都出类拔萃之外,你还注重修养的提高,充满热情地培养了一些特殊兴趣。你用几个暑假在本地大学里预习大学课程,或参加专门技能的夏令营或训练营。你学习刻苦、精力集中、全力以赴。所以,你在数学、钢琴、曲棍球等众多方面都很出色。

掌握这些技能当然没有错,全力以赴成为最优秀的人也没有错。错误之处在于这个体系遗漏的地方:即任何别的东西(everything else)。我并不是说因为选择钻研数学,你在充分发展话语表达能力的潜力方面就失败了;也不是说除了集中精力学习地质学之外,你还应该研究政治学;也不是说你在学习钢琴时还应该学吹笛子。毕竟,专业化的本质就是要专业性。可是,专业化的问题在于它把你的注意力限制在一个点上,你所已知的和你想探知的东西都限界于此(it narrows your attention to the point where all you know about and all you want to know about)。真的,你能知道的一切就只是你的专业了。

专业化(specialization)的问题是它让你成为专家(specialist),切断你与世界上其他任何东西的联系,不仅如此,还切断你与自身其他潜能的联系(It cuts you off, not only from everything else in the world, but also from everything else in yourself.)。当然,作为大一新生,你的专业才刚刚开始。在你走向所渴望的成功之路的过程中,进入斯坦福是你踏上的众多阶梯中的一个。再读三年大学,三五年法学院或医学院或博士,然后再干若干年住院实习生或博士后或助理教授。总而言之,进入越来越狭窄的专业化轨道。你可能从政治学专业的学生变成了律师或者公司代理人,再变成专门研究消费品领域的税收问题的公司代理人。你从生物化学专业的学生变成了博士,再变成心脏病学家,再变成专门做心脏瓣膜移植的心脏病医生。

再次,做这些事没有任何错。只不过,在你越来越深入地进入这个轨道后,再记得你最初的样子(remember who you once were)就益发困难了。你开始怀念那个曾经谈钢琴和打曲棍球的人,思考那个曾经和朋友热烈讨论人生和政治以及在课堂内容的人在做什么。那个活泼能干的19岁年轻人已经变成了只想一件事的40岁中年人。(The 19-year-old who could do so many things, and was interested in so many things, has become a 40-year-old who thinks about only one thing.)难怪年长的人这么乏味无趣。(That's why older people are so boring.)“哎,我爸爸曾经是非常聪明的人,但他现在除了谈论钱和肝脏外再无其他。” ("Hey, my dad's a smart guy, but all he talks about is money and livers.")

还有另外一个问题。

或许你从来没有想过当心脏病医生,只是碰巧发生了而已。随大流最容易,这就是体制的力量。(It's easy, the way the system works, to simply go with the flow.)我不是说这个工作容易,而是说做出这种选择很容易。或者,这些根本就不是自己做出的选择。你来到斯坦福这样的名牌大学是因为聪明的孩子都这样(because that's what smart kids do.)。你考入医学院是因为它的地位高,人人都羡慕。你选择心脏病学是因为当心脏病医生的待遇很好。你做那些事能给你带来好处,让你的父母感到骄傲,令你的老师感到高兴,也让朋友们羡慕。从你上高中开始,甚至初中开始,你的唯一目标就是进入最好的大学,所以现在你会很自然地从“进入下个阶段”的角度看待人生(you naturally think about your life in terms of
"getting into" whatever's next)。“进入”就是能力的证明,“进入”就是胜利。先进入斯坦福,然后是约翰霍普金斯医学院,再进入旧金山大学做实习医生等。或者进入密歇根法学院,或高盛集团(GoldmanSachs)或麦肯锡公司(McKinsey)或别的什么地方。你迈出了这一步,下一步似乎就必然在等着你。
也许你确实想当心脏病学家。十岁时就梦想成为医生,即使你根本不知道医生意味着什么。你在上学期间全身心都在朝着这个目标前进。你拒绝了上大学预修历史课(AP history)时的美妙体验的诱惑,也无视你在医学院第四年的儿科学轮流值班时照看孩子的可怕感受。

但不管是什么,要么因为你随大流,要么因为你早就选定了道路,20年后某天醒来,你或许会纳闷到底发生了什么:你怎么变成现在这个样子,这一切意味着什么。不是它是什么,不在于它是否“大画面”(big picture)而是它对你意味着什么。 你为什么做它,到底为了什么。这听起来像老生常谈,但这个被称为中年危机(midlife crisis)的“有一天醒来”("waking up one day")一直就发生在每个人身上。

不过,还有另外一种情况,或许中年危机并不会发生在你身上。

让我通过告诉你们一个同伴的故事来解释我的意思吧,即她没有遭遇的情况。几年前,我在哈佛参加了一次小组讨论会,谈到这些问题。后来参加这次讨论的一个学生给我联系,这个哈佛学生正在写有关哈佛的毕业论文,讨论哈佛是如何给学生灌输她所说的“自我效能”(self-efficacy),一种相信自己能做一切的意识。自我效能或更熟悉的说法“自我尊重”(self-esteem)。她说在考试中得了优秀的有些学生会说“我得优秀是因为试题很简单。” 但另外一些学生,那种具有自我效能感或自我尊重的学生,考试得了优秀会说“我得优秀是因为我聪明。”
再次,认为得了优秀是因为自己聪明的想法并没有任何错,不过,哈佛学生没有认识到的是他们没有第三种选择(a third alternative)。当我指出这一点时,她十分震惊。我指出,真正的自尊意味着最初根本就不在乎成绩是否优秀。真正的自尊意味着对此问题的足够认识:尽管你在成长过程中的一切都在教导你要相信自己,但你所达到的登记,还有那些奖励、成绩、奖品、录取通知书等所有这一切,都不能来定义你是谁(defines who you are)。
她还说,这个年轻的女孩子说哈佛学生把他们的自我效能带到了世界上,如她所说的“创新”(innovative)。但当我问她“创新”意味着什么时,她能够想到的唯一例子不过是“世界大公司五百强的首席执行官”( "being CEO of a Fortune 500")。我告诉她这不是创新,这只是成功(that's just successful),而且是根据非常狭隘的成功定义而认定的成功而已。真正的创新意味着运用你的想象力,发挥你的潜力,创造新的可能性。(True innovation means using your imagination, exercising the capacity to envision new possibilities.)
但这里我并不是在谈论技术创新,不是发明新机器或者制造一种新药,我谈论的是另外一种创新,是创造你自己的生活(inventing your own life)。不是走现成的道路而是创造一条属于自己的道路。(Not following a path, but making your own path.)我谈论的想象力是道德想象力(moral imagination;眠按:这个是心理学专业名词)。“道德”在这里无关对错,而是与选择有关。道德想象力意味着创造自己新生的能力(envision new ways to live your life)。
它意味着不随波逐流(going with the flow),不是下一步要“进入”什么名牌大学或研究生院。而是要弄清楚自己到底想要什么,而不是父母、同伴、学校、或社会想要什么。即确认你自己的价值观(own values),思考迈向自己所定义的成功的道路,而不仅仅是接受别人给你的生活(simply accepting the life that you've been handed),不仅仅是接受别人给你的选择。当今走进星巴克咖啡馆,服务员可能让你在牛奶咖啡(latte)、加糖咖啡(macchiato)、特制咖啡(espresso)等几样东西之间做出选择。但你可以做出另外的选择,你可以转身走出去。当你进入大学,人家给你众多选择,或法律或医学或投资银行和咨询以及其他,但你同样也可以做其他事,做从前根本没有人想过的事(something that no one has thought of before)。

让我再举一个反面的例子。

几年前我写过一篇涉及同类问题的文章。我说,那些在耶鲁和斯坦福这类名校的孩子往往比较谨慎,去追求一些稳妥的奖励。我得到的最常见的批评是:教育项目“为美国而教”(Teach for America)如何?从名校出来的很多学生毕业后很多参与这个教育项目,因此我的观点是错误的。我一再听到TFA这个术语。“为美国而教”当然是好东西,但引用这个项目来反驳我的观点恰恰是不得要领,实际上正好证明了我想说的东西。 “为美国而教”的问题或者“为美国而教”已经成为体系一部分的问题,是它已经成为另外一个需要“进入”的门槛。

从其内容来看,“为美国而教”完全不同于高盛或者麦肯锡公司或哈佛医学院或者伯克利法学院,但从它在精英期待的体系中的地位来说,完全是一样的。它享有盛名,很难进入,是值得你和父母夸耀的东西,如果写在简历上会很好看(it looks good on your résumé),最重要的是,它代表了清晰标记的道路(a clearly marked path.)。你根本不用自己创造,什么都不用做,只需申请然后按要求做就行了,就像上大学或法学院或麦肯锡公司或别的什么。它是社会参与方面的斯坦福或哈佛,是另一个栅栏,另一枚奖章。该项目需要能力和勤奋,但不需要一丁点儿的道德想象力。

道德想象力是困难的,这种困难与你已经习惯的困难完全不同。不仅如此,光有道德想象力还不够。如果你要创造自己的生活(invent your own life),如果你想成为真正的独立思想者(truly autonomous),你还需要勇气:道德勇气(moral courage)。不管别人说什么,有按自己的价值观行动的勇气,不会因为别人不喜欢而试图改变自己的想法。具有道德勇气的个人往往让周围的人感到不舒服。他们和其他人对世界的看法格格不入,更糟糕的是,让别人对自己已经做出的选择感到不安全或无法做出选择。只要别人也不享受自由,人们就不在乎自己被关进监狱。可一旦有人越狱,其他人都会跟着跑出去。
在《青年艺术家的肖像》(A Portrait of the Artist as a Young Man)中,詹姆斯•乔伊斯(James Joyce)让主人公斯蒂芬•迪达勒斯(Stephen Dedalus)就19世纪末期的爱尔兰的成长环境说出了如下名言“当一个人的灵魂诞生在这个国家时,有一张大网把它罩住,防止它飞翔。你会给我谈论民族性、语言和宗教。我想冲出这些牢笼。”("When the soul of a man is born in this country there are nets flung at it to hold it back from flight. You talk to me of nationality, language, religion. I shall try to fly by those nets.")

今天,我们面临的是其他的网。
其中之一是我在就这些问题与学生交流时经常听到的一个术语“自我放任”("self-indulgent")。“在攻读学位过程中有这么多事要做的时候(so many other things),试图按照自己的感觉生活难道不是自我放任吗?”“毕业后不去找个真正的工作(getting a real job)而去画画难道不是自我放任吗?”

这些是年轻人只要思考一下稍稍出格(a little bit different)的事就不由自主地质问自己的问题。更糟糕的是,他们觉得提出这些问题是理所应当(feel compelled)的。许多学生在毕业前夕的未来探索中跟我说,他们感受到来自同伴那里的压力(the pressure they felt from their peers),需要为创造性的生活或思想生活辩护(to justify a creative or intellectual life)。好像自己已经走火入魔了似的:抛弃确定无疑的东西是疯了,认为思想生活可行是疯了,想象你有权尝试是疯了。(You're made to feel like you're crazy: crazy to forsake the sure thing, crazy to think it could work, crazy to imagine that you even have a right to try.眠按:“羊霸王”比更外界的压力更厉害。)

想象我们现在面临的局面。这是美国社会的贫困——思想、道德和精神贫困的最明显症状,美国最聪明的年轻人竟然认为听从自己的好奇心行动就是自我放任。你们得到的教导是应该上大学,但你们同时也被告知如果真的想得到教育,那就是“自我放任”。如果你自我教育的话,更糟糕。这是什么道理?进入证券咨询业是不是自我放任?进入金融业是不是自我放任?像许多人那样进入律师界发财是不是自我放任?搞音乐,写文章就不行,因为它不能给人带来利益(what good does that really do anyone)。但为风险投资公司工作就可以。追求自己的理想和激情是自私的,除非它能让你赚很多钱。那样的话,就一点儿也不自私了。(It's selfish to pursue your passion, unless it's also going to make you a lot of money, in which case it's not selfish at all.)

你看到这些观点是多么荒谬了吗?这就是罩在你们身上的网,就是我说的需要勇气的意思。这是永不停息的过程(a never-ending process)。在两年前的哈佛事件中,有个学生谈到我说的大学生需要重新思考人生决定的观点,他说“我们已经做出了决定,我们早在中学时就已经决定成为能够进入哈佛的高材生。”我在想,谁会打算按照他在12岁时做出的决定生活呢?(who wants to live with the decisions that they made when they were 12?) 让我换一种说法,谁愿意让一个12岁的孩子决定他们未来一辈子要做什么呢?或者一个19岁的小毛孩儿?

你能做出的决定是你现在想什么,你需要准备好不断修改自己的决定。
让我说得更明白一些。我不是在试图说服你们都成为音乐家或者作家。成为医生、律师、科学家、工程师或者经济学家没有什么不好,这些都是可靠的、可敬的选择(valid and admirable choices)。我想说的是你需要思考它,认真地思考(think about it hard)。我请求你们做的,是根据正确的理由做出你的选择。我在敦促你们的,是认识到你的道德自由(moral freedom)并热情拥抱它。

最重要的是,不要过分谨慎。(Don't play it safe.)去拒否(RESIST)我们社会给予了过高奖赏的那些卑怯的价值观的诱惑:舒服、方便、安全、可预测的、可控制的。这些,同样是罗网。最重要的是,去拒否失败的恐惧感。是的,你会犯错误。可那是你的错误,不是别人的。你将从错误中缓过来,而且,正是因为这些错误,你更好地认识你自己。由此,你成为更完整和强大的人(a fuller and a stronger person)。
人们常说你们年轻人属于“后情感”一代(a "postemotional" generation),我想我未必赞同这个说法,但这个说法值得严肃对待。你们更愿意规避混乱、动荡和强烈的感情(avoid messy and turbulent and powerful feelings),但我想说,不要回避挑战自我(the challenging parts of yourself),不要否认欲望和好奇心(the desires and curiosities)、怀疑和不满(the doubts and dissatisfactions)、快乐和阴郁(the joy and the darkness),它们可能改变你预设的人生轨迹。大学刚开始,成年时代也才刚开始。打开自己,直面各种可能性吧。这个世界的深广远超你现在想象的边际。这意味着,你自身的深广也将远超你现在的想象。

Tuesday, August 23, 2011

英语邮件



1. I am writing to confirm /enquire/inform you...

Monday, August 15, 2011

LINUX Shell 下求两个文件交集和差集的办法

基本上有两个方法,一个是comm命令,一个是grep命令。分别介绍如下:
comm命令 , Compare sorted files FILE1 and FILE2 line by line. With  no options, produce three-column output.  Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files. 要注意两个文件必须是排序和唯一(sorted and unique)的,默认输出为三列,第一列为是A-B,第二列B-A,第三列为A交B。

如果只想要交集,如下即可:
comm -12 <(sort a.txt|uniq ) <(sort b.txt|uniq )
grep 命令是常用的搜索文本内容的,要找交集,如下即可:
grep -F -f a.txt b.txt
grep不要求排序,但是因为是集合操作,唯一是必须的(不然怎么是集合呢?)。所以:
grep -F -f a.txt b.txt | sort | uniq
差集呢?
 grep -F -v -f a.txt b.txt | sort | uniq
grep -F -v -f b.txt a.txt | sort | uniq
第一行结果为B-A,所以为空;第二行为A-B。注意顺序很重要!

sources:http://blog.csdn.net/autofei/article/details/6579320

Wednesday, July 20, 2011

sed linux/mac

windows下,每一行的结尾是\n\r,而在linux下文件的结尾是\n,那么你在windows下编辑过的文件在linux下打开看的时候每一行的结尾就会多出来一个字符\r, 用cat -A urfile时你可以看到这个\r字符被显示为^M,这时候只需要删除这个字符就可以了。可以使用命令

Linux

sed -i 's/\r$//' urfile

Mac:

sed 's/\r$//' urfile > newfile
or
sed -i '' 's/\r$//' urfile


Removing one (or several) line (s) of a file


Syntax:


sed '{[/]<n>|<string>|<regex>[/]}d' <fileName>
sed '{[/]<adr1>[,<adr2>][/]d' <fileName>
  • /.../=delimiters
  • n = line number
  • string = string found in in line
  • regex = regular expression corresponding to the searched pattern
  • addr = address of a line (number or pattern )
  • d = delete


Examples

Remove the 3rd line:

sed '3d' fileName.txt


Removal of the line containing the string "awk":

sed '/awk/d' filename.txt


Remove the last line:

sed '$d' filename.txt



Remove all empty lines:

sed '/^$/d' filename.txt
sed '/./!d' filename.txt


Remove line "matched" by a regular expression (by eliminating one containing digital characters (at least 1 digit) located at the end of the line).

sed '/[0-9/][0-9]*$/d' filename.txt


Removing the interval between lines 7 and 9.

sed '7,9d' filename.txt 


Same operation but replacing the address by "parameters".

sed '/-Start/,/-End/d' filename.txt



The above examples are only change at the display of the file (stdout1= screen).

For permanent changes to the old versions (<4) use a temporary file for GNU sed use the "-i[suffix]":

sed -i".bak" '3d' filename.txt

source: http://en.kioskea.net/faq/1451-sed-delete-one-or-more-lines-from-a-file

Monday, July 18, 2011

R Plot

1. X/Y 坐标值
x <- seq(-4, 4, len = 101)
y <- cbind(sin(x), cos(x))
matplot(x, y, type = "l", xaxt = "n", yaxt="n")
### xaxt = "n", yaxt="n" => x, y 不画x, y坐标
axis(1, at = c(-pi, -pi/2, 0, pi/2, pi), labels = expression(-pi, -pi/2, 0, pi/2, pi))
###x轴 画坐标,在指定的位置画指定的坐标 
axis(2, at = c(-0.8, -0.5, 0, 03, 0.7), labels = expression(-pi, -pi/2, 0, pi/2, pi))
###y轴 画坐标,在指定的位置画指定的坐标
2. Lengend
legend(1, 0.4, c("Case", "Control", "HapMap"), col = c("red", "blue", "green"), lty = c(1, 1, 1), pch = c(1, 1, 1), merge = TRUE, bg = 'gray90')

第一项:x坐标;第二项:y坐标;第三项:text;第四项:颜色;第五项:线型;第六项:点型

Monday, July 11, 2011

Acer aspire one d255 system restore

Before you go rushing into anything.there is a general confusion when people talk about restore.

Do you mean to restore back a few days or perhaps a week for some reason, or restore/recover the system back to factory conditions ie as you bought it. two totally different operations.

If it is the first one then go to START, ALL PROGRAMS, select ACCESSORIES, Then select SYSTEM TOOLS, Then SYSTEM RESTORE. Click restore. You can then select a highlighted restore point This should be much the same for win 7.

If you mean recover back to factory settings, which will destroy all your data you have added if you do not back it up. Then at start up and during the Acer logo display press and hold down the ALT key and repeatedly press the F10 key.

source:http://answers.yahoo.com/question/index?qid=20110109143354AAgJ559

linux move directory

<Creating directories >
Creating a new, empty directory is very easy. You use the mkdir command:

$ mkdir dir1

That's it. It's really that easy!

< Removing directories >

There are two commands you can use for removing directories.

If the directory is empty, you can use rmdir:

$ rmdir dir1

You can use rmdir only if the directory is empty. If you want to remove a directory with all its contents, you can use rm with the -r option. The -r option tells rm to remove a directory recursively:

$ rm -r dir1

It goes without saying that you can cause a lot of trouble with rm -r if you're not careful! In some cases it might be a good thing to use the -i option when deleting a directory with its contents so that you'd be prompted before each file in the directory gets deleted:

$ rm -ir dir1

< Copying and moving directories >

For copying and moving directories you can use the cp and mv commands just like you use them with files.

Yeah, I know. If you've already tried to copy a directory with cp, you've probably noticed that cp just complains at you. Probably it says something like cp: omitting directory yadda yadda. You see, the cp command wants you to use the -r option if you want to copy a directory with its contents. The -r means "copy recursively":

$ cp -r dir1 dir2

The above creates a directory named dir2 whose contents will be identical to dir1. However, if dir2 already exists, nothing will be overwritten: the directory dir1 will be copied into the dir2 directory under the name dir2/dir1.

When renaming directories, you use the mv command exactly the same way as with files:

$ mv dir1 dir2

When dealing with directories, mv works a bit like cp does. If dir2 doesn't exist, the above will rename dir1 to dir2, but if dir2 exists, the directory dir1 will be moved into the dir2 directory under the name dir2/dir1.


source: http://www.tuxfiles.org/linuxhelp/dirman.html

Friday, July 8, 2011

Installing BioPerl on Mac OS 10.6 Snow Leopard in 6 Easy Steps

source: http://www.sysarchitects.com/bioperl
The strategy I used to install BioPerl was as follows:
1. Use MacPorts to install Perl.
2. Use CPAN to install BioPerl.
Here are the nitty gritty details. You need a live internet connection, as both MacPorts and CPAN expect to be able to download packages.

Step One: XCode Tools

Before MacPorts can be installed, XCode Tools needs to be installed. This is free from Apple and can be installed from the original OS X 10.6 DVD or downloaded from Apple's developer site.
You can tell that XCode Tools is installed by looking for a Developer directory at the root of your hard drive.

Step Two: MacPorts

I simply downloaded the MacPorts Package Installer from the MacPorts site.

Step Three: Install Perl

sudo port install perl5.12

Step Four: Install GraphViz

This is a prerequisite of BioPerl and the BioPerl build will fail if it is not installed. It will download a ton of prequisites first. After typing the following, get a coffee and a sandwich.
sudo port install graphviz

Step Five: Configure CPAN

CPAN likes to have YAML installed. So:
sudo cpan YAML
At this point cpan will realize it's being run for the first time and ask you some questions like
Would you like me to configure as much as possible automatically? [yes]
Selecting the defaults worked fine.
It's nice to have LWP too.
To install LWP, first get to the cpan command prompt:
sudo cpan
Then install it:
install Bundle::LWP

Step Six: Build BioPerl

To install BioPerl, first get to the cpan command prompt:
sudo cpan
At the command prompt, tell CPAN that you want it to automatically get and install any prerequisites it comes across (this saves you hours of choosing "Yes"):
cpan[1]> o conf prerequisites_policy follow
And now, at the cpan prompt, install BioPerl:
install C/CJ/CJFIELDS/BioPerl-1.6.1.tar.gz
[force install C/CJ/CJFIELDS/BioPerl-1.6.1.tar.gz]
It will stop several times along the way. Except for the following question where my selection was to install all optional external modules, the defaults were fine.
Install [a]ll optional external modules, [n]one, or choose [i]nteractively? [n] a
During the tests that BioPerl runs, I saw the following:
Replacement list is longer than search list at Bio/Range.pm line 251.
According to this post, The above are warnings from perl 5.12 that can be ignored (they have been fixed in bioperl-live on github).
For a quick test of BioPerl, put the following into a file named test.pl:

use Bio::Perl;
# this script will only work if you have an internet connection on the
# computer you're using, the databases you can get sequences from
# are 'swiss', 'genbank', 'genpept', 'embl', and 'refseq'
$seq_object = get_sequence('embl',"AI129902");
write_sequence(">roa1.fasta",'fasta',$seq_object);

Then run it:
perl test.pl
and sure enough, a file named roa1.fasta gets written. Yay!
If you are installing BioPerl on a Mac that has multiple user accounts, you'll need to make sure that the following exists in each user's .profile file (at /Users/john/.profile, for example):

# MacPorts Installer addition on 2010-10-04_at_15:32:08: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

This makes it so that when you type perl the Mac will find and use the Perl from MacPorts instead of the system Perl. Also, be aware of scripts that say #!/usr/bin/perl at the top.

Friday, July 1, 2011

R max-vsize and Haploview memory

Use command line options to control the memory available for R.

R --min-vsize=vl --max-vsize=vu --min-nsize=nl --max-nsize=nu --max-ppsize=N

vl, vu, vsizeHeap memory in bytes.
nl, nu, nsizeNumber of cons cells.
NNumber of nested PROTECT calls.

Both options must be integers or integers followed by G, M, K, or k meaning Giga (2^{30} = 1073741824) Mega (2^{20} = 1048576), (computer) Kilo (2^{10} = 1024), or regular kilo (1000).

R --max-vsize=3G   ### 3G, R max

java -jar Haploview.jar -memory 4000 ### 4G memory

Tuesday, June 28, 2011

linux解压 tar/gz/bz/gz2/bz2...压缩与解压缩

linux解压 tar命令

tar命令 tar [-cxtzjvfpPN] 文件与目录 .... 参数:
-c :建立一个压缩文件的参数指令(create 的意思);
-x :解开一个压缩文件的参数指令!
-t :查看 tarfile 里面的文件!
特别注意,在参数的下达中, c/x/t 仅能存在一个!不可同时存在!
因为不可能同时压缩与解压缩。
-z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?
-j :是否同时具有 bzip2 的属性?亦即是否需要用 bzip2 压缩?
-v :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程!
-f :使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!
   例如使用『 tar -zcvfP tfile sfile』就是错误的写法,要写成
   『 tar -zcvPf tfile sfile』才对喔!
-p :使用原文件的原来属性(属性不会依据使用者而变)
-P :可以使用绝对路径来压缩!
-N :比后面接的日期(yyyy/mm/dd)还要新的才会被打包进新建的文件中!
--exclude FILE:在压缩的过程中,不要将 FILE 打包!
范例:
范例一:将整个 /etc 目录下的文件全部打包成为 /tmp/etc.tar [root@linux ~]#
tar -cvf /tmp/etc.tar /etc<==仅打包,不压缩!
[root@linux ~]# tar -zcvf /tmp/etc.tar.gz /etc<==打包后,以 gzip 压缩
[root@linux ~]# tar -jcvf /tmp/etc.tar.bz2 /etc<==打包后,以 bzip2 压缩
# 特别注意,在参数 f 之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。
# 如果加 z 参数,则以 .tar.gz 或 .tgz 来代表 gzip 压缩过的 tar file ~
# 如果加 j 参数,则以 .tar.bz2 来作为附档名啊~
# 上述指令在执行的时候,会显示一个警告讯息:
# 『tar: Removing leading `/" from member names』那是关於绝对路径的特殊设定。

范例二:查阅上述 /tmp/etc.tar.gz 文件内有哪些文件?
[root@linux ~]# tar -ztvf /tmp/etc.tar.gz
# 由於我们使用 gzip 压缩,所以要查阅该 tar file 内的文件时,
# 就得要加上 z 这个参数了!这很重要的!

范例三:将 /tmp/etc.tar.gz 文件解压缩在 /usr/local/src 底下
[root@linux ~]# cd /usr/local/src
[root@linux src]# tar -zxvf /tmp/etc.tar.gz
# 在预设的情况下,我们可以将压缩档在任何地方解开的!以这个范例来说,
# 我先将工作目录变换到 /usr/local/src 底下,并且解开 /tmp/etc.tar.gz ,
# 则解开的目录会在 /usr/local/src/etc 呢!另外,如果您进入 /usr/local/src/etc
# 则会发现,该目录下的文件属性与 /etc/ 可能会有所不同喔!

范例四:在 /tmp 底下,我只想要将 /tmp/etc.tar.gz 内的 etc/passwd 解开而已
[root@linux ~]# cd /tmp
[root@linux tmp]# tar -zxvf /tmp/etc.tar.gz etc/passwd
# 我可以透过 tar -ztvf 来查阅 tarfile 内的文件名称,如果单只要一个文件,
# 就可以透过这个方式来下达!注意到! etc.tar.gz 内的根目录 / 是被拿掉了!

范例五:将 /etc/ 内的所有文件备份下来,并且保存其权限!
[root@linux ~]# tar -zxvpf /tmp/etc.tar.gz /etc
# 这个 -p 的属性是很重要的,尤其是当您要保留原本文件的属性时!
范例六:在 /home 当中,比 2005/06/01 新的文件才备份
[root@linux ~]# tar -N "2005/06/01" -zcvf home.tar.gz /home
范例七:我要备份 /home, /etc ,但不要 /home/dmtsai
[root@linux ~]# tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc
范例八:将 /etc/ 打包后直接解开在 /tmp 底下,而不产生文件!
[root@linux ~]# cd /tmp
[root@linux tmp]# tar -cvf - /etc | tar -xvf -
# 这个动作有点像是 cp -r /etc /tmp 啦~依旧是有其有用途的!
# 要注意的地方在於输出档变成 - 而输入档也变成 - ,又有一个 | 存在~
# 这分别代表 standard output, standard input 与管线命令啦!
# 这部分我们会在 Bash shell 时,再次提到这个指令跟大家再解释啰!


source: http://www.21andy.com/blog/20060820/389.html

*.gz2用gunzip2 *.gz2
For examplegunzip2 *.tar.gz2,解出一个*.tar文件,
然后tar -vxf *.tar即可

.rar格式
解压:[*******]$ rar a FileName.rar
压缩:[*******]$ rar e FileName.rar    
解压后请将rar_static拷贝到/usr/bin目录(其他由$PATH环境变量
指定的目录也行):[*******]$ cp rar_static /usr/bin/rar
.tar
解包:tar xvf FileName.tar
打包:tar cvf FileName.tar DirName
(注:tar是打包,不是压缩!)
———————————————
.gz
解压1:gunzip FileName.gz
解压2:gzip -d FileName.gz
压缩:gzip FileName
.tar.gz 和 .tgz
解压:tar zxvf FileName.tar.gz
压缩:tar zcvf FileName.tar.gz DirName
———————————————
.bz2
解压1:bzip2 -d FileName.bz2
解压2:bunzip2 FileName.bz2
压缩: bzip2 -z FileName
.tar.bz2
解压:tar jxvf FileName.tar.bz2
压缩:tar jcvf FileName.tar.bz2 DirName
———————————————
.bz
解压1:bzip2 -d FileName.bz
解压2:bunzip2 FileName.bz
压缩:未知
.tar.bz
解压:tar jxvf FileName.tar.bz
压缩:未知
———————————————
.Z
解压:uncompress FileName.Z
压缩:compress FileName
.tar.Z
解压:tar Zxvf FileName.tar.Z
压缩:tar Zcvf FileName.tar.Z DirName
———————————————
.zip
解压:unzip FileName.zip
压缩:zip FileName.zip DirName
———————————————
.rar
解压:rar x FileName.rar
压缩:rar a FileName.rar DirName

rar请到:http://www.rarsoft.com/download.htm 下载!
解压后请将rar_static拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp rar_static /usr/bin/rar

———————————————
.lha
解压:lha -e FileName.lha
压缩:lha -a FileName.lha FileName

lha请到:http://www.infor.kanazawa-it.ac.jp/~ishii/lhaunix/下载!
>解压后请将lha拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp lha /usr/bin/

———————————————
.rpm
解包:rpm2cpio FileName.rpm | cpio -div
———————————————
.deb
解包:ar p FileName.deb data.tar.gz | tar zxf -
———————————————
.tar .tgz .tar.gz .tar.Z .tar.bz .tar.bz2 .zip .cpio .rpm .deb .slp .arj .rar .ace .lha .lzh .lzx .lzs .arc .sda .sfx .lnx .zoo .cab .kar .cpt .pit .sit .sea
解压:sEx x FileName.*
压缩:sEx a FileName.* FileName

sEx只是调用相关程序,本身并无压缩、解压功能,请注意!
sEx请到: http://sourceforge.net/projects/sex下载!
解压后请将sEx拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp sEx /usr/bin/

gzip 命令

减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间。gzip 是在 Linux 系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用。
语法:gzip [选项] 压缩(解压缩)的文件名
该命令的各选项含义如下:
-c 将输出写到标准输出上,并保留原有文件。
-d 将压缩文件解压。
-l 对每个压缩文件,显示下列字段:
     压缩文件的大小;未压缩文件的大小;压缩比;未压缩文件的名字
-r 递归式地查找指定目录并压缩其中的所有文件或者是解压缩。
-t 测试,检查压缩文件是否完整。
-v 对每一个压缩和解压的文件,显示文件名和压缩比。
-num 用指定的数字 num 调整压缩的速度,-1 或 --fast 表示最快压缩方法(低压缩比),
-9 或--best表示最慢压缩方法(高压缩比)。系统缺省值为 6。
指令实例:
gzip *
% 把当前目录下的每个文件压缩成 .gz 文件。

gzip -dv *
% 把当前目录下每个压缩的文件解压,并列出详细的信息。

gzip -l *
% 详细显示例1中每个压缩的文件的信息,并不解压。

gzip usr.tar
% 压缩 tar 备份文件 usr.tar,此时压缩文件的扩展名为.tar.gz。

source: http://hi.baidu.com/koomo007/blog/item/4904bb2642928c09918f9d02.html


部分解压

tar部分解压,只解压出需要的文件,这样就解决了tar包过大的情况下,解压速度太慢、解压后占用空间过大的问题。
几个步骤:
查看tar包内包含的文件,如果已经知道这一步可免
tar -tzvf u2file.tar.gz
-rw-r--r-- user/user 45489156 2008-08-04 23:59:46 foder/access.log.20080804
-rw-r--r-- user/user 37469223 2008-08-05 23:59:46 foder/access.log.20080805

#解压单个文件
tar -zxvf u2file.tar.gz foder/access.log.0805

#解压多个文件
tar -zxvf u2file.tar.gz foder/access.log.*

#解压到指定目录
tar -xzvf u2file.tar.gz foder/access.log.0805 -C /new/dir/    # -C 指定解压到的目录.

source:http://angeldog.blog.51cto.com/1108908/292903

Thursday, June 23, 2011

Scatterplot with marginal histograms

The scatterplot is one of the most ubiquitous, and useful graphics. It's also very basic. One of its shortcomings is that it can hide important aspects of the marginal distributions of the two variables. To address this weakness, you can add a histogram of each margin to the plot. We demonstrate using the SF-36 MCS and PCS subscales in the HELP data set.

scatterhist = function(x, y, xlab="", ylab=""){
 zones=matrix(c(2,0,1,3), ncol=2, byrow=TRUE)
 layout(zones, widths=c(4/5,1/5), heights=c(1/5,4/5))
 xhist = hist(x, plot=FALSE)
 yhist = hist(y, plot=FALSE)
 top = max(c(xhist$counts, yhist$counts))
 par(mar=c(3,3,1,1))
 plot(x,y)
 par(mar=c(0,3,1,1))
 barplot(xhist$counts, axes=FALSE, ylim=c(0, top), space=0)
 par(mar=c(3,0,1,1))
 barplot(yhist$counts, axes=FALSE, xlim=c(0, top), space=0, horiz=TRUE)
 par(oma=c(3,3,0,0))
 mtext(xlab, side=1, line=1, outer=TRUE, adj=0,     at=.8 * (mean(x) - min(x))/(max(x)-min(x)))
 mtext(ylab, side=2, line=1, outer=TRUE, adj=0,     at=(.8 * (mean(y) - min(y))/(max(y) - min(y))))
 }

ds = read.csv("http://www.math.smith.edu/r/data/help.csv")
with(ds, scatterhist(mcs, pcs, xlab="MCS", ylab="PCS"))

An Example of ANOVA using R

 In its simplest form ANOVA provides a statistical test of whether or not the means of several groups are all equal, and therefore generalizes t-test to more than two groups. The t-test tells us if the variation between two groups is "significant".

(方差分析ANOVA又称变异数分析或F检验,其目的是推断两组或多组资料的总体均数是否相同,检验两个或多个样本均数的差异是否有统计学意义)

An Example of ANOVA using R

by EV Nordheim, MK Clayton & BS Yandell, November 11, 2003

In class we handed out ”An Example of ANOVA”. Below we redo the example using R.
There are three groups with seven observations per group. We denote group i values by yi:
> y1 = c(18.2, 20.1, 17.6, 16.8, 18.8, 19.7, 19.1)
> y2 = c(17.4, 18.7, 19.1, 16.4, 15.9, 18.4, 17.7)
> y3 = c(15.2, 18.8, 17.7, 16.5, 15.9, 17.1, 16.7)

Now we combine them into one long vector, with a second vector, group, identifying group
membership:

> y = c(y1, y2, y3)
> n = rep(7, 3)
> n
[1] 7 7 7
> group = rep(1:3, n)
> group
[1] 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3

Here are summaries by group and for the combined data. First we show stem-leaf diagrams.

> tmp = tapply(y, group, stem)
The decimal point is at the |
16 | 8
17 | 6
18 | 28
19 | 17
20 | 1
The decimal point is at the |
15 | 9
16 | 4
17 | 47
18 | 47
19 | 1
The decimal point is at the |
15 | 29
16 | 57
17 | 17
18 | 8
> stem(y)
The decimal point is at the |
15 | 299
16 | 4578
17 | 14677
18 | 24788
19 | 117
20 | 1

Now we show summary statistics by group and overall. We locally define a temporary
function, tmpfn, to make this easier.

> tmpfn = function(x) c(sum = sum(x), mean = mean(x), var = var(x),n = length(x))
> tapply(y, group, tmpfn)
$`1`
       sum       mean        var          n
130.300000  18.614286   1.358095   7.000000
$`2`
       sum       mean        var          n
123.600000  17.657143   1.409524   7.000000
$`3`
       sum       mean        var          n
117.900000  16.842857   1.392857   7.000000
> tmpfn(y)
       sum       mean        var          n
371.800000  17.704762   1.798476  21.000000

While we could show you how to use R to mimic the computation of SS by hand, it is
more natural to go directly to the ANOVA table. See Appendix 11 for other examples of the
use of R commands for ANOVA.

> data = data.frame(y = y, group = factor(group))
> fit = lm(y ~ group, data)
> anova(fit)
Analysis of Variance Table
Response: y
          Df Sum Sq Mean Sq F value  Pr(>F) 
group      2 11.007  5.5033  3.9683 0.03735 *
Residuals 18 24.963  1.3868                 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The anova(fit) object can be used for other computations on the handout and in class.
For instance, the tabled F values can be found by the following. First we extract the treatment
and error degrees of freedom. Then we use qt to get the tabled F values.

> df = anova(fit)[, "Df"]
> names(df) = c("trt", "err")
> alpha = c(0.05, 0.01)
> qf(alpha, df["trt"], df["err"], lower.tail = FALSE)
[1] 3.554557 6.012905

A confidence interval on the pooled variance can be computed as well using the anova(fit)
object. First we get the residual sum of squares, SSTrt, then we divide by the appropriate
chi-square tabled values.

> anova(fit)["Residuals", "Sum Sq"]
[1] 24.96286
> anova(fit)["Residuals", "Sum Sq"]/qchisq(c(0.025, 0.975), 18,lower.tail = FALSE)
[1] 0.7918086 3.0328790

Five statistical things I wished I had been taught 20 years ago

These are the pieces of hard won statistical knowledge I wish someone had taught me 20 years ago rather than my meandering, random walk approach.


1. Non parametric statistics. These are statistical tests which make a bare minimum of assumptions of underlying distributions; in biology we are rarely confident that we know the underlying distribution, and hand waving about central limit theorem can only get you so far. Wherever possible you should use a non parameteric test. This is Mann-Whitney (or Wilcoxon if you prefer) for testing "medians" (Medians is in quotes because this is not quite true. They test something which is closely related to the median) of two distributions, Spearman's Rho (rather pearson's r2) for correlation, and the Kruskal test rather than ANOVAs (though if I get this right, you can't in Kruskal do the more sophisticated nested models you can do with ANOVA). Finally, don't forget the rather wonderful Kolmogorov-Smirnov (I always think it sounds like really good vodka) test of whether two sets of observations come from the same distribution. All of these methods have a basic theme of doing things on the rank of items in a distribution, not the actual level. So - if in doubt, do things on the rank of metric, rather than the metric itself.


2. R (or I guess S). R is a cranky, odd statistical language/system with a great scientific plotting package. Its a package written mainly by statisticians for statisticians, and is rather unforgiving the first time you use it. It is defnitely worth persevering. It's basically a combination of excel spreadsheets on steriods (with no data entry. an Rdata frame is really the same logical set as a excel workbook - able to handle millions of points, not 1,000s), a statistical methods compendium (it's usually the case that statistical methods are written first in R, and you can almost guarantee that there are no bugs in the major functions - unlike many other scenarios) and a graphical data exploration tool (in particular lattice and ggplot packages). The syntax is inconsistent, the documentation sometimes wonderful, often awful and the learning curve is like the face of the Eiger. But once you've met p.adjust(), xyplot() and apply(), you can never turn back.

3. The problem of multiple testing, and how to handle it, either with the Expected value, or FDR, and the backstop of many of piece of bioinformatics - large scale permutation. Large scale permutation is sometimes frowned upon by more maths/distribution purists but often is the only way to get a sensible sense of whether something is likely "by chance" (whatever the latter phrase means - it's a very open question) given the complex, hetreogenous data we have. 10 years ago perhaps the lack of large scale compute resources meant this option was less open to people, but these days basically everyone should be working out how to appropriate permute the data to allow a good estimate of "surprisingness" of an observation.

4. The relationship between Pvalue, Effect size, and Sample size - this needs to be drilled into everyone - we're far too trigger happy quoting Pvalues, when we should often be quoting Pvalues and Effect size. Once a Pvalue is significant, it's higher significance is sort of meaningless (or rather it compounds Effect size things with Sample size things, the latter often being about relative frequency). So - if something is significantly correlated/different, then you want to know about how much of an effect this observation has. This is not just about GWAS like statistics - in genomic biology we're all too happy about quoting some small Pvalue not realising that with a million or so points often, even very small deviations will be significant. Quote your r2, Rhos or proportion of variance explained...


5. Linear models and PCA. There is a tendency often to jump to quite complex models - networks, or biologically inspired combinations, when our first instinct should be to crack out the well established lm() (linear model) for prediction and princomp() (PCA) for dimensionality reduction. These are old school techniques - and often if you want to talk about statistical fits one needs to make gaussian assumptions about distributions - but most of the things we do could be either done well in a linear model, and most of the correlation we look at could have been found with a PCA biplot. The fact that these are 1970s bits of statistics doesn't mean they don't work well.
 
 

Sunday, June 19, 2011

Side-by-side histograms

In R, the lattice package provides a similarly direct approach.
ds = read.csv("http://www.math.smith.edu/r/data/help.csv")
ds$gender = ifelse(ds$female==1, "female", "male")
library(lattice)
histogram(~ cesd | gender, data=ds)


sources: http://sas-and-r.blogspot.com/2011/06/example-840-side-by-side-histograms.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+SASandR+%28SAS+and+R%29

Computing Odds Ratios in R

for two binary variables, x and y, each taking the values 0 and 1, the odds ratio is defined on the basis of the following four numbers:

            N00 = the number of data records with x = 0 and y = 0
            N01 = the number of data records with x = 0 and y = 1
            N10 = the number of data records with x = 1 and y = 0
            N11 = the number of data records with x = 1 and y = 1

Specifically, the odds ratio is given by the following expression:

OR = N00 N11 / N01 N10

Similarly, confidence intervals for the odds ratio are easily constructed by appealing to the asymptotic normality of log OR, which has a limiting variance given by the square root of the sum of the reciprocals of these four numbers.  The R procedure oddsratioWald.proc available from the companion website for Exploring Data computes the odds ratio and the upper and lower confidence limits at a specified level alpha from these four values:

oddsratioWald.proc <- function(n00, n01, n10, n11, alpha = 0.05){
  #
  #  Compute the odds ratio between two binary variables, x and y,
  #  as defined by the four numbers nij:
  #
  #    n00 = number of cases where x = 0 and y = 0
  #    n01 = number of cases where x = 0 and y = 1
  #    n10 = number of cases where x = 1 and y = 0
  #    n11 = number of cases where x = 1 and y = 1
  #
  OR <- (n00 * n11)/(n01 * n10)
  #
  #  Compute the Wald confidence intervals:
  #
  siglog <- sqrt((1/n00) + (1/n01) + (1/n10) + (1/n11))
  zalph <- qnorm(1 - alpha/2)
  logOR <- log(OR)
  loglo <- logOR - zalph * siglog
  loghi <- logOR + zalph * siglog
  #
  ORlo <- exp(loglo)
  ORhi <- exp(loghi)
  #
  oframe <- data.frame(LowerCI = ORlo, OR = OR, UpperCI = ORhi, alpha = alpha)
  oframe
}

Including “alpha = 0.05” in the parameter list fixes the default value for alpha at 0.05, which yields the 95% confidence intervals for the computed odds ratio, based on the Wald approximation described above.  An important practical point is that these intervals become infinitely wide if any of the four numbers Nij are equal to zero; also, note that in this case, the computed odds ratio is either zero or infinite.  Finally, it is worth noting that if the numbers Nij are large enough, the procedure just described can encounter numerical overflow problems (i.e., the products in either the numerator or the denominator become too large to be represented in machine arithmetic).  If this is a possibility, a better alternative is to regroup the computations as follows:

OR = (N00 / N01) x (N11 / N10 )


To use the routine just described, it is necessary to have the four numbers defined above, which form the basis for a two-by-two contingency table.  Because contingency tables are widely used in characterizing categorical data, these numbers are easily computed in R using the table command.  As a simple example, the following code reads the UCI mushroom dataset and generates the two-by-two contingency table for the EorP and GillSize attributes:

> mushrooms <- read.csv("mushroom.csv")
>
> table(mushrooms$EorP, mushrooms$GillSize)
  
       b    n
  e 3920  288
  p 1692 2224
>
>

(Note that the first line reads the csv file containing the mushroom data; for this command to work as shown, it is necessary for this file to be in the working directory.  Alternatively, you can change the working directory using the setwd command.) 


To facilitate the computation of odds ratios, the following preliminary procedure combines the table command with the oddsratioWald.proc procedure, allowing you to compute the odds ratio and its level-alpha confidence interval from the two-level variables directly:


TableOR.proc00 <- function(x,y,alpha=0.05){
  #
  xtab <- table(x,y)
  n00 <- xtab[1,1]
  n01 <- xtab[1,2]
  n10 <- xtab[2,1]
  n11 <- xtab[2,2]
  oddsratioWald.proc(n00,n01,n10,n11,alpha)
}

The primary disadvantage of this procedure is that it doesn’t tell you which levels of the two variables are being characterized by the computed odds ratio.  In fact, this characterization describes the first level of each of these variables, and the following slight modification makes this fact explicit:


TableOR.proc <- function(x,y,alpha=0.05){
   #
   xtab <- table(x,y)
   n00 <- xtab[1,1]
   n01 <- xtab[1,2]
   n10 <- xtab[2,1]
   n11 <- xtab[2,2]
   #
   outList <- vector("list",2)
   outList[[1]] <- paste("Odds ratio between the level [",dimnames(xtab)[[1]][1],"] of the first variable and the level [",dimnames(xtab)[[2]][1],"] of the second variable:",sep=" ")
   outList[[2]] <- oddsratioWald.proc(n00,n01,n10,n11,alpha)
   outList
 }

Specifically, I have used the fact that the dimension names of the 2x2 table xtab correspond to the levels of the variables x and y, and I have used the paste command to include these values in a text string displayed to the user.  (I have enclosed the levels in square brackets to make them stand out from the surrounding text, particularly useful here since the levels are coded as single letters.)  Applying this procedure to the mushroom characteristics EorP and GillSize yields the following results:

> TableOR.proc(mushrooms$EorP, mushrooms$GillSize)
[[1]]
[1] "Odds ratio between the level [ e ] of the first variable and the level [ b ] of the second variable:"

[[2]]
   LowerCI       OR  UpperCI alpha
1 15.62615 17.89073 20.48349  0.05

>

Almost certainly, the formatting I have used here could be improved – probably a lot – but the key point is to provide a result that is reasonably complete and easy to interpret. 

Finally, I noted in my last post that if we are interested in using odds ratios to compare or rank associations, it is useful to code the levels so that the computed odds ratio is larger than 1.  In particular, note that applying the above procedure to characterize the relationship between edibility and the Bruises characteristic yields:

> TableOR.proc(mushrooms$EorP, mushrooms$Bruises)
[[1]]
[1] "Odds ratio between the level [ e ] of the first variable and the level [ f ] of the second variable:"

[[2]]
     LowerCI        OR   UpperCI alpha
1 0.09014769 0.1002854 0.1115632  0.05

>

It is clear from these results that both Bruises and GillSize exhibit odds ratios with respect to mushroom edibility that are significantly different from the neutral value 1 (i.e., the 95% confidence interval excludes the value 1 in both cases), but it is not obvious which variable has the stronger association, based on the available data.  The following procedure automatically restructures the computation so that the computed odds ratio is larger than or equal to 1, allowing us to make this comparison:


AutomaticOR.proc <- function(x,y,alpha=0.05){
  #
   xtab <- table(x,y)
   n00 <- xtab[1,1]
   n01 <- xtab[1,2]
   n10 <- xtab[2,1]
   n11 <- xtab[2,2]
   #
   rawOR <- (n00*n11)/(n01*n10)
   if (rawOR < 1){
     n01 <- xtab[1,1]
     n00 <- xtab[1,2]
     n11 <- xtab[2,1]
     n10 <- xtab[2,2]
     iLevel <- 2
   }
   else{
     iLevel <- 1
   }
   outList <- vector("list",2)
   outList[[1]] <- paste("Odds ratio between the level [",dimnames(xtab)[[1]][1],"] of the first variable and the level [",dimnames(xtab)[[2]][iLevel],"] of the second variable:",sep=" ")
   outList[[2]] <- oddsratioWald.proc(n00,n01,n10,n11,alpha)
   outList
 }

Note that this procedure first constructs the 2x2 table on which everything is based and then computes the odds ratio in the default coding: if this value is smaller than 1, the coding of the second variable (y) is reversed.  The odds ratio and its confidence interval are then computed and the levels of the variables used in computing it are presented as before.  Applying this procedure to the Bruises characteristic yields the following result, from which we can see that GillSize appears to have the stronger association, as noted last time:

> AutomaticOR.proc(mushrooms$EorP, mushrooms$Bruises)
[[1]]
[1] "Odds ratio between the level [ e ] of the first variable and the level [ t ] of the second variable:"

[[2]]
   LowerCI       OR  UpperCI alpha
1 8.963532 9.971541 11.09291  0.05