How to interpret F- and p-value in ANOVA?

Question: I am new to statistics and I currently deal with ANOVA. I carry out an ANOVA test in R using
<code>aov(dependendVar ~ IndependendVar)
</code>
I get – among others – an F-value and a p-value.
My null hypothesis ($H_0$) is that all group means are equal.
There is a lot of information available on how F is calculated, but I don't know how to read an F-statistic and how F and p are connected.
So, my questions are:

How do I determine the critical F-value for rejecting $H_0$?
Does each F have a corresponding p-value, so they both mean basically the same? (e.g., if $p<0.05$, then $H_0$ is rejected)
Comment: Have you tried the commands `summary(aov(dependendVar ~ IndependendVar)))` or `summary(lm(dependendVar ~ IndependendVar))`? Do you mean all the group means are equal to each other and equal to 0 or just to each other?
Comment: For an intuitive explanation look at the [Yhat](http://blog.yhat.com/posts/r-lm-summary.html) blog on the topic of regression.
Comment: yes, I did try the `summary(aov...)`. Thanks for the `lm.*`, did not know about this :-)

I don't get what you mean by equal to 0. If that's short for my 0-Hypothesis than the Hypothesis would need a value, and I did not test on specific one, so in this case: just to each other!
Answer: The F statistic is a ratio of 2 different measure of variance for the data.  If the null hypothesis is true then these are both estimates of the same thing and the ratio will be around 1.
The numerator is computed by measuring the variance of the means and if the true means of the groups are identical then this is a function of the overall variance of the data.  But if the null hypothesis is false and the means are not all equal, then this measure of variance will be larger.
The denominator is an average of the sample variances for each group, which is an estimate of the overall population variance (assuming all groups have equal variances).
So when the null of all means equal is true then the 2 measures (with some extra terms for degrees of freedom) will be similar and the ratio will be close to 1.  If the null is false, then the numerator will be large relative to the denominator and the ratio will be greater than 1.  Looking up this ratio on the F-table (or computing it with a function like pf in R) will give the p-value.
If you would rather use a rejection region than a p-value, then you can use the F table or the qf function in R (or other software).  The F distribution has 2 types of degrees of freedom.  The numerator degrees of freedom are based on the number of groups that you are comparing (for 1-way it is the number of groups minus 1) and the denominator degrees of freedom are based on the number of observations within the groups (for 1-way it is the number of observations minus the number of groups).  For more complicated models the degrees of freedom get more complicated, but follow similar ideas.
Comment: In all parametric statistics there is a direct functional link between the test statistic (F in this case) and the p-value.  These have been put into table for convenience, but can also be computed directly.  You can either use alpha to find the cut-off for a critical region to compare the test statistic to (which I think is more intuitive) or use the computed test statistic to find the p-value to compare to alpha.  In either case we start with an alpha level and a test statistic formula that follows a given distribution when the null is true.
Comment: Thanks for the explanation!
I assume that if I can look up the F value on a table to see the p-value, than the the p and F are just two ways to express the likelyhood that a result like the one analysed can occur if the H0 is right?
Answer: The best way to think about the relationship between $F$, $p$, and the critical value is with a picture:

The curve here is an $F$ distribution, that is, the distribution of $F$ statistics that we'd see if the null hypothesis were true. In this diagram, the observed $F$ statistic is the distance from black dashed line to the vertical axis. The $p$ value is the dark blue area under the curve from $F$ to infinity. Notice that every value of $F$ must correspond to a unique $p$ value, and that higher $F$ values correspond to lower $p$ values.
You should notice a couple of other things about the distribution under null hypothesis:
1) $F$ values approaching zero are highly unlikely (this is not always true, but it's true for the curve in this example)
2) After a certain point, the larger the $F$ is, the less likely it is. (The curve tapers off to the right.)
The critical value $C$ also makes an appearance in this diagram. The area under the curve from $C$ to infinity equals the significance level (here, 5%). You can tell that the $F$ statistic here would result in a failure to reject the null hypothesis because it is less than $C$, that is, its $p$ value is greater than .05. In this specific example, $p=0.175$, but you'd need a ruler to calculate that by hand :-)
Note that the shape of the $F$ distribution is contingent on its degrees of freedom, which for ANOVA correspond to the # of groups (minus 1) and # of observations (minus the # of groups). In general, the overall "shape" of the $F$ curve is determined by the first number, and its "flatness" is determined by the second number. The above example has a $df_1 = 3$ (4 groups), but you'll see that setting $df_1 = 2$ (3 groups) results in a markedly different curve:

You can see other variants of the curve on Mr. Wikipedia Page. One thing worth noting is that because the $F$ statistic is a ratio, large numbers are uncommon under the null hypothesis, even with large degrees of freedom. This is in contrast to $\chi^2$ statistics, which are not divided by the number of groups, and essentially grow with the degrees of freedom. (Otherwise $\chi^2$ is analogous to $F$ in the sense that $\chi^2$ is derived from normally distributed $z$ scores, whereas $F$ is derived from $t$-distributed $t$ statistics.)
That's a lot more than I meant to type, but I hope that covers your questions!
(If you're wondering where the diagrams came from, they were automatically generated by my desktop statistics package, Wizard.)
Answer: To answer your questions:

You find the critical F value from an F distribution (here's a table).  See an example.  You have to be careful about one-way versus two-way, degrees of freedom of numerator and denominator.
Yes.
Comment: Marcus Morrisey: I think you're confusing one vs two tails with one- vs two-way. The F-test doesn't have multiple "tails" to choose from, but one-way ANOVA vs two-way ANOVA needs to be considered when constructing the test statistic.
Comment: It is not meaningful to talk about one- or two-way comparisons in an omnibus test such as the F-test.


O que são refresh token, access tokens e grant type?

Question: Estava pesquisando sobre segurança em APIs REST e encontrei os termos refresh tokens, access tokens e grant type se referindo a forma como os tokens funcionam e como o cliente solicita os recursos
O que são e quais as suas diferenças?
Answer: Access Tokens - É um tipo de credencial que você pode utilizar para dar permissão
a sistemas externos interagirem com a sua aplicação. Como você bem citou por exemplo,
seu conjunto de APIs Rest só poderiam ser consumidas por meio de um identificador que
você mesmo oferece para seus sistemas parceiros. Esse ID é o Access Token. Um exemplo
prático disso, é quando você precisa consumir alguma API do Google/Facebbok.
Refresh Tokens - Ocasionalmente, você pode querer verificar de tempos em tempos o ID
(Access Token) que aquele sistema que está consumindo a sua API possui. Pode ser por
motivos de segurança, monetização da sua API ou mesmo a frequência de uso da api. Funciona da seguinte forma: Você dá para o seu parceiros 2 chaves: 1) O Access Token
(com tempo de vida curto) e 2) O Refresh Token (Usado para pegar um novo Access Token).
Dessa forma, quando o seu parceiro requisitar a sua aplicação, ele envia essas 2 chaves
e o seu sistema verifica se o Access Token está expirado. Caso esteja, você gera um
novo Access Token usando o Refresh Token que o parceiro lhe enviou.
Grant Types - Quando você ouvir esse termo, referece-se as maneiras que um sistema
externo possui para obter acesso a um Access Token para consumo da sua API. Podendo ser eles:

Authorization code
Implicit
Resource owner credentials
Client credentials
Refresh token

Todos esses conceitos da sua pergunta, fazem parte da especificação do OAuth 2.0 e você
pode obter mais detalhes aqui (OAuth 2.0 Docs) e aqui (OAuth 2.0 Workflow Vídeo).
Comment: Show,
Aí no caso o que sempre muda de tempo em tempo é o access_token.

No caso para salvar os dados no banco de dados, eu preciso salvar o refresh_token que é a chave de acesso para conseguir um novo access_token.

E o access_token é necessário salvar no BD? Ou simplesmente posso só usar o refresh_token com o código para solicitar um novo access_token e assim obtê-lo para acessar as informações?
Answer: Access tokens são credenciais usadas para acessar recursos protegidos.
Refresh tokens são credenciais usadas para obter um novo acess token.
Grant type é usado quando o cliente quer receber access token sem transmitir informações importantes, como o client secret.
Access tokens e Refresh tokens
Grant type


View não retornando os dados atualizados do BD

Question: tenho uma view de banco que quando cadastro um novo registro a mesma view traz os valores desatualizados para minha listagem. Ela só traz os dados de forma atualizado se eu derrubar o servidor e subir novamente.
estou usando Spring Data e abaixo segue mais detalhes para ajudar:
@RequestMapping("/serviceList")
public ModelAndView getMenuServiceList(Model model) {
    ModelAndView mv = new ModelAndView("service/serviceList");

    // Dados estão chegando desatualizados!!!
    List<VwOpenService> openServiceList = serviceFacade.getOpenServiceList();

    mv.addObject("serviceListRegister", openServiceList);
    countOfBudgets(model);
    return mv;
}

Camada de Serviço
public List<VwOpenService> getOpenServiceList() {
    return vwOpenService.findAll();
}

Repositorio (Spring Data)
@Repository
public interface OpenServiceRepository extends BaseRepository<VwOpenService, Long>{

    List<VwOpenService> findAll();

}

Answer: O problema era unica e exclusivamente relacionado com cache, logo bastou adicionar a seguinte propriedade em minha entidade @Cache(isolation=CacheIsolationType.ISOLATED) do Eclipselink que acabou sanando o problema.


How to render a Commerce pane programmatically?

Question: I've the following code:
$panes = commerce_checkout_panes();
$payment_pane = $panes['commerce_payment'];

which loads one of Commerce pane which contains the array like:
array (size=15)
  'title' => string 'Payment' (length=7)
  'page' => string 'review' (length=6)
  'file' => string 'includes/commerce_payment.checkout_pane.inc' (length=43)
  'base' => string 'commerce_payment_pane' (length=21)
...

How do I render that pane programmatically?
This is part of commerce_checkout_form_review form (which is normally present at /checkout/%/review), but I need to render only payment part (checkboxes) but in different place.
Answer: Panes are forms. Run them through drupal_get_form but you'll need to pass in some extra options:
require_once drupal_get_path('module', $payment_pane['module']) . '/' . $payment_pane['file'];
$order = commerce_order_load($order_id);
$payment_form = drupal_get_form($payment_pane['callbacks']['checkout_form'], $payment_pane, $order);
$output = drupal_render($payment_form);

Comment: This gets me all the pane elements but in raw format.. Any idea how I can get the themes results ?


RequestMapping works on private methods

Question: Now, my understanding, in general, is that  @RequestMapping methods need to be public. Can they also be private? If so when would we use this?
The reason why I am asking this is that I noticed that @RequestMapping worked on private methods as well. Why is this so?
Is it because spring access these methods through reflections so access modifiers aren't really considered? Is this a bug or a feature that has uses?
Comment: @RafałSokalski very well quoted from the question you linked, still doesn't answer anything.
Comment: Raised an issue here https://jira.spring.io/projects/SPR/issues/SPR-16878.  Probably a duplicate. But well hoping for a response from them someday.
Comment: Possible duplicate of [Why does Spring allow controller annotated request mappings on private methods?](https://stackoverflow.com/questions/7322227/why-does-spring-allow-controller-annotated-request-mappings-on-private-methods)
Comment: @RafałSokalski doesn't really answer the question, i.e. why does Spring allow it. I suspect it's an oversight / not seen as necessary. It's really the programmer's fault.
Comment: Java does not provide a mechanism for limiting the target of annotations based on access modifier
Comment: Why not ? He asked why it works on private methods and there is an answer
Comment: @RafałSokalski it's the wrong answer. It's not that Java allows annotations on private methods that's the issue, it's that Spring allows those annotation on private methods. It could easily prevent them.
Comment: That's right @Kayaman. My mistake
Comment: Well that was fast: Resolved, Works as Designed...
Comment: Thanks for asking. This was source of confusion when I saw my IDE pointing out an annotated method as candidate for deletion (never used anywhere)
Answer: Now the real reason (if one exists) is hard to say without getting into the heads of the Spring developers, and because this was implemented quite a while ago.
I would guess that this was an oversight, as there's not a significant advantage in using private methods as targets for request mapping. Sure, you can't call them from your other code anymore, but if you're calling controller methods from your code, you deserve all the problems you get.
This link describes an interesting situation where the request mapping works for a package private method, but since AOP only works for public methods the result is confusion and destruction. There's also 4 (four!) places given where a fix could be applied to prevent non-public methods from being targets of <code>@RequestMapping</code>.
So I would classify this as a (minor) bug. Now it's up to the programmers to stay on their toes and remember to make those methods public. I'll see if I can find an existing bug ticket for this.
Answer: As responded by pivotal in the JIRA ISSUE

This indeed works as designed. We generally don't restrict visibility declarations on reflective methods, leaving that choice up to the developer. That said, for this particular case, I would recommend public declarations or potentially package-visible declarations (without a visibility keyword), with private handler methods actually being more of a niche effect here.

RequestMapping works on private methods


consuming web api, ports on different machine

Question: my simple web app has web api and web mvc project. from mvc app I'm consuming web api service using ajax.
Right now my uri looks like this
var uri = 'http://localhost:2266/api/cars';

and on web api side I need to enable cors for communication with my mvc app.
[EnableCors(origins: "http://localhost:2256", headers: "*", methods: "*")]

this setup working just fine on my machine, since I want to share this with my friend how can I make this ports values 2256 and 2266 to be same on each machine?\
Or if it's not what do you suggest to make this values configurable?

Thank you, but obviously I was not clear enough: I'm asking how can I know on
  different computer which port should be used, and upon that to include
  that port instead of this 2256, 2266?
Comment: Give multiple values by comma separating the origins
Answer: The port number is just the tooling (VS) making it easy for you to debug locally (localhost) - it "separates" each of your web sites by assigning a random port number all living in your local machine under 'localhost` (aka "domain").
You can in fact assign one yourself (or change whatever VS assigns) with the caveat of making sure it doesn't conflict with any other service/existing port in use in your local machine (more below).

"share this with my friend"

Unsure what that means. As above localhost is local, so assuming on the (live/production) net - then you assign a port number (in your server/IIS settings) - it's your API so you "dictate" how external "friends" can access/connect.
Caveats:
As mentioned above, just like in your local environment (which is less restrictive being local), in production/live internet, aside from the standard ports (80, 443, 20, 21, 22, 25, etc.) you may run into issues with firewalls, which ports to use (conflict with other existing services), etc. which is a broad topic  and frankly its been a long time since I've done net ops - TLDR; if they are completely separate applications (as it seems), then you're probably better off doing same on live - e.g. subdomains - www.foo.com (mvc) api.foo.com (api) and not deal with assigning port numbers manually at all (defaults will apply - 80 for http, 443 for https).
Hth.
Answer: You can separate multiple origins with commas:
[EnableCors(origins: "http://localhost:2256,http://localhost:2266", headers: "*", methods: "*")]

From MSDN:

Parameters origins Type: System.String Comma-separated list of origins
  that are allowed to access the resource. Use "*" to allow all.
Answer: The ports which are using for your Web API application hosting will not be accessible outside of your computer and also it might get changed when you close and open Visual Studio and run Web API again.
It would be best to host your Web API using a domainname (such as "apionlocal.com") on local machine and create a host entry on the local machine.
The host entry would look like 127.0.0.1 apionlocal.com
Retrieve netrowk IP of your computer by running "ipconfig" command on command prompt and share it with your friend.
Your friend also need to enter the host entry on his machine with the IP of your machine.
The host entry would look like <<your computer IP>> apionlocal.com
Your friend need to call API using the domainname "apionlocal.com".
You can configure multiple origins in "EnableCors" using comma separated values.
EnableCors(origins: "http://localhost:2256,<<Url of your friend's application>>", headers: "*", methods: "*")]

Comment: Note: Assumptions you're making - `ipconfig` - Is the "friend" in same local (sub) net? If not, Is that the publicly route-able IP or not? If yes: Is the local machine running IIS that has been configured for external communications? If not: more stuff to do in addition to checking prior mentioned IIS check
Comment: Yes I making assumption that both the computers are in the same network. If that's not the case then surely there is more work to do.


Use of the symbolic operator $\left[e^{\frac{\partial}{\partial x}}\right]$ in Taylor's expansion

Question: We know that Taylor's series expansion of a generic function $f(x)$, in the abscissa point $x_0\in\mathbb{R}$ is given by:
$$f(x)=\sum_{n=0}^{\infty}\frac{(x-x_0)^n}{n!}f^{(n)}(x_0) \tag{1}$$
$$f(x)=\left[e^{(x-x_0)\frac{\partial}{\partial x}}\right]f(x_0) \tag{2}$$
Why if I expand the exponential in $(2)$ into an infinite sum and move the $(x)$ part into the sum, I'll get $(1)$ through a translation that brings the point $x_0$ to the point $x=x_0+(x-x_0)$ where
$$e^{(x-x_0)\frac{\partial}{\partial x}}\equiv \sum_{n=0}^{\infty}\frac{(x-x_0)}{n!}\frac{\partial^{(n)}}{\partial x^n}, \quad ?$$
What is the connection between moment operator impulse $p_x\longrightarrow -i\hbar\frac{\partial}{\partial x}$ along a direction,  $x$ and the $(3)$?
$$f(x)=\left[e^{(x-x_0)\frac{\partial}{\partial x}}\right]f(x_0)\color{teal}{\equiv \left[e^{-\dfrac i\hbar (x-x_0)p_x}\right]} \tag{3}$$
Comment: Note that $$\left((x-x_0)\frac{\partial}{\partial x}\right)^n$$ is not the same as $$(x-x_0)^n\frac{\partial^{(n)}}{\partial^{(n)}x}$$ since $x-x_0$ does not commute with $\partial/\partial x.$
Comment: Another issue with how you write (2) is that you have it operate on a constant $f(x_0)$ which does not give you what you want. The way to write it to get what you want is to write it on the form $f(t + x) = e^{t\partial_{x}}f(x)$.
Comment: What do you mean by "why"? From a purely computational perspective, an answer to your question is "because if you expand the exponential in (2) into an infinite sum and move the "$(x)$" part into the sum, you'll get (1)". A rigorous mathematician will want to make sense of the exponential by explaining where exactly it is computed, but this is not too difficult (though the answer will include the words "Banach algebra" or at least "topological $\mathbb{Q}$-algebra", with the details depending on what kind of function $f$ is). Do you want a motivation?
Comment: I'm not going to edit the post until I know what exactly the remaining question is. As to the motivation behind $e^{t \partial/\partial x}$ acting like a shift  by $t$, there are *probably* some pictures and ideas in some people's heads that give this fact a non-computational explanation, but I don't know them well enough to give a good answer.
Comment: @darijgrinberg In the meantime hello and I thank you for your comment so much. The first part of your comment is exactly what I would like to know "because if you expand the exponential in (2) into an infinite sum and move the "$(x)$" part into the sum, you'll get (1)". You are 100% authorized to edit my question also because I am not a native of English and not knowing the topic at all I do not know how to make my question clearer.
Comment: @darijgrinberg Keep in mind that I have never studied these topics and I am simply interested in the mathematical passages without  "Banach algebra" or at least "topological $\mathbb{Q}-$algebra$". It is too difficult for me with all sincerity. I'm sure you found my thanks.
Comment: @ThomasAndrews I apologize once again but I am not an expert in this field. Thank you very much for your cooperation. Keep in mind that I have only a few notes but I could better understand from your answers. Excuse me very much.
Comment: @Winther I tried to ask the best of my question. Excuse me, too.
Comment: Thank you very very much to the users that reopened my closed question. Thank you very much.
Answer: Let's first start with a precise formulation of the equation you are referring to. For a (sufficiently nice) function $f$ we have
$$f(x+\epsilon) = e^{\epsilon\frac{d}{dx}}f(x)$$
Note that we need it to act on a function $f(x)$ and not $f(x_0)$ as you have (as this is just a constant). Also we cannot have $(x-x_0)\frac{d}{dx}$ in the exponential since $((x-x_0)\frac{d}{dx})^n \not= (x-x_0)^n\frac{d^n}{dx^n}$.
As to why this equation holds. First of all the definition of $e^A$ when $A$ is an operator is nothing but the usual Taylor series so $e^A \equiv 1 + A +\frac{A^2}{2} + \ldots$ so if we write out what we mean by the right hand side it becomes the series
$$(1 + \epsilon \frac{d}{dx} + \frac{\epsilon^2}{2}\frac{d^2}{dx^2} + \ldots)f(x)\\ = f(x) + \epsilon \frac{df(x)}{dx} + \frac{\epsilon^2}{2}\frac{d^2f(x)}{dx^2}+\ldots$$
If you consider this as representing a function of just $\epsilon$ for a fixed $x$ then you will see that this is nothing but the Taylor expansion of the function $g(\epsilon) = f(x+\epsilon)$ about the point $\epsilon=0$.
The connection with the momentum operator becomes $f(x+\epsilon) = e^{-\frac{i}{\hbar} \epsilon p_x }f(x)$. This is sometimes phrased as the momentum operator being the generator for translations (which intuitively makes sense: momentum is what causes change in position). To understand this more deeply I suggest reading more about the mathematics of quantum mechanics which can be found in any introductory textbook. For more see e.g. this or this.


Make Linux server route packets destined for its external ip to localhost

Question: I've a router with a certain static ip a.b.c.d that's connected to a Linux server on one side and to the internet on the other.
Accessing a software installed on the Linux server from outside using the IP address a.b.c.d:portxx works fine.
However, if a browser opened by someone from the server itself tries to access the same software as  a.b.c.d:portxx it fails. Trying localhost:portxx again works fine.
So my diagnosis is that the DSL router is being dumb and not realizing that a.b.c.d is itself.
Is there a way to fix this, prefrably without changing anything at the router? i.e. Through /etc/hosts or some other mechanism on the server can any packet going to a.b.c.d be rerouted to localhost?
Is this likely to break anything else?
Comment: Try to configure a.b.c.d as an alias IP on lo:0 should work (limit to browser on the Linux server).
Comment: You mean the router is forwarding traffic for `a.b.c.d` towards the linux server which presumably has a private IP address? This is not quite clear from your question.
Answer: The problem is not in router. Router do what have been configured for - it translate traffic destination a.b.c.d:portxx to your linux server. It not work, but for understanding, you have to see what happen on network. For example your linux server is 192.168.1.2 and your router is 192.168.1.1 on your LAN network

From server you send packet
src 192.168.1.2:1024 dst a.b.c.d:portxx
on router is made translation (back to server)
src 192.168.1.2:1024 dst 192.168.1.2:portxx
packet come to server application, it replies - and send reply packet
src 192.168.1.2:portxx dst 192.168.1.2:1024
packet come (stay) on server to client aplication, but this connection is not know, because you initiate connection to a.b.c.d and have a reply from 192.168.1.2 and not from (a.b.c.d) - packet is dropped.

So possible solution:
1) on router, if you can, set SNAT from packet comming from local network to your NATed public ip. If you have linux router, try something
iptables -t nat -I PREROUTING -s 192.168.0.0/24 -d a.b.c.d -j SNAT --to-source 192.168.1.1

You changed source packet address for packet go through router from inner network, server application reply back to 192.168.1.1, and SNAT rule when receive reply, correctly map packet back to your client application on server. This solution work for all inner network computers, but on server you see all request coming from router address 192.168.1.1.
2) On server, you can make REDIRECT traffic by iptables
 iptables -t nat -I OUTPUT -d a.b.c.d -p tcp --dport portxx -j REDIRECT --to-ports portxx

It redirect outgoing connection from your server to local port on server. I think, this could be best solution for your case
3) Adding a.b.c.d address on server could be solution for some cases, but sometimes server daemon (and it is application specific) do not listen on all ip address or give another reply for other address.
4) If you using hostnames and not ip address, you can redefine /etc/hosts on linux server - this is easiest and sometimes help (DNS return: linuxserver a.b.c.d) so in /etc/hosts you write line
192.168.1.2 linuxserver

And connection from linux server to "linuxserver" go directly to 192.168.1.2


Is using an amp sim along with a passive speaker a good idea for home practie and small gigs

Question: I am fairly new to using amp simulators for guitars, I was trying to figure out the best setup I could have for practicing at home and for jamming sessions. I will list down my requirements of the setup in order.

I am able to get out good sound at both lower volumes for home practice and high enough to hold it's own while playing with a drummer

The sound through the speakers are not distorted by any of the setup

Low latency

Based on the requirements and a little looking around the net , I was contemplating the following setup.

Guitar to an audio interface like focusrite 2i2 or Behringer UM2
The audio interface through the usb into the ipad/pc
The audio interface through rca cables to a studio monitor like epronus 4.5

Can the above be a upgrade over my current setup of plugging in an aux cable from my ipad to an amplifier on clean channel ? Will the difference in sound be worth it to invest the extra money into all the equipments ?
Comment: Good idea is subjective.  Personally, I am pretty satisfied with my laptop, interface, and digital effects as a practice and recording setup but I would not be comfortable gigging with this.  Dedicated hardware effects or even digital effect pedals are much more reliable than just about anything running Windows or iOS/mac OS.
Comment: @Edward The reason I am looking into amp sims instead of digital pedal effects is because they come in much cheaper and are easier to experiment with. If you could give your views on how you think your setup were to work if you added a monitor speaker, turned up the volume and jammed in small rooms with other people, it would be very helpful here. For reference, I currently use an amp sm in my ipad , connect the guitar through an interface to it , and through an aux connect the ipad to my amplifier on clean. But at higher volumes , I notice a drastic reduce in quality of the sound
Comment: Since you are already using an amp sim, you should try sending your output to a full range loudspeaker, instead of a guitar amp.  With an appropriate amp and speaker I could totally get my practice setup to work in a band setting.  There's no technical reason why an iPad would give worse sound at high volumes (in fact I'd expect the opposite... better sound at high volumes, if the volume control is done digitally) but a guitar amp is not designed for hi-fi sound.
Answer: This kind of setup is OK for practicing at home. But IMO it's a pain to move around from place to place and it's probably about 3 too many points of failure for playing a gig and probably is not going to be anywhere near loud enough for that (or band practice). A cheap, powered PA speaker will probably get you there, volume-wise, but the reliability and convenience is still going to be an issue. For a gig, if you need a lot of effects and don't have the physical hardware, I'd look at some kind of modeling amp or else a multi-fx unit and powered PA speakers.
Answer: Personally, I have plugged my acoustic guitar into my Focusrite 2i4 which is plugged into my Mac with a virtual amp running and then run out to both a PA System and Adam Audio T7Vs. I have had no problem with this, the latency isn't enough to disturb my playing or even notice that much. However, I have no experience with plugging an iPad into an amp but it sounds like it should work just as well.


How big is the download for my users if my app requires the 2015 Android Vision API?

Question: I am interested in adding face detection to my app (com.google.android.gms.vision.face the Google Play services 7.8 version as described here here and here)
But in the documentation it says 'Adding the vision functionality dependency to your project's AndroidManifest.xml will indicate to the installer that it should download the dependency on app install time'
Its very important to me that my App size should be small and not require a huge  download- so does anyone know how big the 'dependency' for com.google.android.gms.vision.face will be and how much it will add to my download for users that don't already have it?
Also do people know if iOS works the same way?
Answer: Your app size always depends upon the artwork you have used to beautify your app interface, how detailed your application has been developed and how many dependency the application is using, sometime the application size is very small on app store, but after downloading the app on phone, the app installs dependency on run time and consume some disk space.This approach save developers to submit heavy applications to the store.
This can be true for both platforms i.e. iOS and Android. I am expert on iOS development so don't know about this specific dependency com.google.android.gms.vision.face. So any expert on Android might answer this. But I think it might not take so much memory as, it will not contains any images but few kbs of files.
Comment: Hi thanks for your thoughts... I have been converting some javascript face detectors to C# because anything that is based on OpenCV tends to be absolutely huge- generally 30meg or so at least, and thats not because of images, its just code... I don't know if Android/iOS face detection is based on OpenCV but whether it is or not, but I think its very likely that it will be a pretty big chunk of code, unless they have specifically tried to make it not so.
Comment: Do you know if iOS has face detection built in or if it adds it on demand like Android is?


Highlight immediate cells after conditional formatting rule is satisfied

Question: I have a column which looks like this -

Col1

A

B

C

A

D

V

A

X

My first conditional formatting is to highlight all the cells where Col1 contains "A".
But I also want that after all the A cells have been highlighted it should highlight the next immediate cell after A no matter what the value is.
How to go about that?
Edit 01 -
Unable to figure out what am I missing here?
Comment: For your 'green rule' you need to change the change the range for which you have defined the formatting to be from `A2:A11`, and amend the test to be `=$A1="A"` so that the referenced cell is the one _before_ the start of your range
Answer: The 1st rule below applies conditional formatting if the current cell contains A

and the 2nd applies conditional formatting if the preceding cell contains A.
Comment: This is formatting the cell above A and not below, I would like to format the below one.
Comment: @Maxima the screenshot clearly shows that the cells _below_ those containing `A` have been highlighted
Comment: I just tried replicating this and it is working opposite, all the cells above A have been highlighted. Can I edit my question and share the ss?
Comment: @Maxima yes, of course, you can edit your question - the key with conditional formatting, though, is always to have the '$` references correct vs the range for which you have defined the formatting


Use of $\mapsto$ and $\to$

Question: I'm confused as to when one uses $\mapsto$ and when one uses $\to$. From what I understand, we use $\to$ when dealing with sets and $\mapsto$ when dealing with elements but I'm not entirely sure.
For example which of the two is used for the following? $$\begin{pmatrix} x \\ y \\ z \end{pmatrix} \cdots \begin{pmatrix} x+y \\ z+y \\ x+z \\ -z\end{pmatrix}$$
Comment: The common usage is to use "$\rightarrow$" when showing the domain and range, and to use "$\mapsto$" when showing to what a specific or generic element of the domain maps. The main advantage that I see for using "$\mapsto$" is that the function need not be named. For example, one could speak of the function mapping $\mathbb R \rightarrow \mathbb R$ where $x \mapsto x^2$. You recognize this as a simple quadratic, but note that I haven't named the function. The name isn't really part of the function definition, after all -- just the domain, range, and rule matters.
Comment: See also http://math.stackexchange.com/questions/760085/is-there-a-difference-between-writing-f-x-rightarrow-y-and-writing-fx-mapst.
Comment: And http://math.stackexchange.com/questions/651205/regarding-the-notation-f-a-mapsto-b.
Answer: The $\to$ arrow points from the domain of a function to its codomain or target set.  The $\mapsto$ arrow (fittingly called <code>\mapsto</code> in TeX) shows what an individual element of the domain will be mapped to, i.e. it shows what the function does while $\to$ shows where it operates (so to say).
So, the elaborate way to write a function definition is
$$f:\begin{cases}A\to B\\x\mapsto f(x)\end{cases}$$
where "$f(x)$" will typically be something like "$x^2+42$" or whatever.  So, both arrows play different roles when describing the function and they are both needed to describe the function as a whole.
But note that you might have a function like
$$f:\begin{cases}{\cal P}(\{1,2,3\})\to \mathbb{N}\\A\mapsto |A|\end{cases}$$
where there's a set on the left side of the $\mapsto$, so the rule isn't as easy as "$\to$ is for sets and $\mapsto$ for the rest".  (As every set theorist will be eager to explain to you, everything is a set anyway...)

Two examples:
$$f_1:\begin{cases}\mathbb{R}\to \mathbb{R}\\x\mapsto x^3\end{cases}
\quad\quad
f_2:\begin{cases}\mathbb{N}\to \mathbb{R}\\x\mapsto x^3\end{cases}$$
Here $f_1$ and $f_2$ are different functions.  They do the same thing, but on different domains.
$$g_1:\begin{cases}\mathbb{R}\to \mathbb{R}\\x\mapsto x^3\end{cases}
\quad\quad
g_2:\begin{cases}\mathbb{R}\to \mathbb{R}\\x\mapsto x^5\end{cases}$$
And $g_1$ and $g_2$ are again different functions.  This time, they act on the same domain, but they do different things.
Answer: The difference is that $\mapsto$ denotes the function itself.  Thus you need not name the function.  $a\mapsto b$ fully describes the action of the function.  $\to$, on the other hand, describes only the domain and codomain.  Thus one might say $x\mapsto x+1$ is equivalent to $f(x)=x+1$, in which case we would say $f:\mathbb{R}\to\mathbb{R}$.
Answer: Your operative definition of $\longrightarrow$ and $\longmapsto$ are correct. In your example you are dealing with vectors in $\mathbb{R}^n$, which are elements of a set, so you should use $\longmapsto$.
see also this wikipedia article: http://en.wikipedia.org/wiki/List_of_mathematical_symbols
Comment: Careful!  This has nothing to do with being an element of a set or not.
Comment: @Frunobulax I see your point. I intended to say that *if* you are dealing with elements of a set then you should use $\mapsto$. Indeed, if you consider a function defined over a collection of sets, these sets are elements.

Use of $\mapsto$ and $\to$


How can I notate this slur with LilyPond?

Question: I have a slur that starts on as multi-voice and ends on a single voice as measure 3–4 of the following:

Here's what I've got so far (right hand only):
\relative c' {
  << { c4 c c c8 c c4 bes8 aes4. aes8 aes } \\
     { g8 aes f g4 aes f8 aes8 g f r8 r2 } >>
  << { bes8 bes2 aes8( g f } \\
     { f8 g ees f4  r r8 } >>
  <f ees>4.) g8 ees des \clef treble
}

With this, I'm getting errors about an unfinished slur.
I suspect that this is because the slur starts inside the << … >> scope and tries to cross that border.
Answer: Here are two possible solutions.
1: You don't seem to need two voices from aes8 onwards, so use this:
\relative c' {
  << { c4 c c c8 c c4 bes8 aes4. aes8 aes } \\
     { g8 aes f g4 aes f8 aes8 g f r8 r2 } >>
  << { bes8 bes2 } \\
     { f8 g ees f4 } >>
     aes8( g f <f ees>4.)
  g8 ees des \clef treble
}

2: You can extend the two-voice stuff longer and use s4. as an "empty" second voice.
\relative c' {
  << { c4 c c c8 c c4 bes8 aes4. aes8 aes } \\
     { g8 aes f g4 aes f8 aes8 g f r8 r2 } >>
  << { bes8 bes2 aes8( g f <f ees>4.) } \\
     { f8 g ees f4  r r8 s4. } >>
  g8 ees des \clef treble
}

Answer: You can extend the two-voice stuff longer but you don't need spacer rests in the second voice. The musical expression is as long as the longest voice.
Further the rests in the second voice look unnatural.
I would use spacer rests here.
\relative c' {
  << { c4 c c c8 c c4 bes8 aes4. aes8 aes } \\
     { g8( aes f g4) aes f8 aes8( g f s8 \once\hideNotes aes2) } >>
  << { bes8 bes2 \stemDown aes8( g f <f ees>4.) } \\
     { f8( g ees f4) s s8 } >>
  g8( des' f \clef treble as bes)
}

Further it's not always clear where is the slur attached.
The slur in question binds notes with stem down what usually designates the second voice.
But there are rests below the whole first stave.
This calls for redesign.


"Couldn't find a file descriptor referring to the console" on Ubuntu bash on Windows

Question: I have a problem with Bash on Ubuntu on Windows. If I type "open (filename)" on Mac terminal, it opens the file with the right program but if I try to use it on Windows bash, it says: "Couldn't find a file descriptor referring to the console".
I have also tried xdg-open and gnome-open but none of them works. How can the issue be fixed, and how does the open command work?
Comment: You could try using the batch file command `start`. However, that is an internal command to `cmd`. So you need to wrap it as `cmd /c start "" "filename"`
Comment: `open(1)` on Linux is a deprecated alias for `openvt(1)`.
Comment: Doesn't work for me :/
Comment: What error do you see with command mentioned above? BTW, you might need to convert paths from Windows to Linux or vice versa.
Answer: Instead of open u can use xdg-open which does the same thing, independently of application i.e. pdf, image, etc. It will open a new virtual terminal (I have tried this on Linux)
Example:
xdg-open ~/Pictures/Wallpapers/myPic.jpg
xdg-open ~/Docs/holidays.pdf
Answer: For linux, use xdg-open. open is for Mac OS. open in linux is an name alias of openvt (open virtual terminal).
To simplify it, you can append the following line to ~/.bashrc or ~/.zshrc depends on the shell you are using.
alias o="xdg-open" # o stands for open

Then next time you can just type like the following to reduce some keyboard strokes.
o file_name.pdf
Comment: Off-topic: I also define my remote commands like that!
`s` shows running jobs
`p` prints most recent output
`o` displays the file
Comment: Alternatively, define `open` as an alias or function to make all your normal scripts work alike on OS X and Linux. https://github.com/fatso83/dotfiles/commit/7d9b685e9ba1edba243fc89e78095b27c5ace37b#diff-faf0d10d25b6ac7fcd15598e065e4f66R21
Answer: That's because open is a Mac specific command, it is not available under Linux (ubuntu), Mac open can execute a file (if the file is executable), or open the file into a text editor (if it is a document or text file) or open a directory.
Comment: Makes sense. But there is similar command on Linux and Ubuntu called "xdg-open" so I think there is a way to implement it on Windows bash as well @hcheung. I just installed xdg-utils package but it opens files and folders inside bash. Is there any way to open files through windows programs?
Comment: I'm window-free for more than 10 years! Hope someone could help.
Comment: I have a `/bin/open` app on my Linux OS. There indeed is an `open` cmd for Linux.
Answer: For opening a file to write in Ubuntu on Windows bash, you can type -:

nano filename.txt

The above command will allow you to write/edit in the file after which, you can use ctrl+x and then press 'y' to save. Check/view the file content using -:

cat filename.txt


What are some popular choices for visualizing 4-dimensional data?

Question: Say I have the following four dimensional data, where first three can be considered as coordinates, and the last one can be considered as values.
<code>c1, c2, c3, value
1, 2, 6, 0.456
34, 34, 12 0.27
12, 1, 66 0.95
</code>
How to better visualize the effect of the first three coordinates on the last value?
I're aware of three methods.
One is 3D plot for the first three coordinates with the size of points as the four value. But it is not that easy to see the trend in the data.
Another is using a series of 3D plot, each of which is with a coordinate fixed.

Another one may be a socalled "trellis graphs" in lattice of R. Not sur eif it is for this purpose but it seems so.
Comment: Do you need a static display (eg, for a paper)?
Answer: If the first three are just spatial coordinates and the data are sparse you can simply do a 3D scatter plot with differently sized or colored points for the value.
Looks something like this:

(source: gatech.edu)
If your data is intended to be continuous in nature and exists on a lattice grid, you can plot several isocontours of the data using Marching Cubes.
Another approach when you have dense 4D data is to display several 2D "slices" of the data embedded in 3D. It will look something like this:
Comment: The colored 3D scatterplot is only really suitable for continuous functions on 3D data. If the gradient of the function changes smoothly then you can see some pattern across the point scatter. Similarly the volume visualization at bottom works best in this scenario too. If the function is very noisy you will have a hard time seeing anything. If you have 4 explanatory variables (like for doing PCA or clustering) plotting 3 in Euclidean coordinates and the 4th using some nonlinear mapping to color in introducing some perceptual bias, which can't be quantified.
Comment: @DianneCook that's true. I guess that's what I get for always working with smooth, continuous 3D volumetric data ;)
Comment: Hey, that's what the quesiton asked %^)
Answer: Do you have four quantitative variables? If so, try tours, parallel coordinate plots, scatterplot matrices. The tourr (and tourrGui) package in R will run tours, basically rotation in high dimensions, you can choose to project into 1D, 2D or more, and there is a JSS paper that you can read to get started cited in the package. Parallel coordinate plots and scatterplot matrices are in the GGally package, also scatterplot matrices are in the YaleToolkit package. You can also look at the http://www.ggobi.org for videos and more documentation on all of these.
If your data is entirely categorical you should use mosaic plots, or variants. Take a look at the productplots package in R, also vcd has some reasonable functions, or the ggparallel package to do the equivalent of parallel coordinate plots for categorical data. Also, just found the extracat package has some functions for displaying categorical data.
I misread the question, originally, because I stopped at the question, and neglected to read the full description. Similar to the approach below (coloring points in 3D) you can use linked brushing to explore functions defined on high-dimensional spaces. Take a look at the video here which shows doing this for a 3D multivariate normal function. The brush paints points with high density (high function values) and then moves to lower and lower density values (low function values). The locations where the function is sampled are shown in a 3D rotating scatterplot, using the tour, which could be used to look at 4, 5, or higher dimensional domains also.
Answer: Try Chernoff faces. The idea is to attach the variables to facial features. For instance, size of the smile would one variable, roundness of the face is another etc. As ridiculous as it sounds, this may actually work if you find out a smart way to map variables to features.
Another way is to show 2-d projections of the 3-d phase diagram. Say you have x1,x2,x3,x4 your variables. For each value of x4, draw 3-d graph of (x1,x2,x3) points, and connect the points. This works best when x4 is ordered, e.g. it's date or time.
UPDATE:
You can also try bubble plots. Three dimensions would usual cartesian x,y,z, and the 4th dimension would the size of the bubble point.
You can try animation, i.e. use time as fourth dimension.
Also a combination of bubble and animation: x,y, bubble and time.
Also, related to Chernoff is glyph plot, which may look a little more serious. It's stars with length of rays proportional to variable values.
Comment: Chernoff faces were used in serious research, afaik.
Comment: chernoff faces are a terrible idea! if you have to use an icon plot use a starplot. If you have a really small data set these might be useful, but try plotting 1000 icons and see if you can really see anything!
Comment: Chernoff faces can be extraordinarily useful, especially when the dimensionality is around 10-20 variables.  For four dimensions they aren't as effective as other kinds of graphical representations.
Comment: Thank you for the answer. It seems the second option is possible to my problem. I think the first one seems not that serious for a research paper. Basically I would like the plot can reveal some trend or influence of three factors on the value (fourth dimension).


How to findViewById in a Fragment from another layout, not the one inflated as the root layout?

Question: I am using a Fragment with a ViewPager, I need to set text in the ViewPager from my fragment but I am unable to, as I a keep getting:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference

This is how I have initialized the TextViews from the ViewPager's XML file:
View root = inflater.inflate(R.layout.fragment_library, container, false);
.
.
contentHeading = root.findViewById(R.id.content_heading);
contentBody = root.findViewById(R.id.content_body);
.
.
return root;

Answer: It's not possible to directly access from child layout.
A simple way is  using interfaces.
You can define an interface in Fragment constructor  then implement it in root Fragment which hosts viewPager .
interface SomeInterface
{
public void callback (Type xxx)
}

Parent fragment must implement interface to listen any callBack
 ParentFragment implements SomeInterface
    {
    ...
         @override
         public void callBack(Type xxx)
         {
                //Change view pager
         }
    }

and then pass this fragment as a listener in your viewpager constructor and childFragment constructor.
Comment: I am still new to Android studio, so can you please help me out? Do I have to create another fragment for this? How do I setup a listener with this fragment? The whole process is still not clear to me.
Comment: i found another answer  here .  https://stackoverflow.com/questions/39500413/change-viewpager-fragment-from-child-fragment
Comment: Actually I want to change my viewpager from the parent fragment that contains the viewpager
Comment: Not the other way round
Comment: where did you use findviewByid ?. it must be placed in onViewCreated()
Comment: I used it inside onCreateView(), all my other findViewByIds are working find, just the ones that are in a different layout than the inflated root layout.


Is Perceptron a data-structure or an algorithm or both?

Question: I found Perceptron in the discussions of (overlapping of disciplines is acknowledged):

Neural Network
Machine Learning
Data Mining, Pattern Recognition
Genetic Algorithm

In the discussion of Neural Network, it is defined as:

Perceptron is a single layer neural network.

In the discussion of Machine Learning, it is defined as:

In machine learning, the Perceptron is an algorithm for supervised learning of binary classifiers.

In the discussion of Data Mining, it is defined as:

One of the older approaches to this problem in the machine learning literature
  is called the perceptron algorithm, and was invented by Frank Rosenblatt
  in 1956.

In the discussion of Evolutionary ALgorithm, it is defined as:

???

So, my questions are,

Is Perceptron a data structure or an algorithm or both?
Can you prescribe a book where I can learn about Perceptrons from Data Mining point of view?
Can you prescribe a book where I can learn about Perceptrons from Evolutionary Algorithm point of view?
Answer:
A perceptron is simply a single-layer neural network. When we refer to neural networks more broadly, we are referring to multi-layer perceptrons because these typically have more than one hidden layer. It is an algorithm that is used specifically for training of binary classifiers.
You might find the following of use: "Support Vector Machines and Perceptrons: Learning, Optimization, Classification, and Application to Social Networks", by Murty and Raghava. The book focuses on application of SVMs and perceptrons to social networks, but given this area relies significantly on data mining to conduct analysis, there might be some good examples here.
"Neural Networks and Genome Informatics, Volume 1 (Methods in Computational Biology and Biochemistry)" by Wu and McLarty describes how to apply neural networks to the field of genome informatics, and may be quite informative in this regard.

Disclaimer: I have no affiliation with the authors of the titles I cited, or any other relationship therein. I have not read the titles personally, but anticipate that they might be useful for the information you are seeking.


Prove or Disprove $A \subseteq C \land B \subseteq D $ is equivalent to $A \times B \subseteq C \times D$

Question: Can this statement be proved? because if i insert values, LHS is not equal to RHS.
For example,
let  $A=\{1\}, B=\{1,2\}, C=\{1\}, D=\{1\}$ then
$A\times B = \{1,2\}, C\times D=\{1\}$
Comment: Welcome to Mathematics Stack Exchange.  [Here](https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference) is a Mathjax tutorial.  The [Cartesian product](https://en.wikipedia.org/wiki/Cartesian_product) $A\times B=\{(a,b)\mid a\in A, b\in B\},$ so $\{1\}\times\{1,2\}=\{(1,1),(1,2)\}$
Comment: Please check for a possible typo. Maybe the condition is $A\subseteq C\land B\subseteq D$, i.e. $\land$ ( "and") instead of $\cap$ (" intersection ").
Comment: $A \times B \subseteq C \times D$ doesn't not imply that $A \subseteq C$ and $B \subseteq D$. For instance, $\varnothing \times \{1,\dots,100\} = \varnothing \subseteq \{0\} \times \{1\}$ but $\{1,\dots,100\} \nsubseteq \{1\}$.
Comment: @azif00 Indeed, one needs to require that $A$ and $B$ be nonempty for the statement to be true.
Comment: Nice name. ${}{}$
Comment: @StinkingBishop The original unedited post shows that is what he meant.
Answer: The Cartesian product makes a set of pairs.  So for example:
$$\{1, 2\} \times \{a, b, c\} = \{(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)\}$$
It is all possible pairs where the first element is from the first set and the second element is from the second set.  Try working out some examples with this Cartesian product definition.
Answer: We only have $\Rightarrow$.
To prove $\Rightarrow:$ If $A\times B=\emptyset$, we are done. Suppose
that $A\times B\neq\emptyset$. Let $(x,y)\in A\times B$, then $x\in A$
and $y\in B$. $x\in A$ and $A\subseteq C$ implies that $x\in C$.
$y\in B$ and $B\subseteq D$ implies that $y\in D$. Therefore $(x,y)\in C\times D$.
This shows that $A\times B\subseteq C\times D$.
We do not have $\Leftarrow$.
Counter-example. Let $A=\{1,2\}$, $B=\emptyset$, $C=\{1\}$, $D=\{3\}$.
Since $B=\emptyset$, we have that $A\times B=\emptyset$. It follows
that $A\times B\subseteq C\times D$. On the other hand, clearly $A\not\subseteq C$.


Linear regression sample size advice

Question: I'm involved in  sample size calculation for an oncology clinical trial. Our Primary outcome is quality of life (quantitative, normal).
There are two treatment regimes. Therefore I started with a simple t-test sample size calculation. With an effect size of 0.55, pow=.8, alpha=.05 we need overall 106 participants. Considering lost to fup and death before QOL measurement accrual size rise to 152 participants.
Trial is multicentre, with randomization stratified by centre. Patients can have different type of tumor (nsclc, cholangiocarcinoma, stomach, pancreatic)
The funding institution referees requested to (freely translating) "increment sample size to account heterogeneity of patients involved". They did not request stratified randomisation center*tumor (maybe due to likely imbalance for a  small sample size), eventually suggested a minimization.
I'm starting to think about a linear model like the following, to fullfill requests
QOL = f(Treatment.dummy, TumorType.dummies)
Typically effect size relies on the  R^2 with and without the covariate of interest. However given the state of the literature, i don't know how to make an educated guess about this stuff.
The only idea that remains (at least to me) is to simulate with Monte Carlo. In the end it would be an F test of model with vs without Treatment.dummy.
Given a certain n (growing beetween simulation steps):

I would simulate proportion of different tumor patients recruited, given infos from our clinical database.
Given the tumor type I would simulate proportion of patients randomized to Treatment in that strata (...thinking about Uniform with mean .5 ... eg U(0.35,0.65)
For pts in control group, given tumor type, i would simulate QOL given normative data of the instrument
For pts in treatment group, given tumor type, i would simulate QOL given normative data of the instrument AND effect-size of interest

Then do the regression model, the test and get the power.
Another way would be to start from the t-test sample, and then increment it given models sample size rule of thumbs (eg 20 pts per added variable); but I don't like it very much because you loose grip with power-analysis.
Any other approach? Any suggestion (even "yes, do the Monte Carlo simulation") would be very appreciated.
Comment: But if you do not include other determinants for quality of life, for which there are a lot, then your statistical procedure is not even asymptotically correct? Turning this around - without all determinants known you can not simulate (ie. forecast) new datapoints.
Comment: thanks ima for the feedback...randomisation is expected to make groups reasonably comparable
Answer: I am not sure how you would even simulate data if you don't know what parameters to put in (and, as you said, that involves $R^2$ with and without covariates; you might not explicitly enter those into a simulation, but they'd be there in the raw data.
If the literature doesn't have good estimates for your particular area, does it have them for any related areas? Some other form of cancer, perhaps? I'd be surprised if there was nothing usable - cancer (as you doubtless know) has been researched a lot! But if you can't find anything, you have to guess and then you have to be able to defend your guess.
Once you make a guess, you could either simulate the data or use standard power calculations. The former gives you a lot more control but is more complex and takes longer. The latter is easy but makes assumptions (sometimes hidden ones) in the calculation.
Comment: thanks Peter for the feedback, i've edited the answer to give a little more details
Answer: Ultimately, if there are no valid applicable estimates in this area, one sensible thing to do would be to perform a pilot study first. Then use the estimates from this pilot study to design the clinical trial.
Comment: Aghila, thank you for feedback, I agree; unfortunately in our case time constraint imposed by financing istitution doesn't allow to do both the studies.
Comment: This is pretty standard advice but it has been criticized. The problem is that the results of the pilot study will themselves have so much uncertainty that power analyses based on them are just too uncertain to be useful. Trusting them would be akin to assuming that the pilot study was enough to reveal the true magnitude of the effect (and variability) and that the main study will merely allow it to "reach significance". [More on this and a reference](http://stats.stackexchange.com/questions/64388/calculating-when-significance-will-be-reached-in-a-b-test-chi2-test-of-the/64393#64393).
Comment: Well, based on the pilot study estimates you can compute confidence intervals and get an idea about the magnitudes of your effects. You can, for example, use the limits of your CIs in your power calculations and see the worst case/best case scenarios. Its certainly better than nothing.
Comment: That's an idea but it needed to be pointed out and will in any case probably not work as it would require the pilot study to produce a statistically significant effect. Otherwise, the CI is going to contain 0 (or whatever effect size corresponds to the null hypothesis) and the worse case scenario could be anything (and will not correspond to the lower bound of the CI, incidentally). Relying on that not happening most of the time means assuming the pilot study is already properly powered, begging the whole question.

Linear regression sample size advice


Is the svn nightly commit script built to capture all possible scenarios?

Question: I have a nightly svn commit script that should take into account all possible scenarios and commit new things to our svn repository.  Basically I am running the following steps:

svn status [path] to add any new files
svn status [path] to delete any manually removed files
dumping mysql development database
svn commit all the above changes with a default message.

Here is the script that we are using:
#!/bin/bash
echo "Adding new files to the nightly commit"
svn status  [path] | grep ? | sed 's/[?MD]//g' | xargs  -I {} svn add {}
echo "Removing files manually deleted"
svn status  [path] | grep ! | sed 's/[!]//g' | xargs -I {} svn del {}
echo "Dumping our development database"
mysqldump  --add-drop-database --add-locks --create-options --disable-keys --extended-insert --result-file=/repopath/database.sql databasename
svn commit /repopath/ -m "Nightly Automatic commit of changes"

I just want to make sure that the ? and ! are taken care, and that I don't have any other scenarios that I have not think of.  Any help will or improvement to this script will be very helpful.  Feel free to use this script as you please for any of your SysAdmin tasks.
Answer:
"xargs svn add" should be enough, why are you using -I {} ?
I wouldn't do this at all. You'll probably get a lot of tempfiles in SVN. You may put a CD-image there one day.
I wouldn't do this. Your comment will be completely meaningless. What did I change, etc? Why not just commit when you have actually changed something?
Mysql is evil sometimes. You need to make sure that the database dump is actually OK. Are you reading the stderr output from the script in the morning?
With time, your repo will get really big (depending on DB size and changes), with no good way to shrink it.
You'll want to escape both ! and ?. Or quote them. With singlequotes, '!' will work, "!" can cause trouble.

In summary: I think you got everything covered (except point 6), but I wouldn't do this if I were you.
Comment: Thanks Thomas, your comments are very valuable. We have to go this route due to a design flaw that we currently have in one of our systems.  We are working towards solving this design flaw.  thanks again.
Answer: You can also go svn add on all the files in your directory. Files that have been added already and are already under version control will generate an error message, but it'll add all the new ones.


Can I use entityreference module with my custom entity to display it?

Question: I've attached a new entityreference field to users that referenced my custom entity type, say it's called my_entity. When I dpm() the user or view the tokens, I can see my custom entity properties (id, name, etc) but when I view the user I do not see the field label or the entity label.
I threw a dpm($items) into hook_field_formatter_view() inside entityreference.module and
discovered that there are 0 items available to be displayed, but they are available in many other places! (as described above)
In hook_entity_info():
<?php
return array('my_entity' => array(
  'label' => t('My Entity'),
  'controller class' => 'MyEntityController',
  'base table' => 'my_entity',
  'uri callback' => 'my_entity_uri',
  'load hook' => 'my_entity_load',
  'fieldable' => FALSE,
  'label callback' => 'my_entity_label',
  'entity keys' => array(
    'id' => 'id',
    'label' => 'name',
  ),
);
?>

I tried just setting the entity keys['label'] to the schema field, which is supposed to be adequate to set the label, but I also tried 'label callback' and even setting up the bundle info, which is not necessary for my entity.
I've also tried adding the property into hook_entity_property_info() in the hope that it would be "made aware" to other modules, but no luck:
<?php
return array('my_entity' => array(
  'properties' => array(
    'name' => array(
      'label' => 'Name',
      'type' => 'text',
      'schema field' => 'name',
    ),
  ),
);
?>

Any ideas?
Comment: I'm not strong on this stuff, but I did notice this comment: https://api.drupal.org/comment/48533#comment-48533 ... this would indicate that if you are returning a static value rather than storing the value in the db, the $items will be an empty array ?
Comment: Thanks for tracking that down! There's a reference to `hook_field_prepare_view()` which could help me out here.
Answer: I figured this one out. Entityreference runs entity_access() before returning $items:
$items[$id][$delta]['access'] = entity_access('view', $field['settings']['target_type'], $target_entities[$item['target_id']]);

To get this working, you need to set the 'access callback' property in hook_entity_info(), which is an extended property that is checked by entity.module, not by core's entity functionality. So, for example:
<?php
return array('my_entity' => array(
  'label' => t('My Entity'),
  'controller class' => 'MyEntityController',
  'base table' => 'my_entity',
  'uri callback' => 'my_entity_uri',
  'load hook' => 'my_entity_load',
  'fieldable' => FALSE,
  'label callback' => 'my_entity_label',
  'access callback' => 'my_access_check',
  'entity keys' => array(
    'id' => 'id',
    'label' => 'name',
  ),
);

function my_access_check($op, $entity, $account, $entity_type) {
  // ...do something
  return TRUE;
}
?>


Suffix array using qsort() and strcmp

Question: I have the following code to create a sorted suffix array but there is simply no output. I run the program and it halts for 1-2secs and then exits.
The code is based off the c++ answer on the following website: https://www.geeksforgeeks.org/suffix-array-set-1-introduction/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>

struct suffix
{
    int index;
    char *suff;
};

int cmp(const void *a, const void *b)
{
    const struct suffix *a1 = a;
    const struct suffix *b1 = b;
    return strcmp(a1->suff, b1->suff) < 0? 1 : 0;
}

int *buildSuffixArray(char *txt, int n)
{
    struct suffix suffixes[n];

    for (int i = 0; i < n; i++)
    {
        suffixes[i].index = i;
        suffixes[i].suff = (txt+i);
    }

    qsort(suffixes, n, sizeof(int), cmp);

    int *suffixArr = (int*)malloc(n * sizeof(int));
    for (int i = 0; i < n; i++)
    {
        suffixArr[i] = suffixes[i].index;
    }

    return suffixArr;
}

void printArr(int arr[], int n)
{
    for (int i = 0; i < n; i++)
    {
        printf("%d", arr[i]);
    }
    printf("\n");
}

int main()
{
    char txt[] = "banana";
    int n = strlen(txt);
    int *suffixArr = buildSuffixArray(txt, n);
    printf("following is suffix array for %s\n", txt);
    printArr(suffixArr, n);
    return 0;
}

Since there is no output, I assume that the problem is within the 'buildSuffixArray' function, specifically with qsort. I have tried fixing it but had no luck. Any help would be appreciated.
Comment: `qsort(suffixes, n, sizeof(int), cmp);` should be `qsort(suffixes, n, sizeof suffixes[0], cmp);`
Comment: The `cmp()` function must return a negative, zero or positive value depending on whether the first argument sorts before, equal to or after the second value.  Your `cmp()` function returns only `1` or `0`.  This will screw up any sorting.  If the values compared are A and B and they are not equal, then `cmp(A, B)` must return a value of the opposite sign to `cmp(B, A)`, but your code does not.  It would be sufficient to return the value from `strcmp()`.  Note that the magnitude of the result does not matter — only the sign of the result.
Comment: Fyi, you don't need a struct to do this. A pointer array and some pointer math based on the base address of your input string will do it for you and grant the same results. It may even make it overall-clearer what you're really doing (sorting a raft of suffix strings based on pointers, all peeking into the same string buffer).
Comment: @JonathanLeffler It seems that the return value from `strcmp()` should be negated before returning it in this case, i.e. change `return strcmp(a1->suff, b1->suff) < 0? 1 : 0;` to `return -strcmp(a1->suff, b1->suff);`. Alternatively, the arguments of `strcmp` could be swapped to negate the result: `return strcmp(b1->suff, a1->suff);`.
Comment: ds778104,  Tip: `int *suffixArr = (int*)malloc(n * sizeof(int));` --> `int *suffixArr = malloc(sizeof suffixArr[0] * n);`.  No cast,  size to object, not type, sizeof first.
Comment: @IanAbbott: If, as seems plausible but is not stated, the requirement is for a sort in descending alphabetic order, then yes, you're right — the return value from `strcmp()` needs to be negated.  It would have been helpful if the question was an [MCVE] and had included the desired output as well as the actual output.
Comment: @WeatherVane Thanks for that answer. I am trying to implement this into a dictionary.txt file and am having no luck. I have read the file into a buffer and am trying to implement the above code but it isnt working. Any suggestions?
Comment: @JonathanLeffler It looked like the code was trying to sort in descending order (based on returning 1 when a<b), but in the linked-to problem it looks like it should be sorting in ascending order. The linked-to C++ code uses `std::sort()` which has different rules than `qsort()` for the comparison function (return `true` if first argument less than second argument). So a comparison function for C++ `std::sort()` is no good for C `qsort()`. OP just (more or less) copied the comparison function from the C++ code without adapting it properly for use with `qsort()`.
Answer: Summarizing the comments in the question from Weather Vane and Jonathan Leffler:

OP is passing the wrong element size to qsort(). qsort(suffixes, n, sizeof(int), cmp); should be qsort(suffixes, n, sizeof suffixes[0], cmp);. (Weather Vane).
The cmp function must return a negative value if the first argument sorts before the second argument, zero if they sort equal, or a positive value if the first argument sorts after the second argument. OP's cmp function returns 1 if the first argument is less than the second argument, otherwise 0. This will screw up any sorting by qsort(). (Jonathan Leffler)

It appears that the cmp function written by OP was based on the C++ code from Suffix Array | Set 1 (Introduction). In particular, OP's return strcmp(a1->suff, b1->suff) < 0? 1 : 0; is based on the similar return strcmp(a.suff, b.suff) < 0? 1 : 0; in the C++ code. The problem is that the C++ code uses std::sort(), not qsort() and the rules for the return value of the comparison functions are different.
As Jonathan Leffler points out, it would be sufficient for OP's cmp function to return the value from strcmp() directly:
    return strcmp(a->suff, b->suff);

OP's printArr() function prints the integers in the array with no separation between each number. The correction is trivial.

Suffix array using qsort() and strcmp


Changing blocks based on visitor's country

Question: On a Drupal 6 site I am trying to display blocks on my site based on user's country.

To do this I had to install  'IP to Country' module
Updated IP to Country
Created a new block and added the following code into the block body to print the user's country code:
<?php
$co=module_invoke('ip2cc','get_country',$_SERVER['REMOTE_ADDR'];);
print($co->country_code);
?>

Then, under 'Show block on specific pages' selected 'Show if the following PHP code returns TRUE (PHP-mode, experts only).' and then added the below mentioned code, so that the block is displayed based on the country ID.
<?php $co->country_code == "IN" ?>

After doing all these the block is getting disabled for the ID mentioned, eg: If 'IN' is mentioned the block should only be displayed for Indian visitors, but the block is actually being disabled.
Comment: did u load ip database?
Comment: Yes I did load the IP database, and confirmed by downloading the 'ip-to-country.csv' file.
Answer: Your code seems to be right. You've mis-spelled the module name in the module_invoke function at #3 and misplaced the semicolon ;
Try this:
<?php

$detectedcountry = module_invoke('ip2country','get_country',$_SERVER['REMOTE_ADDR']);
$us_canada = array(
  'US','CA'
);

//return true in block visibility when the country appears to be in detected country
if(in_array($detectedcountry,$us_canada)){
  return true;
}

?>

Comment: No need to say sorry ;-) Just put `return TRUE;` in your code at #4 after `if($co->country_code == 'IN')`.
Comment: I tried above mentioned code, but it is not working for me for 'IN' country code.
Comment: @AnAnD try to `print` the value of the `$detectedcountry` array in your custom module, using some `hook` (`hook_init` would help); and check to see it the countries are actually being loaded. Except that I don't think there might be a problem here.
Comment: btw, I am using http://drupal.org/project/ip2cc module and the module name is ip2cc
Comment: I am able to print the country code using the code that I have mentioned above.
Comment: @AnAnD : We both are completely on different pages :P
My solution would be applicable for http://drupal.org/project/ip2country and not for ip2cc
Comment: @AnAnD : IN the problem statement, you didn't return `TRUE` when the code is `IN`, that should be the reason of it not working.
Comment: I am sorry, I am installing the 'ip2country' module now
Comment: I tried, but no luck, below is the code:
`country_code);`

`if($co->country_code == 'IN'){`
`return true;`
`}`

`?>`


Are nested functions a bad thing in gcc ?

Question: I know that nested functions are not part of the standard C, but since they're present in gcc (and the fact that gcc is the only compiler i care about), i tend to use them quite often.
Is this a bad thing ? If so, could you show me some nasty examples ?
What's the status of nested functions in gcc ? Are they going to be removed ?
Answer: Nested functions really don't do anything that you can't do with non-nested ones (which is why neither C nor C++ provide them). You say you are not interested in other compilers - well this may be atrue at this moment, but who knows what the future will bring? I would avoid them, along with all other GCC "enhancements".
A small story to illustrate this - I used to work for a UK Polytechinc which mostly used DEC boxes - specifically  a DEC-10 and some VAXen. All the engineering faculty used the many DEC extensions to FORTRAN in their code - they were certain that we would remain a DEC shop forever. And then we replaced the DEC-10 with an IBM mainframe, the FORTRAN compiler of which didn't support any of the extensions. There was much wailing and gnashing of teeth on that day, I can tell you. My own FORTRAN code (an 8080 simulator) ported over to the IBM in a couple of hours (almost all taken up with learning how to drive the IBM compiler), because I had written it in bog-standard FORTRAN-77.
Comment: Nested functions can access variables of the function in which they are declared. How do you manage this with non-nested functions?
Comment: Nested functions are useful; they give the programmer some of the benefits of anonymous lambdas (for example, less painful use of functions taking other functions as arguments, less code duplication), without the overhead of allocating closures. Given the ubiquity of GCC, the risk of using a non-standard GNU extension is not comparable to relying on a feature which was implemented in a non-portable compiler for a single brand of machine. And, because the scope of the nested functions is purely local, modules using the feature can still be linked to modules produced by any other compiler.
Comment: nested functions are also useful because you can limit the scope of it. For example why expose a helper function for just another function to all others in the file? Also less parameter passing in complex cases, because you can just use the parent function's variables as global ones
Comment: @LB I doubt there is anything bad about the implementation - they are (like I said) simply not necessary.
Comment: @MatthewMitchell: the problem is how to pass the function like an argument to another. See [this example](https://github.com/sisoputnfrba/so-commons-library/blob/846af05d3b4a2beb3ac8026f66c1d1a2c73f20c8/tests/unit-tests/test_list.c#L265-269): how can you work around that without nested functions?
Comment: I really understand this argument, but is there something fundamentally bad about the implementation of these nested functions ? Or does it break some kind of C philosophy  ?
Comment: I am working on a big embedded project and I am finding the embedded extreme save of time, clarity of code .. basically it overrides the need for ugly boilerplate code when dealing with callback-based API design.
Comment: @mgarciaisaia Pass the variables to the function? If it's a lot of data you are dealing with you could pass a pointer to a structure. But I can understand how a Java-like callback system could be nice, though it surely isn't necessary.
Comment: Nested functions are *extremely* useful in embedded processing environments or wherever stack space is at a premium.  See https://stackoverflow.com/a/44601897/558639
Comment: @vlopez What ubiquity, now that LLVM is preferred over GCC on many platforms?
Answer: Like most programming techniques, nested functions should be used when and only when they are appropriate.
You aren't forced to use this aspect, but if you want, nested functions reduce the need to pass parameters by directly accessing their containing function's local variables.  That's convenient.  Careful use of "invisible" parameters can improve readability.  Careless use can make code much more opaque.
Avoiding some or all parameters makes it harder to reuse a nested function elsewhere because any new containing function would have to declare those same variables.  Reuse is usually good, but many functions will never be reused so it often doesn't matter.
Since a variable's type is inherited along with its name, reusing nested functions can give you inexpensive polymorphism, like a limited and primitive version of templates.
Using nested functions also introduces the danger of bugs if a function unintentionally accesses or changes one of its container's variables.  Imagine a for loop containing a call to a nested function containing a for loop using the same index without a local declaration.  If I were designing a language, I would include nested functions but require an "inherit x" or "inherit const x" declaration to make it more obvious what's happening and to avoid unintended inheritance and modification.
There are several other uses, but maybe the most important thing nested functions do is allow internal helper functions that are not visible externally, an extension to C's and C++'s static not extern functions or to C++'s private not public functions.  Having two levels of encapsulation is better than one.  It also allows local overloading of function names, so you don't need long names describing what type each one works on.
There are internal complications when a containing function stores a pointer to a contained function, and when multiple levels of nesting are allowed, but compiler writers have been dealing with those issues for over half a century.  There are no technical issues making it harder to add to C++ than to C, but the benefits are less.
Portability is important, but gcc is available in many environments, and at least one other family of compilers supports nested functions - IBM's xlc available on AIX, Linux on PowerPC, Linux on BlueGene, Linux on Cell, and z/OS.  See
 http://publib.boulder.ibm.com/infocenter/comphelp/v8v101index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fnested_functions.htm
Nested functions are available in some new (eg, Python) and many more traditional languages, including Ada, Pascal, Fortran, PL/I, PL/IX, Algol and COBOL.  C++ even has two restricted versions - methods in a local class can access its containing function's static (but not auto) variables, and methods in any class can access static class data members and methods.  The upcoming C++ standard has lamda functions, which are really anonymous nested functions.  So the programming world has lots of experience pro and con with them.
Nested functions are useful but take care.  Always use any features and tools where they help, not where they hurt.
Answer: There are times nested functions can be useful, particularly with algorithms that shuffle around lots of variables.  Something like a written-out 4-way merge sort could need to keep a lot of local variables, and have a number of pieces of repeated code which use many of them.  Calling those bits of repeated code as an outside helper routine would require passing a large number of parameters and/or having the helper routine access them through another level of pointer indirection.
Under such circumstances, I could imagine that nested routines might allow for more efficient program execution than other means of writing the code, at least if the compiler optimizes for the situation where there any recursion that exists is done via re-calling the outermost function; inline functions, space permitting, might be better on non-cached CPUs, but the more compact code offered by having separate routines might be helpful.  If inner functions cannot call themselves or each other recursively, they can share a stack frame with the outer function and would thus be able to access its variables without the time penalty of an extra pointer dereference.
All that being said, I would avoid using any compiler-specific features except in circumstances where the immediate benefit outweighs any future cost that might result from having to rewrite the code some other way.
Answer: As you said, they are a bad thing in the sense that they are not part of the C standard, and as such are not implemented by many (any?) other C compilers.
Also keep in mind that g++ does not implement nested functions, so you will need to remove them if you ever need to take some of that code and dump it into a C++ program.
Comment: that's funny, they mention the paper Lexical closures for C++ but do not implement the extension in g++
Comment: Unfortunately C and C++ standard committees are completely different, even the common compiler toolkits like GCC and Clang use the same backend for C and C++
Comment: @SwiftMango GCC and Clang use the same backend as each other? Or GCC and Clang use their own respective backends to serve both C and C++?
Comment: @JamesM.Lay The latter.
Answer: Nested functions can be bad, because under specific conditions the NX (no-execute) security bit will be disabled.  Those conditions are:

GCC and nested functions are used
a pointer to the nested function is used
the nested function accesses variables from the parent function
the architecture offers NX (no-execute) bit protection, for instance 64-bit linux.

When the above conditions are met, GCC will create a trampoline https://gcc.gnu.org/onlinedocs/gccint/Trampolines.html.  To support trampolines, the stack will be marked executable.  see: https://www.win.tue.nl/~aeb/linux/hh/protection.html
Disabling the NX security bit creates several security issues, with the notable one being buffer overrun protection is disabled.  Specifically, if an  attacker placed some code on the stack (say as part of a user settable image, array or string), and a buffer overrun occurred, then the attackers code could be executed.
Comment: You already said this, but it bears repeating: no trampoline is generated (and ergo no security risk) *unless* the code takes the address of a nested function.  For many styles of programming, this is rare.
Answer: update
I'm voting to delete my own post because it's incorrect.  Specifically, the compiler must insert a trampoline function to take advantage of the nested functions, so any savings in stack space are lost.
If some compiler guru wants to correct me, please do so!
original answer:
Late to the party, but I disagree with the accepted answer's assertion that

Nested functions really don't do anything that you can't do with
non-nested ones.

Specifically:
TL;DR: Nested Functions Can Reduce Stack Usage in Embedded Environments
Nested functions give you access to lexically scoped variables as "local" variables without needing to push them onto the call stack.  This can be really useful when working on a system with limited resource, e.g. embedded systems.  Consider this contrived example:
void do_something(my_obj *obj) {
    double times2() {
        return obj->value * 2.0;
    }
    double times4() {
        return times2() * times2();
    }
    ...
}

Note that once you're inside do_something(), because of nested functions, the calls to times2() and times4() don't need to push any parameters onto the stack, just return addresses (and smart compilers even optimize them out when possible).
Imagine if there was a lot of state that the internal functions needed to access.  Without nested functions, all that state would have to be passed on the stack to each of the functions.  Nested functions let you access the state like local variables.
Comment: Unless someone can show that my `update` comment is incorrect, I propose to delete this post on the basis that it is simply wrong.
Answer: I agree with Stefan's example, and the only time I used nested functions (and then I am declaring them inline) is in a similar occasion.
I would also suggest that you should rarely use nested inline functions rarely, and the few times you use them you should have (in your mind and in some comment) a strategy to get rid of them (perhaps even implement it with conditional #ifdef __GCC__ compilation).
But GCC being a free (like in speech) compiler, it makes some difference... And some GCC extensions tend to become de facto standards and are implemented by other compilers.
Another GCC extension I think is very useful is the computed goto, i.e. label as values. When coding automatons or bytecode interpreters it is very handy.
Answer: Nested functions can be used to make a program easier to read and understand, by cutting down on the amount of explicit parameter passing without introducing lots of global state.
On the other hand, they're not portable to other compilers. (Note compilers, not devices. There aren't many places where gcc doesn't run).
So if you see a place where you can make your program clearer by using a nested function, you have to ask yourself 'Am I optimising for portability or readability'.
Answer: I'm just exploring a bit different kind of use of nested functions. As an approach for 'lazy evaluation' in C.
Imagine such code:
void vars()
{
  bool b0 = code0; // do something expensive or to ugly to put into if statement
  bool b1 = code1;

  if      (b0) do_something0();
  else if (b1) do_something1();
}

versus
void funcs()
{
  bool b0() { return code0; }
  bool b1() { return code1; }

  if      (b0()) do_something0();
  else if (b1()) do_something1();
}

This way you get clarity (well, it might be a little confusing when you see such code for the first time) while code is still executed when and only if needed.
At the same time it's pretty simple to convert it back to original version.
One problem arises here if same 'value' is used multiple times. GCC was able to optimize to single 'call' when all the values are known at compile time, but I guess that wouldn't work for non trivial function calls or so. In this case 'caching' could be used, but this adds to non readability.
Answer: I need nested functions to allow me to use utility code outside an object.
I have objects which look after various hardware devices. They are structures which are passed by pointer as parameters to member functions, rather as happens automagically in c++.
So I might have
    static int ThisDeviceTestBram( ThisDeviceType *pdev )
    {
        int read( int addr ) { return( ThisDevice->read( pdev, addr ); }
        void write( int addr, int data ) ( ThisDevice->write( pdev, addr, data ); }
        GenericTestBram( read, write, pdev->BramSize( pdev ) );
    }

GenericTestBram doesn't and cannot know about ThisDevice, which has multiple instantiations. But all it needs is a means of reading and writing, and a size. ThisDevice->read( ... ) and ThisDevice->Write( ... ) need the pointer to  a ThisDeviceType to obtain info about how to read and write the block memory (Bram) of this particular instantiation. The pointer, pdev, cannot have global scobe, since multiple instantiations exist, and these might run concurrently. Since access occurs across an FPGA interface, it is not a simple question of passing an address, and varies from device to device.
The GenericTestBram code is a utility function:
    int GenericTestBram( int ( * read )( int addr ), void ( * write )( int addr, int data ), int size )
    {
        // Do the test
    }

The test code, therefore, need be written only once and need not be aware of the details of the structure of the calling device.
Even wih GCC, however, you cannot do this. The problem is the out of scope pointer, the very problem needed to be solved. The only way I know of to make f(x, ... ) implicitly aware of its parent is to pass a parameter with a value out of range:
     static int f( int x )
     {
         static ThisType *p = NULL;
         if ( x < 0 ) {
             p = ( ThisType* -x );
         }
         else
         {
             return( p->field );
         }
    }
    return( whatever );

Function f can be initialised by something which has the pointer, then be called from anywhere. Not ideal though.
Answer: Nested functions are a MUST-HAVE in any serious programming language.
Without them, the actual sense of functions isn't usable.
It's called lexical scoping.
Comment: which means most of the existing languages are not for "serious programming"!!


Commerce line item not referenced by the orders

Question: We have a strange situation here where some Commerce Line Items exist in the database, referencing orders through their order_id property, but that aren't referenced by the order through it's field line_items (field_data_commerce_line_items table). Views listing line items show these although when looking at their respective orders they aren't appearing. It is causing wrong calculation of these view.
Is there any explanation as why these line items still exist and can they be deleted safely?
I can display these line using the following SQL request :
<code>SELECT * FROM `commerce_line_item` cli
LEFT OUTER JOIN field_data_commerce_line_items fdcli on fdcli.entity_id = cli.order_id AND fdcli.`commerce_line_items_line_item_id` = cli.line_item_id
LEFT JOIN field_revision_commerce_line_items frcli ON frcli.`commerce_line_items_line_item_id` = cli.line_item_id
WHERE fdcli.entity_id IS NULL;
</code>
[EDIT]
I changed the the request to reference to revision table. It does happens that some lines are referenced in a revision, but most are not.
Comment: What about `field_revision_commerce_line_items`?
Comment: Changed the request, but not much enlightment comes from it :(
Answer: This typically happens when an administrator adds a line item to an existing order via the order edit form and doesn't submit the form. The line item has already been created, but the order hasn't been updated to reference it. We refer to these as orphaned line items, and they're safe to delete as needed.
I implemented a much better approach with Inline Entity Form, which defers any write action for referenced entities until the form is submitted, but last I tried its line item support wasn't fully functional for the site I was working on. May be better now.
Comment: Thanks for the answer, I'll try to validate if the site administrators did add such line.


AP Statistics exam

Question: I have a good handle on probability theory, at least I understand the book I 1st course in probablity by Ross.
However, I am having a hard time understanding Statistics, I got a prep book to teach me but it seems to be just logical deductions are given as the reason for why $\frac{\sigma}{\sqrt{n}}$ for the st.dev of a sample for a random sample.
I am asking for any good books online that would give some more mathematical reason why statistics work.
My level: I read and mostly understood the book listed above.
I am studying for the AP Statistics exam.
Comment: Also see [Free statistical textbooks](http://stats.stackexchange.com/q/170/2981) for other online resources for studying statistics.
Comment: Does this answer your question? [Path to mathematical statistics without analysis background: ideal textbook for self study](https://stats.stackexchange.com/questions/160261/path-to-mathematical-statistics-without-analysis-background-ideal-textbook-for)
Comment: What is the difference between a "logical deduction" and a mathematical proof?
Answer: There are many challenges for most learning statistics (which I think you rightly have noticed is not like learning probability or other math.)
Expecting there are mathematical reasons why statistics work is one misperception to get over. There are logical reasons why it works (in hard to fully grasp ways) that can be displayed in mathematics but also in physics. In fact one of the earliest to grasp the logic of Bayesian analysis - Francis Galton - did that by building and running a physical machine a two stage Quincunx.

Stigler, Stephen M. 2010. Darwin, Galton and the statistical
  enlightenment. Journal of the Royal Statistical Society: Series A
173(3):469-482.

I am interested in working this up, for high school and even grade school students - but not there yet. One thing I am worried about is that an ability to be very abstract is likely a requirement - but you seemed to have that. Have a good look at Fig 5 in the reference above and think about it carefully. I have made an animation of that in a PDF here. You need to play with the forward and rewind buttons to play it.

AP Statistics exam