All About Statistics Sat, 03 Jun 2017 14:16:06 +0000 en-US hourly 1 http://wordpress.org/?v=3.4.2 statsblogshttps://feedburner.google.com June Reading List http://feedproxy.google.com/~r/statsblogs/~3/LrteHsrCaKc/ /2017/06/03/june-reading-list-3/#comments Sat, 03 Jun 2017 14:16:00 +0000 Dave Giles /?guid=68b6a34406bf66d8c570532e39aaca7b Here are some suggestions for you:Ai, C. and E. C. Norton, 2003. Interaction terms in logit and probit models. Economics Letters, 80, 123-129.Hirschberg, J. and J. Lye, 2017. Inverting the indirect - the ellipse and the Boomerang: Visualizing the confi...

The post June Reading List appeared first on All About Statistics.

]]>
(This article was originally published at Econometrics Beat: Dave Giles' Blog, and syndicated at StatsBlogs.)

Here are some suggestions for you:
  • Ai, C. and E. C. Norton, 2003. Interaction terms in logit and probit models. Economics Letters, 80, 123-129.
  • Hirschberg, J. and J. Lye, 2017. Inverting the indirect - the ellipse and the Boomerang: Visualizing the confidence intervals of the structural coefficient from two-stage least squares. Journal of Econometrics, in press.
  • Kim, I. and S. Park, 2017. Likelihood ratio tests for multivariate normality. Communications in Statistics - Theory and Methods, in press.
  • Knotek, E. S. and S. Zaman, 2017. Financial nowcasts and their usefulness in macroeconomic forecasting. Working Paper 17-02, Federal Reserve Bank of Cleveland.
  • Marczak, M. and V. Goméz, 2017. Monthly US business cycle indicators: A new multivariate approach based on a band-pass filter. Empirical Economics, 52, 1379-1408.
  • Sherwood, C. and D. W. Kwak, 2017. New insights into an old problem - enhancing student learning outcomes in an introductory statistics course. Applied Economics, in press.
© 2017, David E. Giles



Please comment on the article here: Econometrics Beat: Dave Giles' Blog

The post June Reading List appeared first on All About Statistics.

]]>
/2017/06/03/june-reading-list-3/feed/ 0 /2017/06/03/june-reading-list-3/
A collection of quotes from William James that all could’ve come from . . . Bill James! http://feedproxy.google.com/~r/statsblogs/~3/YamCUf6X4cA/ /2017/06/03/a-collection-of-quotes-from-william-james-that-all-couldve-come-from-bill-james/#comments Sat, 03 Jun 2017 13:53:28 +0000 Andrew http://andrewgelman.com/?p=34604

From a few years ago, some quotes from the classic psychologist that fit within the worldview of the classic sabermetrician: Faith means belief in something concerning which doubt is theoretically possible. A chain is no stronger than its weakest link, and life is after all a chain. A great many people think they are thinking […]

The post A collection of quotes from William James that all could’ve come from . . . Bill James! appeared first on Statistical Modeling, Causal Inference, and Social Science.

The post A collection of quotes from William James that all could’ve come from . . . Bill James! appeared first on All About Statistics.

]]>
(This article was originally published at Statistical Modeling, Causal Inference, and Social Science, and syndicated at StatsBlogs.)

From a few years ago, some quotes from the classic psychologist that fit within the worldview of the classic sabermetrician:

Faith means belief in something concerning which doubt is theoretically possible.

A chain is no stronger than its weakest link, and life is after all a chain.

A great many people think they are thinking when they are merely rearranging their prejudices.

A man has as many social selves as there are individuals who recognize him.

Acceptance of what has happened is the first step to overcoming the consequences of any misfortune.

An act has no ethical quality whatever unless it be chosen out of several all equally possible.

Be willing to have it so. Acceptance of what has happened is the first step to overcoming the consequences of any misfortune.

Belief creates the actual fact.

Compared to what we ought to be, we are half awake.

Do something everyday for no other reason than you would rather not do it, so that when the hour of dire need draws nigh, it may find you not unnerved and untrained to stand the test.

Great emergencies and crises show us how much greater our vital resources are than we had supposed.

Human beings can alter their lives by altering their attitudes of mind.

If any organism fails to fulfill its potentialities, it becomes sick.

If you want a quality, act as if you already had it.

In the dim background of mind we know what we ought to be doing but somehow we cannot start.

Individuality is founded in feeling; and the recesses of feeling, the darker, blinder strata of character, are the only places in the world in which we catch real fact in the making, and directly perceive how events happen, and how work is actually done.

It is only by risking our persons from one hour to another that we live at all. And often enough our faith beforehand in an uncertified result is the only thing that makes the result come true.

It is our attitude at the beginning of a difficult task which, more than anything else, will affect its successful outcome.

It is wrong always, everywhere, and for everyone, to believe anything upon insufficient evidence.

No matter how full a reservoir of maxims one may possess, and no matter how good one’s sentiments may be, if one has not taken advantage of every concrete opportunity to act, one’s character may remain entirely unaffected for the better.

Nothing is so fatiguing as the eternal hanging on of an uncompleted task.

Some are more Bill-James-like than others, but, as a whole, this list is kind of amazing.

The post A collection of quotes from William James that all could’ve come from . . . Bill James! appeared first on Statistical Modeling, Causal Inference, and Social Science.



Please comment on the article here: Statistical Modeling, Causal Inference, and Social Science

The post A collection of quotes from William James that all could’ve come from . . . Bill James! appeared first on All About Statistics.

]]>
/2017/06/03/a-collection-of-quotes-from-william-james-that-all-couldve-come-from-bill-james/feed/ 0 /2017/06/03/a-collection-of-quotes-from-william-james-that-all-couldve-come-from-bill-james/
Hey—here are some tips on communicating data and statistics! http://feedproxy.google.com/~r/statsblogs/~3/leUBU0Dh36o/ /2017/06/02/hey-here-are-some-tips-on-communicating-data-and-statistics/#comments Fri, 02 Jun 2017 18:31:54 +0000 Andrew http://andrewgelman.com/?p=35374

This fall I’ll be again teaching the course, Communicating Data and Statistics. Here’s the rough course plan. I’ll tinker with it between now and September but this is the basic idea. (The course listing is here, but that online description is out of date; the course plan linked above is more accurate.) Here are the […]

The post Hey—here are some tips on communicating data and statistics! appeared first on Statistical Modeling, Causal Inference, and Social Science.

The post Hey—here are some tips on communicating data and statistics! appeared first on All About Statistics.

]]>
(This article was originally published at Statistical Modeling, Causal Inference, and Social Science, and syndicated at StatsBlogs.)

This fall I’ll be again teaching the course, Communicating Data and Statistics.

Here’s the rough course plan. I’ll tinker with it between now and September but this is the basic idea. (The course listing is here, but that online description is out of date; the course plan linked above is more accurate.)

Here are the topics for the 13 weeks of the course:

1. Introducing yourself and telling a story
2. Principles of statistical graphics
3. Teaching
4. Making effective graphs
5. Communicating variation and uncertainty
6. Displaying fitted models
7. Giving a presentation
8. Dynamic graphics
9. Writing
10. Collaboration and the scientific community
11. Data processing and programming
12. Student projects
13. Student projects

Communication is central to your job as a quantitative researcher. Our goal in this course is for you to improve at all aspects of statistical communication, including writing, public speaking, teaching, informal conversation and collaboration, programming, and graphics.

Always keep in mind your goals and your audience.

Never forget, as one of our blog commenters reminds us: your closest collaborator is you six months ago . . . and she doesn’t reply to email!

The course is intended for Ph.D. students from all departments on campus; it is also open to some masters and undergraduate students who have particular interest in the topic.

This is my favorite course ever. As a student, you’ll get practice in all sorts of useful skills that are central to data and statistics, and you’ll participate in fast-moving conversations with fellow students with different backgrounds and experiences. In the interstices, you’ll learn all sorts of important ideas and methods in statistical design and analysis, that you’d never learn anywhere else. It’s the course where we first introduced statistics diaries. It’s the course where (a prototype version of) ShinyStan was one of the final projects!

You don’t want to miss this one.

The class will meet twice a week.

The post Hey—here are some tips on communicating data and statistics! appeared first on Statistical Modeling, Causal Inference, and Social Science.



Please comment on the article here: Statistical Modeling, Causal Inference, and Social Science

The post Hey—here are some tips on communicating data and statistics! appeared first on All About Statistics.

]]>
/2017/06/02/hey-here-are-some-tips-on-communicating-data-and-statistics/feed/ 0 /2017/06/02/hey-here-are-some-tips-on-communicating-data-and-statistics/
You’ll never guess this one quick trick to diagnose problems with your graphs and then make improvements http://feedproxy.google.com/~r/statsblogs/~3/wKi4J0va-aw/ /2017/06/02/youll-never-guess-this-one-quick-trick-to-diagnose-problems-with-your-graphs-and-then-make-improvements/#comments Fri, 02 Jun 2017 13:16:47 +0000 Andrew http://andrewgelman.com/?p=34737

The trick is to consider graphs as comparisons. Here’s the story. This post from several years ago shows a confusing and misleading pair of pie charts from a Kenyan election: The quick reaction would be to say, ha ha, pie charts. But that’s not my point here. Sure, pie charts have problems and I think […]

The post You’ll never guess this one quick trick to diagnose problems with your graphs and then make improvements appeared first on Statistical Modeling, Causal Inference, and Social Science.

The post You’ll never guess this one quick trick to diagnose problems with your graphs and then make improvements appeared first on All About Statistics.

]]>
(This article was originally published at Statistical Modeling, Causal Inference, and Social Science, and syndicated at StatsBlogs.)

The trick is to consider graphs as comparisons.

Here’s the story. This post from several years ago shows a confusing and misleading pair of pie charts from a Kenyan election:

The quick reaction would be to say, ha ha, pie charts. But that’s not my point here. Sure, pie charts have problems and I think they’re almost never the right way to share data. But sometimes they’re not so bad.

To see the problem with the above display, we have to go back to first principles. And, with graphs, the first principle is always to consider what comparisons you would like to display, and what comparisons does the graph facilitate.

In this example, the main goal seems to be to compare the official results to the new exit poll. Thus, there are four comparisons to be made in parallel. A second goal is to compare the four categories within each dataset.

What about the pie charts? What comparisons do they easily allow?

The most salient point of any pie chart is that the percentages add up to 100%. So the first thing the graphs do is allow each of the proportions to be visually compared to the reference points of 100%, 50%, and 0%, and also 25% and 75%. We can see pretty clearly that in each dataset there are no candidates who received more than 50%, and there are two candidates who received between 25% and 50%.

But the pair of pie charts do not make it at all easy to compare each candidate from official results to the new poll. Part of that is perverse design choices, as the locations of the four “slices” have been permuted from one pie to another. But even if that had not been done—even if the four categories had been kept in pretty much the same position in each graph, and even if the coloring had been kept consistent—it would still be very difficult to compare angles of the different pies.

Basically the only way you can do it is to compare the numbers. And in that case a table would be clearer, as the relevant pairs could be written side by side. I’d prefer a dot plot.

Why, then, the pie? Part of this must be sheer convenience: whoever made these plots happened to know to make pies. But I think it’s more than that. I think the real appeal of the pie is that it graphically shows the percentages adding up to 100. And, sure, that’s something, but in this case it doesn’t really help with what I think is the key comparison of interest.

I had the same problem with Florence Nightingale’s clock plot. People think that graph is the coolest thing in the world—the wheel of time and all that—but it doesn’t facilitate the time-series comparisons that are the real goal in that example.

So, again, the point is not simply Don’t do pie charts (although I would endorse that message).

Rather, the point is: When making graphs, think about the comparisons you want readers to be able to visualize, and then evaluate possible displays based on their performance in making such comparisons clear.

The post You’ll never guess this one quick trick to diagnose problems with your graphs and then make improvements appeared first on Statistical Modeling, Causal Inference, and Social Science.



Please comment on the article here: Statistical Modeling, Causal Inference, and Social Science

The post You’ll never guess this one quick trick to diagnose problems with your graphs and then make improvements appeared first on All About Statistics.

]]>
/2017/06/02/youll-never-guess-this-one-quick-trick-to-diagnose-problems-with-your-graphs-and-then-make-improvements/feed/ 0 /2017/06/02/youll-never-guess-this-one-quick-trick-to-diagnose-problems-with-your-graphs-and-then-make-improvements/
The code (and other stuff…) http://feedproxy.google.com/~r/statsblogs/~3/eFyQ9GAvW8I/ /2017/06/02/the-code-and-other-stuff/#comments Fri, 02 Jun 2017 10:56:00 +0000 Gianluca Baio /?guid=07fe27ae739c2d37731567b986cf064c I've received a couple of emails or comments on one of the General Election posts to ask me to share the code I've used. In general, I think this is a bit dirty and lots could be done in a more efficient way $-$ effectively, I'm doing this out of ...

The post The code (and other stuff…) appeared first on All About Statistics.

]]>
(This article was originally published at Gianluca Baio's blog, and syndicated at StatsBlogs.)

I've received a couple of emails or comments on one of the General Election posts to ask me to share the code I've used. 

In general, I think this is a bit dirty and lots could be done in a more efficient way $-$ effectively, I'm doing this out of my own curiosity and while I think the model is sensible, it's probably not "publication-standard" (in terms of annotation etc).

Anyway, I've created a (rather plain) GitHub repository, which contains the basic files (including R script, R functions, basic data and JAGS model). Given time (which I'm not given...), I'd like to put a lot more description and perhaps also write a Stan version of the model code. I could also write a more precise model description $-$ I'll try to update the material on the GitHub.

On another note, the previous posts have been syndicated in a couple of places (here and here), which was nice. And finally, here's a little update with the latest data. As of today, the model predicts the following seats distribution.

                mean        sd 2.5% median 97.5%
Conservative 352.124 3.8760350  345    352   359
Labour       216.615 3.8041091  211    217   224
UKIP           0.000 0.0000000    0      0     0
Lib Dem       12.084 1.8752228    8     12    16
SNP           49.844 1.8240041   45     51    52
Green          0.000 0.0000000    0      0     0
PCY            1.333 0.9513233    0      2     3
Other          0.000 0.0000000    0      0     0

Labour are still slowly but surely gaining some ground $-$ I'm not sure the effect of the debate earlier this week (which was deserted by the PM) are visible yet as only a couple of the polls included were conducted after that.

Another interesting thing (following up on this post) is the analysis of the marginal seats that the model predicts to swing from the 2015 Winners. I've updated the plot, which now looks as below.


Now there are 30 constituencies that are predicted to change hand, many still towards the Tories. I am not a political scientists, so I don't really know all the ins and outs of these, but I think a couple of examples are quite interesting and I would venture some comment...

So, the model doesn't know about the recent by-elections of Copeland and Stoke-on-Trent South and so still label these seats as "Labour" (as they were in 2015), although the Tories have actually now control of Copeland.

In the prediction given the polls and the impact of the EU referendum (both were strong Leave areas with with 60% and 70% of the preference, respectively) and the Tories did well in 2015 (36% vs Labour's 42% in Copeland and 33% to Labour's 39% in 2015). So, the model is suggesting that both are likely to switch to the Tories this time around.

In fact, we know that at the time of the by-election, while Copeland (where the contest was mostly Labour v Tories) did go blue, Stoke didn't. But there, the main battle was between the Labour's and the UKIP's candidate (UKIP had got 21% in 2015). And the by-election was fought last February, when the Tories lead was much more robust that it probably is now.


Another interesting area is Twickenham $-$ historically a constituency leaning to the Lib Dems, which was captured by the Conservatives in 2015. But since then, in another by-election the Tories have lost another similar area (Richmond Park,with a massive swing) and the model is suggesting that Twickenham could follow suit, come next Thursday. 


Finally, Clapton was the only seat won by UKIP in 2015, but since then, the elected MP (a former Tory-turned-UKIP) has defected the party and is not contesting the seat. This, combined with the poor standing of UKIP in the polls produces the not surprisingly outcome that Clapton is predicted to go blue with basically no uncertainty...

These results look reasonable to me $-$ not sure how life will turn out of course. As many commentators have noted much may depend on the turn out among the younger. Or other factors. And probably there'll be another instance of the "Shy-Tory effect" (I'll think about this if I get some time before the final prediction). But the model does seem to make some sense...



Please comment on the article here: Gianluca Baio's blog

The post The code (and other stuff…) appeared first on All About Statistics.

]]>
/2017/06/02/the-code-and-other-stuff/feed/ 0 /2017/06/02/the-code-and-other-stuff/
U.K. news article congratulates YouGov on using modern methods in polling inference http://feedproxy.google.com/~r/statsblogs/~3/4FJDHBCgz8k/ /2017/06/01/u-k-news-article-congratulates-yougov-on-using-modern-methods-in-polling-inference/#comments Thu, 01 Jun 2017 21:04:44 +0000 Andrew http://andrewgelman.com/?p=35368

Mike Betancourt pointed me to this news article by Alan Travis that is refreshingly positive regarding the use of sophisticated statistical methods in analyzing opinion polls. Here’s Travis: Leading pollsters have described YouGov’s “shock poll” predicting a hung parliament on 8 June as “brave” and the decision by the Times to splash it on its […]

The post U.K. news article congratulates YouGov on using modern methods in polling inference appeared first on Statistical Modeling, Causal Inference, and Social Science.

The post U.K. news article congratulates YouGov on using modern methods in polling inference appeared first on All About Statistics.

]]>
(This article was originally published at Statistical Modeling, Causal Inference, and Social Science, and syndicated at StatsBlogs.)

Mike Betancourt pointed me to this news article by Alan Travis that is refreshingly positive regarding the use of sophisticated statistical methods in analyzing opinion polls.

Here’s Travis:

Leading pollsters have described YouGov’s “shock poll” predicting a hung parliament on 8 June as “brave” and the decision by the Times to splash it on its front page as “even braver”.

It is certainly rare for a polling company to produce a seats prediction. They usually leave that to psephologists and political scientists.

Good catch: YouGov’s chief scientist is Doug Rivers, who’s a political scientist. And the new method they’re using is multilevel regression and poststratification (MRP or Mister P), which was developed by . . . me! And I’m a political scientist too.

Travis continues:

But it is even more unusual for a company to suddenly employ a new polling model 10 days before a British general election.

Good point! That really would be an unusual practice. Fortunately, So, sure, MRP is not so new—our first paper on the method (“Poststratification into many categories using hierarchical logistic regression,” with Tom Little) was published 20 years ago.

Travis then supplies some details of YouGov’s forecast:

The Tories are in line to lose 20 seats, giving them 310, and Labour is set to gain 30, giving it 257 . . . But as Stephan Shakespeare, YouGov’s chief executive, notes in an accompanying analysis, that is only a central projection that “allows for a wide range of error” and he concedes: “However, these are just the midpoints and, as with any model, there is leeway either side. The Tories could end up with as many as 345 and Labour as few as 223, leading to an increased Conservative majority.” . . . The Times says the projection means the Tories “could get as many as 345 seats on a good night . . . and as few as 274 on a bad night”. That is a pretty wide range.

It’s good to see Travis explaining that realistic forecasts have wide ranges of uncertainty.

He continues with some details:

The methodology involved is described as “multi-level regression and post-stratification” analysis and is based on a substitute for traditional constituency polling, which it regards as “prohibitively expensive”. Shakespeare claimed YouGov tested it during last year’s EU referendum campaign and it produced leave leads every time. What a shame YouGov did not feel like sharing it with voters while their own published referendum polls showed a remain lead right up to polling day.

Travis missed a beat on this one! YouGov did share their MRP estimates during the EU referendum campaign. Ummm . . . let me google that . . . here it is: “YouGov uses Mister P for Brexit poll”: it’s an article by Ben Lauderdale and Doug Rivers which includes this graph showing Leave in the lead:

freddie1

OK, it’s good we got that settled.

Travis concludes:

In an industry already suffering from an existential crisis of public confidence it is indeed a “brave” decision to come up with this one 10 days before a general election and promise to publish its results several times more before polling day.

“Brave” is perhaps overstating things, but, yes, I agree with Travis that presenting MRP estimates is the honorable way to go. Using the best available methods based on the best available knowledge, and giving appropriately wide uncertainty intervals: that’s how to do it.

It’s indeed a shame that Travis was not aware that YouGov had released a report with MRP in the lead-up to the Brexit vote. Also Travis, coming from the U.K., might not have realized that MRP was used in U.S. polls too. For example there was this Florida poll from September, 2016, which was analyzed by four different groups:

Charles Franklin, who estimated Clinton +3
Patrick Ruffini, who estimated Clinton +1
New York Times, who estimated Clinton +1
Sam Corbett-Davies, David Rothschild, and me, who estimated Trump +1. We used MRP.

That said, I don’t have any crystal ball. Shortly before the election I was promoting a forecast that gave Clinton a 92% chance of winning the election. That forecast didn’t use MRP; it aggregated information from state polls without appropriately accounting for expected levels of systematic error. I should’ve used MRP myself—I would’ve, but I wasn’t working with the raw data. In this upcoming U.K. election, YouGov does have the raw polling data so of course they are using MRP; it would at this point be a strange choice not to.

Anyway, it’s cool that Alan Travis conveyed some subtleties of polling to the British newspaper audience, even if he did miss one or two things.

Full disclosure: YouGov gives some financial support to the Stan project.

P.S. Thanks to Steven Johnson for the photo at the top of this post.

P.P.S. More on yougov’s use of MRP here.

The post U.K. news article congratulates YouGov on using modern methods in polling inference appeared first on Statistical Modeling, Causal Inference, and Social Science.



Please comment on the article here: Statistical Modeling, Causal Inference, and Social Science

The post U.K. news article congratulates YouGov on using modern methods in polling inference appeared first on All About Statistics.

]]>
/2017/06/01/u-k-news-article-congratulates-yougov-on-using-modern-methods-in-polling-inference/feed/ 0 /2017/06/01/u-k-news-article-congratulates-yougov-on-using-modern-methods-in-polling-inference/
Announcing a new venture http://feedproxy.google.com/~r/statsblogs/~3/fGRK0zzED9M/ /2017/06/01/announcing-a-new-venture/#comments Thu, 01 Jun 2017 17:00:00 +0000 junkcharts /?guid=334c67e55d536b276fe0bf7aa41cdaa9 Kaiser Fung introduces Principal Analytics Prep

The post Announcing a new venture appeared first on All About Statistics.

]]>
(This article was originally published at Junk Charts, and syndicated at StatsBlogs.)

This is a great time for people in the data business. If you go on Linkedin and look for data jobs, there are several thousand open positions, just in the New York area. Every department within any business is accumulating data, and they need people to help them get value out of the data.

There are also lots of people I meet who would like to transition their careers to take advantage of these open positions but too many of them are being turned away. Many of these people have great backgrounds in other fields (economics, chemistry, psychology, engineering, IT, etc.), and have the analytical smarts to excel in these new data jobs. They are not getting hired. That's because as hiring managers, we prefer hiring the experienced person who doesn't need additional training. We also poach experienced people from other employers, instead of training new talent, creating a vicious cycle.

This is the problem that I am trying to solve by launching my new venture - Principal Analytics Prep.

 

We_make_data_unicorn_design

 

The single biggest complaint about the talent pool by hiring managers is that people's skills are too narrow, sometimes too technical, sometimes too "soft". Hiring managers in the business units outside engineering/software development, for example, marketing, operations, finance, customer service, want to hire people who can analyze and interpret data in the business context, communicate findings to non-technical audiences, as well as contribute to inter-departmental working teams to solve business problems.

For Principal Analytics Prep, I have assembled a group of passionate instructors - who are in director or above positions in industry, and hiring managers for their teams - to design a broad-based curriculum that helps people upgrade their skills to meet industry needs. Our courses range from coding to statistical reasoning to business skills. The faculty have worked at places such as American Express, Cisco, Goldman Sachs, HBO, McKinsey, Mount Sinai, SiriusXM Radio, and Vimeo, with an average of 10 years in industry.

We are not a pure coding academy, therefore we want to assemble people from all disciplines.

We will be launching the first class of students this summer in NYC.

***

Blog readers, you can help me in the following ways:

  • If you know anyone who's looking to upgrade their skills and get into the business analytics/data science field, tell them about the program
  • If you are interested in teaching a course, contact me
  • I am also looking for part-time help with administration and operations, so if you believe in my vision, contact me

If you have suggestions, please leave a comment. Thank you.

 

 



Please comment on the article here: Junk Charts

The post Announcing a new venture appeared first on All About Statistics.

]]>
/2017/06/01/announcing-a-new-venture/feed/ 0 /2017/06/01/announcing-a-new-venture/
In defense of wrapr::let() http://feedproxy.google.com/~r/statsblogs/~3/-c_xOUMbXUY/ /2017/06/01/in-defense-of-wraprlet/#comments Thu, 01 Jun 2017 16:01:20 +0000 John Mount http://www.win-vector.com/blog/?p=5013 Saw this the other day: In defense of wrapr::let() (originally part of replyr, and still re-exported by that package) I would say: let() was deliberately designed for a single real-world use case: working with data when you don’t know the column names when you are writing the code (i.e., the column names will come later … Continue reading In defense of wrapr::let()

The post In defense of wrapr::let() appeared first on All About Statistics.

]]>
(This article was originally published at Statistics – Win-Vector Blog, and syndicated at StatsBlogs.)

Saw this the other day:

Wraprvstidyeval

In defense of wrapr::let() (originally part of replyr, and still re-exported by that package) I would say:

  • let() was deliberately designed for a single real-world use case: working with data when you don’t know the column names when you are writing the code (i.e., the column names will come later in a variable). We can re-phrase that as: there is deliberately less to learn as let() is adapted to a need (instead of one having to adapt to let()).
  • The R community already has months of experience confirming let() working reliably in production while interacting with a number of different packages.
  • let() will continue to be a very specific, consistent, reliable, and relevant tool even after dpyr 0.6.* is released, and the community gains experience with rlang/tidyeval in production.

If rlang/tidyeval is your thing, by all means please use and teach it. But please continue to consider also using wrapr::let(). If you are trying to get something done quickly, or trying to share work with others: a “deeper theory” may not be the best choice.

An example follows.

In “base R” one can write:

d <- data.frame(x = 1:3)

If we know the column name we wish to add to this data frame we write:

d$newColumn <- 1

The above is “non-parameterized” evaluation in that the variable name is taken from the source code, and not from a variable carrying the information. This is great for ad-hoc analysis, but it would be hard to write functions, scripts and packages if this was the only way we had to manipulate columns.

This isn’t a problem as R supplies an additional parameterized notation as we show here. When we don’t know the name of the column (but expect it to be in a variable at run time) we write:

# code written very far away from us
variableHoldingColumnName <- 'newColumn' 

# our code
d[[variableHoldingColumnName]] <- 1

The purpose of wrapr::let() is to allow one to use the non-parameterized form as if it were parameterized. Obviously this is only useful if there is not a convenient parameterized alternative (which is the case for some packages). But for teaching purposes: how would wrapr::let() let us use the “$” as if it were parameterized (which we would have to do if [[]] and [] did not exist)?

With wrapr::let() we can re-write the “dollar-sign form” as:

wrapr::let(
   c(NEWCOL = variableHoldingColumnName),
   {
     d$NEWCOL <- 1
   }
)

The name “NEWCOL” is a stand-in name that we write all our code in terms of. The expression “c(NEWCOL = variableHoldingColumnName)” is saying: “NEWCOL is to be interpreted as being whatever name is stored in the variable variableHoldingColumnName.” Notice we can’t tell from the code what value is in variableHoldingColumnName, as that won’t be known until execution time. The alias list or vector can be arbitrarily long and built wherever you like (it is just data). The expression block can be arbitrarily large and complex (so you need only pay the mapping notation cost once per function, not once per line of code).

And that is wrapr::let().

If you don’t need parametric names you don’t need wrapr::let(). If you do need parametric names wrapr::let() is one of the most reliable and easiest to learn ways to get them.

A nice article from a user recording their experience trying different ways to parameterize their code (including wrapr::let()) can be found here.

If you wish to learn more we have a lot of resources available:

And many more examples on our blog.



Please comment on the article here: Statistics – Win-Vector Blog

The post In defense of wrapr::let() appeared first on All About Statistics.

]]>
/2017/06/01/in-defense-of-wraprlet/feed/ 0 /2017/06/01/in-defense-of-wraprlet/
Another serious error in my published work! http://feedproxy.google.com/~r/statsblogs/~3/udbW4cGSdg8/ /2017/06/01/another-serious-error-in-my-published-work/#comments Thu, 01 Jun 2017 13:56:35 +0000 Andrew http://andrewgelman.com/?p=34471

Uh oh, I’m starting to feel like that pizzagate guy . . . Here’s the background. When I talk about my serious published errors, I talk about my false theorem, I talk about my empirical analysis that was invalidated by miscoded data, I talk my election maps whose flaws were pointed out by an angry […]

The post Another serious error in my published work! appeared first on Statistical Modeling, Causal Inference, and Social Science.

The post Another serious error in my published work! appeared first on All About Statistics.

]]>
(This article was originally published at Statistical Modeling, Causal Inference, and Social Science, and syndicated at StatsBlogs.)

Uh oh, I’m starting to feel like that pizzagate guy . . .

Here’s the background. When I talk about my serious published errors, I talk about my false theorem, I talk about my empirical analysis that was invalidated by miscoded data, I talk my election maps whose flaws were pointed out by an angry blogger, and I talk about my near-miss regarding Portugal.

OK, fine. But then I was going through old blog posts and I’d found a published error of mine that I’d completely forgotten about! It was a statement in one of my most influential papers—just a small part of the paper, it didn’t change our main results, but we really were wrong, and arguably our mistake misled people. I’m glad that later researchers were suspicious of our statement, checked it, and pointed out how we’d been wrong.

The post Another serious error in my published work! appeared first on Statistical Modeling, Causal Inference, and Social Science.



Please comment on the article here: Statistical Modeling, Causal Inference, and Social Science

The post Another serious error in my published work! appeared first on All About Statistics.

]]>
/2017/06/01/another-serious-error-in-my-published-work/feed/ 0 /2017/06/01/another-serious-error-in-my-published-work/
How to choose a seed for generating random numbers in SAS http://feedproxy.google.com/~r/statsblogs/~3/ywJZPLnmv8I/ /2017/06/01/how-to-choose-a-seed-for-generating-random-numbers-in-sas/#comments Thu, 01 Jun 2017 09:29:48 +0000 Rick Wicklin http://blogs.sas.com/content/iml/?p=19408

Last week I was asked a simple question: "How do I choose a seed for the random number functions in SAS?" The answer might surprise you: use any seed you like. Each seed of a well-designed random number generator is likely to give rise to a stream of random numbers, [...]

The post How to choose a seed for generating random numbers in SAS appeared first on The DO Loop.

The post How to choose a seed for generating random numbers in SAS appeared first on All About Statistics.

]]>
(This article was originally published at The DO Loop, and syndicated at StatsBlogs.)

Last week I was asked a simple question: "How do I choose a seed for the random number functions in SAS?" The answer might surprise you: use any seed you like. Each seed of a well-designed random number generator is likely to give rise to a stream of random numbers, so you can view the various streams as statistically equivalent.

Random means random

To be clear, I am talking about using a seed value to initialize a modern, high-quality, pseudorandom number generator (RNG). For example, in SAS you can use the STREAMINIT subroutine to initialize the Mersenne twister algorithm that is used by the RAND function. If you are still using the old-style RANUNI or RANNOR functions in SAS, please read the article "Six reasons you should stop using the RANUNI function to generate random numbers."

A seed value specifies a particular stream from a set of possible random number streams. When you specify a seed, SAS generates the same set of pseudorandom numbers every time you run the program. However, there is no intrinsic reason to prefer one stream over another. The stream for seed=12345 is just as random as the stream for the nine-digit prime number 937162211.

Some people see the number 937162211 and think that it looks "more random" than 12345. They then assume that the random number stream that follows from CALL STREAMINIT(937162211) is "more random" than the random number stream for CALL STREAMINIT(12345). Nope, random means random. In modern pseudorandom generators, the streams for different seeds should have similar statistical properties. Furthermore, many RNGs use the base-2 representation of the seed for initialization and (12345)10 = (11000000111001)2 looks pretty random! In fact, if you avoid powers of 2, the base-2 representations of most base-10 numbers "look random."

Initialization: Hard for researchers, easy for users

Researchers who specialize in random number generators might criticize what I've said as overly simplistic. There have been many research papers written about how to take a 32-bit integer and use that information to initialize a RNG whose internal state contains more than 32 bits. There have been cases where a RNG was published and the authors later modified the initialization routine because certain seeds did not result in streams that were sufficiently random. There have been many discussions about how to create a seed initialization algorithm that is easy to call and that almost always results in a high-quality stream of random numbers.

These are hard problems, but fortunately researchers have developed ways to initialize a stream from a seed so that there is a high probability that the stream will have excellent statistical properties. The relevant question for many SAS programmers is "can I use 12345 or my telephone number as seed values, or do I always need to type a crazy-looking nine-digit sequence?" My response is that there is no reason to prefer the crazy-looking seed over an easy-to-type sequence such as your phone number, your birthday, or the first few digits of pi.

Choosing a random seed

If you absolutely insist on using a "random seed," SAS can help. If you call the STREAMINIT subroutine with the value 0, then SAS will use the date, time of day, and possibly other information to manufacture a seed when you call the RAND function. SAS puts the seed value into the SYSRANDOM system macro variable. That means you can use %PUT to display the seed that SAS created, as follows:

data _null_;
call streaminit(0);   /* generate seed from system clock */
x = rand("uniform");
run;
%put &=SYSRANDOM;
SYSRANDOM=1971603567

Every time you run this program, you will get a different seed value that you can use as the seed for a next program.

A second method is to use the RAND function to generate a random integer between 1 and 231-1, which is the range of valid seed values for the Mersenne twister generator in SAS 9.4m4. The following program generates a random seed value:

data _null_;
call streaminit(0);
seed = ceil( (2**31 - 1)*rand("uniform") ); 
put seed=;
run;
seed=1734176512

Both of these methods will generate a seed for you. However, the randomly generated seed does not provide any benefit. For a modern, high-quality, pseudorandom number generator, the stream should have good statistical properties regardless of the seed value. Using a random seed value does not make a stream "more random" than a seed that is easier to type.

The post How to choose a seed for generating random numbers in SAS appeared first on The DO Loop.



Please comment on the article here: The DO Loop

The post How to choose a seed for generating random numbers in SAS appeared first on All About Statistics.

]]>
/2017/06/01/how-to-choose-a-seed-for-generating-random-numbers-in-sas/feed/ 0 /2017/06/01/how-to-choose-a-seed-for-generating-random-numbers-in-sas/