How to understand ROC curve

During a layover on a Chrismas vacation to Alaska, I asked my friend who majors in statistic what an ROC curve is--a concept that had confused me for a long time. Although my friend gave me a detailed explanation, the only conclusion I remember is that the farther the curve is above from the y=x line, the better the ROC curve is. But how? Back home from vacation, I decided to figure it out. 

The x & y axis for ROC curve are False positive rate (FPR) and True positive rate (TPR) respectively. What are they? let me use a simply example from wikipedia to explain these concepts:

 

"imagine a study evaluating a test that screens people for a disease. Each  person taking the test either has or does not have the disease. The test outcome can be positive (classifying the person as having the disease) or negative (classifying the person as not having the disease). The test results for each subject may or may not match the subject's actual status. In that setting:

  • True positive: Sick people correctly identified as sick
  • False positive: Healthy people incorrectly identified as sick
  • True negative: Healthy people correctly identified as healthy
  • False negative: Sick people incorrectly identified as healthy

after getting the numbers of true positives, false positives, true negatives, and false negatives, the sensitivity and specificity for the test can be calculated. If it turns out the sensitivity is high then any person who has the diseases is likely to be classified as positive by the test. On the other hand, if the specificity is high, any person who does not have the disease is likely to be classified as negative by the test. " 

 They also give two straightforward pictures to illustrate concepts of sensitivity and specificity:


As for calculation of sensitivity, specificity, and FPR, we have:

sensitivity (TPR) = TP / (TP + FN)

specificity = TN / (TN + FP)

FPR = FP / (TN + FP) = 1 - specificity


Apparently, we hope TPR is as high as possible, and this is why the ROC curve should be farther above away y = x line.


 

 

Impossible triangle in life

In MRI, there is an "impossible triangle" formed by SNR, spatial resolution, and scan time. Improving any two inevitably comes at the expense of the third. High SNR and high resolution demand long scan times; short scans with high resolution suffer from low SNR; and achieving both high SNR and short scan times requires sacrificing spatial resolution.

I recently realized that life seems to follow a similar "impossible triangle" defined by money, time, and energy. In youth, we possess time and energy but lack money. In middle age, we gain money and energy but lose time. In old age, we may finally have time and money, yet no longer have the energy to fully enjoy them.

 


 

Good to know

Greg Mankiw's blog is a website I visit often. I just realized that he’s the author of the two well-known economics textbooks Principles of Macroeconomics and Principles of Microeconomics. I had only known these books and their author by their Chinese names — which is a bit embarrassing.

[Visual Studio] .dll & .lib

 DLL = Dynamic Link Library

 it contains compiled machine code for functions, classes, etc., but not in a form the linker can use directly.

 DLLs are loaded at runtime (when your program starts, or later if you load them manually).

 if the DLL is missing at runtime, you get errors like

The program can't start because *.dll is missing...

There are two types of .lib files in Visual Studio:

 (a) Static Library (.lib)

  • Contains all compiled code directly
  • Gets copied into your .exe during linking
  • No DLL is needed at runtime--the code is inside your executable

 (b) Import Library (.lib)

  • This is the one used with DLLs
  • It does not contain the code itself -- it only contains symbol information (function names, addresses) so the linker knows:
    • Which functions your code will call
    • That they will be found inside a specific DLL at runtime.
  • At link time, you give the linker the .lib (so it knows what you're calling) and at runtime you place .dll next to your .exe (so it can actually run).

Think of the .lib as the map that tells your program "The hammer is in that toolbox over there", and the .dll as the toolbox itself. 

 

 

env not found in kernel picker on vs code

If you are testing the *.ipynb files using vs code, after you create a new env with conda:

$ conda create -n <your_name> 

you will notice that you can NOT find env name you just created. Installing ipykernel will help you address this issue

$ conda install ipykernel 

Why don't Students like School

Until recently, I didn't know that there is a well-know book titled Why don't students like school?, written by Daniel T. Willingham, a professor at our Univeristy — the University of Virginia. The book offers some insightful ideas about how we think:

  • The mind is not designed for thinking—it's designed to save you from thinking: In other words, thinking is effortful, and students will avoid it unless they are motivated and the conditions are right.
  • People are naturally curious—but only if the problem is the right level of difficulty: If it's too hard, they give up; if it's too easy, they get bored.
  • Memory is the residue of thought: We remember what we think about. So, lessons should focus students' thinking on the right things. 
  • Factual knowledge is essential for critical thinking: The more you know, the easier it is to understand, learn new things, and think critically.
  • Students learn better when lessons are meaningful and connected to prior knowledge.
  • Teaching should build on stories, emotions, and visuals—because those are what the brain remembers best.
Here is a brief summary of this article. 

 

Present Perfect Tense & Simple Past Tense

  1.  Present Perfect Tense (have/has + past participle) 
  • Form:
    • I have eaten, She has gone, We have finished.
  • Use:
    • Refers to past actions that are connected to the present. Often used when:
      • The exact time is not mentioned
      • The result still matters now
      • The action has happened at some point in the past (unspecified time)
  • Examples
    • I have eaten breakfast. (You may still be full now)
    • She has visited Japan. (In her life, at some time -- we don't say when)
    • We've just finished the project. (The result affects the present)
 

     2. Simple Past Tense (verb + -ed or past form)

  • Form:
    • I ate, She went, We finished
  • Use:
    • Refer to completed actions that in the past usually with a specific time (even if it's implied)
  • Examples:
    • I ate breakfast at 8 a.m. (Specific time in the past)
    • She visited Japan in 2020.
    • We finished the project last week

Kahil Gibran: On Children

And a woman who held a babe against her bosom said, Speak to us of Children.

And he said:

Your children are not your children.

They are the sons and daughters of Life's longing for itself.

They come through you but not from you.

And though they are with you yet they belong not to you.

You might give them your love but not your thoughts,

For they have their own thoughts.

You may house their bodies but not their souls,

For their souls dwell in the house of tomorrow, which you cannot visit, not even in your dreams.

You may strive to be like them, but seek not to make them like you.

For life goes not backward nor tarries with yesterday.

You are the bows from which your children as living arrows are sent forth.

The archer sees the mark upon the path of the infinite, and He bends you    with his might that His arrows may go swift and far. 

Let your bending in the archer's hand be for gladness;

For even as He loves the arrow that flies, so He loves also the bow that is stable.

Taste

[statement] this article is from Andrew Abbott's book: Methods of Discovery: Heuristics for the Social Sciences
 
---

Conventions and the problem of knowing them bring us to the matter of taste. Judging one's ideas becomes much easier when one begins  to acquire scholarly taste. By taste, I mean a general, intuitive sense of whether an idea is likely to be a good one or not. It is of course important not to become a slave of ones' taste, to try new things as one tries new foods. But developing a sense of taste makes things a lot easier.

The foundation of good taste -- like the foundation of good heuristic -- is broad reading. It is not necessary that all the reading be of good material, only that it be broad and that it always involve judgment and reflection. A musical metaphor is again useful. A good pianist always practices not only technique and repertoire but also sight-reading for pianists. A pianist practicing sight-reading grabs a random piece of music and reads it through, playing steadily on in spite of  mistakes and omissions. So, too, should you just pick up pieces of social science or sociology or whatever and just read through them, whether you know the details of the methods, see the complexities of the argument, or even like the style of analysis. The obvious way to do this is to pick up recent issues of journals and quickly read straight through them.

You learn many things from such broad reading. You learn the zones of research in the discipline. You learn the conventions of each zone, and you figure out which you like and which you don't like. You learn what interests you and what does not. Of course, you should not let your interests dictate your reactions, just as you should disregard, when you are "sight-reading," conventions with which you disagree. When you find you don't like a paper's methodology and you think its concepts don't make sense, force yourself to go on and ask what there is that you can get out of it -- perhaps some facts, a hypothesis, even (in the worst case) some references. In the best disciplinary journals, every article will have something to teach you, even those articles that lie completely outside your own preferences.

 This is also a useful rule for seminars and lectures, which are another useful place to develop your taste. There is no point in sitting through a lecture or talk whose methods you hate, self-righteously telling yourself about the "positivist morons" or the "postmodern bullshit" or whatever. All that does is reinforce your prejudices and teach you nothing. Judge a talk or a paper with respect to what it is itself trying to do. This is hard, but by working at it, you will gain a much surer sense of both the strengths and weaknesses of your own preferences. You will become able to gather useful ideas, theories, facts, and methodological tricks from material that used to tell you nothing.

You will, of course, run into plenty of bad stuff: bad books, bad papers, bad talks. The symptoms are usually pretty clear: pontification, confusion, aimlessness, overreliance on authorities. Other  signs are excessive attention to methods rather than substance and long discussions of the speaker's or writer's positions on various important debates. But even bad material can t each you things. Most important, it can teach you how to set standards for an article or talk on its own terms. What was the writer trying to accomplish? For the truly terrible, what should the write have been trying to accomplish? This last is the question that enables you to judge material on its own grounds, by imagining the task it should have set itself.

Of  course, it is also important self-consciously to read good work. Oddly enough, good work will not teach you as much as will bad. Great social science  tends to look self-evident after the fact, and when it's well written, you may not be able to see what the insight was that instituted a new paradigm. What you take away from good work is more its sense of excitement and clarity, its feeling of ease and fluidity. Not that these are very imitable. But they set an ideal.

How does one find such good work? At the start, you ask people you know -- faculty members, friends, fellow students. You also look at influential material, although -- again oddly -- there is plenty of influential material that is badly argued and opaque. Soon your taste will establish itself, and you can rely more on your own judgment. There is no substitute for practice and, in particular, for "sight-reading." You just need to learn to read and make judgments, always working around your own prejudices to separate bad work from work you simply don't like.

Developing this taste about others' ideas is a crucial step toward judging your own. Even given all the hints scattered throughout this chapter, judging your own ideas is the hardest task of all. The only way to become skilled at it is to acquire general taste and then carefully and painfully turn that taste on your own thinking. The skill of learning to find good and bad things in the work of others can be the best help in finding the good and bad things in your own work.