4
$\begingroup$

A short while ago my first question was closed because it was about programming (well, it wasn't my intent but I understand why, so I deleted the question). Now, I wonder if it is OK sharing codes in answers to explain the things better by showing the application.

I read some very old questions sound familiar but nothing recently. What is the community's current policy/opinion about this?

$\endgroup$
1
  • 9
    $\begingroup$ I am kind of baffled at the premise of the question or more specifically I am confused: are you asking if you can provide snippet of codes in your answer? Surely why not? Go ahead. As long as the code helps to answer the query and is relevant, you can plausibly add that. There are thousands of answers involving codes. If you are asking anything different, then please elaborate. $\endgroup$ Aug 14, 2023 at 1:08

2 Answers 2

9
$\begingroup$

By all means provide code in your answers, but don't make it the focal point. The website is about statistics, not about programming.

People reading an answer are not necessarily familiar with the programming language used in that answer, or may not even know programming at all. The person who originally asked the question might be familiar with the language, but you're not writing just for this person - you are also writing for people who may encounter a similar problem with a different language or software.

So unless the question is inherently related to a specific programming language, generally the core of the answer should be language-agnostic.

Now, using code to illustrate the answer can be a nice and useful addition (personally, I often understand things faster when an answer is illustrated with code), but you can't expect code in a specific language to be useful to all readers interested in the question.

$\endgroup$
8
  • 8
    $\begingroup$ Without naming names, note that "everyone uses Y" will be wrong empirically for any software Y and "everyone should use, or would be well advised to use, Y" may be a personal opinion but it is not CV policy for any Y either. (I first used X but then realised that it's the new name of Twitter.) $\endgroup$
    – Nick Cox
    Aug 14, 2023 at 9:50
  • 3
    $\begingroup$ There are definitely some borderline cases at times for when it is just code and when it is an actual answer. My litmus test for that is simply checking what the answer is saying when all the code is deleted. $\endgroup$ Aug 14, 2023 at 16:38
  • 1
    $\begingroup$ @NickCox +1. Even if one considers "everyone should use, or would be well advised to use, Y" not as an opinion but as a somehow objective statement based on various criteria, it would be only correct at a specific point in time. If CV had been already around in the 1980s or 1990s, today we would have some (hopefully still correct) answers with examples based on statistical tools no longer in use today. So an answer based on nothing but a specific software or language is problematic, at least regarding its usefulness in the medium- or long-term future. $\endgroup$
    – J-J-J
    Aug 14, 2023 at 17:28
  • $\begingroup$ @ShawnHemelstrand That's a simple and neat way of checking an answer for this kind of issue! $\endgroup$
    – J-J-J
    Aug 14, 2023 at 17:41
  • 4
    $\begingroup$ Most of what worked in my favourite software in 1985 still works now! $\endgroup$
    – Nick Cox
    Aug 14, 2023 at 17:45
  • 1
    $\begingroup$ @NickCox On the other hand, some very specialized statistical software developed at my current place of work in the 1990s can no longer run on a modern computer :) But that was very niche. $\endgroup$
    – J-J-J
    Aug 14, 2023 at 17:49
  • 1
    $\begingroup$ I will believe you if you believe me. $\endgroup$
    – Nick Cox
    Aug 14, 2023 at 17:58
  • $\begingroup$ @NickCox We have a deal. $\endgroup$
    – J-J-J
    Aug 14, 2023 at 18:16
6
$\begingroup$

When I write answers here, I would say half the time I include R code snippets as a way for people to follow along with my thought process as I show them what I'm doing with it. I by no means just answer without contextualizing that code. The purpose is to illustrate either a statistical concept or troubleshooting somebody's statistical question that involves something more coding focused.

There are two examples below which showcase what I mean. One talks about chi-square tests by using R as a guide to follow along. The other is a similarly written answer for an MI question.

Chi-squared test.

Multiple imputation.

$\endgroup$
4
  • $\begingroup$ actually, the second question seems to be about programming, in someways more than my closed question (to solve the problem i went to another related community. My question here. This makes me more confused about the community's/admin's aproach to it. But I get what you mean thank you. $\endgroup$
    – Erdem Şen
    Aug 14, 2023 at 19:03
  • $\begingroup$ Perhaps sharing your CV question would make it clear why. $\endgroup$ Aug 14, 2023 at 23:00
  • 3
    $\begingroup$ @ErdemŞen Fundamentally that second question is about a statistical procedure (multiple imputation) not about the syntax of a particular programming language. The point of the question was why the procedure produces different results depending on how the data is formatted - if the question had simply wanted to know how to code it in R, that would have been off-topic. If the question had asked how R, in particular, performs imputation, I think that would likely be closed as off-topic as well. But in this case the statistical part of the question was entirely language-agnostic. $\endgroup$
    – Silverfish
    Aug 16, 2023 at 22:41
  • 5
    $\begingroup$ @ErdemŞen The fact that question title referred to a particular R package is a red herring: but it is often helpful when people explain exactly what software they use and what commands they ran, because sometimes procedures are implemented subtly differently. And note that Shawn's answer uses a different R package instead - It would have worked equally well if Shawn had given an answer using Stata or Minitab or SPSS instead of R , or a codeless answer with just a manual calculation. But as the original asker was an R user, they doubtless found R code helpful for understanding. $\endgroup$
    – Silverfish
    Aug 16, 2023 at 22:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .