All About Statistics Sun, 11 Jun 2017 13:33:41 +0000 en-US hourly 1 http://wordpress.org/?v=3.4.2 statsblogshttps://feedburner.google.com Why I’m not participating in the Transparent Psi Project http://feedproxy.google.com/~r/statsblogs/~3/WzLq5mWeTYM/ /2017/06/11/why-im-not-participating-in-the-transparent-psi-project/#comments Sun, 11 Jun 2017 13:33:41 +0000 Andrew http://andrewgelman.com/?p=34769

I received the following email from psychology researcher Zoltan Kekecs: I would like to ask you to participate in the establishment of the expert consensus design of a large scale fully transparent replication of Bem’s (2011) ‘Feeling the future’ Experiment 1. Our initiative is called the ‘Transparent Psi Project’. [https://osf.io/jk2zf/wiki/home/] Our aim is to develop […]

The post Why I’m not participating in the Transparent Psi Project appeared first on Statistical Modeling, Causal Inference, and Social Science.

The post Why I’m not participating in the Transparent Psi Project appeared first on All About Statistics.

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

I received the following email from psychology researcher Zoltan Kekecs:

I would like to ask you to participate in the establishment of the expert consensus design of a large scale fully transparent replication of Bem’s (2011) ‘Feeling the future’ Experiment 1. Our initiative is called the ‘Transparent Psi Project’. [https://osf.io/jk2zf/wiki/home/] Our aim is to develop a consensus design that is mutually acceptable for both psi proponent and mainstream researchers, containing clear criteria for credibility.

I replied:

Thanks for the invitation. I am not so interested in this project because I think that all the preregistration in the world won’t solve the problem of small effect sizes and poor measurements. It is my impression from Bem’s work and others that the field of psi is plagued by noisy measurements and poorly specified theories. Sure, preregistration etc. would stop many of the problems–in particular, there’s no way that Bem would’ve seen 9 out of 9 statistically significant p-values, or whatever that was. But I can’t in good conscience recommend the spending of effort in this way. I think any serious work in this area would have to go beyond the phenomenological approach and perform more direct measurements, as for example here: http://marginalrevolution.com/marginalrevolution/2014/11/telepathy-over-the-internet.html . I’ve not actually read the paper linked there so this may be a bad example but the point is that one could possibly study such things scientifically with a physical model of the process. To just keep taking Bem-style measurements, though, I think that’s hopeless: it’s the kangaroo problem (http://andrewgelman.com/2015/04/21/feather-bathroom-scale-kangaroo/). Better to preregister than not, but better still not to waste time on this or similarly-hopeless problems (studying sex ratios in samples of size 3000, estimating correlations of monthly cycle on political attitudes using between-person comparisons, power pose, etc.). I recognize that some of these ideas, ESP included, had some legitimate a priori plausibility, but, at this point, a Bem-style experiment seems like a shot in the dark. And, of course, even with preregistration, there’s a 5% chance you’ll see something statistically significant just by chance, leading to further confusion. In summary, preregistration and consensus helps with the incentives, but all the incentives in the world are no substitute for good measurements. (See the discussion of “in many cases we are loath to recommend pre-registered replication” here: http://andrewgelman.com/2017/02/11/measurement-error-replication-crisis/).

Kekecs wrote back:

Thank you for your feedback. We fully realize the problem posed by small effect size. However, this problem in itself can be solved simply by throwing a larger sample at it. In fact based on our simulations we plan to collect 14,000-60,000 data points (700 – 3,000 participants) using bayesian analysis and optional stopping, aiming to reach a Bayes factor threshold of 60 or 1/60. Our simulations show that using these parameters we only have a p = 0.0004 false positive chance, so it is highly unlikely that we would accidentally generate more confusion on the field just by conducting the replication. On the contrary, by doing our study, we will effectively more than double the amount of total data accumulated so far by Bem´s and others studies using this paradigm, which should help with clarity on the field by introducing good quality, credible data.

You might be right though that the measurements itself is faulty, and that we cannot expect precognition to work in an environmentally invalid situation like this. But in reality, we don’t have any information on how precognition should works if it really does exist, so I am not sure what would be a better way of measuring it than seeing how effective are people at predict future events.

Our main goal here is not really to see whether precognition exists or not. The ultimate aim of our efforts is to do a proof of concept study where we will see whether it is possible to come to a consensus on criterion of acceptability and credibility in a field this divided, and to come up with ways in which we can negate all possibilities of questionable research practice. This approach can then be transferred to other fields as well.

I then responded:

I still think it’s hopeless. The problem (which I’ll say using generic units as I’m not familiar with the ESP experiment) is: suppose you have a huge sample size and can detect an effect of 0.003 (on some scale) with standard error 0.001. Statistically significant, preregistered, the whole deal. Fine. But then you could very well see an effect of -0.002 with different people, in a different setting. And -0.003 somewhere else. And 0.001 somewhere else. Etc. You’re talking about effects that are indistinguishable given various sources of leakage in the experiment.

I support your general goal but I recommend you choose a more promising topic than ESP or power pose or various other topics that get talked about so much.

Kekecs replied:

We are already committed to follow through with this particular setting. But I agree with you that our approach can be easily transferred to the research of other effects and we fully intend to do that.

If you put it that way, your question is all about construct validity. Whether we can detect the effect that we really want to detect, or are there other confounds that bias the measurement. In this particular experimental setting which is simple as stone (basically people are guessing about the outcomes of future coin flips) the types of bias that we can expect are more related to questionable research practices (QRPs) than anything else. The only way other types of bias, such as personal differences in ability (sampling bias), participant expectancy, and demand characteristics, etc., can have an effect is if there is truly an anomalous effect. For example if we detected an effect of 0.003 with 0.001 SE only because we accidentally sampled people with high psi abilities, our conclusion that there is a psi effect would still be true (although our effect size estimate would be slightly off).

That is why in this project we are focusing mainly on negating all possibilities of QRPs and full transparency. I am not sure what other types of leakage can we have in this particular experiment if we addressed all possible QRPs. Would you care to elaborate?

I responded:

Just in answer to that last question: I’m not sure what other types of leakage might exist—it’s my impression that Bem’s experiments had various problems, so I guess it depends how exact a replication you’re talking about. My real point, though, is if we think ESP exists at all, then an effect that’s +0.003 on Monday and -0.002 on Tuesday and +0.001 on Wednesday probably isn’t so interesting. This becomes clearer if we move the domain away from possible null phenomena such as ESP or homeopathy, to things like social priming, which presumably has some effect, but which varies so much by person and by context to be generally unpredictable and indistinguishable from noise. I don’t think ESP is such a good model for psychology research because it’s one of the few things people study that really could be zero.

And then Kekecs closed out the discussion:

In response, I find doing this effort on the field of ESP interesting exactly because the effect could potentially be zero. Positive findings have an overwhelming dominance in both psi literature, and social sciences literature in general. In the case of most other social science research, it is a theoretical possibility (but unrealistic) that researchers just get lucky all the time and they always ask the right questions, that is why they are so effective in finding positive effects. Again, this is obviously cannot be true for the entirety of the literature, but for each topic studied individually, it can be quite probable that there is an effect if ever so small, which blurs the picture about publication bias and other types of bias in the literature. However, it may be that there is no ESP effect at all. In that case, we would have a field where the effect of bias in research can be studied in its purest form.

From another perspective, precognition in particular is a perfect research topic exactly because these designs by their nature are very well protected from the usual threats to internal validity, at least in the positive direction. It is hard to see what could make a person perform better at predicting the outcome of a state of the art random number generator if there is no psi effect. Bias can always be introduced by different questionable research practices (QRPs), but if we are able to design a study completely immune the QRPs, there is no real possibility for bias toward type I error. Of course, if the effect really exists, all the usual threats to validity can have an influence (for example, it is possible that people can get “psi fatigue” if they perform a lot of trials, or that events and contextual features, or even expectancy can have an effect on performance), but we cannot make a type I error in that case, because the effect exists, we can only make errors in estimating the size of the effect, or a type II error.

So understanding what is underlying the dominance of positive effects in ESP research is very important. If there is no effect, psi literature can serve as a case study for bias in its purest form, which can help us understand it in other research fields. On the other hand, if we find an effect when all QRPs are controlled for, we may need to really rethink our current paradigm.

I continue to think that the study of ESP is irrelevant for psychology, both for substantive reasons—there is no serious underlying theory or clear evidence for ESP, it’s all just hope and intuition—and for methodological reasons, in that zero is a real possibility. In contrast, even silly topics such as power pose and embodied cognition seem to me to have some relevance to psychology and also involve the real challenge that there are no zeroes. Standing in an unusual position for two minutes will have some effect on your thinking and behavior; the debate is what are the consistent effects, if any. That’s my take, anyway; but I wanted to share Kekecs’s view too, given all the effort he’s putting into this project.

The post Why I’m not participating in the Transparent Psi Project 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 Why I’m not participating in the Transparent Psi Project appeared first on All About Statistics.

]]>
/2017/06/11/why-im-not-participating-in-the-transparent-psi-project/feed/ 0 /2017/06/11/why-im-not-participating-in-the-transparent-psi-project/
Likelihood calculation for the g-and-k distribution http://feedproxy.google.com/~r/statsblogs/~3/_Fy-ZiinRow/ /2017/06/10/likelihood-calculation-for-the-g-and-k-distribution/#comments Sat, 10 Jun 2017 22:33:44 +0000 Pierre Jacob http://statisfaction.wordpress.com/?p=4993     Hello, An example often used in the ABC literature is the g-and-k distribution (e.g. reference [1] below), which is defined through the inverse of its cumulative distribution function (cdf). It is easy to simulate from such distributions by drawing uniform variables and applying the inverse cdf to them. However, since there is no closed-form […]

The post Likelihood calculation for the g-and-k distribution appeared first on All About Statistics.

]]>
(This article was originally published at R – Statisfaction, and syndicated at StatsBlogs.)

 

gandkhistogram

Histogram of 1e5 samples from the g-and-k distribution, and overlaid probability density function

 

Hello,

An example often used in the ABC literature is the g-and-k distribution (e.g. reference [1] below), which is defined through the inverse of its cumulative distribution function (cdf). It is easy to simulate from such distributions by drawing uniform variables and applying the inverse cdf to them. However, since there is no closed-form formula for the probability density function (pdf) of the g-and-k distribution, the likelihood is often considered intractable. It has been noted in [2] that one can still numerically compute the pdf, by 1) numerically inverting the quantile function to get the cdf, and 2)  numerically differentiating the cdf, using finite differences, for instance. As it happens, this is very easy to implement, and I coded up an R tutorial at:

github.com/pierrejacob/winference/blob/master/inst/tutorials/tutorial_gandk.pdf

for anyone interested. This is part of the winference package that goes with our tech report on ABC with the Wasserstein distance  (joint work with Espen Bernton, Mathieu Gerber and Christian Robert, to be updated very soon!). This enables standard MCMC algorithms for the g-and-k example. It is also very easy to compute the likelihood for the multivariate extension of [3], since it only involves a fixed number of one-dimensional numerical inversions and differentiations (as opposed to a multivariate inversion).

Surprisingly, most of the papers that present the g-and-k example do not compare their ABC approximations to the posterior; instead, they typically compare the proposed ABC approach to existing ones. Similarly, the so-called Ricker model is commonly used in the ABC literature, and its posterior can be tackled efficiently using particle MCMC methods; as well as the M/G/1 model, which can be tackled either with particle MCMC methods or with tailor-made MCMC approaches such as [4].

These examples can still have great pedagogical value in ABC papers, but it would perhaps be nice to see more comparisons to the ground truth when it’s available; ground truth here being the actual posterior distribution.

  1. Fearnhead, P. and Prangle, D. (2012) Constructing summary statistics for approximate Bayesian computation: semi-automatic approximate Bayesian computation. Journal of the Royal Statistical Society: Series B, 74, 419–474.
  2. Rayner, G. D. and MacGillivray, H. L. (2002) Numerical maximum likelihood estimation for the g-and-k and generalized g-and-h distributions. Statistics and Computing, 12, 57–75.
  3. Drovandi, C. C. and Pettitt, A. N. (2011) Likelihood-free Bayesian estimation of multivari- ate quantile distributions. Computational Statistics & Data Analysis, 55, 2541–2556.
  4. Shestopaloff, A. Y. and Neal, R. M. (2014) On Bayesian inference for the M/G/1 queue with efficient MCMC sampling. arXiv preprint arXiv:1401.5548.



Please comment on the article here: R – Statisfaction

The post Likelihood calculation for the g-and-k distribution appeared first on All About Statistics.

]]>
/2017/06/10/likelihood-calculation-for-the-g-and-k-distribution/feed/ 0 /2017/06/10/likelihood-calculation-for-the-g-and-k-distribution/
Financial anomalies are contingent on being unknown http://feedproxy.google.com/~r/statsblogs/~3/XvG-XUQmfzs/ /2017/06/10/financial-anomalies-are-contingent-on-being-unknown/#comments Sat, 10 Jun 2017 13:22:21 +0000 Andrew http://andrewgelman.com/?p=34765

Jonathan Falk points us to this article by Kewei Hou, Chen Xue, and Lu Zhang, who write: In retrospect, the anomalies literature is a prime target for p-hacking. First, for decades, the literature is purely empirical in nature, with little theoretical guidance. Second, with trillions of dollars invested in anomalies-based strategies in the U.S.market alone, […]

The post Financial anomalies are contingent on being unknown appeared first on Statistical Modeling, Causal Inference, and Social Science.

The post Financial anomalies are contingent on being unknown appeared first on All About Statistics.

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

Jonathan Falk points us to this article by Kewei Hou, Chen Xue, and Lu Zhang, who write:

In retrospect, the anomalies literature is a prime target for p-hacking. First, for decades, the literature is purely empirical in nature, with little theoretical guidance. Second, with trillions of dollars invested in anomalies-based strategies in the U.S.market alone, the financial interest is overwhelming. Third, more significant results make a bigger splash, and are more likely to lead to publications as well as promotion, tenure, and prestige in academia. As a result, armies of academics and practitioners engage in searching for anomalies, and the anomalies literature is most likely one of the biggest areas in finance and accounting. Finally, as we explain later, empiricists have much flexibility in sample criteria, variable definitions, and empirical methods, which are all tools of p-hacking in chasing statistical significance.

Falk writes:

A weakness in this study is that the use of a common data period obscures the fact that financial anomalies are contingent on being unknown: known (true) anomalies will be arbitraged away so that they no longer exist. Their methodology continues to estimate many of these anomalies after the results of the studies were public knowledge and heavily scrutinized. This should attenuate the results. (It would be interesting to see if the results weakened the earlier the study was published. On a low-hanging fruit theory, it should be just the opposite.) It’s as if Power Pose worked until Amy Cuddy wrote about it, at which point everyone wised up and the effect went away. Effects like that are really hard to replicate.

Falk’s comment, about financial anomalies being contingent on being unknown, reminds me of something: In finance (so I’m told), when someone has a great idea, they keep it secret and try to milk all the advantage out of it that they can. This also happens in some fields of science: we’ve all heard of bio labs that refuse to share their data or their experimental techniques because they want to squeeze out a couple more papers in Nature and Cell. Given all the government funding involved, that’s not cool, but it’s how it goes. But in statistics, when think we have a good idea, we put it out there for free, we scream about it and get angry that other people aren’t using our wonderful methods and our amazing free software. Funny, that.

P.S. For an image, I went and googled *cat anomaly*. I recommend you don’t do that. The pictures were really disturbing to me.

The post Financial anomalies are contingent on being unknown 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 Financial anomalies are contingent on being unknown appeared first on All About Statistics.

]]>
/2017/06/10/financial-anomalies-are-contingent-on-being-unknown/feed/ 0 /2017/06/10/financial-anomalies-are-contingent-on-being-unknown/
Correcting bias in meta-analyses: What not to do (meta-showdown Part 1) http://feedproxy.google.com/~r/statsblogs/~3/TwKF9AodG6E/ /2017/06/09/correcting-bias-in-meta-analyses-what-not-to-do-meta-showdown-part-1/#comments Fri, 09 Jun 2017 21:38:51 +0000 Nicebread /?guid=8c974f1eb86de9466956bce473d3cfdc tl;dr: Publication bias and p-hacking can dramatically inflate effect size estimates in meta-analyses. Many methods have been proposed to correct for such bias and to estimate the underlying true effect. In a large simulation study, we studied which me...

The post Correcting bias in meta-analyses: What not to do (meta-showdown Part 1) appeared first on All About Statistics.

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

tl;dr: Publication bias and p-hacking can dramatically inflate effect size estimates in meta-analyses. Many methods have been proposed to correct for such bias and to estimate the underlying true effect. In a large simulation study, we studied which methods do (not) work well under which conditions, and give some recommendations what not to use. Estimated […]

The post Correcting bias in meta-analyses: What not to do (meta-showdown Part 1) appeared first on Nicebread.



Please comment on the article here: Nicebread

The post Correcting bias in meta-analyses: What not to do (meta-showdown Part 1) appeared first on All About Statistics.

]]>
/2017/06/09/correcting-bias-in-meta-analyses-what-not-to-do-meta-showdown-part-1/feed/ 0 /2017/06/09/correcting-bias-in-meta-analyses-what-not-to-do-meta-showdown-part-1/
Surprise? http://feedproxy.google.com/~r/statsblogs/~3/JNUo9Z0QiVE/ /2017/06/09/surprise/#comments Fri, 09 Jun 2017 21:00:00 +0000 Gianluca Baio /?guid=177ad179d20d26ecd3d8c0ad6c10a3b1 So: for once I woke up this morning feeling slightly quite tired for the late night, but also rather upbeat after an election. The final results of the general election are out and have produced quite some shock. Throughout yesterday, it look...

The post Surprise? appeared first on All About Statistics.

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




So: for once I woke up this morning feeling slightly quite tired for the late night, but also rather upbeat after an election. The final results of the general election are out and have produced quite some shock. 

Throughout yesterday, it looked as though the final polls were returning an improved majority for the Conservative party $-$ this would have been consistent with the "shy Tory" effect. Even Yougov had presented their latest poll suggesting a seven points lead and improved Tory majority. So I guess many people were unprepared for the exit polls, which suggested a very different figure...

First off, I think that the actual results have vindicated Yougov's model (rather than the poll), based on a hierarchical model informed by over 50,000 individual-level data on voting intention as well as several other covariates. They weren't spot on, but quite close. 

Also, the exit polls (based on a sample of over 30,000) were remarkably good. To be fair, however, I think that exit polls are different than the pre-election polls, because unlike them they do not ask about "voting intentions", but the actual vote that people have just cast.

And now, time for the post-mortem. My final prediction using all the polls at June 8th was as follows:

                mean       sd 2.5% median 97.5%     OBSERVED
Conservative 346.827 3.411262  339    347   354          318
Labour       224.128 3.414861  218    224   233          261
UKIP           0.000 0.000000    0      0     0            0
Lib Dem       10.833 2.325622    7     11    15           12
SNP           49.085 1.842599   45     49    51           35
Green          0.000 0.000000    0      0     0            1
PCY            1.127 1.013853    0      2     3            4

Not all bad, but not quite spot on either and to be fair, less spot on than Yougov's (as I said, I was hoping they were closer to the truth than my model, so not too many complaints there!...).

I've thought a bit about the discrepancies and I think a couple of issues stand out:

  1. I (together with several other predictions and in fact even Yougov) have overestimated the vote and, more importantly, the number of seats won by the SNP. I think in my case, the main issue had to do with the polls I have used to build my model. As it has happened, the battleground in Scotland has been rather different than the rest of the country, I think. But what was feeding into my model were the data from national polls. I had tried to bump up my prior for the SNP to counter this effect. But most likely this has exaggerated the result, producing an estimate that was too optimistic.
  2. Interestingly, the error for the SNP is 14 seats; 12 of these, I think, have (rather surprisingly) gone to the Tories. So, basically, I've got the Tory vote wrong by (347-318+12)=41 seats $-$ which if you actually allocate to Labour would have brought my prediction to 224+41=265. 
  3. Post-hoc adjustements aside, it is obvious that my model had overestimated the result for the Tories, while underestimating Labour's performance. In this case, I think the problem was that the structure I had used was mainly based on the distinction between leave and remain areas at last year's referendum. And of course, these were highly related to the vote that in 2015 had gone to UKIP. Now: like virtually everybody, I have correctly predicted that UKIP would get "zip, nada, zilch" seats. In my case, this was done by combining the poor performance in the polls with a strongly informative prior (which, incidentally, was not strong enough and combined with the polls, I did overestimate UKIP vote share). However, I think that the aggregate data observed in the polls had consistently tended to indicate that in leave areas the Tories would have had massive gains. What actually happened was in fact that the former UKIP vote has split nearly evenly between the two major parties. So, in strong leave areas, the Tories have gained marginally more than Labour, but that was not enough to swing and win the marginal Labour seats. Conversely, in remain areas, Labour has done really well (as the polls were suggesting) and this has in many cases produced a change in colours in some Conservative marginal seats.
  4. I missed the Green's success in Brighton. This was, I think, down to being a bit lazy and not bothering telling the model that in Caroline Lucas' seat the Lib Dem had not fielded a candidate. This in turn meant that the model was predicting a big surge in the vote for the Lib Dems (because Brighton Pavilion is a strong remain area), which would eat into the Green's majority. And so my model was predicting a change to Labour, which never happened (again, I'm quite pleased to have got it wrong here, because I really like Ms Lucas!).
  5. My model had correctly guessed that the Conservatives would regain Richmond Park, but that the Lib Dems had got back Twickenham and Labour would have held Copeland. In comparison to Electoralcalculus's prediction, I've done very well in predicting the number of seats for the Lib Dems. I am not sure about the details of their model, but I am guessing that they had some strong prior to (over)discount the polls, which has lead to a substantial underestimation. In contrast, I think that my prior for the Lib Dems was spot on.
  6. Back to Yougov's model, I think that the main, huge difference, has been the fact that they could rely on a very large number of individual level data. The published polls would only provide aggregated information, which almost invariably would only cross-tabulate one variable at a time (ie voting intention in Leave vs Remain, or in London vs other areas, etc $-$ but not both). To actually be able to analyse the individual level data (combined of course with a sound modelling structure!) has allowed Yougov to get some of the true underlying trends right, which models based on the aggregated polls simply couldn't, I think.
It's been a fun process $-$ and all in all, I'm enjoying the outcome...



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

The post Surprise? appeared first on All About Statistics.

]]>
/2017/06/09/surprise/feed/ 0 /2017/06/09/surprise/
Managing intermediate results when using R/sparklyr http://feedproxy.google.com/~r/statsblogs/~3/s5qV4Z_nYfs/ /2017/06/09/managing-intermediate-results-when-using-rsparklyr/#comments Fri, 09 Jun 2017 15:37:32 +0000 John Mount http://www.win-vector.com/blog/?p=5034 In our latest “R and big data” article we show how to manage intermediate results in non-trivial Apache Spark workflows using R, sparklyr, dplyr, and replyr. Handle management Many Sparklyr tasks involve creation of intermediate or temporary tables. This can be through dplyr::copy_to() and through dplyr::compute(). These handles can represent a reference leak and eat … Continue reading Managing intermediate results when using R/sparklyr

The post Managing intermediate results when using R/sparklyr appeared first on All About Statistics.

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

In our latest “R and big data” article we show how to manage intermediate results in non-trivial Apache Spark workflows using R, sparklyr, dplyr, and replyr.


NewImage

Handle management

Many Sparklyr tasks involve creation of intermediate or temporary tables. This can be through dplyr::copy_to() and through dplyr::compute(). These handles can represent a reference leak and eat up resources.

To help control handle lifetime the replyr supplies record-retaining temporary name generators (and uses the same internally).

The actual function is pretty simple:

print(replyr::makeTempNameGenerator)
## function(prefix,
##                                   suffix= NULL) {
##   force(prefix)
##   if((length(prefix)!=1)||(!is.character(prefix))) {
##     stop("repyr::makeTempNameGenerator prefix must be a string")
##   }
##   if(is.null(suffix)) {
##     alphabet <- c(letters, toupper(letters), as.character(0:9))
##     suffix <- paste(base::sample(alphabet, size=20, replace= TRUE),
##                     collapse = '')
##   }
##   count <- 0
##   nameList <- c()
##   function(dumpList=FALSE) {
##     if(dumpList) {
##       v <- nameList
##       nameList <<- c()
##       return(v)
##     }
##     nm <- paste(prefix, suffix, sprintf('%010d',count), sep='_')
##     nameList <<- c(nameList, nm)
##     count <<- count + 1
##     nm
##   }
## }
## <bytecode: 0x7f8659110708>
## <environment: namespace:replyr>

For instance to join a few tables it can be a good idea to call compute after each join (else the generated SQL can become large and unmanageable). This sort of code looks like the following:

# create example data
names <- paste('table', 1:5, sep='_')
tables <- lapply(names, 
                 function(ni) {
                   di <- data.frame(key= 1:3)
                   di[[paste('val',ni,sep='_')]] <- runif(nrow(di))
                   copy_to(sc, di, ni)
                 })

# build our temp name generator
tmpNamGen <- replyr::makeTempNameGenerator('JOINTMP')

# left join the tables in sequence
joined <- tables[[1]]
for(i in seq(2,length(tables))) {
  ti <- tables[[i]]
  if(i<length(tables)) {
    joined <- compute(left_join(joined, ti, by='key'),
                    name= tmpNamGen())
  } else {
    # use non-temp name.
    joined <- compute(left_join(joined, ti, by='key'),
                    name= 'joinres')
  }
}

# clean up temps
temps <- tmpNamGen(dumpList = TRUE)
print(temps)
## [1] "JOINTMP_9lWXvfnkhI2NPRsA1tEh_0000000000"
## [2] "JOINTMP_9lWXvfnkhI2NPRsA1tEh_0000000001"
## [3] "JOINTMP_9lWXvfnkhI2NPRsA1tEh_0000000002"
for(ti in temps) {
  db_drop_table(sc, ti)
}

# show result
print(joined)
## Source:   query [3 x 6]
## Database: spark connection master=local[4] app=sparklyr local=TRUE
## 
## # A tibble: 3 x 6
##     key val_table_1 val_table_2 val_table_3 val_table_4 val_table_5
##   <int>       <dbl>       <dbl>       <dbl>       <dbl>       <dbl>
## 1     1   0.7594355   0.8082776 0.696254059   0.3777300  0.30015615
## 2     2   0.4082232   0.8101691 0.005687125   0.9382002  0.04502867
## 3     3   0.5941884   0.7990701 0.874374779   0.7936563  0.19940400

Careful introduction and management of materialized intermediates can conserve resources (both time and space) and greatly improve outcomes. We feel it is a good practice to set up an explicit temp name manager, pass it through all your Sparklyr transforms, and then clear temps in batches after the results no longer depend no the intermediates.



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

The post Managing intermediate results when using R/sparklyr appeared first on All About Statistics.

]]>
/2017/06/09/managing-intermediate-results-when-using-rsparklyr/feed/ 0 /2017/06/09/managing-intermediate-results-when-using-rsparklyr/
UK election summary http://feedproxy.google.com/~r/statsblogs/~3/Fg-kLPsy2d8/ /2017/06/09/uk-election-summary/#comments Fri, 09 Jun 2017 14:36:18 +0000 Andrew http://andrewgelman.com/?p=35584

The Conservative party, led by Theresa May, defeated the Labour party, led by Jeremy Corbyn. The Conservative party got 42% of the vote, Labour got 40% of the vote, and all the other parties received 18% between them. The Conservatives ended up with 51.5% of the two-party vote, just a bit less than Hillary Clinton’s […]

The post UK election summary appeared first on Statistical Modeling, Causal Inference, and Social Science.

The post UK election summary appeared first on All About Statistics.

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

The Conservative party, led by Theresa May, defeated the Labour party, led by Jeremy Corbyn.

The Conservative party got 42% of the vote, Labour got 40% of the vote, and all the other parties received 18% between them. The Conservatives ended up with 51.5% of the two-party vote, just a bit less than Hillary Clinton’s share last November.

In the previous U.K. general election, two years ago, Conservative beat Labour, 37%-30%, that’s 55% of the two-party vote.

The time before, the Conservatives received 36%, compared to Labour’s 29%. The Conservatives again had received 55% of the two-party vote.

As with the Clinton-Trump presidential election and the “Brexit” election in the U.K. last year, the estimates from the polls turned out to give pretty good forecasts.

The predictions were not perfect—the 318-262 split in parliament was not quite the 302-269 that was predicted, and the estimated 42-38 vote split didn’t quite predict the 43.5-41.0 split that actually happened (those latter figures, for Great Britain only, come from the Yougov post-election summary). And the accuracy of the seat forecast has to be attributed in part to luck, given the wide predictive uncertainty bounds (based on pre-election polls, the Conservatives were forecast to win between 269 and 334 seats). The predictions were done using Mister P and Stan.

The Brexit and Clinton-Trump poll forecasts looked bad at the time because they got the outcome wrong, but as forecasts of public opinion they were solid, only off by a percentage point or two in each case. In general we’d expect polls to do better in two-party races or, more generally, in elections with two clear options, because then there are fewer reasons for prospective voters to change their opinions. In most parts of the U.K., this 2017 election was a two-party affair, hence it should be no surprise that the final polls were accurate (after suitable adjustment for nonresponse), even if, again, there was some luck that they were as close as shown in these graphs by Jack Blumenau:

P.S. I like Yougov and some of our research is supported by Yougov, but I’m kinda baffled cos when I googled I found this page by Anthony Wells, which estimates 42% for the Conservatives, 35% for Labour, and a prediction of “an increased Conservative majority in the Commons,” which seems to contradict their page that I linked to above, with that prediction of a hung parliament. That’s the forecast I take seriously because it used MRP, but then it makes me wonder why their “Final call” was different. Once you have a model and a series of polls, why throw all that away when making your final call?

The post UK election summary 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 UK election summary appeared first on All About Statistics.

]]>
/2017/06/09/uk-election-summary/feed/ 0 /2017/06/09/uk-election-summary/
On Formality http://feedproxy.google.com/~r/statsblogs/~3/gJaeCED5Prk/ /2017/06/09/on-formality/#comments Fri, 09 Jun 2017 00:00:00 +0000 English Blog on Yihui Xie | 谢益辉 https://yihui.name/en/2017/06/on-formality/

As I said on the About page, I don’t like formality. There is absolutely no need to tie my educational degree to my last name. Actually I feel uncomfortable with other people calling me “Dr Xie”. Anyone can just call me by my first name.1 In my opinion, the best way to show respect to people is not through these titles (Doctor or Professor), but the true care about their work. For the same reason, I’m not excited at all when someone simply says “hey, I’m big fan of you”, but I’m truly happy if someone discovers something I worked on (semi-)secretly and also thinks it is cool.

A couple of months ago, a secretary from a certain university booked a flight for me. When I got the E-ticket, my name was shown as “Dr Yihui Xie”. I was kind of speechless and wondered if I would be able to pass the security at the airport since my first name is definitely not “Dr”. I asked her not to include the doctor title in my name. Then a week later, she booked my hotel, and my name became “Yihui Dr Xie”. Cool. Now I have got a new middle name.

WAT

I still remember when I first went to Iowa State University, Di pulled me in front of her computer, pointed at one of my emails on the screen, and said “that is good”. She meant I called her “Di” instead of “Dr Cook”.

Of course, not every professor can accept this. I also had an experience with emailing a Korean professor around 2008, and heard thunders rolling back, “Do you call seniors in China using their first names?!” Actually no. In China, we never dare to use the first name to call our professors.

Anyway, I just want to clarify in this post that you do not need to call me “Dr Xie”. Occasionally people also call me “Prof Xie”. I’m not a professor. I’m just a software engineer.


  1. Due to the Chinese culture, I feel weird when someone calls me using my last name “Xie”. When people use the last name to call someone, that typically means (1) the person has died; and (2) it is sensitive to talk about this person (e.g. a past President or influential politician), so they only use the last name but most people should know whom it refers to. ↩

The post On Formality appeared first on All About Statistics.

]]>
(This article was originally published at English Blog on Yihui Xie | 谢益辉, and syndicated at StatsBlogs.)

As I said on the About page, I don’t like formality. There is absolutely no need to tie my educational degree to my last name. Actually I feel uncomfortable with other people calling me “Dr Xie”. Anyone can just call me by my first name.1 In my opinion, the best way to show respect to people is not through these titles (Doctor or Professor), but the true care about their work. For the same reason, I’m not excited at all when someone simply says “hey, I’m big fan of you”, but I’m truly happy if someone discovers something I worked on (semi-)secretly and also thinks it is cool.

A couple of months ago, a secretary from a certain university booked a flight for me. When I got the E-ticket, my name was shown as “Dr Yihui Xie”. I was kind of speechless and wondered if I would be able to pass the security at the airport since my first name is definitely not “Dr”. I asked her not to include the doctor title in my name. Then a week later, she booked my hotel, and my name became “Yihui Dr Xie”. Cool. Now I have got a new middle name.

WAT

I still remember when I first went to Iowa State University, Di pulled me in front of her computer, pointed at one of my emails on the screen, and said “that is good”. She meant I called her “Di” instead of “Dr Cook”.

Of course, not every professor can accept this. I also had an experience with emailing a Korean professor around 2008, and heard thunders rolling back, “Do you call seniors in China using their first names?!” Actually no. In China, we never dare to use the first name to call our professors.

Anyway, I just want to clarify in this post that you do not need to call me “Dr Xie”. Occasionally people also call me “Prof Xie”. I’m not a professor. I’m just a software engineer.


  1. Due to the Chinese culture, I feel weird when someone calls me using my last name “Xie”. When people use the last name to call someone, that typically means (1) the person has died; and (2) it is sensitive to talk about this person (e.g. a past President or influential politician), so they only use the last name but most people should know whom it refers to. ↩



Please comment on the article here: English Blog on Yihui Xie | 谢益辉

The post On Formality appeared first on All About Statistics.

]]>
/2017/06/09/on-formality/feed/ 0 /2017/06/09/on-formality/
Campaign Response Testing no longer published on Udemy http://feedproxy.google.com/~r/statsblogs/~3/1hzw5UP-mnw/ /2017/06/08/campaign-response-testing-no-longer-published-on-udemy/#comments Thu, 08 Jun 2017 18:33:32 +0000 John Mount http://www.win-vector.com/blog/?p=5028 Our free video course Campaign Response Testing is no longer published on Udemy. It remains available for free on YouTube with all source code available from GitHub. I’ll try to correct bad links as I find them. Please read on for the reasons. Udemy recently unilaterally instituted a new policy on free courses: “When a … Continue reading Campaign Response Testing no longer published on Udemy

The post Campaign Response Testing no longer published on Udemy appeared first on All About Statistics.

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

Our free video course Campaign Response Testing is no longer published on Udemy. It remains available for free on YouTube with all source code available from GitHub. I’ll try to correct bad links as I find them.

Please read on for the reasons.

Udemy recently unilaterally instituted a new policy on free courses: “When a free course has a Recent Review Rating less than 4.1 and is flagged with a ‘high degree of confidence’ the course will be hidden from Udemy’s search.”

Campaign Response Testing is a free course with an all-time average rating of 4.14 and a recent rating of 3.85. We have kept the code up to date and answered student questions (there was no backlog of student questions).

Obviously others should have opinion of our public work (which may or may not be good). And we are keeping the course up for free with no-sign up necessary on YouTube (as we in no way want to hurt or inconvenience students).

But I do have an issue with Udemy’s new system: it is completely vulnerable to griefers and spammers. Accounts with “no skin in the game” (having paid nothing, possibly not even have watched the course, and without having to leave any review text in addition to the “high degree of confidence” star rating) can belittle free courses at will and in bulk. Currently there is no effective dispute mechanism (other than superficial palliatives such as: “answer student questions”), and like all lop-sided “fights against semi-anonymous trolls” it would be a pointless effort anyway. I understand the desire to increase the quality of free content (it is Udemy’s “introduction”) but I feel the introduced system would obviously be unworkable even before it was introduced.

So with hopefully no harm to our subscribers I am un-publishing the course. As is the case with Udemy policy anybody already subscribed should continue to have access to the course through Udemy. And as I have said: we have long sense ported the entire free course to YouTube and Github for free and login-free sharing.



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

The post Campaign Response Testing no longer published on Udemy appeared first on All About Statistics.

]]>
/2017/06/08/campaign-response-testing-no-longer-published-on-udemy/feed/ 0 /2017/06/08/campaign-response-testing-no-longer-published-on-udemy/
The (Lance) Armstrong Principle http://feedproxy.google.com/~r/statsblogs/~3/k3IpxQyThtA/ /2017/06/08/the-lance-armstrong-principle/#comments Thu, 08 Jun 2017 13:56:08 +0000 Andrew http://andrewgelman.com/?p=34759 If you push people to promise more than they can deliver, they’re motivated to cheat. The post The (Lance) Armstrong Principle appeared first on Statistical Modeling, Causal Inference, and Social Science.

The post The (Lance) Armstrong Principle appeared first on All About Statistics.

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

If you push people to promise more than they can deliver, they’re motivated to cheat.

The post The (Lance) Armstrong Principle 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 The (Lance) Armstrong Principle appeared first on All About Statistics.

]]>
/2017/06/08/the-lance-armstrong-principle/feed/ 0 /2017/06/08/the-lance-armstrong-principle/