Storing user responses to questionnaires using controllers in Ember

Question: I'm using Ember to create a profiler app (like one of those personality quizzes you sometimes get in magazines). It presents a series of 10 questions, each with 7 multiple choice answers, with each answer having a different allocated score. Each response gets added up to a score out of 100. Users will eventually be able to store their answers, so they can redo it at a later date to see if they've improved.
But being (very) new to Ember, I have got stuck on collecting and storing a users responses as individual records.
My problem is that I use a QuestionsController to load in the question from a Fixture (Question), together with its possible Answer (a separate, related Fixture).
So when someone clicks on an answer (e.g. using a button, but when I've got my head round it I'll probably use radio buttons), it's capturing their response... but what do I do with it next?
I thought the best approach would be to have a separate ResponseController that created records of the individual responses (which I could then total), but Ember expects the captured responses to be handled by the QuestionsController, not the ResponseController (which is what I think SHOULD be doing it).
I can't seem to get my head around how to do this, particularly how all the different parts of Ember fit together and interact across controllers.
The Javascript
// Models

App.Question = DS.Model.extend ({
label: DS.attr('string'),
    answers: DS.hasMany('App.Answer')
    });

App.Answer = DS.Model.extend ({
    question: DS.belongsTo('App.Question'),
    label: DS.attr('string'),
    value: DS.attr('number')
});

App.Response = DS.Model.extend ( {
    question:   DS.attr('string'),          // Question_id that was responded to
    score:      DS.attr('number'),          // The score of the selected answer
    answer:     DS.belongsTo('App.Answer')  // The answer
    });

// Controllers

App.QuestionsController = Ember.ArrayController.extend( {

    select: function( question, score, answer ) {

    // this next bit is clearly not right, but I don't know why...
        App.Response.storeResponse( question, score, answer );

    }
});

App.ResponseController = Ember.ObjectController.extend( {

    storeResponse: function( question, score, answer ) {

    // this next bit is clearly not right, but I don't know why.
        createRecord ( { question: question, score: score, answer: answer  } );
    }
});

The HTML

Progress
I have the templates working fine; it displays the questions and answers correctly (or at least as I'd expect). The button is capturing the correct response. But I really don't know how to get the data from there into storage.
The responses I get in the console vary (depending on my attempts to solve) from "Undefined" to "Can't find variable storeResponse".
Answer: You can use the needs api to communicate across controllers. For instance you can declare that the QuestionController needs access to the ResponseController with,
needs: ['response'],
responseBinding: 'controllers.response',

Ember will then inject the response controller instance into the QuestionController which can be accessed with this.get('response'). Then your select action handler can invoke storeResponse on it.
select: function( question, score, answer ) {
  var controller = this.get('response');
  controller.storeResponse(question, score, answer);
}

Comment: Thank you for such a clear answer and example. I will come back and let you know the outcome.
Comment: It works! I had been getting lost as many of the examples I had found were either deprecated or only provided snippets that didn't explain how to apply it properly. Thank you again.


Does Frequentist statistics still make sense when the experiment is not repeatable?

Question: Frequentist statistics is based on the idea that probability should be viewed objectively, that an event's probability is the limit of its relative frequency in many trials, and that probabilities can be found by a repeatable objective process.
Given this, does frequentist statistics still make sense if an experiment cannot be repeated in practice? To give a very simple example. Suppose I have a vase and I want to measure its mass $M$ using a somewhat unreliable scale that gives me readings of $X=M+\epsilon$ where $\epsilon \sim N(0,1)$. I obtain measurements $X_1,X_2,\dots,X_n$ on which I do frequentist inference (calculate the maximum likelihood, confidence intervals of $M$ etc.), all well and good. However, suppose then I accidentally break my vase and the pieces are not retrievable, then is frequentist inference still valid? The whole idea of confidence intervals for example relies on the idea that upon repeated experiments, a 95% confidence interval will capture the true value of the parameter 95% of the time, but if I can only ever do the experiment once, how is the confidence interval meaningful?
The above example is obviously very artificial and stupid but there are countless situations in the real world where repeated experiments or collections of the same datasets is not possible. For example, data that was specific to a particular time in the past, like if you're trying to infer the net CO2 emissions on earth in the year 2005 based on data collected in 2005. In those situations, how does frequentist statistics justify itself? Or should one concede to Bayesian inference when repeat experiments/recollection of data is not possible?
Comment: Simple answer, Yes. We start with a (admittedly idealized) model. Take your vase example. Pre-sample, under the model we know that the confidence procedure with random sampling produces CIs covering the parameter 95% of the time. No actual repetitions are required. Also, if you look at a large number of independent 95% CIs from different problems then if their underlying models were valid (a big ask) approximately 95% would contain their respective parameters.
Comment: @SextusEmpiricus. The accepted answer in your linked question is  an off-topic Bayesian commentary on p-values.
Comment: @GrahamBornholt When there are three close votes or a binding close vote (diamond moderator or someone with a gold badge for a question tag), that kind of comment automatically disappears, since the information is contained in the closure message.
Comment: @GrahamBornholt I'm not sure why you made this your business but it's me who first suggested the duplicate. If you read that thread carefully, you'll notice that it has two answers. And the second answer, although not the accepted one, explains nicely that's the theory is based on the repeatability of statistical procedure, not the repeatability of the data.
Comment: @dipetkov I'm not sure everyone has access to the closure messages. // I second your take that the second answer is a good one.
Comment: @GrahamBornholt Care to post that as an answer?
Comment: ok, though haven't addressed the last para.
Comment: Does this answer your question? [Is a frequentist approach to inference appropriate when working with non-repeatable data?](https://stats.stackexchange.com/questions/304810/is-a-frequentist-approach-to-inference-appropriate-when-working-with-non-repeata)
Comment: What makes inference valid or meaningful? Does it matter whether it is frequentist or Bayesian, or does it matter what you do with it?
Comment: @123456 It is unfortunate that your question was closed. It is a much better question than the "duplicate question", only the titles look similar. As soon as I made my comment about the off-topic nature of the accepted answer to that question (see above), Sextus Empiricus deleted the comment and the question was closed.
Comment: Your duplicate comment was first. I also agree with the second answer in that question as a good anwer for that question. My only comment was about the accepted answer in that question as being a hopeless answer to this question.
Comment: @dipetkov I also think that this question deserves an answer since the question is more detailed about confidence intervals.
Comment: @GrahamBornholt you may not accept the answer to the other question, but that doesn't make the question non-duplicate?
Comment: As an answer to the question here one could write an answer with a quote to [BigBendRegion's answer](https://stats.stackexchange.com/a/529697) in that other post.
Comment: If this question was still closed, no such answer would be possible. In such a case, we would be forced to answer this question as an answer in the other question when that question already has an accepted answer. Meta question, do members typically keep adding new answers once an answer has been accepted?
Comment: I gave the third vote to the non-accepted answer to the other answer because I thought it was a good one, but I also gave an answer to this one because IMHO it was a sufficiently different question and because my answer here hopefully clarifies some common misunderstandings regarding CIs on this site.
Comment: @GrahamBornholt if a better answer is possible to the question *"Is a frequentist approach to inference appropriate when working with non-repeatable data?"* then it can be better posted under that other question rather than under a new post with basically the same question *"Does Frequentist statistics still make sense when the experiment is not repeatable?"*. It is not very convenient for such multiple questions to exist. Especially because of the subjective nature where more different answers may occur that would be nice to have in a single place.
Comment: @SextusEmpiricus I'm uncomfortable with these (pseudo) philosophical questions, and frankly, about taking them seriously by writing an answer. These are deep questions that have inspired serious thinkers to write whole books. Even the most carefully written 3 paragraphs seem to me to only create the illusion of having answered the question. And most importantly one can do great and meaningful statistical analysis even though the deep philosophical questions haven't been fully answered (by anyone) yet.
Answer: You have hit on the major challenge to the frequentist interpretation
As a preliminary observation, the usual examples of non-repeatable events used for this question relate to predictions of one-off things like the outcome of an election.  Unlike your vase example, these are situations where the event of interest is not repeatable, even in principle.  For example, if a polling firm was previously attempting to determine the probability that Obama would beat Romney in the 2012 US election, what is the frequentist interpretation of the probablity of this one-off event (in the non-repeatable context in which it occurs)?  I will make reference to these kinds of events rather than your vase event, since they better capture the philosophical issue you are raising.

What you have hit on here is really the main philosophical challenge made against the frequentist interpretation of probability.  We often wish to make probabilistic predictions in relation to one-off events that occur in a very specific context and which cannot be repeated in the same context.  Much of the discipline of predictive analysis applies to one-off events and probability and statistics seems like a natural discipline to use to inform such prediction.  For example, a polling company might want to determine the probability that Obama will beat Romney in the 2012 election.  (Imagine asking this question in, say, late October of 2012, when we don't yet know the answer.)  But what, if anything, would the "probability" of this one-off event mean in the frequentist paradigm?  Even if people were to run the presidential election between Obama and Romney over and over again, after the first time it would never again occur under the same political context as the one that was of actual interest (and so it would not really be a repitition of the same election).  So the question to the frequentist is: Can we use probability in such cases, and if so, how can it be accorded the frequentist interpretation?
Frequentists have generated two main answers to this challenge.  One answer to this challenge is that we shouldn't use probability in such contexts and that the attempt to do so is illusory because the event under consideration is non-repeatable even in principle.  This view delimits the application of probability and statistics and says that it should only be applied in a relatively narrow class of problems where we have events that are (at least in principle) repeatable.  In that case it is possible to deploy the frequentist interpretation with respect to the infinite sequence of repititions that is (in principle) possible.  Another answer to this challenge is to invoke the metaphysical hypothesis of a "multiverse" and say that any event that is a one-off event in our own universe is just one manifestation of an infinite set of outcomes under the same context that occur (or in principle could occur) in parallel universes.  This view claims that any event is (in principle) repeatable by virtue of the fact that other outcomes were possible and that all possible outcomes occurs in "some universe".  As you can see, these issues stray into philosophical territory and raise questions about the admissibility and sensibleness of speculating on unobserved (and unobservable) repititions of an experiment or event.  There may be other answers I'm unfamiliar with, but they would probably be variations of these two general strategies (i.e., either delimit the scope of application of probability, or somehow assert that all events are repeatable in principle).
While I would encourage you to read more broadly on philosophy and probability to learn more about this topic, my own view is that neither of the above responses of the frequentist viewpoint are satisfactory.  My view is that the frequentist approach to probability cannot explain probability in all contexts and so should not be seen as a valid basis for probability theory.  The more sensible approach is to view probability as an epistemological concept --- a decision-making tool developed to assess uncertainty, subject to some important measurement and consistency desiderata.  As I've noted in many other posts (see e.g., here and here), the frequentist interpretation is valid to the extent that it essentially just asserts the LLN --- all practitioners of all philosophical schools that use probability accept the LLN and thereby accept the frequentist interpretation in contexts where it applies.
Comment: Thank you for your very detailed answer! The reason I used the examples I did is that mass is an objective quantity that should have a true value and be inferable under the frequentist paradigm. The probability of winning a specific election on the other hand seems a lot more like a social construct and therefore seem to make more sense in a Bayesian framework. Would you say even in the case when the parameter is something like mass, the frequentist interpretation is still unsatisfactory if the experiment in principle can't be repeated (like mass of CO2 emissions on earth in 2005)?
Answer: Simple answer, yes the frequentist approach is still viable. We start with a (admittedly idealized) model. Take your vase example. Pre-sample, under the model we know that the confidence procedure with random sampling produces CIs covering the parameter 95% of the time. No actual repetitions are required. Also, if you look at a large number of independent 95% CIs from different problems then if their underlying models were valid (a big ask) approximately 95% would contain their respective parameter.
Regarding your real life example using past one-off data, the question is whether it is reasonable to treat the data as if it was a realization from an underlying model with random variables. For this to give valid frequentist inferences, you would also need to make sure that the choice of model by you was made before you saw the actual data.
Comment: Suppose you had a suite of possible models available to you, and you looked at the data first and noticed one fit very well. That could be more of a curve-fitting exercise, and can invalidate inferences based on the same data (I am sure some will object to this proviso). Your last question is unanswerable I think. How close is close enough, and remember the model is an idealized model anyway. In statistics, everything is provisional given our currently available knowledge.
Comment: Sorry can you elaborate a bit more on what you mean by 'you would also need to make sure that the choice of model by you was made before you saw the actual data'? Also a separate question if you don't mind, does the likelihood you've chosen have to be the 'correct' one in some sense for the inference to be valid?


Implementing folder redirection with mutiple profiles per workstation

Question: We have an existing 2003 server with a mixture of XP and Windows 7 workstations. Users are advised to store documents on network drives so that they are backed up. However, some staff just store documents locally (surprise, surprise).
To try to safeguard this local data, the proposal is to implement folder redirection for MyDocuments and Desktop (and perhaps Application Data). At the moment, we are only really concerned about backups, and are not too bothered that staff have the same desktop, etc, when they log on to different workstations. Although that might be a useful byproduct.
Some members of staff log into multiple workstation each with a set of local documents, etc. (eg when working from different offices). Also, many workstations have multiple profiles, because they have been used by lots of different staff.
Do I need to consolidate all the "MyDocuments", etc. across the workstation into one folder per user profile, before before implementing folder redirection? Otherwise, how can the server resolve duplicates, etc.
Or is there a simpler way to solve the backup problem?
All advice appreciated.
Thanks
Answer: Please could you ellaborate a little more?
How many machines are we talking about?
Are the other offices on the domain? Are these "local documents" standard files all users should have, which are supposed to be read only templates on a central share?
I would definately sort out the disperate files to a central (user drive maps, etc) first. I suspect this cultural issue will be your biggest hurdle.
Folder redirection can be enabled to move contents of Desktop/Docuemtents to new location but for that to be useful the user would have to log on to every PC they ever used to ensure that all the "desktop" and "documents" files get moved/merged to the server. Therefore it would probably be prudent to get users to manually tidy up files to the network location then enable folder redirection without moving content to the new location. They can then continue to use the network location and if they slip up and start using the Desktop and Documents folders you can rest assured they are redirected to the server and backed up.
I would also first disable offline files on the shares (caching setting) unless you have laptop users who need this - in which case separate the laptops and PCs with OUs and use Group Policy to enable offline files for laptops and disable offline files for PCs. Make sure all PCs rebooted and offline files disabled is in force before redirecting folders or they start to sync! Just another feature which has its uses but can be a headache if trying to keep things simple.
To solve the backup issue without redirection you could script the workstations to run periodic copies of Desktop and Documents folders to a server share. I wouldn't recommend that due to space concerns, necessity for workstation to be switched on, etc.
Comment: Thanks for the response. There are approx 25 workstations, all on the same domain. The "local documents" are private to each user and are mostly standard office documents. I think you are right that the "cultural change" might be the biggest problem. In partcicular one manager has his own workstation, then his PA has another workstation which is also logged in under the manager's username. How will this work with central storage? What if they both create a document with the same name?


Como colocar um overflow numa div com script para deixar listas fixas no cabeçalho?

Question: Olá, estou tentando acrescentar um overflow:scroll no meu projeto, mas isso invalida o script que deixa a div marker fixa no topo até chegar na próxima div.
http://jsfiddle.net/5cC83/5/
Se tirar o overflow:scroll do css na .divContexto o código funciona corretamente com a div .marker ficando fixa no topo da div contexto ao rolar a página. Mas como terão vários blocos na pagina que irei criar eu preciso fazer funcionar mesmo com overflow:scroll.
Alguém poderia me ajudar a solucionar o problema?
Answer: Você poderia colocar uma div a mais englobando a .divContexto para que o pai tenha o scroll?
Em jQuery você poderia fazer algo como
$(".divContexto").wrap("rolagem");

E no CSS a div .rolagem que teria o scroll.


Are we frequentists really just implicit/unwitting Bayesians?

Question: For a given inference problem, we know that a Bayesian approach usually differ in both form and results from a fequentist approach. Frequentists (usually includes me) often point out that their methods don't require a prior and hence are more "data driven" than "judgement driven". Of course, Bayesian's can point to non-informative priors, or, being pragmatic, just use a really diffuse prior.
My concern, especially after feeling a hint of smugness at my fequentist objectivity, is that perhaps my purportedly "objective" methods can be formulated in a Bayesian framework, albeit with some unusual prior and data model. In that case, am I just blissfully ignorant of the preposterous prior and model my frequentist method implies?
If a Bayesian pointed out such a formulation, I think my first reaction would be to say "Well, that's nice that you can do that, but that's not how I think about the problem!". However, who cares how I think about it, or how I formulate it. If my procedure is statistically/mathematically equivalent to some Bayesian model, then I am implicitly (unwittingly!) performing Bayesian inference.
Actual Question Below
This realization substantially undermined any temptation to be smug. However, I'm not sure if its true that the Bayesian paradigm can accommodate all frequentist procedures (again, provided the Bayesian chooses a suitable prior and likelihood). I know the converse is false.
I ask this because I recently posted a question about conditional inference, which led me to the following paper: here (see 3.9.5,3.9.6)
They point out Basu's well-known result that there can be more than one ancillary statistic, begging the question as to which "relevant subset" is most relevant. Even worse, they show two examples of where, even if you have a unique ancillary statistic, it does not eliminate the presence of other relevant subsets.
They go on to conclude that only Bayesian methods (or methods equivalent to them) can avoid this problem, allowing unproblematic conditional inference.

It may not be the case that Bayesian Stats $\supset$ Fequentist Stats -- that's my question to this group here. But it does appear that a fundamental choice between the two paradigms lies less in philosophy than in goals: do you need high conditional accuracy or low unconditional error:

High conditional accuracy seems applicable when we have to analyze a singular instance -- we want to be right for THIS particular inference, despite the fact that this method may not be appropriate or accurate for the next dataset (hyper-conditionality/specialization).

Low unconditional error is appropriate when if we are willing make conditionally incorrect inferences in some cases, so long as our long run error is minimized or controlled. Honestly, after writing this, I'm not sure why I would want this unless I were strapped for time and couldn't do a Bayesian analysis...hmmm.

I tend to favor likelihood-based fequentist inference, since I get some (asymptotic/approximate) conditionality from the likelihood function, but don't need to fiddle with a prior - however, I've become increasingly comfortable with Bayesian inference, especially if I see the prior a a regularization term for small sample inference.
Sorry for the aside. Any help for my main problem is appreciated.
Comment: an edit to the post seems to have messed up the link, but there isn't enough information for me to fix it.
Comment: @DikranMarsupial thanks for noticing that. I added back in the link.
Answer: Bayesians and Frequentists do not only differ in how they obtain inferences, or how similar or different these inferences can be uncertain certain prior choices. The main difference is how they interpret probability:
Bayesian probability:

Bayesian probability is one interpretation of the concept of probability. In contrast to interpreting probability as frequency or propensity of some phenomenon, Bayesian probability is a quantity that is assigned to represent a state of knowledge, or a state of belief.

Frequentist probability:

Frequentist probability or frequentism is a standard interpretation of probability; it defines an event's probability as the limit of its relative frequency in a large number of trials. This interpretation supports the statistical needs of experimental scientists and pollsters; probabilities can be found (in principle) by a repeatable objective process (and are thus ideally devoid of opinion). It does not support all needs; gamblers typically require estimates of the odds without experiments.

These two definitions represent two irreconcilable approaches to defining the concept of probability (at least so far). So, there are more fundamental differences between these two areas than whether you can obtain similar estimators or same conclusions in some parametric or nonparametric models.
Comment: I don't think they are completely irreconcilable, a long run frequency is a perfectly reasonable basis for a state of knowledge or belief.
Comment: @DikranMarsupial This is actually an open problem in philosophy of science. I see your point, but the reconciliation is not that straightforward.
Comment: Thanks Pollo. I agree with you that Frequentists and Bayesians interpret probability differently. As I stated in my preamble, I am focusing not on what they think about probability, but the mechanics of doing inference. If every frequentist inference method has a Bayesian analog (isomorphism, mathematically speaking), then frequentist inference is $functionally$ equivalent to Bayesian inference, regardless of philosophical differences.
Comment: surely frequentist would be functionally equivalent if there were also a frequentist analog for every Bayesian procedure, which can't be true as Bayesians can talk of probabilities for things without long run frequencies, but frequentists can't.
Comment: @DikranMarsupial yes, that's why I asked if fequentist are a subset of Bayesian (I acknowledged that the converse is known to be false).
Comment: @DikranMarsupial perhaps more accurately, I should say that each frequentist procedure has an equivalent Bayesian analog...not that the two approaches are equivalent (the implication is uni-directional, if at all).
Comment: @Bey, Ah, "equivalent" implies both directions for me, hence the misinterpretation.
Comment: Bayesian statistics can certainly be used to make inferences about long run frequencies, so to some extent it is about the way the question is posed.
Comment: @DikranMarsupial I think my question is rather unambiguous...for a given frequentist inference procedure, does there exist a bayesian procedure that, given the same data, will lead to the same inferences. If so, then thay are functionally equivalent.
Answer: I would argue that frequentists are indeed often "implicit/unwitting Bayesians", as in practice we often want to perform probabilistic reasoning about things that don't have a long run frequency.  The classic example being Null Hypothesis Statistical Testing (NHST), where what we really want to know is the relative probabilities of the Null and Research Hypotheses being true, but we cant do this in a frequentist setting as the truth of a particular hypothesis has no (non-trivial) long run frequency - it is either true or it isn't.  Frequentist NHSTs get around this by substituting a different question, "what is the probability of observing an outcome at least as extreme under the null hypothesis" and then compare that to a pre-determined threshold.  However this procedure does not logically allow us to conclude anything about whether H0 or H1 is true, and in doing so we are actually stepping out of a frequentist framework into a (usually subjective) Bayesian one, where we conclude that the probability of observing such an extreme value under H0 is so low, that we can no longer believe that H0 is likely to be true (note this is implicitly assigning a probablility to a particular hypothesis).
Note it isn't actually true that frequentist procedures don't have subjectivity or priors, in NHSTs the threshold on the p-value, $\alpha$, serves much the same purpose as the priors $p(H_0)$ and $p(H_1)$ in a Bayesian analysis.  This is illustrated by the much-discussed XKCD cartoon:

The main reason the frequentists conclusion is unreasonable is that the value of $\alpha$ does not represent a reasonable state of knowledge regarding the detector and/or solar physics (we know that it is extremely unlikely that the sun has exploded, and rather less so that the detector has a false alarm).  Note in this case the conclusion that the sun has exploded inferred from a low p-value (a Bayesian inference) but is not logically entailed by it.  The subjectivity is still there, but not stated explicitly in the analysis and often neglected.
Arguably confidence intervals are often used (and interpreted as) an interval in which we can expect to see the observations with a given probability, which again is a Bayesian interpretation.
Ideally statisticians ought to be aware of the benefits and disadvantages of both approaches and be prepared to use the right framework for the application at hand.  Basically we should aim to use the analysis that provides the most direct answer to the question we actually want answered (and not quietly substitute a different one), so a frequentist approach is probably most efficient where we actually are interested in long-run frequencies and Bayesian methods where that is not the case.
I suspect that most frequentist questions can be answered by a Bayesian as there is nothing to stop a Bayesian from answering questions like "what is the probability of observing a result at least as extreme if $H_0$ is true", however I'll need to do a bit of reading on that one, interesting question.
Comment: I think it works as a criticism of "null ritual" statistics, where NHSTs are used as a recipe from the statistics cookbook without thinking/understanding the procedure (probably including me when I started out ;o).
Comment: I agree with your analysis of this cartoon. It's funny, but I sometimes see people bringing it up as some argument against frequentist statistics and that's just silly. "Extraordinary claims require extraordinary evidence"; no sane frequentist statistician would be willing to take some meager $p<0.05$ evidence to support such an extraordinary claim as here.
Comment: I think a big problem with NHST is less the ritualized p<0.05 and more that it artificially restricts the space of hypotheses. I mean, they are not considering (as hypotheses) the numerous other reasons that it would be dark other than "the sun exploded". This is what I really dislike about NHST...it's so conservative towards the null. Also, I wonder what the power of this test would be?
Comment: IMHO the main value of NHSTs is as a sanity-check hurdle to stop us getting overly excited about our research hypothesis, so favouring the null is perhaps not such a bad thing.  The p-value fallacy (interpreting it as the probability that $H_0$ is true) is another major problem (again caused by a it being treated as a direct answer to the question we want answered). p<0.05 is a reasonable sanity check for many practical applications, but not universal.  ISTR there is a good quote from Fisher about this depending on the nature of the analysis, but I can never find it when I want it!
Comment: @DikranMarsupial agree! Fisher envisioned them assisting with agricultural experiments, which is where the p-value came from. Evaluating pesticides and fertilizers is nothing like evaluating non-replicable existential questions...wrong tool for the job.
Comment: *"NHST, where what we really want to know is the relative probabilities of the Null and Research Hypotheses being true..."* Bayesians do, but not Frequentists! Often we know the Null is false, but not whether we collected enough data to get estimates with adequate precision. Consider a CI for a difference in means. If I'm not confident that the CI is all >0 or all <0, then I need more data to be confident about the sign of the effect, even if I never believe the effect could be 0. "Fail to reject Null" = "there's too little data to estimate this parameter well, so let's not try w/o more data."
Comment: And re: the XKCD cartoon, I believe (hope?) that no sensible Frequentist would do NHST in a setting where sample size is irrelevant to the test's outcome :)
Comment: @civilstat sadly I think there are plenty who would follow the "null ritual" in just such a manner.  I'm afraid that scientists actually *do* want to know if their hypothesis is probably true, which is why there are interpretation problems when they use frequentist rather than Bayesian tests. Outside quality control, it seems to me that generally we are asking the Bayesian question, rather than the frequentist one as we are interested in the results of a specific experiment.
Comment: @DikranMarsupial Yes, many sadly follow the null ritual :) But among "Bayesians who know what they're doing" and "Frequentists who know what they're doing," the *intentions* behind NHST are completely different. I agree with you that a Freq can't say model A is more likely than B, which is what a Bayesian gets. But Freq NHST asks "Do I have enough data?" which is *also* a question scientists care about. And Freq's broader question "Does this method work on most datasets?" is also of interest---even Bayesians seem to care about calibration in most settings.
Comment: @civilstat Unfortunately power calculations seem very rare in practice (but perhaps field-dependent).  Bayesians can formulate the "how much data do I need" question as well, because Bayesians can ask all the same questions that frequentists can, because they have a less restrictive definition of probability.


Firebase observer not working, why won't it keep a watch on the value change?

Question: I am trying to set a Firebase observer by calling the following:
ref.child(id).child("isLocked").observe(.value, with: { snapshot in

    print("isLocked = ", snapshot.value!)

})

When the view loads it works perfectly. It prints out the correct value.
When I go change the value either in Firebase itself or on a separate device the isLocked is never printed again. When it should be since I have an observer on the path. What gives?
The end goal here is to have a UIButton available based on if the lock value is true of false.
The view is loaded with the button.isHidden = true.
UPDATE
I found the source of my issue with observer not "Working"
It would seem that there is a timing issue.
In the previous view controller (which segues into the new view controller) I am calling ref.child(pID).child("isLocked").removeAllObservers() in the 'viewDidDisappear' function
And in the new view controller I am 'trying' to setup the same path observer 'ref.child(id).child("isLocked").observe(.value, with: { snapshot in'
which I guess the removeAllObservers() trumps the setup of the new observer!? How do I get over this!?
Comment: Can you include the minimal code that shows how you change the database on the other device?
Comment: @FrankvanPuffelen I'm going directly in Firebase and changing the lock value from true to false and vise versa and nothing happens.
Comment: @FrankvanPuffelen I also added more detail to what I am trying to achieve with the `lock` value switching to true or false
Comment: That's very uncommon. Are you sure you're changing the `isLocked` under the correct ID? Also note, since you said "or on a separate device" I assumed you could also make the change in code, which makes it easier to see what's going on.
Comment: @FrankvanPuffelen yes... if I put the observer on `.childChanged' it does work!? but again its only on change.... I have no clue why it wont take on .value!?
Comment: @FrankvanPuffelen i updated the question, it seems like its a timing issue with removing the previous VC observer and trying to create the new observer in the new VC. How can I fix that, if you know!?
Comment: Changing the type of listener won't make a difference. The `value` event fires when the data at or under the reference or query changes. I'm not sure what the race condition is. It's hard to give a specific answer without seeing the minimal code that reproduces it.
Comment: @FrankvanPuffelen see my response and you can try it yourself. Using the `ref.child(pID).child("isLocked").removeAllObservers() in the viewDidDisappear` in the first view controller and calling the same 'path' `ref.child(pID).child("isLocked")` in the view controller segued to will not allow the observer to set. This may be a Firebase issue.
Comment: You might want to check when `viewDidDisappear` and the new view controller run. I expect you'll find that the `viewDidDisappear` fires last (since the new view needs to show before the old one can disappear), and thus your call to `removeAllObservers` happens after you attach the listener in the new view.
Comment: Here's the issue; the code we need to see is not included in your question and the code included in your question is somewhat unrelated to the question. *When the view loads it works perfectly. It prints out the correct value.* which may be because it's being called during the loading process. However, if your view goes out of scope, so does that code so it would not be called if you change the value within the Firebase console. However, that's just a guess. Please take a moment and review [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)
Answer: I found the source of my issue with observer not "Working"
It would seem that there is a timing issue.
In the previous view controller (which segues into the new view controller) I am calling ref.child(pID).child("isLocked").removeAllObservers() in the viewDidDisappear function
And in the new view controller I am 'trying' to setup the same 'path observer' ref.child(id).child("isLocked").observe(.value, with: { snapshot in.
Which I guess the removeAllObservers() trumps the setup of the new observer!?
To remedy this you need to setup specific handles per observer! Make sure to use unique var names and no reuse and then call the following instead of removeAllObservers():
ref.child(id).child("isLocked").removeObserver(withHandle: confirmVCRefHandle!)

the above handle name confirmVCRefHandle is unique and the timing issue is overcome!
Comment: "I guess the removeAllObservers() trumps the setup of the new observer!?" Nope, that seems very unlikely. The two calls are unrelated, and Firebase has no knowledge of the views in your app. More likely is that your` removeAllObservers()` call happens after you've registered the observer in the new view, hence that observer is immediately removed.
Comment: @FrankvanPuffelen I am in agreement, thus why I said its a 'timing' issue. But as I wrote in my 'response' the need to ensure you use unique handles is require since, and you also stated, the viewDidDisappear and the new view controller run. I expect you'll find that the viewDidDisappear fires last (since the new view needs to show before the old one can disappear), and thus the call to removeAllObservers happens after attaching the listener in the new view.
Answer: Try this:
ref.child(id).observe(.childChanged, with: { snapshot in

    if snapshot.key == "isLocked" {
        if let value = snapshot.value as? Bool {
            print(value)
        }
    }
})

Comment: Observing on `.childchanged` won't start the listener until after the value changes as least once. So it does not work for my use case.
Comment: Also I changed the value in Firebase directly and the observer did not listen for the change.
Comment: Yeah. In my project I use both .childChanged and .childAdded. And .childRemoved too.
I believe only .childAdded loads all values when it starts and later adds only added then items.
Comment: .value will reduce your code and not require .childAdded, .childChanged and in the instance there is .childRemoved


How should one handle a javax.persistence.OptimisticLockException?

Question: I'm new to JPA so forgive me if not being clear.
Basically I want to prevent concurrent modifications by using Optimistic Locking.
I've added the @Version attribute to my entity class.
I need to know if this algorithm on handling OptimisticLockException is sound.
I'm going to use the Execute Around Idiom like so:
<code>interface UpdateUnitOfWork
{
    doUpdate( User user ); /* may throw javax.persistence.PersistenceException */
}

public boolean exec( EntityManager em, String userid, UpdateUnitOfWork work)
{
    User u = em.find( User, userid );
    if( u == null )
        return;

    try
    {
        work.doUpdate( u );
        return true;
    }
    catch( OptimisticLockException ole )
    {
        return false;
    }
}

public static void main(..) throws Exception
{
    EntityManagerFactory emf = ...;
    EntityManager em = null;

    try
    {
        em = emf.createEntityManager();

        UpdateUnitOfWork uow = new UpdateUnitOfWork() {
            public doUpdate( User user )
            {
                user.setAge( 34 );
            }
        };

        boolean success = exec( em, "petit", uow );
        if( success )
            return;

        // retry 2nd time
        success = exec( em, "petit", uow );
        if( success )
            return;

        // retry 3rd time
        success = exec( em, "petit", uow );
        if( success )
            return;
    }
    finally
    {
        em.close();
    }
}
</code>
The question I have is how do you decide when to stop retrying ?
Answer:
The question I have is how do you decide when to stop retrying ?

In my opinion, Optimistic Locking should be used when modifying the same object in the same time is an exceptional situation.
Now, if this situation occurs, and if the process was manual, I would  warn the user that the modifications couldn't be saved and ask him to save his changes again.
If the process is automated, it can make sense to implement an automatic retry mechanism but I wouldn't retry more than something like 3 or 5 times, depending on the processing time (and I'd use recursive calls to implement this). If an automated process fails 5 times in a row on an concurrent access problem, then it is very likely competing with another automated process and they are either not working on independent chunks of data (which is bad for parallelization) or the strategy is just not the right one. In both case, retrying more is not the right solution.


For continuous $g$, prove that $1+\left(\int^{1}_{0}g^2(x)dx\right)^3>\left(\int^{1}_{0}g(x)\right)^3$

Question:
If $g:[0,1]\rightarrow \mathbb{R}$ be a continuous function Then
  Prove that $$1+\bigg(\int^{1}_{0}g^2(x)dx\bigg)^3>\bigg(\int^{1}_{0}g(x)dx\bigg)^3$$

My attempt:
$\bullet\;\; $If $|g(x)|\geq 1,$ Then $\displaystyle \int^{1}_{0}g^2(x)dx\geq \int^{1}_{0}g(x)dx$
$$\bigg(\int^{1}_{0}g^2(x)dx\bigg)^3\geq \bigg(\int^{1}_{0}g(x)dx\bigg)^3$$
$$1+\bigg(\int^{1}_{0}g^2(x)dx\bigg)^3> \bigg(\int^{1}_{0}g(x)dx\bigg)^3$$
$\bullet\; $ If $|g(x)|<1,$ Then $\displaystyle 1>\bigg(\int^{1}_{0}g(x)dx\bigg)^3$
$$1+\bigg(\int^{1}_{0}g^2(x)dx\bigg)^3>\bigg(\int^{1}_{0}g(x)dx\bigg)^3$$
Thus, I've proven the claim. Please comment on my solution.
If the above is wrong, then how can I fix it?
Comment: What if $g(x)$ attains (absolute) values both smaller and larger than 1 on the interval $[0,1]$?
Comment: @jacky The problem is that when you take each case, say, $|g(x)| \le 1$, you're still doing $\int_{[0,1]} g(x) dx$ and not something like $\int_{[0,1] \cap A} g(x) dx$ where $A = \{x \in [0,1] | |g(x)| \le 1\}$. What you've done is show the inequality is true first for the case when the image of $g$ is a subset $(-\infty,-1] \cup [1,\infty)$ and second for the case when the image of $g$ is a subset of $(-1,1)$. But these two cases are not the only possible cases. The image of $g$ could be like $[-7,\frac12]$, a subset of neither $(-\infty,-1] \cup [1,\infty)$ nor $(-1,1)$.
Comment: i did not understand . Can you give me one example
Answer: Your proof is wrong because you may have $|g(x)| \geq 1$ for some values of $x$ and $|g(x)| < 1$ for some other values of $x$.
Here is  a valid proof: By Holder's/ Cauchy-Schwarz inequality $(\int_0^{1} g(x) dx)^{2} \leq \int_0^{1} g^{2}(x)dx$. So it remains to see that $y^{3/2} <1+y^{3}$ where $y =\int_0^{1} g^{2}(x)dx$. Now consider the function $f(y)=1+y^{3} -y^{3/2}$. Check that this function attains its minimum of $[0, \infty)$ at the point $y=\frac  1{2^{2/3}}$ and that the value at this point is $>0$. Hence $f(y) >0$ for all $y$.  That finishes the proof.
Comment: @JohnSmithKyon $(\int_0^{1} g(x)dx)^{2}=(|\int_0^{1} g(x)dx|)^{2}\leq (\int_0^{1} |g(x)|dx)^{2}\leq (\int_0^{1} |g(x)|^{2}dx)$
Comment: Why $\left(\int_0^1 g dx\right)^2 \le \int_0^1 g^2 dx$ and not $\left(\int_0^1 |g| dx\right)^2 \le \int_0^1 g^2 dx$ ?
Answer: The problem: When you take each case, say, $|g(x)| \le 1$, you're still doing $\int_{[0,1]} g(x) dx$ and not something like $\int_{[0,1] \cap A} g(x) dx$ where $A = \{x \in [0,1] | |g(x)| \le 1\}$. What you've done is show the inequality is true first for the case when the image of $g$ is a subset $(-\infty,-1] \cup [1,\infty)$ and second for the case when the image of $g$ is a subset of $(-1,1)$. But these two cases are not the only possible cases. The image of $g$ could be like $[-7,\frac12]$ (I believe the image has to be a closed interval), a subset of neither $(-\infty,-1] \cup [1,\infty)$ nor $(-1,1)$. Try $g$ as the line from the point (not interval!) $(0,-7)$ to the point (not interval!) $(1,\frac12)$.
What I think it sounds like you want to try to do: Decompose $g$ into $g = g1_A + g1_{A^c}$ where $1_B: [0,1] \to \mathbb R$ is indicator function on the set $B$.

For example, $|x| = |x|1_{(-\infty,0)} + |x|1_{[0,\infty)}$ $= (-x)1_{(-\infty,0)} + (x)1_{[0,\infty)}$ because $|x|1_{(-\infty,0)}$ $= (-x)1_{(-\infty,0)}$ and $|x|1_{[0,\infty)}$ $= (x)1_{[0,\infty)}$
Maybe this could work, but I think it's a big headache. For example, try expanding $(g1_A + g1_{A^c})^3$.

Typically: The way to go about problems like these is to use an inequality that relates the square of an integral $(\int_a^b g(x) dx)^2$ to the integral of a square $\int_a^b g^2(x) dx$ or more generally the power of an integral $(\int_a^b g(x) dx)^p$ to the integral of a power $\int_a^b g^p(x) dx$. I believe the most common are Minkowski's inequality, Hölder's inequality and the Cauchy–Bunyakovsky–Schwarz inequality.
Let's try the following version of Hölder's inequality:

Let $a,b \in \mathbb R$ with $a < b$. Let $f,g: [a,b] \to \mathbb R$
  be functions that are continuous over their common domain $[a,b]$. Let
  $p,q \in [1,\infty)$ with $\frac1p + \frac1q = 1$
$$\int_a^b |fg| dx \le \left(\int_a^b |f|^p dx\right)^{\frac1p} \left(\int_a^b |g|^q dx\right)^{\frac1q}$$

By choosing $f$ as the constant function with value $1$ and choosing $p=q=2$, we get:
$$\int_a^b |g| dx \le \left(b-a\right)^{\frac12} \left(\int_a^b |g|^2 dx\right)^{\frac12} = \left(b-a\right)^{\frac12} \left(\int_a^b g^2 dx\right)^{\frac12}$$
Assuming $b-a=1$, we get:
$$\int_a^b |g| dx \le \left(\int_a^b g^2 dx\right)^{\frac12} \tag{A}$$
$\int_a^b |g| dx \ge 0$ since $|g|(x):=|g(x)| \ge 0$ for all $x \in [a,b]$. Then $(A)$ is equivalent to $(B)$ as follows:
$$\left(\int_a^b |g| dx\right)^2 \le \int_a^b g^2 dx \tag{B}$$
Anyway, I think I won't really use $(B)$. Raising both sides of $A$ to $3$, we get:
$$\left(\int_a^b |g| dx \right)^3 \le \left(\int_a^b g^2 dx\right)^{\frac32} \tag{C}$$
Since $g(x) \le |g|(x):=|g(x)|$ for all $x \in [a,b]$, $\int_a^b g dx \le \int_a^b |g| dx $ and then:
$$\left(\int_a^b g dx \right)^3 \le \left(\int_a^b |g| dx \right)^3 \tag{D}$$
Combining $(C)$ and $(D)$, we get:
$$\left(\int_a^b g dx \right)^3 \le \left(\int_a^b g^2 dx\right)^{\frac32} \tag{E}$$
If we somehow show $(F)$ as follows, then combining $(E)$ and $(F)$ and letting $a=0$ and $b=1$ yields the desired inequality.
$$\left(\int_a^b g^2 dx\right)^{\frac32} \le 1 + \left(\int_a^b g^2 dx\right)^3 \tag{F}$$
To show $(F)$: Let $c \in \mathbb R$. The inequality $c^{\frac 32} \le 1+c^3$ is true if (and only if I guess) $c \ge 0$. Here, we have $c=\int_a^b g^2 dx \ge 0$ since $(g^2)(x):=(g(x))^2 \ge 0$ for all $x \in [a,b]$.
Remark: The desired inequality is true for $0$ and $1$ replaced with, respectively, $a$ and $b$ for any real numbers $a$ and $b$ where $b-a=1$
How to prove $c^{\frac 32} \le 1+c^3$ if $c \ge 0$ without wolfram alpha: Consider the function $f: [0,\infty) \to \mathbb R$, $f(c) := 1+c^3 - c^{\frac 32}$. We want to show that $image(f)=f([0,\infty)) \subseteq [0,\infty)$, i.e. $f(c) \ge 0$ for all $c \ge 0$. Observe that $f$ is second-differentiable. Then use first and second derivatives to show that $f$ has a global minimum at some point $(c_0,f(c_0))$. If $f(c_0) \ge 0$ (Note: Actually, $f(c_0)$ isn't zero, but even if it were, then that would be okay since we want to show $f \ge 0$ not $f > 0$), then $f(c) \ge f(c_0) \ge 0$ for all $c \in Domain(f) = [0,\infty)$


Use of generating function in combinatorial proof

Question: In Combinatorial proof of summation of $\sum\limits_{k = 0}^n {n \choose k}^2= {2n \choose n}$, the product
$\left(\sum_{a=0}^n\binom{n}{a}x^a\right)\left(\sum_{b=0}^n\binom{n}{b}x^{n-b}\right)=\sum_{c=0}^{2n}\left(\sum_{a+n-b=c}\binom{n}{a}\binom{n}{b}\right)x^c$
This approach uses a "generating function" and collects all the coefficients of $x^{c}$ for fixed $c$ into $\sum_{a+n-b=c}\binom{n}{a}\binom{n}{b}$,  to get $\sum_{c=0}^{2n}\left(\sum_{a+n-b=c}\binom{n}{a}\binom{n}{b}\right)x^c$
I know that $\left(\sum_{a=0}^n\binom{n}{a}x^a\right)\left(\sum_{b=0}^n\binom{n}{b}x^{n-b}\right)= \sum_{a=0}^{n}\sum_{b=0}^{n}\binom{n}{a}\binom{n}{b}x^{a+n-b}$, but it remains unclear how one can obtain  $\sum_{c=0}^{2n}\left(\sum_{a+n-b=c}\binom{n}{a}\binom{n}{b}\right)x^c$ from the initial product.
Answer: When $a,b$ run from $0$ to $n$, the sum $a+n-b$ runs from $0$ to $2n$, so you collect the coefficients.
More generally, the LHS is the product of two polynomials, say $(\sum_{k=0}^n a_kx^k)(\sum_{k=0}^n b_k x^k)$, of degree $n$, so their product will have degree $2n$. The coefficient of $x^c$ in the product for $0 \leq c \leq 2n$ is $\sum_{i=0}^c a_ib_{c-i}$ (this is easy to check).
Answer: Here we also have an application of the Cauchyproduct of series.

\begin{align*}
\left(\sum_{a=0}^n\binom{n}{a}x^a\right)\left(\sum_{b=0}^n\binom{n}{b}x^{n-b}\right)
=\sum_{c=0}^{\color{blue}{2n}}\left(\sum_{\color{blue}{{a+(n-b)=c}}\atop{a\geq 0,n-b\geq 0}}\binom{n}{a}\binom{n}{b}\right)x^c\tag{1}
\end{align*}

We have the (blue marked) upper limit $2n$ which comes from $x^ax^{n-b}=x^{a+n-b}$ if $a=(n-b)=n$, i.e. $a=n$ and $b=0$.
We have $x^c=x^ax^{n-b}$ with $0\leq c\leq 2n$. In order to get the coefficient $x^c=x^{a+(n-b)}$ we have the (blue marked) condition $a+(n-b)=c$ as lower limit in the inner sum.


How to describe a repeated measures GLMM?

Question: In this experiment cows were fed with two different types of grass (Treatment) and we measured the weight gain over time, keeping track of the individual's ID. Sex of the individual was also taken into account. I used GLMM to analyze the data, using (1+Sampling | ID) to account for the repeated measure design.
Weight gain ~ Treatment * sex + Sampling + (1+Sampling | ID)
My question is, how do you describe in a paper the random effect that accounts for the repeated measures? So far I have: "treatment, sex and sampling were included as fixed effects, as well as the interaction term between treatment and sex. Sampling and the individual's ID were included as random effects". But I think that last part is not accurate.
Thanks
Comment: Can you say more about `sampling`? I assume these are the time points when you measured weight. How many time points? Do you treat sampling as discrete or continuous? Were all cows measured at the same time points after starting the experiment? Also, what exactly is the outcome variable? The weight or difference in weight between consecutive measurements? Did you measure weight before the experiment started?
Comment: @dipetkov Correct, `sampling` is the time points when cows were weighted, which happened every 2 weeks for 6 months. The variable is treated as continuous.  All cows were weighted at the beginning of the experiment and they were all weighted at the same time during every sampling event. The response variable is the cumulative gain in weight since the beginning of the experiment.
Comment: It seems to me the random slope assumption is strong, esp. if the cows were adult cows. You have 12 measurements per cow and assume the relationship with time is linear. Why did you include the random slope? Have you made plots of the average/individual growth to evaluate this choice?
Answer: With your model formula:
Weight gain ~ Treatment * sex + Sampling + (1+Sampling | ID)

...you have described the fixed effects fine, but the random effects description should be expanded a little:
Something like: "Treatment, sex and Sampling were included as fixed effects, as well as the interaction term between Treatment and sex. Random intercepts were fitted for ID and random slopes were fitted for Sampling"
I would also suggest looking into the the comments by @dipetkov about fitting random slopes for Sampling (that should be a new question).


For random forest, what's the difference between out-of-bag error and k-fold cross validation?

Question: I am trying to forecast a time series using random forest.
In order to validate my model, I came cross two tests: OOB and K-fold cross validation. My question is:

For a time series, is out-of-bag error a out of sample test, does it make sense to test the accuracy "backward" using the historical data when I am trying to find the prediction accuracy?
What is the difference between holding the last few points of the data and do a out of sample test vs a OOB?
Comment: I think on ts or any other ordered data you can only have structured cv, i.e. take the first $n-k$ observations for training, the remaining $k$ for cross-validation
Comment: @Alex Agree. I read a few documents and people are referring out-of-bag "Prediction accuracy" indicator which confused me. Maybe OOB doesn't apply to time series after all ...
Comment: just use cross-validation error. In sklearn package you can use GridSearchCV class for this
Answer: OOB error will give a misleading indication of performance on a time-series dataset because it will be evaluating performance on past data using future data. This does not give a good indication of the model's ability to perform on future data. Therefore, use a methodology like TimeSeriesSplit.
By holding out future data points for model evaluation, you examine your model's ability to perform in the future. To build your intuition on why it's "cheating" to evaluate your forecasting ability using future data points: suppose I ask you to predict my weight a year from now, given measurements I took over the past 365 days. That might be challenging, unless you see a clear pattern. Now suppose that I ask you to predict my weight on day 155 of the 365 days I already recorded, and all I do is hold out day 155. You could easily estimate my weight as (w[154] + w[156]) / 2. You just took the average of the weights between two days. But did you forecast the future? (No.) Does a measurement of your success imply you can predict my future weight? (Certainly not!)


Prove that second partial derivatives does not depend on the order of differentiation

Question: I'm trying to prove that if
$$\dfrac{\partial^2 f}{\partial x \partial y} \quad \text{and} \quad  \dfrac{\partial^2 f}{\partial y \partial x}$$
are continuous in an open set containing $a \in \mathbb{R}^2$, then they are equal using the definition of derivative:
First, I say
$$ \dfrac{\partial^2f}{\partial x \partial y} = \dfrac{\partial}{\partial x} \left( \dfrac{\partial f}{\partial y} \right) = \dfrac{\partial}{\partial x} \left( \lim_{h \to 0} \dfrac{f(x,y+h)-f(x,y)}{h} \right) = \lim_{k \to 0} \dfrac{1}{k} \left( \lim_{h \to 0} \dfrac{f(x+k,y+h)-f(x+k,y)}{h} - \lim_{h \to 0} \dfrac{f(x,y+h)-f(x,y)}{h} \right) = \\ \lim_{k \to 0} \left( \lim_{h \to 0} \dfrac{f(x+k,y+h)-f(x+k,y)-f(x,y+h)+f(x,y)}{kh} \right) $$
Then I do the same thing for $ \dfrac{\partial^2 f}{\partial y \partial x} $, and I get
$$ \lim_{h \to 0} \left( \lim_{k \to 0} \dfrac{f(x+k,y+h)-f(x+k,y)-f(x,y+h)+f(x,y)}{kh} \right)$$
My question is: am I allow to say that those limits are equal because both
$$\dfrac{\partial^2 f}{\partial x \partial y} \quad \text{and} \quad  \dfrac{\partial^2 f}{\partial y \partial x}$$
are continuous on $a$, or do I need something extra?
Please let me know if the question is clear enough, or if I made some silly mistakes :)
Thanks in advance!
Comment: This is known as *Clairaut's Theorem*. Googling "proof of Clairaut's Theorem" yields many results including this one: http://www.math.ubc.ca/~feldman/m105/mixedPartials.pdf
Comment: For weaker result from the link there is [this pdf](http://cupid.economics.uq.edu.au/mclennan/Classes/Ec5113/ec5113-lec08-2.2.99.pdf)
Comment: FYI, the act of taking a derivative is called "differentiation," not "derivation."
Comment: @SantiMontouliu Please recall that if the OP is solved you can evaluate to accept an answer among the given, more details here https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work
Answer: Under these hypotheses the standard way to prove that is to consider some new auxiliary functions and use MVT theorem (refer to Schwarz's theorem).
The same result can be proved also under the hypotheses of the existence of $f_x(x,y)$ and $f_y(x,y)$ in the open domain and that $f_x(x,y)$ and $f_y(x,y)$ are differentiable at the point $a$.


Prove that $(n!)^ 2 \gt n^n$

Question: Prove the above by

by mathematical induction
By any other method.

I was just asked to prove this so I thought of using mathematical induction.
My effort :
I started first by verification and the inequality was true for n=3, 4...
Then the assumption step $(k!)^ 2 \gt k^k$
But after that while proving it for n=k+1 I was getting stucked inthe very next step.
Comment: See https://in.answers.yahoo.com/question/index?qid=20101228053634AAoodWA.
Answer: Assuming that $(k!)^ 2 \gt k^k$ we write
$$((k+1)!)^ 2 = (k!)^2 \cdot (k+1)^2 \gt k^k \cdot (k+1)^2. \tag {*}$$
Now we compare the RHS (*) with $(k+1)^{k+1}\ $:
$$\dfrac{(k+1)^{k+1}}{ k^k \cdot (k+1)^2}=\dfrac{(k+1)^{k}}{ k^k \cdot (k+1) }=\dfrac{1}{k+1} \cdot {\left(1+\dfrac{1}{k}\right)^{k}}. $$
Now using the binomial formula, we have for $k \geqslant {3}$
$$
\left(1+\dfrac{1}{k}\right)^{k}=1+k\cdot \dfrac{1}{k}+\dfrac{k(k-1)}{2!\ k^2}+\ldots+ \dfrac{k(k-1)\cdots(k-(k-2)) }{(k-1)!\ k^{k-1}}+\dfrac{k(k-1)\cdots2\cdot{1}}{k!\ k^{k}}\\
< 1+1+\dfrac{1}{2!}+\ldots+\dfrac{1}{(k-1)!}+\dfrac{1}{k!} \\
< 1+1+\dfrac{1}{2}+\ldots+\dfrac{1}{2^{k-1}}+\dfrac{1}{2^k} < 3,
$$
thus for $k \geqslant {3}$
$$\dfrac{1}{k+1} \cdot {\left(1+\dfrac{1}{k}\right)^{k}} < 1.$$
Therefore,
$$ k^k \cdot (k+1)^2 > (k+1)^{k+1}.$$
 Edit:
The multiplicative variant of Gauss's trick is very elegant. Writing squared factorial in the right and reverse order we have
$$(n!)^2 = [1\cdot 2  \cdots (n-1)\cdot n]\cdot[n\cdot (n-1)  \cdots 2\cdot 1]= \prod_{k=1}^{n}{k(n+1-k)} . $$
In order to show that each term ${k(n+1-k)} \geqslant n$ we consider
 $$k(n+1-k) - n = kn + k -k^2 - n = n(k-1) -k(k-1)=(k-1)(n-k) \geqslant 0$$
for $1 \leqslant k \leqslant n.$
Thus
$$\prod_{k=1}^{n}{k(n+1-k)}  \geqslant \prod_{k=1}^{n}{n} = n^n.$$
Comment: Can you also describe Gaussian's trick of multiplication variant.
Comment: I edited my answer.
Comment: Thanks for the explanation

Prove that $(n!)^ 2 \gt n^n$


Other options to "balance source" in haproxy

Question: I have haproxy listening on several ports and pointed at several backend servers.
Ideally, I would like it so that repeated communications to the same port get pointed at the same backend.
"balance source" isn't workable because often requests come from the same source.
Is this doable?
I'm also open to non-haproxy solutions. The protocol being used isn't important but is definitely not http. Just assume its ssh and you shouldn't go wrong.
EDIT: To clarify, imagine I have 10 'backend servers' and 5 'clients'. Each backend server can only ever cope with one connection at a time. I have more servers than required incase some become unavailable. I will manually point each client to the haproxy port(s). I want to ensure each client always gets to a backend server (which is simple) but preferably to the same one each time as long as it is available.
Answer: Here's how I solved my problem.
frontend name_of_frontend
    bind *:20000-20010
    default_backend     servers

backend servers
    balance roundrobin
    stick-table type integer size 1k expire 3h
    stick on dst_port
    server name ip-address check maxconn 1
    ...
    server name ip-address check maxconn 1

Willy warned in a previous answer's comment that it "will not guarantee that each client will go to a different port".
In my specific case, I have complete control over my 'clients'. The only reason I am pointing them at different ports on the proxy server is so that I can identify them as different clients. This is most definitely not a 'public' system.
Comment: This is precisely the solution I came here for. Thanks for sharing.
Answer: Haproxy does not implement ip:port persistence because in a proxy it doesn't make any sense. Doing this makes a lot of sense in a packet-based load balancer (eg: LVS) because it allows stateless load balancing with round-robin like distribution and persistence. But in a proxy, the connections are necessarily maintained on both ends from the beginning to the end. So I really don't know what you're trying to precisely achieve.
If what you need is just a destination port -> server relation, that looks quite strange, because you need to listen on far more ports than you have servers in order to get a smooth balancing. I'm really not sure you'd want to do that.
Comment: Just reread your latest comment. Yep that's probably what I'll end up doing. The only annoying bit is that I have (e.g.) 10 servers used to begin with and 5 'backups'. I don't have enough to give each server 1 backup, nor can I really put a backup on more than one server incase it is accessed twice.
Comment: Yes & I fully appreciate I'm nowhere near your standard use case. I'm just hoping I can 'bodge' a solution to a problem I have with haproxy seen as its already so close. With regards your number of ports > number of servers expectation, no that isn't true and I'll update my question.
Comment: hmmm reading about stick store-request/stick-table etc. etc. make me think this 'might' be possible...
Comment: Then dest port hashing will not guarantee that each client will go to a different port. What you'd better do then is to manually assign the servers to the ports. It would be a lot easier for your case.
Answer: I'm not an expert on haproxy, but I know it does have other load balancing options besides source (at a minimum it has round-robin).  I'd advise checking the HAProxy documentation to see what the capabilities and limitations are of each load balancing mode.
You can also achieve what you want by using the pf firewall (in one of its many incarnations -- pfSense is a good one if you need a GUI).  Set up load balancing on the firewall (round-robin or similar) with the sticky-address option set and you should have a workable setup.
Comment: Seems like the OP needs source "IP-Port" persistence, rather than just IP persistence. With HTTP, HAProxy can just insert a cookie with the serverid, and then use that to ensure the client sticks to one server. I'm not sure if it can do IP:Port, and AFAIK, LVS doesn't do this either.
Comment: @James If that's the case I'm pretty sure haproxy can't do IP:Port without the ability to tweak the protocol data -- I *THINK* pf can, but I've never tested it (The state table entries that are used to preserve the mapping include port numbers though, so it should work as expected)


Views expose filter of start and end dates

Question: I want an expose filter of start date and end date. I want to show the events that have start or end date between these two dates. If end date is not given in filter then display all the events having start date greater than filter's start date.
Answer: Add the filter like that :
<code>Start Date >= Filter's Stat Date

End Date <= Filter's End Date
</code>


Views 3 doesn't recognize a declared handler. Why not?

Question: In modules/addressfield/addressfield.module I have:
<code>/**
 * Implements hook_views_api().
 */
function addressfield_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'addressfield') . '/views',
  );
}
</code>
and
<code>/**
*  Implements hook_field_views_data_alter
*
* @param mixed $result
* @param mixed $field
*/
function addressfield_field_views_data_alter (&$result, $field) {
  if (array_key_exists('field_data_field_address', $result)) {
    $result['field_data_field_address']['field_address_country'] += array(
      'title' => t('Country'),
      'help' => t('The Country name of the field'),
      'field' => array(
        'handler' => 'addressfield_views_handler_field_country',
        'click sortable' => TRUE,
      ),
    );
  }
}
</code>
In modules/addressfield/views/addressfield.views.inc:
<code>/**
 * Implementation of hook_views_handlers().
 */
function addressfield_views_handlers() {
  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'addressfield') . '/views',
    ),
    'handlers' => array(
      'addressfield_views_handler_field_country' => array(
        'parent' => 'views_handler_field',
      ),
    ),
  );
}
</code>
This file doesn't get triggered in the debugger when I clear the cache. I don't understand this.
The handler is in modules/addressfield/views/addressfield_views_handler_field_country.inc which I took from the location module:
<code>/**
 * @file
 * Country field handler.
 */

class addressfield_views_handler_field_country extends views_handler_field {

  function option_definition() {
    $options = parent::option_definition();
    $options['style'] = array('default' => 'name');
    return $options;
  }

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['style'] = array(
      '#title' => t('Display style'),
      '#type' => 'select',
      '#options' => array('name' => t('Country name'), 'code' => t('Country code')),
      '#default_value' => $this->options['style'],
    );
  }

  function render($values) {
      return check_plain(strtoupper($values->{$this->field_alias}));
  }
}
</code>
Any advice on how to get this to work would be helpful. Thank you.
Comment: Just a general comment. The current api version of views itself is '3.0-alpha1', so you can't use 3. You should share your copy of views, because it's from the future ;)
Comment: I had this problem it showed in the logs as "Notice: Uninitialized string offset: 1 in views_get_handler()"  sticking here so if someone searches for that they will find this helpful page.
Comment: Just a tip: execute "drush vd" once ... this will show you some debug messages if handlers are missing somehow.
Answer: Which core version? In Drupal 7, hook_views_handlers() is gone, add your files to your .info file instead.
<code>files[]=views/addressfield_views_handler_field_country.inc
</code>
Comment: It actually says so in the Views advanced help pages (page "Upgrading to Drupal 7 (API)")
Comment: You'd think Drupal could emit a watchdog warning that it won't load the file because it's not whitelisted.  I should invoice Dries for the hours I've spent chasing this down.
Comment: In addition to the .inc file I also had to include my MYMODULE.views.inc file in my .info file.  Any reason why that might be?  If I don't include it then my views plugin is not detected.


Relation of $n$-th variation, Gâteaux and Fréchet derivatives

Question: Let $E$ be a Banach space, $U \subset E$ be an open subset of $E$ and $f: U \to \mathbb{R}$ a given function. For fixed $x_{0}, h \in E$, there exists $t_{0} \ge 0$ such that $x_{0} + (-t_{0},t_{0})h \subset U$. Thus, we can introduce a new function $F_{h}: (-t_{0},t_{0}) \to \mathbb{R}$ by setting $F_{h}(t) = f(x_{0}+th)$. Suppose $F_{h}$ is $N$ times differentiable on $(-t_{0},t_{0})$, so we can consider its Taylor expansion:
$$F_{h}(t) = F_{h}(0) + \sum_{n=1}^{N}\frac{t^{n}}{n!}F_{h}^{(n)}(0) + R_{N} $$
for all $t \in (-t_{0},t_{0})$. Here, $R_{N}$ is just the remainder coming from Taylor's expansion. The term $F_{h}^{(k)}(0)$ is called the $n$-th variation of $f$ at $x_{0}$ in the direction of $h$.
My question is: what is the relation between the $n$-th variation of $f$ at $x_{0}$ in the direction of $h$ and the Gâteaux and Fréchet derivative of $f$? I am guessing that, in order to establish such a relation, I have to assume that $f$ is $N$ times Fréchet or Gâteaux differentiable or that the $n$-th variation exists for all $h$?
Comment: One direction is simple: If $f$ is $n$-fold differentiable, then $ f^{(n)} (x_0)(h,\dots, h) = F_h^{(n)} (0)$. The other direction is in general false, since for example $F_h^{(1)}$ need not be linear in $h$.
Comment: @jd27 you mean Fréchet differentiable?
Comment: yes, of course (it is the "true" definition of differentiability).
Answer: It is easy to establish the equivalence of the following two statements:

$f$ is Gâteaux differentiable at $x_0$.
the first variation exists for all $h \in E$ and $h \mapsto F_h^{(1)}(0)$ is linear and continuous.

For higher order derivatives, we merely have that

$f$ is Gâteaux differentiable of order $n$ at $x_0$

implies that

the $n$-th variation of $f$ at $x_0$ exists for all $h \in E$ and $F_h^{(n)} = q(h,h,\ldots,h)$, where $q \colon E^n \to \mathbb R$ is multilinear, symmetric and continuous.

The converse does not hold, because we cannot infer differentiability of $f$ at points in a neighborhood of $x_0$. Indeed, consider $E = \mathbb R$ and something like
$$
x \mapsto x^3 g(x),
$$
where $g \colon \mathbb R \to [-1,1]$ is arbitrary. Then, $g$ possesses a second-order expansion at $x_0 = 0$, but may fail to be differentiable at $x \ne 0$.
Comment: Thanks. So, if $f$ is $n$ times Fréchet differentiable, it will be $n$ times Gâteaux differentiable and also the $n$-th variation of $f$ exists for all $h$, right? And then each $F_{h}^{(n)}(0)$ equals the $n$-th order Fréchet derivative.
Comment: Do you by any chance know a good reference where I can check the proofs of the results you mention?
Comment: Yes, Fréchet differentiability implies Gâteaux differentiability. As a reference, I can recommend the classical "Differential calculus" by Cartan.


Showing the following bound

Question:
My attempt. I split the inequality into a sum of two parts:
$$\mathbb{P}(S_N-\mu\le{-\delta\mu}) + \mathbb{P}(S_N-\mu\ge{\delta\mu})$$
rearranging to make the LHS of the inequality $S_N$ and applying chernoff bounds I obtained:
$\le(\frac{1}{1+\delta})^{\mu+\mu\delta}e^{\mu\delta}+(\frac{1}{1-\delta})^{\mu-\mu\delta}e^{-\mu\delta}$
but can't to bound this by anything that resembles the bound in the question.
Have I gone completely the wrong direction?
Answer: Applying the generic Chernoff bound, for $s>0$,
\begin{align}
\mathsf{P}(S_N\ge (1+\delta)\mu)&\le e^{-s(1+\delta)\mu}\prod_{i=1}^N\mathsf{E}e^{sX_i} \\
&\le e^{-s(1+\delta)\mu}\prod_{i=1}^N e^{(e^s-1)p_i} \\
&=e^{(e^s-1-s(1+\delta))\mu}
\end{align}
because for $x\in[0,1]$,
$$
e^{sx}\le 1+(e^s-1)x\le e^{(e^s-1)x},
$$
and $\sum_{i=1}^Np_i=\mu$. Finally, optimizing over $s$, one gets
$$
\mathsf{P}(S_N\ge (1+\delta)\mu)\le e^{-(\ln(1+\delta)(1+\delta)-\delta)\mu}\le e^{-c\mu\delta^2}
$$
for some constant $c>0$ ($\because\delta\in (0,1])$. The second bound can be found similarly.

Showing the following bound


WiredTiger storage engine reports a large number of rollbacks in MongoDB

Question: We have a MongoDB replication set consisting of three members:
        "members" : [
                {
                        "_id" : 6,
                        "host" : "10.0.0.17:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 2,
                        "tags" : {
                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 7,
                        "host" : "10.0.0.18:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 2,
                        "tags" : {
                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 8,
                        "host" : "10.0.0.19:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 2,
                        "tags" : {
                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
        ],

The cluster is under moderate load, not more than few tens of requests per second.
db.serverStatus() on a primary reports that almost all transactions are rolled back:
"transaction begins" : 2625009877,
"transaction checkpoint currently running" : 0,
"transaction checkpoint generation" : 22618,
"transaction checkpoint max time (msecs)" : 5849,
"transaction checkpoint min time (msecs)" : 153,
"transaction checkpoint most recent time (msecs)" : 1869,
"transaction checkpoint scrub dirty target" : 0,
"transaction checkpoint scrub time (msecs)" : 0,
"transaction checkpoint total time (msecs)" : 11017082,
"transaction checkpoints" : 22617,
"transaction checkpoints skipped because database was clean" : 0,
"transaction failures due to cache overflow" : 0,
"transaction fsync calls for checkpoint after allocating the transaction ID" : 22617,
"transaction fsync duration for checkpoint after allocating the transaction ID (usecs)" : 354402,
"transaction range of IDs currently pinned" : 0,
"transaction range of IDs currently pinned by a checkpoint" : 0,
"transaction range of IDs currently pinned by named snapshots" : 0,
"transaction range of timestamps currently pinned" : 8589934583,
"transaction range of timestamps pinned by the oldest timestamp" : 8589934583,
"transaction sync calls" : 0,
"transactions committed" : 30213144,
"transactions rolled back" : 2594972913,
"update conflicts" : 578

Basically, my questions are:
What is going on here? Is it normal to have so many transactions and so many rollbacks? If not, what is a root cause and hot to fix it?
Upd.: We upgraded to 3.6.8-2.0 (this was the latest Percona package in 3.6 series) and the problem persisted.
Answer: Many of the metrics in db.serverStatus().wiredTiger can be confusing since they are reflecting the underlying WiredTiger storage engine metrics and terminology rather than the MongoDB API. Terms like transactions, sessions, and rollbacks have a different context for storage internals than the end user MongoDB features. Some of the exposed metrics aren't very useful for end user monitoring, but they may provide diagnostic insight for developers familiar with the underlying storage API.

What is going on here?

The WiredTiger storage engine uses Multiversion Concurrency Control (MVCC) to provide concurrent access to internal threads that are reading and writing data. The MongoDB server has an integration layer which implements commands exposed via the MongoDB API (used by drivers) using the underlying storage engine API.
In the WiredTiger API there are internal sessions and transactions so that internal threads can work with a consistent snapshot of data. An internal transaction can end by being committed (data was written) or rolled back (transaction aborted intentionally or due to error).

Is it normal to have so many transactions and so many rollbacks?

Yes, this is normal. Readonly queries via the MongoDB integration layer use the WiredTiger transaction API for consistent reads, but since they never have data to commit the transactions are intentionally aborted and will add to the "transactions rolled back" metric.
The "transactions rolled back" metric can also be incremented for other use cases such as write conflicts (concurrent internal updates to the same document which will be transparently retried).

If not, what is a root cause and how to fix it?

This metric should not be a particular focus for concern or monitoring.


Best 'failover service' for windows which can monitor/start/stop services on 2 machines?

Question: Given the following situation:

2 machines (could be more, but 2 would already be great)
They both are configured exactly the same (same services are installed)
They can see each other in the network

Is there a service which I can install on both machines, and which do frequent alive checkes to the same service on the other machine? If they both see each other, the one with the highest priority wins and will enable (or keep enabled) all registered running processes. The other service will stop all registered services on their machine.
In case of failure of the high priority machine, the other system will detect this and start the services.
So in short: a failover service
I tried to find something like this on google but did not find anything.
I'm keen on finding an existing solution, otherwise I have to roll my own.
Answer: If you want a proper solution, you should look at either MSCS (if you have shared storage) or NeverFail/WanSyncHA/DoubleTake (google them and check out the whitepapers)
Manual scripts are OK for basic and very primitive stuff, but they might lead to serious data corruption, if they fail to mediate shared access, or fail to detect splitbrain and avoid it.
Comment: These solutions are in a league of their own. I agree that having things like that would be sweet, but for our situation it might be a bit overkill
Comment: mscs does exactly what I need. And the commenters (under my own answer) are right in that it is tricky to roll your own which works as reliable and good.
Answer: You could definiatly roll your own, maybe a powershell script and a scheduled task.
Otherwise, you could look at using Microsoft Clustering. You might need to do some research to see if your service supports it, it provides some other features which maybe harder to build yourself. e.g. Fail-back, resource grouping (your service, storage for the service, registry keys, networking).
Comment: I should have mentioned that the storage requires some type of shared storage setup (iSCSI,FC)
Comment: powershell doesn't seem like a bad idea actually. I've meaning to look into this and this could be a good reason ;^)   Any ideas on the best/easiest dev environment (with some basic syntax highlighting, intellisense?)?
Comment: powergui is my fav IDE, but MS have packaged one up with powershell2
Answer: ok... rolled my own.
Made a small .Net service app which does just what I described. With some syslog notifications  and possibility to notify people via sms in case of failovers.
I'll see and try to get it on codeplex or sourceforge for others to use/build upon
When this has happened I'll post the url here in the comments
Comment: wow. what was wrong with configuring a generic service in MSCS??
Comment: I highly disrecommend this method.  There are so many things which can go wrong that you may not have thought of.


$\mathbb{C}[t]$ module , module isomorphisms

Question:
If $V$ is a $\mathbb{C}$-vector space, and $a\in End \ V $, then we let $V_a$ be the $\mathbb{C}[t]$-module with ground set $V$ and scaling defined by: $$Pv=P(a)v, \ \ (P\in \mathbb{C}[t], \ v\in V)$$
i) Suppose $M$ is a $\mathbb{C}[t]$-module. Then there exist $V,a$ and a $\mathbb{C}[t]$-module isomorphism $f:M\rightarrow V_{a}$.
ii) Suppose $R= \mathbb{C}[t]/t^{2}\mathbb{C}[t]$ and let $M$ be a $R$-module. Then there exist $V,a$ so that $a^{2}=0$ and also a $R$-module isomorphism $f:M\rightarrow V_{a}$.

i) To show that this is true, we must find a module homomorphism which is one-to-one and onto. If $P(t)= b_{n}t^{n}+b_{n-1}t^{n-1}+...b_{1}t+b_{0}$ and one puts: $P(a)=b_{n}a^{n}+b_{n-1}a^{n-1}+...+b_{1}a+b_{0}I$, then $a^{n}$, where I is the identity and $a^{n}$ is the composition of a with itself ($va^{n}=(...(va)a...)a)$ This is then made into a $\mathbb{C}[t]$ module by: $P(t)v = P(a)v$.
How to construct the isomorphism $f: M\rightarrow V_{a}$?
ii) I know that there must be a vector space with  $a^{2}=0$ because the factorial ring contains $t^{2}\mathbb{C}[t]$, but I don't see how to show that it exists and also not how to construct a module isomorphism?
Would be glad if somebody could answer my questions.
Answer: I don't understand your remarks, so forgive me for not addressing them. It does seem like you know how the $V_a$ are constructed, which is good. We'll need that.
For both of these, note that $M$ is already a vector space over $\mathbf{C}$. The next thing to think about is whether the map $M \to M$ given by $x \mapsto tx$ is $\mathbf{C}$-linear. If it is, then I think you have found your $a$. The rest is just filling in details, but of course this can also be tricky—I'm certainly willing to say more.
Added. Let $V$ be $M$, viewed as a $\mathbf{C}$-vector space. View $a$ as a $\mathbf{C}$-linear map $V \to V$. We obtain a $\mathbf C[t]$-module $V_a$ by the construction you describe. You want to show that the map $M \to V_a$ which is the identity as a map of sets is actually $\mathbf C[t]$-linear; so check that for $P(t) \in \mathbf{C}[t]$, $x \in M = V_a$ we have
\[
P(t)x = P(a)x.
\]
This is really close to being a tautology!
Comment: Thank you Dylan Moreland. The map given by $x \mapsto tx$ is C-linear because  $t(zx) = z(tx)$ and $t(x+y)=t(x)+t(y)$. I can't undrstand where you are going with this. I would be very glad if you could show me.
Comment: @Tashi The plan is to have $V = M$ with this $\mathbf{C}$-linear structure, and to have $a$ as above: $a(x) = tx$. Can you check that this works?
Comment: Thank you @Dylan Moreland: If $P(t) = a_{n}t^{n}+....a_{0}$, then $P(a(x))=a_{n}(tx)^{n}+...+a_{0} $. Then by $P(t)v=P(a)v$ this is again a $\mathbb{C}[t]$ module. I don't think this is what you had in mind...
Comment: But a isn't a homomorphism (so also not a isomorphism): Since  a(x+y)= tx+ty = a(tx)+a(ty) but $txy = a(xy)\ne a(x)a(y)  = txty$?? So $a(x)=tx$ won't work...?
Comment: @Tashi It needs to be a homomorphism of _modules_, and really $M$ doesn't come with a notion of multiplication with itself.
Comment: So all that's left is to show that it is also a bijection? For ii) how can there be an a with $a^{2}=0 $ not equal 0 ?  Thank you.
Comment: @Tashi It's clearly a bisecting, because as a map of sets we just have the identity. You want to show that we get a map of $\mathbf C[t]$-modules. I will try to write this out later, but it's a bit tedious. For (ii), think about matrices like $\begin{pmatrix}0&1\\0&0\end{pmatrix}$.
Comment: Sorry... I am a little bit confused.
Comment: Er, that should be "bijection". Hurray for autocorrect.
Comment: @Tashi We could talk in chat about this sometime, if you want. I don't know if talking about each point in the comments is going to work!
Comment: That would be great. Thank you!!
Comment: @Tashi Hm. Trying to invite someone to a room seems impossible at the moment, so just drop into the main room sometime and say hello if you want to chat. I'm around pretty often.


Latent class analysis order classes

Question: I am performing a latent class analysis with covariates. I want to calculate the predicted probabilities for the membership to different classes. However, if the order of the classes changes (as I rerun the model) I obtain different results for the predicted probability of the same class but in a different order. Does anyone encountered this problem before? I increased the number of maximum iterations in the model, but it does not seem to help. Also the classes' composition changes slightly when I rerun the model.
f  <- cbind(a1, a2, a3, a4) ~ sex + age + age_sq + inc
lc <- poLCA(f, mydata, nclass=3, graphs=TRUE, maxiter=50000)

where a1, a2, a3, a4 and inc varies between 1 and 4.  This is the class composition, for example:
$a1
           Pr(1)  Pr(2)  Pr(3)  Pr(4)
class 1:
class 2:
class 3:

$a2
....

Comment: It is not a model for ordered classes. First, I estimate model a) as below. Then, I reestimate model a), but as you said algorithms for estimating LCA are randomized so class 1 in the first estimation would not necessarily correspond to class 1 in the second estimation but for example in the second estimation the same vector of probabilities would be called class 3. However, no matters how we call them, class 1 in the first estimation is identical to class 3 in the second estimation. Hence, I would expect that the predicted probabilities are the same for class 1 (1st est) and class 3(2nd est)
Comment: Since algorithms for estimating LCA are randomized: are you sure that the only thing that changes is not just the class labels (e.g. class 1 becomes class 2 and class 2 becomes class 1) ..?
Comment: Yes, I am sure.. There are different results for the predicted probability of the same class when it is in a different order. The estimation of the predicted probability should be the same, no matter which is class estimated first, right?
Comment: There are LCA models for ordered classes - are you using one of those? Also, for me it is not really clear what is your problem, so it would be good if you could provide more detailed description followed with an example of your problem.
Comment: Model a) : f <- cbind(a1 a2 a3 a4) ~ male + age+ age_sq + educ+ inc + married + wealth
lc <- poLCA(f, mydata, nclass = 3, graphs = TRUE, maxiter = 50000)
Comment: How much do the probabilities vary? Are the predicted classes exactly the same besides the probabilities? And also, what is your data? Please edit your question to add those information.
Answer: What you're describing isn't a "problem" per se. Since the three latent classes are unordered, their labeling is completely arbitrary. In any particular run of the poLCA function, it's normal for the labels on the latent classes (1, 2, or 3) to switch around, as they simply depend on what random starting points the poLCA function's estimation algorithm happened to select.  As long as each fit achieves the same maximum log-likelihood, the fitted models are all the same, regardless of how the class labels turn out.
For models with covariates, the label-switching will result in different coefficients on the predictor variables (although the class-conditional response probabilities will be the same).  This is because the latent class that's used as the baseline for calculating the covariate effects changes.  Again, though, the fit of the model is mathematically and substantively the same.
For more information on ordering latent classes, see section 5.6 of the poLCA user's manual at http://dlinzer.github.io/poLCA/. This section also describes the use of the poLCA.reorder() function for manually reordering the latent classes in your model.  If you are primarily interested in each observation's posterior class membership probabilities, see section 5.3 of the user's manual and the posterior element of the estimated poLCA model object.
Comment: Thank you for your help! I checked and the predicted probabilities for the same classes (in a different order) change depending on different values of the  loglikelihood. However, when I want to estimate the multinomial logit model to study the effect of covariates on class membership (in particular how the probabilities varies by income quartile), the same model (with a different order of classes) produces different predicted prior probabilities of latent class membership holding all the other variables at the mean for different income quartiles (income quartile 1, 2, 3 and 4). Thank you
Comment: Welcome to CV and thanks for your answer @Drew! This was also my first thought however OP suggests in his comments that it is not the case. Unfortunately, we did not get any further information, so your answer is still probably the most likely explanation.

Latent class analysis order classes


Conversão de resposta em listas

Question: Pessoal estou com um pequeno problema em meu algorítimo tenho que receber um "nome de uma instituição" qualquer digitado pelo usuário e converte-lo em lista para usa-lo futuramente em outras condições porem esta convertendo pra string todas as letras do nome e colocando em uma lista ficando assim impossibilitado de usa-lo como uma nova lista declarada pelo "usuário" para usa em outras condições.
instituicão = []

    print("Digite o nome da instituição que deseja adicionar.\n 0 - Para
    parar de adicionar\n")
    while True:
        instituicão_add = input("digite alguma instituicao")
        #Supor que o usuário botou "ADD"
        conversão_lista = list(instituicão_add)

        #funcionaria se tivesse em str mas o print vai sair como dito
        #ja  para o input direto nao sei qual condição bota para parar
        if instituicão_add == "0": #<<< ???
            break
        else:
           instut.append(conv_list)
           print(instituicão)
           #Ai no caso meu print sai se tiver str(input("")) assim [['a', 'd', 'd']]
           #O certo para min seria sair assim [["alguma coisa"]]

for indice,na_lista in enumerate(instituicão):
    print(indice, "-", na_lista)

inst = int(input("\nQual instituição deseja escolher?"))

x = inst #recebendo o indice que seria pra entra na lista que desejasse

if inst == x:
         dinheiro = int(input("\nQuanto deseja doar?\n")
         instituicão[x].append(dinheiro)
         print("Obrigado por ajudar esta instituição")
         print(instituicão[x])

Aqui nesse ultimo "print" desejava que saia [["valor de dinheiro doado"]], pelo usuario dentro da instituicao adicionada por ele e transformada em lista que deveria retorna [["xxxxx"]], porem não estou conseguindo fazer este algorítimo funcionar assim se poderem me ajudar.
Comment: Python3 deixa você acentuar variáveis - mas não quer dizer que você deva faze-lo!  :-)   Mas se for fazer, é importante manter a consistência: A variável deveria ser `instituição`  (ou `instituicao`) - nunca `instituicão` - como você vai conseguir se lembrar de onde usou noms especiais ou não quando o programa for maior?
Comment: Alias-  tente usas os mesmos nomes para a mesma variável - ter uma "conversão_lista" que você tenta usar algumas linhas abaixo com o nome de "conv_list"  não vai ajudar seu programa a funcionar.
Comment: ei como guardo o valor recebido sem sobrescrever o anterior porque como e dicionario não estou conseguindo salva como faço em listas normais, tipo se na doação digito 1000 e quero doar novamente e digito 20 deveria fica guardado 1020 e não sobrescrever pra 20 e não tenho noção de como fazer isso em dicionario.
Answer: Ok, acho que entendi. Você quer guardar todas as instituicões digitadas pelo utilizador numa lista:
Porque não fazer uma lista de dicionários onde cada um armazena nome da institução e respetiva doação? Se percebi bem o problema, neste contexto penso que seria o melhor:
Python 3.x:
instituicoes = []
while True:
    instituicao_add = input("digite alguma instituicao") #ex: 'stack overflow pt'
    if(instituicao_add == 'exit'):
        break
    instituicoes.append({'nome': instituicao_add})

x = int(input("\nQual instituição deseja escolher?")) # ex: 0

while x >= len(instituicoes) or x < 0: # Verificar se index existe na nossa lista de instituicoes
    x = int(input("\nQual instituição deseja escolher?")) # ex: 0

dinheiro = int(input("\nQuanto deseja doar?\n"))

instituicoes[x]['doação'] = dinheiro # ex: 1000
print("Obrigado por ajudar esta instituição")
print(instituicoes[x]) # output: {'nome':'stack overflow pt', 'doação': 1000}

#para imprimir só o valor doado
print(instituicoes[x]['doação'])

Comment: Mas nesse caso não tenho como usa a "instituição" como lista dentro de lista pra depois "doar", pra alguma dessas instituição só percorrendo a lista pelo indice pra escolher alguma que esteja guardada, já tentei antes isso e tals, mas vlw ainda não da certo por esse fato porque depois não tenho como usala como uma lista informada pelo usuário guardada dentro de outra lista. E já o exit vai finalizar toda a execução eu só preciso da condição em modo de lista que faça entra no break.
Comment: Mas diga-me uma coisa... instituição é uma lista de strings ou uma lista de listas? Sendo assim não percebi bem o que quer armazenar dentro dessa var.

Um à parte: Podem surgir problemas por o noma da variável ter acentos
Comment: Instituição e a lista que recebe as listas com os nomes que o usuário informa o problema e que esta ficando em string e não lista dentro de lista tipo instituição =[ ] ai quando o usuario informace o nome da instituição a ser guardada na lista instituição = [[informada_pelo_usuário]] que tipo ele informaria em nome e o programa fizesse esse nome informado vira uma lista definida pelo usuario sem ter que adicionar manualmente cada instituição no código.Acento e tals botei aqui por costume de escrita  correta, mas no python mesmo não uso.
Comment: Se percebi bem então quer adicionar listas (de instituições). Vou editar em cima de acordo com a solução que possa resolver esse problema.
Comment: Exatamente com o que já aprendi e tentei algumas coisas mas avanças e não conseguir fazer isso de quando o "nome" digitado pelo usuário virase uma lista pra ser guardada dentro de outra lista
Comment: Pode testar esse código extamente como está, se percebi bem isso resolve o seu problema
Comment: Muito obrigado é pelo fato que não tive aulas de dicionario ainda mas compreendi perfeitamente muito obrigado mesmo.
Comment: ei como guardo o valor recebido sem sobrescrever o anterior porque como e dicionario não estou conseguindo salva como faço em listas normais, tipo se na doação digito 1000 e quero doar novamente e digito 20 deveria fica guardado 1020 e não sobrescrever pra 20 e não tenho noção de como fazer isso em dicionario.

Conversão de resposta em listas