when should be choose simple php mail and when smpt with loggin+password?

Question: My Case:
web application that need to send 1,000 messages per day to main gmail account.
(Only need to send email, not need receive emails - email client)
1. option - use php mail function  + sendmail + config php.ini
php example:
<?php
$to      = 'firstname.lastname@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: email@example.com' . "\r\n" .
    'Reply-To: email@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

php.ini config (ubuntu):
sendmail_path = /usr/sbin/sendmail -t -i

pros:don't need email account, easy to setup
cons:?

2. option - use Zend_Mail + transport on smpt+ password auto
php example(need include Zend_Mail classes):
$config = array('auth' => 'login',
                  'username' => 'myusername',
                  'password' => 'password');
  $transport = new Zend_Mail_Transport_Smtp('mail.server.com', $config);
  $mail = new Zend_Mail();
  $mail->setBodyText('This is the text of the mail.');
  $mail->setFrom('email@example.com', 'Some Sender');
  $mail->addTo('email@example.com', 'Some Recipient');
  $mail->setSubject('TestSubject');
  $mail->send($transport);

pros:?
cons:?
Questions:

Can 1 option be filtered by gmail email server as spam?
please can you add pros + cons to options above

Thanks
Answer: Both options can be filtered by Google as spam.  Set Googles' Bulk Senders Guidelines.
Option 1 is simpler to setup, and won't gather a collection of undelivered messages.
Option 2 is more reliable and will gather undelivered messages along with the reason the message wasn't delivered.
EDIT: Whichever option you use, it may be best to use an authenticated connection to Gmail. (login with your credentials.)
Rules my email serves uses that Google may also apply.
Hosts which use any of the following in their HELO command are always spam.  (These rules apply only to unauthenticated mail submission.)

An unqualified hostname (example).
My domain name or IP address.
Any other IP address (192.0.2.10).
A domain literal ([192.0.2.10]).
An SPF record exists prohibiting use of the IP address to send email for the either: the domain in the Helo command; or the domain returned by the PTR record for the IP address.

Hosts that are most likely not to be sending spam meet all of these criteria:

rDNS is configured PTR (192.0.2.10) -> A (mail.example.com) -> PTR (192.0.2.10).
Uses their FQDN (fully qualified domain name) in the Helo command (mail.example.com).
FQDN is not a second level domain (example.com).
FQDN has an SPF record permitting its use as a host ('v=spf1 a -all').
Comment: Thanks, Does gmail filter email -  even not going to spam box?
Comment: All mail servers will filter incoming email to ensure it is not Spam.  Any that don't will be loaded with spam.  I get spam from servers with very good reputations, but far less than I get from those with poor reputations.  I'll edit to add some details.
Comment: I make separated question for this issue:http://serverfault.com/questions/236482/does-gmail-avoid-from-some-emails-even-to-be-in-spam-box
Answer: If you have control of the entire server hosting the domain you could check out the maillogs. Very often Google gives good feedback with a link in their rejects that tells you why it was rejected.
If you send a lot of e-mail and Google does not know you and does not have a reputation on your MTA, then they will throttle your IP address after a number of e-mails. They will continue to reject all e-mail coming from your mail server until the time has passed by.
Generally there should be no problem using normal PHP to send e-mails with.
Comment: in my case I send succeseful emails with php mail function to my gmail app account, until few days ago - they blocked by gmail apps. I looking what can case for that block


Drupal 7 Really Slow on admin pages

Question: I have a Drupal 7 installation and several admin pages are incredibly slow and time out after 30 seconds.  I've tried several things without success:

APC is enabled
innodb_buffer_pool_size is set to 100 M
No unused modules are enabled.  I still have 155 modules enabled, for localization, commerce, captcha, questions & answers, etc.
Standard cache is enabled and JS/CSS compression enabled. Memcached not being used.
Drupal 7, latest version

Even with that, the site is still really slow and there are pages that won't open (time out).  For example, installing a module will always fail the first time.  Accessing the settings of the Language Selection Page module will always fail, and so on.  Any recommendations other than increasing the timeout?
I'm using WAMP.
UPDATE: The time out error shows it takes a while in this function mainly: drupal_flush_all_caches( )   ..\system.admin.inc:1766
Sometimes in other functions too.
Comment: Please specify which admin-pages are slow. Sometimes time outs are due to failing outgoing network connections (e.g. for update-status checks). Update: sorry, ignore me, did not read the question to the end...
Answer: If you can profile your site that's always helpful. https://drupal.stackexchange.com/questions/724/why-is-drupal-7-so-slow
https://groups.drupal.org/node/210683 - Older post but some patches have still not been committed.
https://groups.drupal.org/node/415883 - Speedups for the DB layer (caches mainly).
Because of windows checkout this post and this group
https://groups.drupal.org/node/242443
https://groups.drupal.org/drupal-windows
Answer: After researching a bit more, I think I was able to improve its performance a little bit.
I've changed several variables in MySQL. Some are not recommended really (the first one mainly), but as I'm in development it helps:

Set innodb_flush_log_at_trx_commit = 0  (Source)
Increased query_cache_size and query_cache_limit
Increased innodb_buffer_pool_size
Changed semaphore table to memory by executing this script

Also,

Disabled the Update manager module (not sure if it helped)
Uninstalled the Content Translation (and dependent modules) as I was using Entity translation

Drupal 7 Really Slow on admin pages


An example of $_AM$ is simple but $M^\star_A$ is not?

Question: Let $A$ be a finite dimensional $k$ algebra, $k$ is a field. It is evident that the duality functor ($(-)^\star=hom_k(-,k)$)  preserves the simplicity in the case of finitely generated  $A$- modules (left $A$-modules  to right $A$- modules ) here is a proof in a related question
My question is, could you possibly  provide me with a counterexample of the infinite dimensional case. That is $_AM$ is simple but $M^\star_A$ is not, where $A$ is still finite dimensional?
Answer: If $A$ is a finite dimensional algebra, then every simple $A$-module is finite dimensional, since it is a quotient of the regular module (if $S$ is a simple left module, then for any $0\neq s\in S$, $a\mapsto as$ is a non-zero homomorphism $A\to S$, which is surjective since $S$ is simple).
Comment: @math137 Yes, for indecomposable modules it makes sense, and the dual may not be indecomposable. One way to see this is that for any infinite dimensional module, the natural map $M\to M^{\star\star}$ to the double dual is injective but not surjective, and splits if $M$ is itself the dual of some module, so in that case $M^{\star\star}$ can't be indecomposable. So if $A$ has any infinite dimensional indecomposable module $M$, then either $M$ or $M^{\star}$ is indecomposable with a decomposable dual (depending on whether or not $M^\star$ is decomposable).
Comment: @math137 I'm not sure exactly which aspects you're interested in, or how much you know already, but you might be interested in the notes https://www1.maths.leeds.ac.uk/pure/staff/crawley_b/infdim2.pdf by Crawley-Boevey. He gives some examples using representations of the Kronecker quiver: in particular, the first example in section 1.3 is an indecomposable module whose dual is decomposable.
Comment: That is right, thank you,  so if I edit my question and change it to indecomposable module, or remove the condition on $A$, would my question make sense? The purpose of my question is to see where this functor does not preserve simplicity or indecomposability.  But I thought it makes sense if I asked that way (and you showed that it does not ).
Comment: Could you please tell me where can I read about these facts?
Comment: These are nice notes thank you. With respect to the background I felt  ok when I saw the notes, and I am a beginner in this area. My interest is finite dimensional associative algebras.


Available options to implement a knowledge base or FAQ repository?

Question: I just started with Drupal 7 in an enterprise environment. It's running on IIS7 with MySql as the backend.
I'd like to see this Drupal site host a Knowledge Base or FAQ repository. I did some searches for modules and I haven't found any popular solution.
Ideally, as software/product 'issues' arise and solutions are documented, I want the issue and solution to be easily entered and searched by a small (<100) developer and help desk community.
Any suggestions about how to accomplish this? I'm still getting a grasp on the taxonomy, maybe proper use of taxonomy is all thats really needed?
Comment: So, in the knowledge base, in places where "issues" appear, say, as a page or in a larger list of these issues, would you see them as being identified (titled/labeled) with phrases like "Software crashes on launch" "Software displays blank screen when users press X," or more generically like "White screen of death," "Inability to authenticate," etc.
Answer: Ticketing system
Implement a ticketing system, using the Support module. Popular/great module, to the extend that you can live/agree with the design / assumptions / etc of this module. Definitely worth considering to "get started". Here is a list of features (from its project page):

Ticketing activity is illustrated with colorful charts (depends on the Chart API module).
Tickets can be assigned to users (and users can view all tickets assigned to them).
Tickets support states (new, active, pending, closed, etc) and priorities (low, normal, high, critical, etc).
Configurable email notifications for new and updated tickets.
Email integration allows tickets to be created and updated via email, with support for attachments. New users can be automatically created. Ticket properties can be updated via email (using included support_mailcmd module).
Highly configurable client and user ticket overviews, highlighting tickets that haven't been updated for a long time.
Fully integrated with Drupal's search functionality, users can only search for tickets they have access to.
Supports an unlimited number of clients, each with their own configuration and access permissions.
Tickets are nodes, ticket updates are comments.

Wiki system
Implement a wiki system, using modules such as these ones (excerpts are from their project pages):

Wikitools:

... provides some settings to get a more wiki-like behavior. It aims to be lightweight; all features are optional, and it provides no database tables of its own.
Some of the features of this module are:

Node Creation: Let users create new nodes when they type in a node name which does not exist.
Node Search: Let users search for nodes when they type in a node name which does not exist.
Automatic Redirect: If a title of a moved page is entered, redirect automatically.
Unique Titles: Enforce that titles are unique over all wiki node types.
Move Protection: Disallow change of node titles for users without administer nodes permission.
Underscore as Space: Treat underscores as spaces when doing a node-lookup by title.
Dash as Space: Treat dashes as spaces when doing a node-lookup by title.
Custom wiki 404 pages: pick and choose from links to create, links to search, and an inline node add form.

The module can be used in conjunction with the flexifilter module (of course), the freelinking module by hijacking freelinking links, or together with the pearwiki filter module for various wiki formats.

Freelinking:

... implements a filter framework for easier creation of HTML links to other pages on the site or to external sites.
The framework uses a wiki style format such as [[indicator:target]] as markup to identify links.

The video about Setting Up a Wiki in Drupal 7 contains an interesting introduction to the modules mentioned above (and some other modules you might also want to consider for this purpose).
There is also the Wiki installation profile (either just use that profile, are review it to get inspiration about possibilities). Excerpt from its project page:

... will set up Drupal with the following settings:

Moderator role which can revert / delete pages.
Revisions for pages.
Freelinking - easier creation of HTML links to new or existing pages.
Edit a section of a page (based on header).
Mediawiki input format.
Categorization via free tagging vocabulary.
Views: All pages / All categories / All Images.
Recent changes.

Questions & Answer site
Implement a questions & answers site (similar to "Drupal Answers" here ...), using the Answers module (Disclosure: I'm a co-maintainer of it), for which a Demo site is available.
To experience it yourself, here are the steps to try it out:

Head over to this sandbox site.
Just accept the defaults to create a sandbox demo site (hit the create sandbox button, and wait for the process to complete).
Login to the site (using the suggested defaults).
Create at least 1 question using either the "Add content" menu link and then selecting "Question", or just enter relative path /node/add/question. And complete the title and body of the question.
After you save the question, you'll see the question that's created (in view mode). And below the question, you should see "No answers yet." (since you just completed posting the question). And then there is the "Your Answer" form right below that. That is the form you can use to post an answer to the question.
If you then use that (answer) form to post your answer, and also save that, the (first) answer is shown below the question, and below that answer there is now the "Your Answer" form again (to allow for posting an additional answer).
Use the Questions tab (or enter relative path /questions, to get a list (a tabular display) of all existing questions so far (there should be at least one if you completed the previous step).

Note: you may also want to enable the Answers Theme (sub-module of Answers, new as of 7.x-4.x). After you do, return to the question you created before, and see how the look-and-feel of both the question and related answer(s) below it changed ... Here is a sample screenprint of it:

Groups of users
If your target audience consists of multiple groups of users, then you might want to use the Organic Groups module also.
A great resource for learning about Organic Groups is the (free) video training about Learn Organic groups, a set of 14 videos.
As an alternative you may want to consider the Group module, which only exists as of D7, but already has a pretty stable D8 version also.
Roll your own cookies
After you become more familiar/experienced with Drupal, you could just build your own custom solution. With only site building techniques (using contributed modules), you could probably get pretty far. E.g. using modules such as the Frequently Asked Questions module.
However, I you want more flexibility and (way) more facilities that can be perfectly tuned to your specific needs, then you should consider using modules such as:

Views (Video tutorials: Learn Views).
Rules (Video tutorials: Learn Rules).
Flag (Video tutorials: Learn Flag).
Message (More docu in its Community Documentation).
Answer: Old discussion but I feel the need to chime in because a lot of the things mentioned here are still relevant
The above response has some great suggestions if you want a ticketing or wiki section.  Unfortunately, they don't answer the actual question because an FAQ/knowledgebase is not like either of those things.
There is an FAQ module that is mature and well used/tested. If you just want an FAQ that is worth looking at.  But once you accumulate enough info, where you need to start categorizing it, you will want to move to a knowledge base.
You are right that there aren't any obvious answers for that one, still.  I think the best is to do it using existing modules/features.  More work but more customizable and adaptable.  I have looked around and that seems to be what most people suggest.  Unfortunately, I have not found any how to guides.  So you are on your own and there is definitely a learning curve.
Here is the best discussion of it that I could find. Kind of old but still relevant imo.  The OP mentions the modules they used at the very end of that discussion.  Taxonomy (built in) with parent child hierarchy, taxonomy_menu and taxonomy_menu_trails modules.
https://www.drupal.org/forum/support/post-installation/2013-07-23/best-way-to-build-a-knowledgebase-style-with-drupal
You can start here for how to structure your taxonomy terms in D7.  I don't think it is too much different in D8.
https://www.drupal.org/docs/7/organizing-content-with-taxonomies/about-taxonomies


menu nao fecha depois de clicado

Question: viva!
Estou tendo um problema: tenho um javascript rodando em todas as páginas e quero mantê-lo ativo mesmo se você mudar de página dentro do site (não atualizar), mas o problema é que eu tenho um menu-toggle e toda vez que eu mudo a página, o script começa novamente. então mudei o meu HTML do meu menu e adicionei um atributo ao link rel="history".
Depois de fazer isso, o script funciona sem interrupções como eu queria! mas sempre que clico no link do menu para mudar de pagina, esse mesmo menu continua aberto...  Alguém pode me ajudar?
muito obrigado

main

Press

Contacts

.toggle-menu {
  width: 50px;
  height: 60px;
  position: relative;
  top: 4px;
  left:7px;
  float: left;
  z-index: 998;
}

.toggle-menu i {
  position: absolute;
  display: block;
  height: 4px;
  background: black;
  width: 50px;
  left: 4px;
  -webkit-transition: all .3s;
  transition: all .3s;
-ms-transition: all .3s; /* IE 9 */
-moz-transition: all .3s; /* Firefox */
-o-transition: all .3s;
}

.toggle-menu i:nth-child(1) {
  top: 16px;
}

.toggle-menu i:nth-child(2) {
  top: 27px;
}

.toggle-menu i:nth-child(3) {
  top: 38px;
}

.toggle-menu.active i:nth-child(1) {
  top: 25px;
  transform: rotateZ(45deg);
-ms-transform: rotateZ(45deg); /* IE 9 */
-moz-transform: rotateZ(45deg); /* Firefox */
-webkit-transform: rotateZ(45deg); /* Safari and Chrome */
-o-transform: rotateZ(45deg);
}

.toggle-menu.active i:nth-child(2) {
  background: transparent;
}

.toggle-menu.active i:nth-child(3) {
  top: 25px;
  transform: rotateZ(-45deg);
-ms-transform: rotateZ(-45deg); /* IE 9 */
-mozkit-transform: rotateZ(-45deg); /* Firefox */
-webkit-transform: rotateZ(-45deg); /* Safari and Chrome */
-o-transform: rotateZ(-45deg);
}

.menu-drawer {
  width: 100vw;
background: rgba(255, 255, 255, 0);
    backdrop-filter: blur(17px);
-ms-backdrop-filter: blur(17px); /* IE 9 */
-mozkit-backdrop-filter: blur(17px); /* Firefox */
-webkit-backdrop-filter: blur(17px); /* Safari and Chrome */
-o-backdrop-filter: blur(17px);

  height: 1500px;
  position: absolute;
  left: -1700px;
  top: 0;
  transition: right linear .2s;
  padding-top: 140px;
  text-transform: uppercase;
}

.open {
  left: 0px;
  transition: left linear .2s;
  -ms-transition: left linear .2s; /* IE 9 */
-moz-transition: left linear .2s; /* Firefox */
-webkit-transition: left linear .2s; /* Safari and Chrome */
-o-transition: left linear .2s;

}

.menu-drawer li {

    font-size: 4rem;
    font-family: "Helvetica Neue", Helvetica, sans-serif, "Helvetica Neue Regular", Icons;
    font-style: normal;
    line-height: 1.2;
    font-weight: 700;
    letter-spacing: -1.5px;
    text-align: left;

     }

    .menu-drawer li a {
      text-decoration: none;
      color: black;
       }

      .menu-drawer li a:hover {
        background-color: #000000;
filter: blur(16px);
  -webkit-filter: blur(16px);

  }

$(function() {
  $(".toggle-menu").click(function() {
    $(this).toggleClass("active");
    $('.menu-drawer').toggleClass("open");
  });
});

Comment: Cadê o CSS das classes? Aliás, por que tá usando uma âncora (``) para esse papel? Não é este o dever dela.
Comment: @CypherPotato ja atualizei com CSS !
Answer: Para resolver o problema do menu que permanece aberto ao mudar de página, você pode adicionar um listener de evento no seu código JavaScript para o clique no botão de menu e, ao clicar, alterar a classe do elemento que contém o menu. Algo assim:
const toggleMenuButton = document.querySelector('.toggle-menu');
const menuDrawer = document.querySelector('.menu-drawer');

toggleMenuButton.addEventListener('click', function() {
  menuDrawer.classList.toggle('open');
});

Isso vai fazer com que, ao clicar no botão de menu, a classe "open" seja adicionada ou removida do elemento do menu. Você pode então usar essa classe para controlar a exibição do menu com as regras de estilo CSS que você já possui.
Além disso, você também pode adicionar um listener de evento para o evento "popstate" em window. Esse evento é disparado quando o usuário navega para trás ou para a frente na história do navegador. Dessa forma, você pode remover a classe "open" do menu sempre que o usuário navegar para trás ou para a frente na história do navegador:
window.addEventListener('popstate', function() {
  menuDrawer.classList.remove('open');
});

Espero que isso ajude!
Comment: ola boa tarde. peço desculpa mas nao entendi correto! acrescento esse ao meu codigo inicial, certo?
Comment: Didi, após sua edição, vou editar a minha resposta para um método mais simples.
Comment: me desculpe mas nao funciona... sera que tem email e posso partilhar contigo uma pre visualização? ou outro meio contacto? obrigado

menu nao fecha depois de clicado


What Language To Use To Manipulate OSX Application Windows?

Question: I'm sure many of us have seen vision degradation from too much screen time from programming.
A theory suggests that when they eyes become fixed, tension builds.  And that tension causes the vision to slowly degrade.
This software promises to prevent that fixation...
http://www.central-fixation.com/downloads.php
The problem is it's outdated, and Windows only.
I'd like to write a script that will "swing" all open windows according to a set pattern & speed.  A script that works with OSX 10.9 and later.
I know Python and Javascript but have no idea where to start on this.
Please help me out.
How is it done?  What language is used to manipulate OSX application windows?  And/or simply manipulate the whole desktop window space?
Answer: I haven't tried to do exactly what you are trying to achieve here, but ANYTHING at all related to manipulating OS X should be done via Automator or AppleScript. If you are running Yosemite, the app is called "Script Editor". Anything older and it's called "AppleScript Editor".
Try this site.
Extract:
tell application "Finder" to set the position of the front Finder window to {94, 134}

I know your question is labeled "python" but I believe that AppleScript is the way to go with this.
You can add AppleScript to an Automator workflow with the "script" object. I'm not sure how to make this run periodically, but one option would be to keep it open in the background. You can do this in AppleScript with the delay command:
(do stuff here)
delay (your delay)

Hope this achieves your purpose.


Strcoll UTF-8 Sorting - PHP

Question: I have this array that needs sorting alphabetically, ignoring accents (as in "e" should be right before "é", and "a" should be followed by its variants, such as "à", for example). The array is read from a JSON file, decoded, is organized(or should be), then encoded back (for employees to add objects). My only problem is every letter that has an accent is placed at the end. Here's an example of my code :
$myArray = [
    {"myKey":"Aaa","values":[1,1,1,1,1,1,1]},
    {"myKey":"Test01","values":[1,1,1,1,1,1,1]},
    {"myKey":"Test02","values":[1,1,1,1,1,1,1]},
    {"myKey":"BBB","values":[1,1,1,1,1,1,1]},
    {"myKey":"Écha","values":[1,1,1,1,1,1,1]}
]

setlocale(LC_COLLATE, 'fr_CA.utf8');

usort($myArray, function($a, $b){
    return strcoll($a["myKey"], $b["myKey"]);
});

$myNewFile = json_encode($myArray,JSON_NUMERIC_CHECK|JSON_UNESCAPED_UNICODE);
echo $myNewFile;

The echo gives :
[
    {"myKey":"Aaa","values":[1,1,1,1,1,1,1]},
    {"myKey":"BBB","values":[1,1,1,1,1,1,1]},
    {"myKey":"Test01","values":[1,1,1,1,1,1,1]},
    {"myKey":"Test02","values":[1,1,1,1,1,1,1]},
    {"myKey":"Écha","values":[1,1,1,1,1,1,1]}
]

When it should be :
[
    {"myKey":"Aaa","values":[1,1,1,1,1,1,1]},
    {"myKey":"BBB","values":[1,1,1,1,1,1,1]},
    {"myKey":"Écha","values":[1,1,1,1,1,1,1]},
    {"myKey":"Test01","values":[1,1,1,1,1,1,1]},
    {"myKey":"Test02","values":[1,1,1,1,1,1,1]}
]

I've also tried the following, as I tried my best to find an existing solution with the multiple posts on this subject:
$collator = new Collator('fr_CA.utf8');
$collator->sort($myArray);

and (not necessary since I'm on PHP 7+, but I'm desperate)
usort($myArray["Ingrédients"], 'custom_sort');

function custom_sort(($a, $b){
    return strcoll($a["Ingrédients"], $b["Ingrédients"]);
});

and (since I'm on PHP 7+)
usort($myArray, function($a, $b) {
    return $a['myKey'] <=> $b['myKey'];
});

I've also used different country codes for my setlocale, such as
'fr_CA.utf8', 'fr_FR.utf8', 'fr_CA', 'fr_FR'

Each one of these methods seem to work for everyone in all the posts I've seen so far, but they're quite dated. They all work, apart from sorting accents, so I get the same result I'm getting, no matter the method. The server is on PHP 7.1.1 if that helps.
Comment: Simple working solution: https://3v4l.org/J4Xft
Answer: Ok, so in short, the problem you have is due to the value of the character. strcoll compares strings based on the values of their characters for the character set you are using. I am going to assume you are using utf-8 or something very similar. See UTF-8 for the values, notice how the value of e with an accent mark is much higher than Z? That is why you are having this problem. In order to fix it, you will have to add special cases for the accented characters, as the normal sort with not work otherwise. So, basically, create your own compare function which would put e with an accent mark where f would usually be and so on.
Comment: That actually makes a lot of sense, thanks. I'll get right on it!
Comment: I'll update OP for anyone interested, and as a future reference.

I found the solution after much research on a french forum, dated from 2012, after my replace function actually replaced the text instead of the value.

Strcoll UTF-8 Sorting - PHP


Continuity of the thin QR factorization.

Question: In section 5.2 of the book Matrix Computations by Golub & Van Loan we can find the following result:
Let $A\in\mathbb R^{m\times k}$ be a matrix with full column rank. Then we have the factorization $A=QR$
for some matrix $Q\in \mathbb R^{m\times k}$ with orthonormal columns and some upper triangular matrix $R \in \mathbb R^{k\times k}$ with positive diagonal entries. Moreover the factorization is unique and is called the thin QR factorization of $A$.
I want to show that the factorization is continuous with respect to $A$.
So let $(A_n)$ be a sequence of matrices in $\mathbb R^{m\times k}$, each with full column rank, and suppose that $A_n\to A$. For each $n$, let $Q_nR_n$ denote the thin factorization of $A_n$.
Suppose $Q_{n'}\to Q_0 \in \mathbb R^{m\times k}$ for some subsequence $n'$. Then $Q_0^\top Q_0=\lim Q_{n'}^\top Q_{n'} =I_k$ so $Q_0$ has orthonormal columns. Moreover we have $R_{n'}=Q^\top_{n'}Q_{n'}R_{n'}=Q^\top_{n'}A_{n'}\to R_0$ where $R_0=Q^\top_0A$. Since each $R_{n'}$ is upper triangular with nonnegative diagonal entries, so is $R_0$. Moreover we have
$$QR=\lim Q_{n'}R_{n'}=Q_0R_0$$
and so $\text{rank}(R_0)=\text{rank}(Q_0R_0)=\text{rank}(QR)=\text{rank}(R)=k$. Therefore the diagonal entries of $R_0$ are in fact positive. From the uniqueness of the thin factorization we conclude that $Q_0=Q$ and $R_0=R$.
We have shown that any convergent subsequence of $(Q_n)$ must converge to $Q$. We claim that this implies that $Q_n\to Q$. Otherwise we can construct a subsequence $(Q_{n'})$ which is bounded away from $Q$ by some distance greater than some $\epsilon>0$. Since $\|Q_n\|=\sqrt{k}$ for all $n$, the sequence $(Q_{n'})$ is bounded, and so we can extract a further subsequence converging to some matrix other than $Q$, a contradiction.
Hence $Q_n\to Q$, and repeating the first part of the proof we get $R_n\to R$ as well.
Is this proof correct?
Thanks a lot for your help.
Answer: This looks correct to me. The subsequence argument is a standard one. It can be modified in many ways, e.g. by exploiting that the set of such $Q$ is compact and thus any subsequence $Q_{n'}$ must contain a convergent sub-subsequence which must then converge to $Q$.
You can also prove the continuity of the decomposition by observing that $Q$ is constructed column wise from left to right by means of the Gram-Schmidt process. Each step in the process is a continuous operation which turns a column of $A$ into the corresponding column of $Q$. Then use induction over $k$.
Yet another way is to show that the construction of $R$ via the Cholesky process is a finite sequence of continuous operations.


Extrair apk para colocar na playstore

Question: Estou tendo problemas com Xml das minhas cores. Quando tento finalizar a extração, está dando erro, mas a aplicação corre no meu celular, ja fiz clean and build e está tudo bem, mas em contra partida, quando tento extrair para lançar na playstore, dão os seguintes erros:

Ficheiro Xml com as cores:
Comment: Você possui apenas uma pasta value? ou existem mais para demais densidades? ( values-w820dp, por exemplo? ). Se tiver mais de uma verifique se todas possuem o arquivo color.xml
Comment: tenho apenas uma..
Comment: Poderia postar seu arquivo q contém as cores? Obrigado!
Comment: Ja esta adcionado
Answer: Tente os seguintes passos:

Verifique se retirou o atributo debuggable da tag application no AndroidManifest;
Confira o versionCode e versionName no AndroidManifest;
Retire todos os arquivos que não estão sendo usado;
Teste novamente.
Comment: meu Manifest nao tem o atributo debuggable da tag aplication nem tem o versionCode e VersionName, o projecto corre inclusive ja testei em telemoveis diferentes...mais quanto tento fazer o export...

Extrair apk para colocar na playstore


When to close Statement when using jdbc

Question: I am using odbc to connect mysql database in Java
I write a function "ExecuteQuery", it takes a string parameter as sql statement and returns its resultset. However, when should I close the statement object?
If I close it in function ExecuteQuery, the returned resultset will be closed as well.
If I don't close it, memory leak occurs as I do not have the reference of statement object in caller.  Thank you
Answer: You're taking wrong approach. If you really need such function (which is doubtful), make it accept a Statement as a parameter and make a separate function to create and set up that statement. Then you may wrap your function and ResultSet work in a try..finally block and close the statement in finally.
E.g.
Statement statement = getStatement();
try {
    ResultSet rs = executeQuery(statement, query);
    ...
} finally {
    statement.close();
}

However, if you're facing such problems, you may want to re-consider your architecture. Take a look at Hibernate, for example.
Comment: Then what approach should I use?
Comment: @Bear Depends on your situation. But you're making a meaningless wrapper above JDBC, which doesnt even make your code cleaner. I suggest you either use a pure JDBC or switch to Hibernate (see [ORM](http://en.wikipedia.org/wiki/Object-Relational_Mapping))

When to close Statement when using jdbc


Writing a statement using logical connectives and determining whether it is a logical implication.

Question: I need to write the following statements into logical form and determine whether the conclusion is logically implied by the assumptions.

A sufficient condition of $f$ to be integrable is that $g$ be bounded. A necessary condition for $h$ to be continuous is that $f$ is integrable. Hence, if $g$ is bounded or $h$ is continuous, then $f$ is integrable.

This is my work:
$p$: $f$ is integrable
$q$: $g$ is bounded
$r$: $h$ is continuous
$((q\rightarrow p)\wedge (p\rightarrow r))\rightarrow ((q\vee r)\rightarrow p)$
Is this the correct form? I don't think it is, because it should be a tautology and yet it is not...right?
Answer: No, the second claim should be $r \to p$: $f$ being integrable $p$ is a necessary condition, rather than a sufficient condition. And when something $p$ is a necessary condition for something else $q$, you translate it as $q \to p$
Also, I much prefer to present these statements as three separate statements as part of an argument, rather than as one big conditional statement, so I would symbolize this as :
$q \to p$
$r \to p$
$\therefore (q \lor r) \to p$


Windows 2008 R2 software RAID 1 (disk failure)

Question: I've bought myself a new server that I'm going to use for some various software developing projects. I have a simple question about Windows 2008 R2 x64 software raid. What if disk 1 fails? Will it automatically swap over to disk 2? And boot up on disk 2 after reboot? Or how do you handle this?
Should I use some tools for monitoring my RAID 1? So if it fails or if there are any errors, I will receive an email. Do you know of a tool capable of this? Or can I do it by having a tool monitoring the event viewer?
Finally, I'm looking for a tool to test the speed (read/write) of my harddrives, before and after introducing RAID 1. What's the best free tool out there?
Answer:
What if disk 1 fails? Will it
  automatically swap over to disk 2?

It depends on the computer and how the hard drive failed.  If the BIOS on your computer still sees the first drive it will probably attempted to boot to it.  Typically with software-based RAIDs you have to reconfigured boot drive after a failure.  If you need the computer to be able to survive a disk failure with zero intervention then you really are going to need a good hardware RAID controller.

Should I use some tools for monitoring
  my RAID 1?

Windows will log RAID events to the Eventlog.  There are lots of tools for monitoring the event logs mentioned around the net and on this site.

Finally, I'm looking for a tool to
  test the speed (read/write) of my
  harddrives,

I like BST for for quick testing (http://www.nu2.nu/bst/).
Iometer is far more extensive but it does get a bit complicated because of all the available options.  (http://www.iometer.org/)
Comment: Thank you very much. Do you have any Eventlog monitoring tools that you recommend?


Prove that $f:\mathbb{R}^2\to\mathbb{R}^2$ has a fixed point in a subset of $\mathbb{R}^2$

Question:
Let $f:\mathbb{R}^2\to\mathbb{R}^2$ by defined by $f(x_1, x_2) = \begin{pmatrix}
\frac{1}{3}x^2_2 + \frac{1}{8} \\\
\frac{1}{4}x^2_1 - \frac{1}{6}
\end{pmatrix}$ and let $D = \{ x \in \mathbb{R}^2 : \| x \|_{\infty}\ \leq 1 \}$. Prove that $f$ has a fixed point in $D$.

Obviously the Banach fixed point theorem doesn't apply here, because $f$ isn't lipschitz. I was trying to come up with a solution by calculating the intersections of the two quadratic component functions with $h(x) = x$ separately. I thought i could maybe find the fixed point by comparing the solutions but this didn't work either. I guess there's a simple solution.
Answer: $\newcommand{\norm}[1]{\left\lVert#1\right\rVert}$
You can use the Banach fixed point theorem to solve this problem. As you remarked, the function $f$ is not a contraction, but we are only interested in what happens in $D = [-1,1] \times [-1,1]$. So let us look at the restriction $f |_D$. It is easy to see that it maps $D$ to itself, and it is in fact a contraction. Indeed, for any $(x_1, x_2), (y_1,y_2) \in D$ we have:
\begin{align}
\norm{f(x_1,x_2)-f(y_1,y_2)}^2 &=
\norm{ \begin{pmatrix} 1/3 (x_2^2-y_2^2) \\ 1/4(x_1^2-y_1^2) \end{pmatrix}}^2 \\
&=\frac{1}{9} (x_2^2-y_2^2)^2 +\frac{1}{16} (x_1^2-y_1^2)^2 \\
&=\frac{1}{9} (x_2+y_2)^2(x_2-y_2)^2 + \frac{1}{16} (x_1+y_1)^2(x_1-y_1)^2\\
&\leq \frac{4}{9} (x_2-y_2)^2 + \frac{1}{4} (x_1-y_1)^2 \qquad
\text{since } x_1+y_1 \leq 2 \; \text{and} \; x_2+y_2 \leq 2 \\
&\leq \frac{4}{9} \left( (x_2-y_2)^2 + (x_1-y_1)^2 \right) \\
&=\frac{4}{9} \norm{ \begin{pmatrix} x_1 \\ x_2 \end{pmatrix} - \begin{pmatrix} y_1 \\ y_2 \end{pmatrix} }^2
\end{align}
Taking square roots, we see that $f|_D$ is a contraction. Now, since $D$ is a closed subset of $\mathbb{R}^2$ (which is complete), it is a complete metric space. By the Banach fixed point theorem, we conclude that $f$ has a unique fixed point in $D$.
Comment: Nice answer! Banach fixed point theorem has also the great advantage that we can compute the fixed point by iterating over the function for any starting point in $D$. In this case, the fixed point is $(0.133768871438137, -0.162193138925208).$
Answer: Hint: try applying the Brouwer Fixed Point Theorem.
Comment: Yes! This is exactly what the theorem guarantees! I don't think you need to do something more than that, but I can think about another way :)
Comment: If I understand correctly according to Brouwer's fixed point theorem $f:D \to D$ already has a fixed point (in $D$), since $f$ is continuous. Do you think there's maybe another way of showing this?
Answer: Here is a more elementary approach. The function $f$ has a fixed point at $(x_1, x_2)$ if and only if the following equations are satisfied:
\begin{align}
1/3 \; x_2 ^2 -x_1 +1/8 =0 \\
1/4 \; x_1 ^2-x_2-1/6 = 0
\end{align}
Now you can solve the first equation for $x_2$ and insert this in the second equation to obtain a function of $x_1$ only. Use the continuity of this function and the fact that it changes signs to prove it has a root in some suitable interval. You will need to find a small enough interval to guarantee that the corresponding value for $x_2$ will be in $[-1,1]$. (I think $(1/8,1/4)$ does the trick.)
Comment: Solving the first equation for $x_2$ yields $x_2 = \pm \sqrt{3(x_1-1/8)}$. Taking the positive root and inserting this in the second equation yields the function $\phi$ you have defined above. As you said, this function does not have a root in the interval $[-1,1]$. However, taking the negative root instead yields the function $\psi(x) = 1/4 \; x^2 + \sqrt{3 x - 3/8} -1/6$. I will let you convince yourself that this function has a root in the interval $(1/8 , 1/4)$ (look at the signs of $\psi(1/8)$ and $\psi(1/4)$). Then you will be sure that $x_2 = - \sqrt{3(x_1-1/8)}$ is in $[-1,1]$.
Comment: Thanks a lot! Can you maybe elaborate a bit on how to find this interval? According to my calculations the function $\phi(x_1) := 1/4*x_1^2 - \sqrt (3*x_1 - 3/8) - 1/6$ has its only root at about $3.71$. What's the relation to your interval? Just taking this root and calculating $x_2$ from it doesn't do the trick.
Comment: You are correct. However, you need a root in the interval $[-1,1]$. This is why you must take the negative square root when you solve for $x_2$. Then everything will work out fine. (In this case the root is approximately 0.13)
Comment: Sorry for bugging again, but isn't $x_2^2$ just $3x_1 - 3/8$? Where do you get the $0.13...$ from? I get $\pm 3.28 \notin [1,1]$.
Comment: My confusion stems from the fact that $\phi$ as defined above only has one real root $x^{*} \notin [-1,1]$. I know that both $x_1, x_2$ need to be in $[-1,1]$  otherwise they won't be included in $D$. However, I see no way to come up with such a solution. Then again, I still don't understand the last part of your explanation. What's special about $(1/8, 1/4)$? And where exactly am I supposed to take a negative square root?
Comment: Ooh, I see. Somehow I didn't even think of taking the negative square root *before* inserting in equation two.Thanks again for your help!
Comment: You're welcome!
Answer: If you fancy calulating with differentials, it's fairly easy.
As previously remarked $f$ restricted to $D$ maps $D$ into $D$ (easy). The derivative equals
$$Df = \left( \begin{matrix} 0 & \frac23 x_2 \\ \frac12 x_1 & 0 \end{matrix} \right).$$ The norm (in $\ell^\infty$) is 2/3 on $D$, whence $f_{|D}$ is a contraction. $D$ is closed and connected so there is a unique fixed point.


p(x) in Gaussian mixture model

Question: I've recently learned about Gaussian mixture models (GMM) in school. The formula for a GMM goes something like this:
$$p(x) = \sum_{k=1}^{K} \pi_i\mathcal{N}(x|\mu_i,\,\sigma^{2}_i)$$
Now, I know from probability theory that given a certain sample $x$, the probability for it should sum to 1.
For example, if I roll a six-sided die, the probability that I either get or don't get the number $5$ is equal to 1.
So what exactly does $p(x)$ here represent? The probability that a certain $x$ falls in the model? I feel like I'm missing something fundamental here.
Answer: The formula says that the random variable $X$ in question has probability density function $p(x)$ given by the weighted sum of $K$ different Gaussian densities, with weights summing to one.
The rationale behind a GMM is that, somehow, we believe your observations come from $K$ different groups, with each group having its own distribution. Then you leave the liberty to each observation to belong to any of each group. Thus you can think of data generated by a mixture model in two steps:
(1) draw group $i$ with probability $\pi_i$,
(2) draw an observation from the distribution of the group in (1).
Novices typically confuse the distribution of the mixture model with that of the sum of random variables, say $X_1+X_2+\cdots+X_K$. But, for instance, a sum of $K$ Gaussian random variables, $X_1+\cdots+X_K$, is still a Gaussian, whereas a random variable whose density is the sum of Gaussian densities (as the case in question) is not Gaussian.
Comment: (1) $p(x)$ is just the density at $x$, as for any continuous random variable. The density, as you may recall, is not a probability statement when $X$ is continuous. (2), yes, it's a conditional probability statement. In other terms, $p(x)$ gives you a stochastic representation for your samples when they are thought to belong to (possibly) different clusters; each sample may belong to the $i$th cluster with probability and if it belongs to it, it has distribution $N(\mu_i,\sigma_i^2).$
Comment: I get that. But I still don't understand how p(x) represents a probability. What does p(x) even mean? Also what you're getting to is p(z|x) I think right? The probability that an x belongs to a certain cluster.
Comment: Ah, and 1 - p(x) then represents the probability that the samples belong to no cluster correct?
Comment: No, p(x) IS NOT a probability. Each observation will necessarily belong to one of the clusters as $\sum_i \pi_i=1$.
Comment: But then why doesn't p(x) = 1 summed over the marginals? Is it because it's a density and the density at a specific point is always 0? But what about values near x? Shouldn't that result in some non zero number? I'm very confused here. Thanks for the help btw :)

Also I get why p(z|x) = 1. But that's because we normalize it as such.
Comment: (1) Perhaps you mean $\int_{-\infty}^{\infty} p(x)\dx =1$. This is indeed true as you can easily check by integrating term by term. (2) No, it's not "the density at a specific point is always 0" but instead it is true that $P(X=x)=0$ if $X$ is continuous. Density functions must always be $\geq 0$. One way to think about densities (for continuous $X$) is through the identity $p(x) = d F(x)/d x$, where $F(x) = P(X\leq x)$.
Answer: The first this is that the $p(x)$ represents a density and not a probability in the classical way that an event $x$ is likely to happen with probability $p(x)$.
Then the correct way to think of $p(x)$ is as the weighted sum of densities on a given point $x$. With that said think about the following example:
You have a Normal distribution centred around $-1$ and a Normal distribution centred around $1$. Now someone tells you that a point $x$ is likely to belong to the first normal distribution with probability $\pi =0.2$ then the probability for the point to belong to the second is $1-\pi =0.8$. With that in mind then someone ask you what is the density on the point $x=0$, this naturally will be the sum of both normal distributions on the point $x=0$. But is it only that? You have the information that the second is 4 times more likely than the first one. So, you would expect the density of the second normal distribution to contribute 4 times more than the first one. Hence, you will have that the density on a particular point $x=0$ will be $p(0) = 0.2 * Norm(0;-1,\sigma) + 0.8*Norm(0;1,\sigma)$
And again is not a probability is a density, in discrete case this changes. Hope that helps

p(x) in Gaussian mixture model


Two Study Meta-Analysis: Fixed- vs. Random-effects and heterogeneity

Question: I browsed through several papers and discussion but I am still not sure what is correct.
I conducted two studies on the same topic using similar methods and the same design (independent t-tests). Using R I ran a meta-analysis on both studies based on their Cohen's d. I decided to do a fixed-effect analysis, however the output using metagen of the meta package provides both-fixed and random-analyses. Here is my output
<code>          95%-CI                %W(fixed)  %W(random)
1 0.4111 [-0.0299; 0.8520]      31.3       31.3
2 0.2577 [-0.0398; 0.5553]      68.7       68.7

Number of studies combined: k = 2

                             95%-CI          z      p-value
Fixed effect model   0.3057 [0.0591; 0.5524] 2.43   0.0151
Random effects model 0.3057 [0.0591; 0.5524] 2.43   0.0151

Quantifying heterogeneity:
tau^2 = 0; H = 1.00; I^2 = 0.0%

Test of heterogeneity:
Q d.f.  p-value
0.32    1   0.5721

Details on meta-analytical method:
- Inverse variance method
- DerSimonian-Laird estimator for tau^2
</code>
Why is it that the random and the fixed effect model show the same results? Is this typical or due to only using two studies?
Having an tau^2 = 0 and H = 1, does this mean that the effects are homogeneous or is it due to fixing them for fixed effect model?
And does having an insignficant heterogeneity test mean that the effects or homogeneous or is this test reporting something that does not go along with the tau^2 and H data?
I am happy for any hints on how to fully understand how heterogeneous the effects are. Thanks in advance
Comment: Please type your results in as text (someone will come along afterward to help you format it, if you don't know how) instead of posting an image of it. Images can't be read by screen readers.
Comment: thanks for pointing to that. I didn't really know how to format it correctly but figured it out now
Comment: How do you compute .4111 and .2577 ? What is 1, 2 ?  and .3057 for each ( fixed and random model). Let there be a clear idea in your question. You are interested in overall effect size  or difference in modelling.
Comment: So .4111 and .2577 are the effect sizes (cohen's d) for each of the studies which I calculated in a different spreadsheet. 1 and 2 are the number of the studies and .3057 is the overall effect size (for fixed and random effects as it says). I am interested in the overall effect size and whether the two groups differ significantly from each other. My questions above referred to a) the difference between random and fixed effect models for only two studies and b) whether I have to be bothered by heterogeneity
Comment: Whether you have interest in groups or studies ?
Answer: To answer your questions more or less in order.
The value of $\tau^2$ is estimated as zero so under those circumstances the two models will give the same result. It is not because you have two studies.
With only two studies the estimate of $\tau^2$ will be very imprecisely estimated so in reality you can say little about the true amount of heterogeneity. Even though you specified a fixed effect model the estimate of $\tau^2$ is indeed zero as you can see by comparing the value of $Q$ to its df.
It would in general be a good idea to look at a forest plot to understand heterogeneity but in this case with so few primary studies it is unlikely to be informative.
A recent article (2024) on "study twins" may also be of interest arXiv:2312.09884
Comment: It is the amount of between study variability which counts, not the number of studies. Experiment by adding a constant to one of your estimates and its confidence interval limits (say 5) and you should see a different value for $\tau^2$. I do not think it is safe to draw any conclusions about heterogeneity from two studies.
Comment: Thanks for your quick and detailed answer. So is there any reason based on the method or just using two studies that tau^2 is zero? What does the comparison of Q and df tell me? I am not familiar with which relationships hint at a specific value of tau^2. And, I added the forest plot. Could you derive any conclusion of heterogeneity from it?
Comment: Okay, sound reasonable to draw any conclusions about heterogeneity from just to studies. The idea to add a constant was a very good one! Indeed, tau^2 does change and the results for fixed and random effects begin to differ


onload redirect aleatorio

Question: Gostaria de criar uma função que carregasse uma página aleatória de um determinado endereço. Algo do tipo www.meusite.com/(numeros entre 0-100).html
Acho que a função deveria criar a tag A, depois preencher com o texto www.meusite.com/ + random number + .html; e no final ser ativada por onload dentro da tag body.
Tem como fazer algo do tipo usando JS? Acredito que sim mas nem sei por onde começar.
Agradeço desde já qualquer ajuda.
Comment: Percebes as implicações para o utilizador de ir para uma página e ser redirecionado para outra no browser? Isso é mau e os motores de busca não gostam... Não podes fazer esse redirect no servidor?
Comment: Podes explicar melhor _"ativada por onload dentro da tag body"_? Queres um redirect automático aleatório? ou clicando num link que tem um endereço aleatório?
Comment: Sem click, gostaria que fosse automatico.
Comment: Na verdade eu estou tentando criar uma pagina inicial que abra links aleatorios cada vez que eu abra o browser. os links seriam de paginas com mensagens e frazes do dia de um site especifico
Comment: Concordo com o Sergio, em que isso é daquele tipo de paginas que eu evito a todo o custo, em que estou numa página de repente sou magicamente levado para outra à sorte.
Comment: Como disse acima, a pagina em si nao sera publicada, ficara armazenada localmente no meu Pc,sera usada como pagina inicial. apenas os links estarao online. teoricamente concordo que seja bastante irritante, mas nesse caso como o redirecionamento e para uso pessoal nao vejo problema
Comment: Podes fazer isso também exibindo uma seção da página com a informação aleatória. Aí essa página poderia vir como um `iframe` com página aleatória ou definido no servidor
Answer: No HTML insira um onload que chama uma função:

Função JavaScript:
 function mudarPagina() {
      var random = Math.floor((Math.random() * 100) + 1);
      location.href="http://www.meusite.com/"+random+".html";
 }

Seria isso?
Comment: Exatamente o que eu precisava, mais simples que eu imaginava, porem jamais conseguiria sozinho. Muito Obrigado
Comment: De nada, js é bem simples mesmo recomendo que assista vídeos do [rodrigo branas](https://www.youtube.com/user/rodrigobranas) no youtube para saber mais sobre js, angularjs e nodejs
Comment: Vou ver os videos sim, muito obrigado pela ajuda e pela dica

onload redirect aleatorio


Inequalities involving expectations

Question: Consider four random variables $W, X,Q,Y$, where $Q$ and $Y$ are binary. Assume
$$
\begin{aligned}
& (1) \quad E(Q(X+W)|Y=1)\geq 0\\
& (2) \quad E(W|Y=1)=0\\
& (3) \quad \Pr(Q=1|Y=1,W)=1
\end{aligned}
$$
Note that (2) and (3) imply
$$
(4) \quad E(QW|Y=1)=0
$$
Hence, by combining (1) and (4), we conclude
$$
(5) \quad E(QX|Y=1)\geq 0.
$$
Question: I want to obtain (5) under a condition weaker than (3), ideally, something like
$$
(3')\quad \Pr(Q=1|Y=1,W)> \Pr(Q=0|Y=1,W).
$$
To this end, I am willing to also modify (2), where I suspect we might need something like
$$
(2')\quad E(W|Y=1)\leq 0.
$$
I cannot modify (1).
If this strategy does not seem meaningful, could you advise on an alternative successful strategy? Also, I cannot assume mean independence between $W,Q$ or impose $E(W|Q=1)=0$.
Comment: What is the support of $W$? Is $W$ non-negative? Non-positive? Arbitrary? Can its various conditional supports be affected/restricted, or this should not/cannot happen?
Comment: $W$ is absolutely continuous, with support equal to the real line.
Comment: Its support conditions can be costrained.
Answer: Note that all the $Y=1$ conditions can be dropped, as everything is conditioned on $Y=1$, and $Y$  appears nowhere except in the conditioning part of the statements.
Replacement condition:
(2'). $E(W|Q=1)=0$
This will do the job as a weaker replacement for (2) and (3) together, as a) $E(QW|Q=0) =0$ by construction and b) $Q$ binary together with (2') imply (4), which, as you observe, combined with (1) implies (5).
Note that (2') is a necessary condition for (4) to hold, as
$$E(QW) = 0\cdot p(Q=0) + E(W|Q=1)\cdot p(Q=1)$$
so for $E(QW) = 0$, it must be that $E(W|Q=1) = 0$ or $p(Q=1)=0$, the latter of which simplifies the problem considerably!
This assumption is much weaker than the original (2) and (3); it makes no assumption about $p(Q=1)$, as does (3), and it does not assume the existence of moments for $W$, as does (2), except when $Q=1$.
Comment: 1) I am not assuming mean independence between $W$ and $Q$.  2) Note that whatever conditions you impose, they have to end up with $E(W|Q=1) = 0$, as $E(WQ) = 0\cdot p(Q=0) + E(W|Q=1)\cdot p(Q=1)$, so, for $E(WQ) = 0$, it must be that $E(W|Q=1) = 0$ or $p(Q=0) = 1$.
Comment: Thanks, but I cannot assume mean independence between $W,Q$
Comment: Apologies for not having specified this!!!
Comment: Ok, understood.
Answer: We must have that $W$ and $Q$ are not mean-independent, so they are certainly statistically dependent.
But conditional independence does not imply, nor is implied by, independence.
Assume then conditional independence of $Q$ from $W$ given $Y=1$:
$$A1: \Pr(Q \mid Y=1, W) = \Pr(Q \mid Y=1)$$
From the linearity of expected value we have
$$(1):\; E(Q(X+W)|Y=1)= E(QX|Y=1) + E(QW|Y=1) \geq 0$$
$$\implies E(QX|Y=1) \geq -E(QW|Y=1).$$
So a sufficient condition for what we want is
$$E(QW|Y=1) \leq 0.$$
Under $A1$,
$$E(QW|Y=1)  = E(Q|Y=1) \cdot E(W|Y=1) = E(Q|Y=1) \cdot 0 = 0.$$
Whether the $A1$ assumption is considered a "weaker" assumption than OP's eq. $(3)$,  depends on the particulars of the case.
ADDENDUM
In a later comment the OP informed that the conditional supports can be different than the unconditional ones. In such a case:
We need only to assume $(1)$ and
$$A2: W \mid \{Y=1\}\, \in (-\infty, 0]. $$
From $(1)$ we still get that a sufficient condition for what we want is $E(QW|Y=1) \leq 0$. Since $Q \in \{0,1\}$ and since, under $\{Y=1\}$, $W$ is non-positive, it follows that
$$QW \mid \{Y=1\} \leq 0 \implies E(QW|Y=1) \leq 0$$
$$\implies E(QX|Y=1) \geq 0.$$

Inequalities involving expectations


A rational number which is 50 times its own logarithm to the base 10 is?

Question: This question is from Advanced problems in mathematics for jee . I got it as a challenging question.
I tried it in this way
    50 log x base 10 = x
But there seemed no solution for it as per my level.
**Please don't do it based on option. I want solution as if there was no option given **
Comment: I guess it's 100 ... But I need **solution** not just **answer**
Comment: When options are given you might as well just fill the options in to see which one statistifies the question.
Comment: Sorry that one thing in the question was miss placed. Am sorry
Comment: Since $\ln x$ is concave, $\frac{x\cdot \ln 10}{50}$ can be a tangent or a secant. We test it's a secant and the 2nd root is near $1.04$, not an elementary function.
Answer: We have that $50\log_{10}(x)=x$. Therefore $10^{x}=x^{50}$. Let $x=p/q$, with $(p,q)=1$. Then $$q^{50q}10^{p}=p^{50q}$$
It follows that $q=1$ and $p$ is a power of $10$ (and therefore so is $x$).
Put $x=10^n$. Then $50n=10^n$. Since $2$ and $5$ divide $10$ to the same power, we must have $2|n$. Put $n=2k$. Then $$100k=100^k$$
We see that $k=1$ satisfies the equation, but for $k>1$ we have that $100^k\gg100k$.
Therefore $x=10^2$.

There is another solution to the equation, but it is not rational.
Answer: The solution is 100. Just write the equation:
$$x=50\log x$$
For $x=1$ you have $1=50\times 0$ which is false.
For $x=10$ you have $10=50\times 1$ which is false.
For $x=100$ you have $100=50\times 2$ which is true.
For $x=1000$ you have $1000=50\times 3$ which is false.
If you don't want to check the options the general way to solve this equation is:
$x=50\frac {\ln x} {\ln 10}$
$\frac x {\ln x}=\frac {50} {\ln 10}$
$\frac {\ln x} x=\frac {\ln 10} {50}$
$e^{-\ln x}\ln x=\frac {\ln 10} {50}$
$-e^{-\ln x}\ln x=-\frac {\ln 10} {50}$
Now you apply Lambert's W function which is defined as $W(z)e^{W(z)}=z$
$-\ln x=W(-\frac {\ln 10} {50})$
$$x=e^{-W(-\frac {\ln 10} {50})}$$
Which is equal to $100$
Answer: We have
$$x = 50\log_{10}x \implies x = \log_{10}\left(x^{50}\right) \implies 10^x = x^{50} \implies 2^x \cdot 5^x = x^{50}$$
Hoping that $x$ is an integer, we then see that $x$ has only $2$ and $5$ as its prime divisors, i.e., $x = 2^a 5^b$. This means we have
$$2^x \cdot 5^x = 2^{50a} \cdot 5^{50b}$$
This means $x=50a=50b \implies a=b$, i.e., $x=2^a \cdot 5^b = 10^a$. Further, $50 \mid x$, which means $a \geq 2$. Hence, plugging in $x=10^a$ in $x=50\log_{10}x$, we obtain
$$10^a = 50a$$
Note that for $a>2$, we have $10^a-50a > 0$. Hence, $a=2$ is the only solution, which gives us $x=100$.
Comment: Don't just hope man,
Answer: Here's one way of thinking about it.  The equation is $x=50\log_{10}x$.  Suppose
$x=10^n$.  We need to make some kind of guess to get started.  Might has well gues something we at least will have a chance of solving.
Substituting $10^n$ for $x$ gives
$$10^n=50\log_{10}10^n\implies 10^n=50n$$
So, we need a multiple of $50$ which is also a power of $10$.  The only $n$ which will work are of the form $2\cdot 10^k$.  So,
$$10^{2\cdot 10^k}=50\cdot2\cdot10^k=10^{k+2}$$
We are now reduced to solving,
$$2\cdot10^k=k+2$$
$k=0$ clearly works, but for larger values of $k$ $2\cdot10^k$ will be larger than $k+2$.
If $k=0$, $x=2\cdot 10^0=2$.  Therefore, $x=100$.


Would two different pivotal quantities of the same parameter give the same confidence interval?

Question: I couldn't think of an example but it would be great if someone could give one.
Comment: What do you mean by pivotal quantity?
Comment: A pivotal quantity Q = g(Y;theta) is a function of the data Y and the unknown parameter theta such that the distribution of the random variable Q is fully known ([Wikipedia](http://en.wikipedia.org/wiki/Pivotal_quantity)). There is an example in another question I asked [here](https://stats.stackexchange.com/questions/105727/confidence-interval-for-the-standard-deviation-of-a-normal-distribution-with-kno).
Comment: Ooops, for some reason I read pivotal as pivot, even though I wrote pivotal... It's probably handy the clarification is there anyway.
Answer: If $U(X,\theta)$ is a pivotal quantity, then so is  $g(U(X,\theta))$, where $g(\cdot)$ does not involve the parameter. Therefore, the there are literally infinite numbers of pivots, but not all of them will be of the same length for a given confidence level.
Revised per OP's Comments
As a specific example, lets take the familiar confidence interval for the mean given a sample of size $N$ from a normal population with known standard deviation $\sigma$:
We know from basic statistics that $\frac{\sqrt{N}(\bar X-\mu)}{\sigma}\sim \mathcal{N}(0,1)$, which is free of $\mu$ and therefore is a pivotal quantity for our particular inference problem.
Now, lets take $g(z)=z^2$ as our parameter-free function. If we apply it to the above pivot, we get:
$g\left(\frac{\sqrt{N}(\bar X-\mu)}{\sigma}\right)\sim \chi^2_1$, which is also a pivotal quantity.
If we form a 95%CI from the above two pivotal quantities, we get:
$\bar X \pm \frac{1.96 \sigma}{\sqrt{N}}$ for the familiar "textbook" CI based on a normally distributed pivotal quantity.
For the one based on the Chi-squared pivotal quantity, we have to do a little more work:
$P\left(\chi^2_{(.025,1)}\leq \left(\frac{\sqrt{N}(\bar X-\mu)}{\sigma}\right)^2 \leq \chi^2_{(.975,1)}\right) = 0.95 \rightarrow$
$P\left(\sigma\sqrt{\frac{\sigma \chi^2_{(.025,1)}}{N}} \leq |\mu -\bar X| \leq \sigma\sqrt{\frac{\sigma \chi^2_{(.975,1)}}{N}}\right)=0.95 \rightarrow$
$P\left(\left[\sigma\sqrt{\frac{\chi^2_{(.025,1)}}{N}} \leq \mu-\bar X \leq \sigma\sqrt{\frac{\chi^2_{(.975,1)}}{N}}\right]\cup \left[-\sigma \sqrt{\frac{\chi^2_{(.975,1)}}{N}} \leq \mu-\bar X \leq \sigma \sqrt{\frac{\chi^2_{(.025,1)}}{N}}\right]\right)=0.95 \rightarrow$
$P\left(\left[\bar X+\sigma \sqrt{\frac{\chi^2_{(.025,1)}}{N}} \leq \mu \leq \bar X+\sigma \sqrt{\frac{\chi^2_{(.975,1)}}{N}}\right]\cup \left[\bar X-\sigma \sqrt{\frac{\chi^2_{(.975,1)}}{N}} \leq \mu \leq \bar X-\sigma \sqrt{\frac{\chi^2_{(.025,1)}}{N}}\right]\right)=0.95$
$\square$
Hence, our "CI" in this case is really a confidence set, since it is composed of two disjoint intervals: $\left[\bar X+\sigma \sqrt{\frac{\sigma \chi^2_{(.025,1)}}{N}} \leq \mu \leq \bar X+\sigma \sqrt{\frac{\chi^2_{(.975,1)}}{N}}\right]\cup \left[\bar X-\sigma \sqrt{\frac{\chi^2_{(.975,1)}}{N}} \leq \mu \leq \bar X-\sigma \sqrt{\frac{ \chi^2_{(.025,1)}}{N}}\right]$
This interval is not only qualitatively different from the "typical" CI, but it is also wider, and hence not the optimal interval (we usually want the shortest interval of a given confidence).
Comment: Can you give an example of two pivotal quantities that generate different confidence intervals?
Comment: @VincentWen see example above for the CI for a Gaussian mean.
Comment: @VincentWen I fixed some formatting to make it easier to follow and I realized I didn't add in the square roots, so now this should have the correct coverage (i.e., 95%)
Answer: I don't have the enough reputation to comment on the chi-square derived interval/set below, but it appears to me that the true parameter is not even in the set described: $C(X) = (\bar{X}-c2,\bar{X}-c1) \cup (\bar{X}+c1,\bar{X}+c2)$
It should still be an interval given by the union $C(X) = (\bar{X}-c1,\bar{X}+c1) \cup (\bar{X}-c2,\bar{X}+c2)$ where $c1=\chi^2_{0.025,1}, c2=\chi^2_{0.975,1}$.
Answer: Assume that you observe iid observations $X_1,...,X_n$ from some distribution, for the sake of simplicity let's say they are normal $N(\theta,1)$ for some unknown parameter $\theta$ that you wish to estimate.
By the central limit theorem, a first pivotal quantity
is $$\frac{1}{\sqrt n} \sum_{i=1}^n (X_i - \theta) \sim N(0,1).$$
But the central limit theorem also yields plenty of other pivotal quantities
by applying transformation to each $X_i$, for example
$$\frac{1}{\sqrt{2n}} \sum_{i=1}^n ((X_i-\theta)^2-1) \Rightarrow N(0,1)$$
because $(X_i-\theta)^2$ has mean 0 and variance 2.
How to pick the right pivotal quantity then?
All pivotal quantities are not created equal, and since several (many!) pivotal quantities can be obtained by the central limit theorem, it would be great to have some principled way to do that. In frequentist statistics, where you assume that the dataset comes from a distribution with an unknown parameter $\theta$ that you wish to estimate, two major principles come to mind:

sufficient statistic, see https://en.wikipedia.org/wiki/Sufficient_statistic and the related optimality results, for instance https://en.wikipedia.org/wiki/Minimum-variance_unbiased_estimator.

Maximum-likelihood estimation. If you you know the unknown distribution comes from a parametric family of distributions indexed by an unknown parameter $\theta$, you should start by looking at the Maxmimum-Likelihood estimate of the problem, which satisfies general asymptotic normality properties, and is often optimal in the sense that it achieves the Cramer-Rao lower boud. See https://en.wikipedia.org/wiki/Maximum_likelihood_estimation


Postfix configuration as relay with another server

Question: I'm trying to configure postfix to relay emails sent to mydomain.com to another host (file sharing solution that accepts incoming emails, no other mail server available)
My issue is that it creates a loop : I send an email from email@example.com to email@example.com (gets received fine) and then (as it's a file sharing solution) it will trigger a notification to firstname.lastname@example.com saying that he's got a new mail and this starts a loop (postfix is also the relay used on the file sharing solution to send external emails).
--> file sharing solution (email@example.com) has POSTFIX as smtp relay. Then Postfix is configured to send *@mydomain.com to the file sharing solution. hence the loop
Any idea how to address that ?
Thanks
Answer: It's OK I figured it out.
I wanted the loop to stop and I achieved that by using "smtpd_recipient_restrictions" and "smtpd_restriction_classes" (Postfix discards email sends from sender mydomain.com to recipient mydomain.com).
This post helped my achieving this : postfix block mail to a domain only for a specific destination domain


What is the longest duration a team didn't register a shot on goal in the Stanley Cup Playoffs?

Question: The Pittsburgh Penguins didn't have a shot on goal for about 37 minutes in game 1 of the 2016-17 Stanley Cup finals. Although the Penguins fired a number of shots, they all either went wide or got blocked, and hence non of them counted as a shot on goal.
It's uncommon to not have a shot on goal for an entire period. Did the Penguins break the record for the longest time between 2 shots on goal, in the history of Stanley Cup finals or Stanley Cup playoffs?
If so, please state which team had this record previously.
Answer: I googled "NHL no shots in a period" and found this:

Penguins recover to defeat Predators in Game 1 of Stanley Cup Final (NHL website):

Pittsburgh did not have a shot on goal in the second period. Nashville became the first team to hold an opponent to zero shots in a period during a Stanley Cup Final since the NHL began tracking shots on goal in 1957-58.

The same information was mentioned on NHL Public Relations twitter.

Considering that the source is the NHL, I consider the information reliable (and verifiable). Thus, it seems that this is the longest duration a team didn't register a shot on goal during the Stanley Cup Finals.
(This only answers the first part of your question - which is how it was stated originally. It would be nice to also find records for Stanley Cup playoffs and for regular season.)


the true parameter of confidence interval in a real life example

Question: A nice answer says

A margin of error and a confidence interval are pretty much the same thing - it's the interval in which you are quite confident that the true parameter lies. If you have a 95% confidence interval, that means that if you were to repeat your experiment, 95% of the time the true parameter value would fall within your interval. Roughly speaking, there's a 95% chance that the interval contains the true value. The margin of error is simply describing the width of your confidence interval. So, if you have a confidence interval of [4, 6], you can say that your parameter estimate is 5 with a margin of error of 1.

where the term "true parameter" is used.
I am trying to understand that term. I searched a bit and got a post What, precisely, is a confidence interval?, which seems to talk about CI theoretically without a real life example, which is hard for me to understand.
Assume the U.S. Census Bureau published a survey of people in poverty in 1995. The survey stated a confidence level of 90% for the statistics "The number of people in poverty in the United States is 35,534,124 to 37,315,094."
What the "true parameter" is in the example of Census Bureau's survey? Could someone please give a hint?

The example is adapted from source
Comment: Another of the many "confidence interval" meaning questions worth reading is https://stats.stackexchange.com/questions/26450/why-does-a-95-confidence-interval-ci-not-imply-a-95-chance-of-containing-the
Comment: @Henry Thank you. 230 upvotes indicates that post is really worth reading. I will read it thoroughly and carefully when I get a clear understanding of the basic concept with some real life examples. Would you please recommend some discussion about CI with real life examples, e.g. poll, survey, screening some kind of disease?
Comment: @WXJ96163 it's an interesting request, but you seem to have enough top down exposure to statistics, what's seems to be lacking for you is a theoretical basis. I'm not sure if it's considered off-topic.
Comment: This question appears to answer itself, because the phrase in the quotation "The number of people in poverty in the United States" describes the "true parameter."
Answer: It seems the sticking point of the OP is the phrase "true parameter." In the referenced posts I see a lot of references to "population mean", which may aid understanding initially, until one realizes that "true parameter" and "population mean" do not coincide.
Here is an inarguable statement:
The data target the processes that produced the data.
In almost all situations, including the census, the processes that produced the data do not center on the "population mean," because of numerous biases and other deviations from pure random sampling.
So what one means by "true parameter" is instead a (assumed stable) value of the data-generating process, one which the data targets (or "aims at"). Only in the most pristine of data collection scenarios can this "true parameter" be called a "population mean."
Comment: Your "inarguable" statement looks suspect to me. I think we can all agree (because it's a tautology) that data *reflect* the processes that produced them. It's the word "target" that is bothersome. From the perspective of applying statistical analysis, the objective of a confidence interval is to make a statement about a property of the real world.  Often, the "processes that produced the data" are distractions and annoyances; they are not of direct interest.   It is also generally helpful to distinguish the ontological referent of "true parameter" from its meaning within a specific model.
Comment: I don't like "reflect" in this context, because it suggests that the aim is elsewhere. My point is the data aim at whatever they aim at, yes, tautologically. So the parameter one constructs a confidence interval for may very well not be what they want, but that is realistically, what they get.


Ajuda com chave estrangeira

Question: Tenho um sistema de intranet onde o usuário cria um recado para diferente setores da empresa, apos criar o recado, ele pode ser editado e quando ele sofre uma alteração, ele coloca um hiperlink editado no fim do recado, que  ao ser clicado, abre uma modal com o recado original.
Ate ai tudo bem, o problema é quando um recado sofre mais de uma alteração, meu select pega sempre o primeiro registro, ao invés de pegar todos. Vou tentar descrever como funciona:
TABELA RECADOS tem (id, recado, data, hora) e etc. TABELA RECADOS_EDITADOS tem (id, id_recados <- chave estrangeira de recados.) etc
EXEMPLO:
Faco um INSERT na tabela RECADOS ela recebe o id=31. Se eu modificar esse recado, ocorre um UPDATE na tabela RECADOS e um INSERT na tabela RECADOS_EDITADO, que recebe um id dele e o id_recados=31, que seria a chave estrangeira.
       Se eu fizer outro UPDATE na tabela RECADOS, a tabela  RECADOS_EDITADO sofre outro INSERT com a mesma chave estrangeira 31.
Ai quando eu faco um select por exemplo SELECT * FROM RECADOS_EDITADOS WHERE id_recados = 31, ele pega o primeiro registro com 31 e não todos.
Ja tentei fazer isso e não resolveu:
  $select = mysql_query("SELECT * FROM recadosedit WHERE idRecados = '$id'");
    $v = mysql_fetch_array($select);

    $linhas = mysql_num_rows($select);

    $recadoAnterior = array();
    $dtAlterado = array();
    $hrAlterado = array();

    for($i = 0 ; $i <= $linhas ; $i++){
    $recadoAnterior[$i] = $v['recado'];
    $dtAlterado[$i] = $v['dtAlterado'];
    $hrAlterado[$i] = $v['hrAlterado'];
    }

Na hora de exibir eu também faco um for, mas ele sempre mostra o mesmo registro.
 for($i = 0 ; $i <= $linhas ; $i++){echo '

    '.$recadoAnterior[$i].'
    Data alterado:'.$dtAlterado[$i].' Hora alterado:'.$hrAlterado[$i].'

';
      }

Comment: Wesley, Tenta quebrar o seu problema em partes, primeiro você tem que identificar se tudo esta ok no seu banco de dados, vai nele e faz um select * from RECADOS_EDITADOS WHERE id_recados = 31 se la retornar apenas um registro voce tem que verificar o por que de estar fazendo update no mesmo registro, se ele esta respeitando o primary key se este id  e autoincrement
Comment: Certo, eu fiz isso e ele trouxe 4 registros e no meu código acredito que ele esta pegando esses 4 registro porque no select se eu colocar ORDER BY id DESC ele traz um registro, se eu trocar o DESC por ASC, ele traz outro, então acredito que ele esta pegando todos, só não consigo mostrar todos para o usuário
Comment: esse $v esta pegando todos os registros ? não deveria ser com ele o mysql_num_rows ?
Answer: Faça o seguinte:
$select = "SELECT * FROM recadosedit WHERE idRecados = {$id}";
    if($query = mysql_query($select)){
        if(mysql_num_rows($select)){
            while($resultado = mysql_fetch_array($select)){
                $resultados[] = $resultado;
            }
        }
    }

    if(!empty($resultado)){
        foreach($resultados as $resultado){
            print " Recado: " . $resultado['recado'];
            print " Alterado(data): " . $resultado['dtAlterado']
            print " Alterado(horas): " . $resultado['hrAlterado']   . "
";
        }
    }

Bom, não tenho muito tempo, por isso serei simples e objectivo.
O problema está na forma como retornas os valores dessa consulta com o mysql_fetch_array:
$v = mysql_fetch_array($select);

No caso, armazenas apenas o valor da primeira coluna dos resultados encontrados nessa consulta. Para isso, bastava que introduzisses o mysql_fetch_array num loop, como no exemplo acima:
while($v = mysql_fetch_array($select))
{
...
}

Por que não devemos usar funções do tipo mysql_*?
Comment: Edilson,  agradeco pela grande ajuda, seu codigo deu certo, so precisei trocar o if(!empty($resultado)) por if(!empty($resultados)).
Comment: Mas, quando eu clico no primeiro recado editado ele mostra todas alteração, quando clico no segundo ele mostra todas as alterações do primeiro e do segundo.
Comment: Olha, talvez tenha compreendido mal o problema, podes explicar-te melhor ?
Comment: Seguinte, tem uma pagina de recados, nessa pagina ele faz um select para buscar todos recados que estão em aberto, e uso o while para mostrar o recado, dentro desse while tem um If para verificar se esse recado ja foi editado, caso ele ja tenha sido editado ele mostra o recado e  um hiperlink escrito editado, onde o usuário  clica no editado e aparece o recado anterior em um modal, onde entra o código que você me ajudou, que por sinal deu certo, o único problema que se eu clicar no recado abaixo, ele mostra as edição dele e dos recados que estão acima.
Comment: Coloquei isso no fim do for: unset($resultados); e resolveu, agradeço pela ajuda Edilson
Comment: Talvez porque estavas a reutilizar essa mesma variável.

Ajuda com chave estrangeira


How to determine if there is a statistical difference in the means of multiple groups

Question: I am a statistics newbie who is not only trying to learn statistics, but also R.
I have a list of data which contains 7 variables. I would like to determine if there is a statistical difference in the mean of each group. For sake of explanation (although this is not the actual data parameters), lets say I wanted to compare the weights of fish in 7 different ponds in 7 different states. Each pond has a different number of fish weights. Is there a way in R to automatically determine if there is a difference between each mean? If so, what is it and what function would be most appropriate. Thanks in advance. Also, I apologize for my ignorance as it relates to this topic; however I am trying to learn.
Answer: This is meant to augment Brent Kerby's answer.
Unfortunately, some of the methods that are used in the native stats package in R aren't the most widely applicable.  And unfortunately, these are the methods that you will see most commonly shown in examples.
For example, I don't recommend using the anova function for routine use for reporting the anova table from a linear model.   That function uses type-I sums of squares, and that is probably not what you want.  It doesn't matter in simple balanced designs, but as the models get more complicated and unbalanced, the answers from type-I and type-II sums of squares will be different.
One simple solution here is to use the Anova function from the car package.
For an example, first, let's install packages and make up some data.
### Install packages

if(!require(car)){install.packages("car")}
if(!require(multcompView)){install.packages("multcompView")}
if(!require(lsmeans)){install.packages("lsmeans")}

### Create some toy data

pond   = c(rep("Walden", 4), rep("Koi", 5), rep("Ness", 4))
weight = c(27,25,18,34,77,87,75,80,81,12,15,14,20)
fish   = data.frame(pond, weight)

Model and ANOVA:
Model = lm(weight ~ pond,
           data = fish)
library(car)
Anova(Model)

Similarly, I would avoid post-hoc functions like TukeyHSD to do the mean separation after anova. This function is applicable only for balanced or mildly unbalanced data, and has other limitations.
Luckily there are the packages lsmeans and multcomp, which are far more broadly applicable.
So, in your example,
library(multcompView)
library(lsmeans)

leastsquare = lsmeans(Model,
                      pairwise ~ pond,
                      adjust = "tukey")

leastsquare

cld(leastsquare,
          alpha   = 0.05,
          adjust  = "tukey")

A relatively complete example of a one-way anova in R is here: R Handbook: one-way anova. (Caveat: I am the author of this page).
I know these seem to make using R more complicated, but you are better off learning the more flexible functions from the outset.
A couple of books that may help a beginner in analysis of experiments using R. (Caveat: without much statistical theory, and with some statements some statisticians may disagree with):  The Handbook of Biological Statistics uses SAS, but has links to same examples and analyses in R. And Summary and Analysis of Extension Program Evaluation in R. (Caveat: I am the author of this second book.)
Answer: The classical approach here is called a one-way ANOVA. If you have a data frame fish containing two columns, namely a weight column giving the weight of each fish and a pond column identifying the pond the fish is from (as a factor), then you can execute the ANOVA in R as follows
anova(lm(weight ~ pond, fish))

In the output, the value for PR(>F) gives you the P-value for testing the null hypothesis that the mean fish weight is the same in all 7 ponds.
The ANOVA procedure makes certain assumptions about the data. If these assumptions are violated, for instance if the fish weights are non-normally distributed (especially for small sample sizes) or if the variance of fish weight is substantially different in different ponds, then an alternative approach may be needed. You can find some pointers in the answers here: Alternatives to one-way ANOVA for heteroskedastic data.
You might also consider creating a chart showing a confidence interval for each of the seven means. In particular if the ANOVA leads you to reject the null hypothesis then this could help in interpreting the result.


Is there a way to check if JS thread is busy?

Question: There are some heavy computations that I want to run on my react native app but I only want to run them once react has finished rendering all UI. Is there a way to check if the JS thread is busy?
Comment: Did you ever find a way to do this?
Answer: Yes you can use InteractionManager.runAfterInteractions to wait until all rendering/animation is completed before running your computations. See the documentation here.
Comment: But this is still for user interactions. Know of any other way?
Use case is, I need to wait for a pretty complex app to finish making API calls and rendering to do something.


Evaluate $\int_0^1 dx \phantom{1} (1-x)^{\alpha} x^{\beta} \left( (1-x)^2 a + x^2 b \right)^{-\frac{\alpha+\beta}{2}}$ in terms of Gamma functions

Question: I want to express
\begin{align}
\int_0^1 dx \phantom{1} (1-x)^{\alpha} x^{\beta} \left( (1-x)^2 a + x^2 b \right)^{-\frac{\alpha+\beta}{2}}
\end{align}
In terms of products of Gamma function.
Recall the Beta function
\begin{align}
B(x,y) = \int_0^1 t^{x-1} (1-t)^{y-1} dt = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}
\end{align}
The shape is similar except the additional factor $((1-x)^2 a + x^2 b)$....
Comment: Have you any hypotheses on $\alpha,\beta$? Is $\alpha+\beta$ a positive even integer? (if so, I can help you: in general, I'm not sure)
Comment: @FShrike, At this moment I am guessing that $\alpha, \beta$, as an integer!
Comment: I've cleaned up the final closed form slightly. At any rate, $\Gamma$ does not seem to appear
Answer: I can't answer your question in general, and doubt a general answer exists: but, I can answer a special case.

$\newcommand{\d}{\,\mathrm{d}}\newcommand{\res}{\operatorname{Res}}$Suppose $\alpha,\beta>-1$ and $\alpha+\beta=2m$ where $m\in\Bbb N$ ($m\ge0$ is guaranteed by the conditions on $\alpha,\beta$ and $m=0$ is just handled by the Beta function ordinarily). Suppose also that $a,b>0$. Suppose for now that $\beta$ itself (and thus also $\alpha$) is not an integer - the case where they are (nonnegative) integers follows either from more elementary techniques or from taking limits.
Let $\log_1:\Bbb C^\star\to\Bbb C$ be the logarithm induced by $0\le\arg<2\pi$ and $\log_2:\Bbb C^\star\to\Bbb C$ be the logarithm induced by $-\pi\le\arg<\pi$.
Define: $$f:\Bbb C\setminus[0,1]\to\Bbb C$$Through: $$z\mapsto\exp(\alpha\log_2(1-z))\exp(\beta\log_1(z))\cdot((1-z)^2a+z^2b)^{-m}$$
This is meromorphic (! this crucially relies on $\alpha+\beta\in\Bbb Z$) with poles at the roots of $(1-z)^2a+z^2b=z^2(a+b)-2za+a$, which occur at:
$$\frac{2a\pm\sqrt{4a^2-4a(a+b)}}{2(a+b)}=\frac{a\pm i\sqrt{ab}}{a+b}=:\zeta_{\pm}$$
Integrating on a clockwise oriented dogbone contour, noting that as $z\to x\in(0,1)$ from above the real axis we find $f(z)$ tends to the integrand $(1-x)^\alpha x^\beta((1-x)^2a+x^2b)^{-\frac{\alpha+\beta}{2}}$ but as $z\to x\in(0,1)$ from below the real axis we find $f(z)$ tends to this quantity multiplied by $\exp(2\pi i\beta)\neq1$, we get: $$2\pi i(\res(f;\zeta_+)+\res(f;\zeta_-)+\res(f;\infty))=(1-\exp(2\pi i\beta))\cdot J$$Where $J$ is our desired integral.
The residue at $\zeta_\pm$ will equal the $(m-1)$th coefficient of the Taylor series of: $$z\mapsto\frac{\exp(\alpha\log_2(1-z))\exp(\beta\log_1(z))}{(a+b)^m(z-\zeta_{\mp})^m}=:g_{\pm}(z)$$When expanding about $\zeta_{\pm}$.
I'm not sure right now how to attack this in general, but I'll settle for the case $m=1$ now before I go to sleep.
Then it's easy: we just have to evaluate $g_{\pm}(\zeta_{\pm})$. We get: $$J=\frac{2\pi i}{1-\exp(2\pi i\beta)}(g_+(\zeta_+)+g_-(\zeta_-)+\res(f;\infty))$$
To identify $\res(f;\infty)$ we need to identify the $z^{-1}$ coefficient of the power series expansion of $f$ at $\infty$ - then multiply it by $(-1)$. In the knowledge that this series and the asymptotics are well-defined, to make life easy it suffices to consider the asymptotics as $z\to\infty$ along the positive real axis. With $z\gg0$ real we can compute: $$\begin{align}[z^{-1}]f(z)&=[z^{-1}]\frac{\exp(-\pi i\alpha)}{a+b}\frac{(1-z^{-1})^\alpha}{1-z^{-1}\cdot\frac{2a}{a+b}+z^{-2}\frac{a}{a+b}}\\&=[z^{-1}]\frac{\exp(-\pi i\alpha)}{a+b}(1-\alpha z^{-1}+o(z^{-1}))\left(1+z^{-1}\frac{2a}{a+b}+o(z^{-1})\right)\\&=\frac{\exp(-\pi i\alpha)}{a+b}\left(\frac{2a}{a+b}-\alpha\right)\end{align}$$Hence: $$\res(f;\infty)=\frac{\exp(-\pi i\alpha)}{a+b}\left(\alpha-\frac{2a}{a+b}\right)$$
Now for the ordinary residues.
The modulus of each $\zeta_{\pm}$ is $\sqrt{\frac{a}{a+b}}$. The $\log_1$-argument $\zeta_+$ is $\arctan\sqrt{\frac{b}{a}}=:\phi_1$ and the argument of $\zeta_-$ is $2\pi-\arctan\sqrt{\frac{b}{a}}$. The modulus of each $1-\zeta_{\pm}$ is $\sqrt{\frac{b}{a+b}}$ and the $\log_2$-arguments are $\mp\arctan\sqrt{\frac{a}{b}}=:\mp\phi_2$ respectively. So: $$\begin{align}g_+(\zeta_+)&=\frac{(b/(a+b))^{\alpha/2}\exp(-i\alpha\phi_2)(a/(a+b))^{\beta/2}\exp(i\beta\phi_1)}{2i\sqrt{ab}}\\&=\frac{b^{\alpha/2}a^{\beta/2}}{2i\cdot(a+b)\sqrt{ab}}\exp(i(\beta\phi_1-\alpha\phi_2))\end{align}$$And: $$g_-(\zeta_-)=-\frac{b^{\alpha/2} a^{\beta/2}}{2i\cdot(a+b)\sqrt{ab}}\exp(i(\alpha\phi_2-\beta\phi_1))\exp(2\pi i\beta)$$Concluding: $$J=-\frac{2\pi i\exp(-\pi i\alpha)}{(a+b)(1-\exp(2\pi i\beta))}\left(\frac{2a}{a+b}-\alpha\right)\\+\frac{\pi b^{\alpha/2}a^{\beta/2}}{(a+b)\sqrt{ab}}\left(\cos(\beta\phi_1-\alpha\phi_2)+i\frac{1+\exp(2\pi i\beta)}{1-\exp(2\pi i\beta)}\sin(\beta\phi_1-\alpha\phi_2)\right)$$
Which after some careful simplification becomes: $$\begin{align}\int_0^1\frac{(1-x)^\alpha\cdot x^\beta}{(1-x)^2a+x^2b}\d x&=\pi\cdot\frac{\beta a-\alpha b}{(a+b)^2}\csc(\pi\beta)\\+\pi\cdot\frac{b^{\alpha/2}a^{\beta/2}}{(a+b)\sqrt{ab}}&\cos\left(\alpha\arctan\sqrt{\frac{a}{b}}-\beta\arctan\sqrt{\frac{b}{a}}\right)\\+\pi\cdot\frac{b^{\alpha/2}a^{\beta/2}}{(a+b)\sqrt{ab}}&\cot(\pi\beta)\sin\left(\alpha\arctan\sqrt{\frac{a}{b}}-\beta\arctan\sqrt{\frac{b}{a}}\right)\\\int_0^1\frac{x^\beta\cdot(1-x)^{2-\beta}}{(1-x)^2a+x^2b}\d x&=\frac{\pi}{a+b}\csc\pi\beta\left(\beta-\frac{2b}{a+b}+\left(\frac{a}{b}\right)^{\frac{\beta-1}{2}}\sin\left(\frac{\pi\beta}{2}+2\arctan\sqrt{\frac{a}{b}}\right)\right)\end{align}$$For all positive real $a,b$ and real $-1<\alpha,\beta<3$ with $\alpha+\beta=2$ (regarding this as a limit for integer $\beta,\alpha$).
I have numerical evidence to suggest this revision of the post has no errors :)
I don't have much hope for a closed form in general.


There are infinitely many numbers that can't be written as a sum of a prime and a triangular number

Question: While having lunch in our cafeteria, some mathematicians told me of a quite interesting problem:
There are infinitely many numbers that can't be written as a sum of a prime and a triangular number.
They've said that they all failed to prove that theorem.
Unfortunately, I failed in proving that as well.
Does someone of you know a proof of that? Or is the theorem false at all?
The triangular numbers are given in explicit form as $T_n = \frac{n(n+1)}{2}$.
Comment: The difference of two triangular numbers is usually not prime, so usuallt you cannot write a triangular number in this form. You may or may not want to modify your question to exclude that type of response. Also see http://math.stackexchange.com/questions/1586507/ for this idea.
Comment: In order to improve the quality of the question (which is generally interesting IMO), you can: 1. Include the mathematical definition of *triangular number* (instead of leaving it for the reader to google). 2. Give an example of at least one such number (since it is not that easy to find).
Comment: @quid: Thank you for the link, but I can't see why the difference of two triangular numbers is usually not prime.
Comment: @barak manos: Thank you for your advice. In the link posted by quid, one shows that 2016 can't be written as a sum of a prime and a triangular number.
Answer: Take $n < m$. Notice that $d = m(m+1)/2 - n(n+1)/2 = (1/2)(m-n)(m+n+1)$. Say $m > 2$ is even.
If $n < m - 1$ is odd, then $m + n + 1 > 4$ is even, and so $d$ is composite. If $n < m - 2$ is even, then $d$ will have non-trivial factors $(1/2)(m-n)$ and $m + n + 1$.
This leaves $n = m - 1$, yielding $d = m$, or $n = m - 2$, yielding $d = 2m - 1$. So choose $m$ such that $2m - 1$ is not prime, and the numbers $T_m$ fit the criterion. For instance, $m = 6k + 2$ always works, $k \ge 1$.
Comment: m need not be even, only prime. 30k + 2, 3, 5, 8, 12, 14, 18, 20, 25, 26, 28 will work for k ≥ 1. Now the difficult question: Are there infinitely many non-triangular numbers that are not the sum of a triangular number and a prime?
Comment: @gnasher729 there is a conjecture to the contrary by Z.W. Sun.See conj 1.1 in https://arxiv.org/abs/0803.3737
Comment: After some experimentation, I'd suggest that the integers which are not the sum of a triangular number and a prime are the triangular numbers Tn where neither n nor 2n-1 are prime, plus the numbers 2, 7, 61, 211, and 216. For example, for x = 3,247,410,348 x - Tn is composite for a bit over 1,100 of the largest triangular numbers less than x, but x - Tn would have to be composite for over 80,000 triangular numbers.


Need help with finding the inverse of a matrix using row reduction

Question: I've been trying to find the inverse of the matrix
\begin{pmatrix}1&0&-2&1&0&0\\ 3&1&-2&0&1&0\\ -5&-1&9&0&0&1\end{pmatrix}
using row reduction, but my process seems to be incorrect. Here are the steps I took:
\begin{pmatrix}1&0&-2&1&0&0\\ 3&1&-2&0&1&0\\ -5&-1&9&0&0&1\end{pmatrix} $\underrightarrow{\begin{gathered}R_{2}-3R_{1}\\ R_{3}+5R_{1}\end{gathered}}$
\begin{pmatrix}1&0&-2&1&0&0\\ 0&1&4&-3&1&0\\ 0&-1&-1&5&0&1\end{pmatrix} $\underrightarrow{R_{3}+R_{2}}$
\begin{pmatrix}1&0&-2&1&0&0\\ 0&1&4&-3&1&0\\ 0&0&3&2&1&1\end{pmatrix} $\underrightarrow{\frac{R_{3}}{3}}$
\begin{pmatrix}1&0&-2&1&0&0\\ 0&1&4&-3&1&0\\ 0&0&1&\frac{2}{3} &\frac{1}{3} &\frac{1}{3} \end{pmatrix} $\underrightarrow{R_{2}+2R_{1}}$
\begin{pmatrix}1&0&-2&1&0&0\\ 0&1&0&-1&1&0\\ 0&0&1&\frac{2}{3} &\frac{1}{3} &\frac{1}{3} \end{pmatrix} $\underrightarrow{R_{1}+2R_{3}}$
\begin{pmatrix}1&0&0&\frac{7}{3} &\frac{2}{3} &\frac{2}{3} \\ 0&1&0&-1&1&0\\ 0&0&1&\frac{2}{3} &\frac{1}{3} &\frac{1}{3} \end{pmatrix}
However, the answer I got for the inverse matrix was incorrect. The correct answer is supposed to be:
$$A^{-1}=\left(\begin{array}{ccc}
7 / 3 & 2 / 3 & 2 / 3 \\
-17 / 3 & -1 / 3 & -4 / 3 \\
2 / 3 & 1 / 3 & 1 / 3
\end{array}\right)$$
Can anyone help me identify where I went wrong in my row reduction process? Any help would be greatly appreciated!
Comment: What happened the fourth step? You're supposed to use the bottom $1$ to clear out the third column.
Answer: Your mistake is when you did the operation $R_2 \to R_2 + 2R_1.$ This would introduce a $2$ entry in the $(2,1)$ position (ie. second row, first column), which you don't want. Do the operation $R_2 \to R_2 - 4R_3$ instead.


Confirmação na planilha com Python e Pandas

Question: Estou tentando fazer uma lista de presença com o python, onde o convidado chega, e eu digito o RG dele para confirmar presença em uma planilha do Excel. Porem não estou conseguindo adicionar um ( OK )  nessa planilha,
O Código que eu fiz foi esse.
import pandas as pd

convidados_df = pd.read_excel(f'Cadastro.xlsx')
convidados = convidados_df['NomeCompleto']
identificacao = convidados_df['RG']

dicionario = dict(zip(convidados, identificacao))
rg = 2029300091
PrimeiroDia = []

for chave, valor in dicionario.items():
    if rg == valor:
        PrimeiroDia.append('Confirmado')

print(PrimeiroDia)

assim o resultado sai bacana no terminal.

eu queria mesmo era adicionar um OK na planilha do Excel
Answer: import pandas as pd

import numpy as np

convidados_df = pd.read_excel('Cadastro.xlsx')

rg_input = input('Digite o rg a ser conferido')

convidados_df['Confirmação'] = np.where(convidados_df['RG'] ==rg_input, 'ok', 'no')

convidados_df

convidados_df.to_excel('Cadastro.xlsx')

Comment: Obrigado pela ajuda.
Porém a saída não esta acontecendo, quando estou digitando o ( RG ) ele não esta dando um ( ok ) para confirmar.  Vou adicionar uma nova resposta com uma imagem para você vê como esta ficando, eu gostaria que colocasse um OK cada vez que eu digitar o rg da pessoa. no primeiro dia, segundo dia e terceiro dia.
Se ja tivesse um ok no primeiro dia ele colocasse no segundo, se ja tivesse no segundo ele colocasse no terceiro dia e etc.


Complex matrix eigenvalues

Question: Consider a square matrix with complex entries (e.g. a symplectic one). Let this matrix have a pair of complex conjugate eigenvalues: does this imply that the corresponding eigenvectors are complex conjugate too?
PS: I know that's a very basic and general question, so suggestions to improve it are welcome too
Answer: In general, no. Take, for instance,$$A=\begin{bmatrix}-1 & -1-i \\ 1-i & 1\end{bmatrix},$$whose eigenvalues are $\pm i$. The eigenvectors corresponding to the eigenvalue $i$ are the multiples of $(1,-1)$, whereas the eigenvectors corresponding to the eigenvalue $i$ are the multiples of $(1,i)$.
Comment: I don't understand your question. The imaginary part of a complex vector is a real vector. What is the sign of a vector?
Comment: *Every* vector from $\mathbb C^2$ has that form. Did you mean $[0,\infty)$ instead of $\mathbb R$ perhaps?
Comment: Take $A=\left[\begin{smallmatrix}2+3 i & -2 i \\ 6+2 i & -2-3 i\end{smallmatrix}\right]$, for instance. Again, its eigenvalues are $\pm i$. An eigenvector corresponding to the eigen value $i$ is $(1,1-i)$ and an eigenvector corresponding to the eigen value $i$ is $(1,2-i)$.
Comment: Thank you!! Let me ask a thing more: could a pair of complex conjugated eigenvalues have corresponding eigenvectors whose imaginary part have the same sign?
Comment: Sorry for the bad phrasing! Suppose there's a 2x2 complex matrix with a pair of complex conjugate eigenvalues (e.g. $e^{±iα}$). Could such eigenvalues have corresponding eigenvectors of the form (e.g.) $(β+iδ, ε-iζ)$ and $(η+iθ, κ-iλ)$ (where $α, β, γ, δ, ε, ζ, η, θ, κ, λ \in \mathbb R$)?
Comment: Yes, absolutely. Sorry another time. $α, β, γ, δ, ε, ζ, η, θ, κ, λ \in [0, \infty)$

Complex matrix eigenvalues


Is there a nice way to visualize the convolution of two random variables?

Question: It is easy for me to visualize the distribution of a random variable by drawing its density function.
Suppose I have two independent random variables now. I can plot the densities and visualize how the masses are spread across the real line.  How do I visualize the convolution using that -- is there a way to see how those masses move around and  get "combined" in the convolution?
Comment: Have you seen [this YouTube video](https://youtu.be/Ma0YONjMZLI) about convolution? It cannot get more visual than that!
Answer: take a look at
https://en.wikipedia.org/wiki/Illustration_of_the_central_limit_theorem
In general, RVs that look very asymmetrical and bizarre converge faster than you can imagine to a normal distribution.  This is the Central Limit Theorem in practice.


Java code to send email only works for one email id?

Question: The below code in java is used by me to send email to folks in my team However it only works if  public static String to = "firstname.lastname@example.com"; but it would not work if i have public static String to = "firstname.lastname@example.com, email@example.com"; not sure what am i missing can someone help me to send emails to multiple id at the same time ? currently the code can only send to one person at a time ?
public static String to = "firstname.lastname@example.com, firstname.lastname@example.com";
public static String from= "SANDBOX";
public static String host = "localhost";

public  static void send_production_email(String reportDate){

    System.out.println("Preparing to Send Email to Admin's...");

    Properties properties = System.getProperties();
    properties.setProperty("mail.smtp.host", host);

      Session session = Session.getDefaultInstance(properties);

      try{

         MimeMessage message = new MimeMessage(session);
       message.setFrom(new InternetAddress(from));
       message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

       message.setSubject(" Production Database Backed up Successfully");

       message.setContent("
 Production Database Backup Completed on" +reportDate+"

"
            + "
Please do not respond to this email as this is an auto generated email

"
            +"
Thank You!

" );
       Transport.send(message);
         System.out.println("Sent message successfully....");
      }
      catch (MessagingException mex) {
         mex.printStackTrace();
      }

}

Comment: Have you tried adding multiple recipients?
Comment: Just have: String[] to = { "email@example.com", "email@example.com" }; and call message.addRecipient(Message.RecipientType.TO, new InternetAddress(to[0])); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to[1]));
Comment: DO YOU REALLY WANT ALL OF THE MESSAGE TO BE IN h4 TAGS?
Answer: You need to call message.addRecipient() for each email address or addRecipients() with an array of addresses.
Answer: That's not the way to specify more than one recipient; in short, you must use one "string" per "address", just for you to understand, try modifying temporarily your code for something like this:
// cahnge temporary:
public static String to = "email@example.com";
public static String to2 = "email@example.com";

and also:
message.setRecipients(Message.RecipientType.TO,
        new InternetAddress[] {new InternetAddress(to), new InternetAddress(to2)});