question on functions

Question: The function is defined as follows;
$f=\mathbb{Z}^{+}\times\{0,1\}\rightarrow\mathbb{Z}$ by
$$
f(n,m)=\begin{cases}n-1 & \text{if }m=0\\
-n & \text{if }m=1\end{cases}.
$$
I have to show this function is a bijection and then to find the inverse of f.
How do I start this?
Thank you.
Comment: Well, what have you tried?  Where are you getting stuck?  What don't you understand?  We need a bit more to work off of if we're going to try to point you in the right direction.
Comment: In case you do not have intuition for why this is a bijection, try drawing a picture (where $\mathbb Z^+\times\{0,1\}$ can be regarded as two copies of $\mathbb Z^+$).
Comment: I know that it should be proved the function is injective and surjective in order to prove it's bijective and I know how to prove them. But the first place I stuck is what does it mean Z⁺ *{0,1}
Comment: @Grazel: $\mathbb{Z}^+ \times \{0,1\}$ is simply the set of all pairs $(n,m)$, where $n$ is in $\mathbb{Z}^+$, and $m$ is in $\{0 , 1\}$, that is, $m$ is either $0$ or $1$.
Comment: @fuglede Hey, thank you so much. I really didn't notice that. Now I know the rest.
Comment: For example, can you find the inverse of this function? What does this imply?
Answer: To show that $f$ is a bijection we must show that it is one-to-one and onto.
One-to-one: Show that if $f(a)=f(b)$ for $a,b\in \mathbb{Z}^+\times\{0,1\}$ then $a=b$.
Hint: Separate the cases for
1) $a,b\in \mathbb{Z}^+\times\{0\}$
2) $a,b\in \mathbb{Z}^+\times\{1\}$
3) $a\in \mathbb{Z}^+\times\{0\}, b\in \mathbb{Z}^+\times\{1\}$ (or vice versa wlog)
Hint: Don't forget about the domain!
Onto: Show that for any $b\in \mathbb{Z}$, we can find an $a\in \mathbb{Z}^+\times\{0,1\}$ such that $f(a)=b$.
Hint: Separate the cases for
1) $b\ge0$
2) $b<0$
Your solution to this section should essentially tell you what the inverse of $f$ is.
Comment: @john-can you please explain the inverse part please.
Comment: Sure. The inverse of $f$ is a function $f^{-1}:\mathbb{Z} \rightarrow \mathbb{Z}^+ \times \{0,1\}$ such that $f^{-1}(y)=x \Longleftrightarrow f(x)=y$. So you're essentially just defining $f^{-1}$ based on what you found in the onto section- given an element of $\mathbb{Z} $, which element of $\mathbb{Z}^+ \times \{0,1\}$ mapped to it?

question on functions


Required Fields with unlimited field collection items

Question: I have a D7 instance with a field collection called field_professions and associated to a content type with "unlimited" amounts of fields. Within this field collection I have two fields that are required (field_professional_user and field_professions). I also have an unrequired field called field_serving_since. For the sake of testing I made the entire field collection required.
Now, when I have an item entered, I can enter a 2nd, 3rd etc. item, but whether I fill out all 3 fields, 1 of the required fields, or the unrequired and none of the required fields, it never validates that the fields are required. I can obviously see the red asterisk, but there is no validation.
Comment: Just came across this and for anyone else concerned, Field Collection now handles this correctly.
Answer: I faced This bug in field collection module ( really I didn't find out why they do this :(  ). There is no way to achieve this ( have unlimited and required fields in field collection ).
You just achieve it trickly . (set it unlimited and none-required) . use jquery for validate( checking filled )  fields.
This problem almost accures when you don't want set default value for field .(if you set default by any edit add a waist item  ).
Comment: I was afraid I'd have to do that. It was my plan B. Thanks for the info.
Comment: @CoryFischer Your welcome


the difference between AR(1) estimation and lagged endogenous variable estimation

Question: I'm very new to Time Series models. One of my biggest confusions is why estimation of Y with an AR(1) term is not the same thing as estimation of Y on a lagged value of Y. In other words, How are the following equations different from each other:
Y= Constant + AR(1)
Y= Constant + Y(-1)
Comment: Have a look at this blog post:   http://robjhyndman.com/hyndsight/arimax/
Answer: The likelihood would only differ if you treated the distribution of the first time point differently. If you don't, you'll get the same parameter estimates.
The R code below sets the method= argument of arima() to "conditional-sum-of-squares", which maximizes the same likelihood you would work with if you regressed $y_{2:100}$ on $y_{1:99}$.
y <- arima.sim(model = list(ar=.9), n = 100)
lag.y <- y[-100]
summary(lm(y[-1] ~ lag.y + 0))
arima(y, order = c(1,0,0), method = c("CSS"), include.mean = F)


How do I inject a dateFormatter servide into a service class named MyService?

Question: I have a service class declared like this:
 class MyService implements MyServiceInterface {

I want to get rid of a (working) call to a the static \Drupal::service('date.formatter') function and replace with a injected call to $this->dateFormatter.
I am looking at the most upvoted answer to this question: Make a custom date formatter for view.
It suggests that you can output a custom formatted timestamp like this:
$now = \Drupal::time()->getCurrentTime();
$currenttime = $this->dateFormatter->format($now, 'custom', 'Y-m-d H:i');

However, this does not work for me. It uses an injected call to the public function DateFormatter::format, and the upvoted answer does not explain how to set up the class where it is used to inject this service. This produces a WSOD on my site. The cause is obviously that dateFormatter has not been initialized.
As noted, I know that using a static call works:
$now = \Drupal::time()->getCurrentTime();
$currenttime = \Drupal::service('date.formatter')->format($now, 'custom', 'Y-m-d H:i');

I have a rough idea bout how to set up a service class to initialize an injected service. I.e. I think to be able to use it, I need to do at least three things:

Declare the injected service as an argument in myservice.services.yml.
Declare the injected property as a $protected variable.
Initialize it in the class' contructor.

But I am not even sure if this is correct. And the details eludes me. For example: How do I discover what name to include in myservice.services.yml?
Any guidance will be appreciated.
PS: I have studied this answer: How do I inject services in a service, but I don't understand how it applies to my question.
It has been suggested that Inject a class as dependecy injection in a service is a duplicate. The accepted answer to that question is not about the @date.formatter service that is the subject of my question, and it does not mention using autowire to solve the problem. (Which I learned how to use in the answer I now have accepted.)
Comment: The linked post is how to do it - factories aren't relevant here, date formatter is a singleton service. These days you can also autowire the arguments in services.yml instead of specifying them if you'd prefer. I haven't voted but I'm guessing the downvotes are because this is covered pretty exhaustively on this site already and the greater net at large
Comment: Does this answer your question? [Inject a class as depency injection in a service](https://drupal.stackexchange.com/questions/317368/inject-a-class-as-depency-injection-in-a-service)
Comment: A brief comment explaining *why* you downvote this question would be appreciated. I am open to improving it.
Comment: No, the answer does not address the use case where the service already exists, as is the case with the `@date.formatter` service, so there is no need to create a factory for it. It is an answer for a different use case.
Comment: I now have received an answer introducing the autowire feature. That is not mentioned in the linked post that is supposed to be a duplicate of this one.
Comment: Autowiring is optional, a newer feature - the meat of the question is definitely a duplicate. This is all laid out  with examples in [the documentation](https://www.drupal.org/docs/drupal-apis/services-and-dependency-injection/services-and-dependency-injection-in-drupal-8#s-defining-your-own-services), that's usually the best place to start when confused
Answer: But I am not even sure if this is correct. And the details eludes me. For example: How do I discover what name to include in myservice.services.yml?
Now that Drupal 9 is end of life you no longer need to do that. Replace the argument list with the autowire option:
mymodule.services.yml
services:
  mymodule.my_service:
    class: Drupal\mymodule\MyService
    autowire: true

and in the service class:
  /**
   * The date formatter.
   *
   * @var \Drupal\Core\Datetime\DateFormatterInterface
   */
  protected $dateFormatter;

  /**
   * Constructs \Drupal\mymodule\MyService
   *
   * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
   *   The date formatter.
   */
  public function __construct(DateFormatterInterface $date_formatter) {
    $this->dateFormatter = $date_formatter;
  }

So to discover the service you only need the interface DateFormatterInterface. Use autocomplete and the IDE will automatically add a use statement at the top:
use Drupal\Core\Datetime\DateFormatterInterface;

See the change record: Core services provide aliases for autowiring


appengine sdk clears datastore

Question: I am having a slight problem with the appengine SDK.
When I close it, it clears the datastore.
It is a little annoying to create the test data/users every day, so any help would be great.
I am running OSX, just so you know. And I have read this question.
But I have no file anywhere on my machine with that name. Not even when the SDK is running and the datastore contains data.
The project is not set to clear datastore on startup and I can't see anything else relating to it in the settings.
Does anyone know why this is happening?
Answer: By default, the Python SDK puts the datastore files in your system's temporary directory, thus the persistence of the datastore is not guaranteed. Provide a different path using the --datastore_path argument of dev_appserver.py.
Comment: Great, worked like a charm. Should anyone as clueless as myself, find this later. You can also set this flag in the SDK GUI under info.

appengine sdk clears datastore


Compile app engine in Travis ci and go

Question: Im trying to compile  this project raygun4goGAE on Travis ci.
But im getting  cannot find package "appengine" in any of....  its looks like the build cant find the appengine  dependencies?
I used this question compile-app-engine-application-in-travis  as a reference  how to creat the travis yaml file but i guess im missing something.
This is the yaml file :
<code>language: go
go:
  - 1.2
  - 1.3
  - 1.4
  - tip
env:
  - GOARCH=386
  - GOARCH=amd64
matrix:
  allow_failures:
    - go: tip
install:

  - export  FILE=$(curl https://storage.googleapis.com/appengine-sdks/ | grep -o 'featured/go_appengine_sdk_linux_amd64-[^\<]*' | head -1)
  - curl -O https://storage.googleapis.com/appengine-sdks/featured/$FILE
  - unzip -q $FILE

  - go get github.com/smartystreets/goconvey
  - go get code.google.com/p/go-uuid/uuid
  - go get github.com/kaeuferportal/stack2struct
  - go get golang.org/x/net/context
  - go get google.golang.org/appengine/urlfetch
  - go get google.golang.org/appengine

script:
    - ./go_appengine/goapp test ./tests;
    - ./go_appengine/goapp build ./raygun4goGAE;
</code>
And you can see here the Travis build result .
Answer: Have you try to import google.golang.org/appengine instead
Comment: instead of "appengine"

Compile app engine in Travis ci and go


Word 2013 VBA documents.open shows error file already open

Question: I have a Word macro that opens an XML file, makes some changes, saves and closes the file. The XML file exists but is definitely not open when the code gets to the point below. Just before the file opens I get an error message saying: "Run-time error '-2147024864 (80070020) The process cannot access the file -filename here- because it is being used by another process."
If I end the macro, close the .xml file and restart the macro I don't get the error message the second time.
The error message pops up when the macro is at the code below.
<code>Documents.Open FileName:=strInfoXMLName, ConfirmConversions:=False, Format:=wdOpenFormatText
</code>
Comment: Hard to say what the problem might be without showing your complete code (at least all lines related to opening/closing the file).  Clearly the file *is* open and so throws that error, but it's impossible to tell *why* it's open from one line of code.
Comment: *is definitely not open when the code gets to the point below.*  Inconsistencies cannot exist. When one appears to exist, check your premises. You'll find that at least one of them is mistaken.
Comment: Thank You! for your advice. I only posted the line of code that opens the file because I thought there was a problem with that line of code.  Per your suggestion to post the full code, I began to go through the code and extract only the parts that caused the problem. While I was doing that I only run a bare minimum section of the code and keep adding back all the many other lines of code until the problem showed up. By doing this I ended up getting rid of a lot of garage code that was causing problems.  So, thanks again for suggesting that I examine the code and isolate the problem.
Answer: Be sure to kill all instances of Word before running the sub.  Also be sure to close documents and kill Word at end of sub.
Comment: good advice, thanks, I will test this next week and report back.


How to exclude a recently added user from a list of users in node.js

Question: I have API endpoint /department/getManagersList?department_name=IT which is returning this
{
"status": "success",
"managersList": [
    {
        "id": "6103d29974535fac35286aff",
        "name": "axe deo",
        "role": "Associate React Developer"
    },
    {
        "id": "6103d1e274535fac35286afe",
        "name": "aakash kumar",
        "role": "Vice President Engineering"
    },
    {
        "id": "6103d36074535fac35286b0a",
        "name": "atanu paul",
        "role": "Senior Software Enginner"
    },
    {
        "id": "6103d7c1f2bba5af7cad4083",
        "name": "sam winchester",
        "role": "Junior Node JS Developer"
    }
]
  }

now "sam Winchester" is a new user who just created his profile I want to exclude him or in a nutshell, remove the newly created user from this list. The purpose is to return the names of all the employees of the department excluding the newly created user so that the new user can choose his/her reporting manager. Any idea how to do this?
This is the current code that is returning the above JSON object
adminController.getManagersList = async (req, res) => {
try {
var manager_list = [];
var department_data = {};
var employees_list = [];
var manager_details = {};
var department_name = req.query.department_name;

if (isEmpty(department_name))
  return res.status(400).json({
    status: "failure",
    message: `Department name ${emptyField}`,
  });
department_data = await DepartmentData.findOne({
  department_name: department_name,
})
  .populate("employees")
  .exec();
if (isEmpty(department_data))
  return res
    .status(400)
    .json({ status: "failure", message: `Department ${dataNotFound}` });

employees_list = department_data.employees;

employees_list.forEach((empList) => {
  let department_data = empList.department;
  department_data.forEach((depList) => {
    if (depList.name == department_name) {
      manager_details = {}; // * Making the object empty for next value
      manager_details.id = empList._id;
      manager_details.name = empList.full_name;
      manager_details.role = depList.role;
      manager_list.push(manager_details);
    }
  });

});
res.status(200).json({ status: "success", managersList: manager_list });
} catch (err) {
   console.log(err);
   res
    .status(500)
    .json({ status: "failure", message: "Internal Server Error" });
 }
 };

Comment: If you have access to the new user's id you could filter that user out. Use →
`response.managersList = response.managersList.filter(({ id }) => id !== )`
Comment: yes i do have access to new user id, ket me give that a try
Answer: To remove the last item from your array you could use:
const arr = [1,2,3];
arr.pop();
// arr -> [1,2]

Comment: Or `arr.slice(0, -1)` to avoid unnecessary mutation of the source array.
Answer: Generally speaking you already answered your question here:

The purpose is to return the names of all the employees of the department excluding the newly created user so that the new user can choose his/her reporting manager.

So that you need find all employees who do not have managers yet.
I assume that you have relationship between managers and users as one-to-many, (one manager can have many employees). Not sure what database are you using, but should be something like this:
department_data = await DepartmentData.findOne({
    department_name: department_name,
})
.populate({
    path: 'employees',
    match: { managerId: { $eq: null }},
})
.exec();

also rename "getManagersList" to "getEmployeesList"
Comment: there is no separate DB fro manager, it's coming from the same database as employee
Comment: ) sure, I mean not sure which kind of database (mySql, Postgres, MongoDB... etc) is used. Have you tried example above, if yes, what result you get?
Comment: the database is MongoDB, I have used the splice method example above, seems to work so far.


\r does not generate a line break

Question: I use the following code:
if (delanaloge.equals(stari)) {
    if (novi.equals("-")) {
           zdruzen = " -";
    } else {
       zdruzen = zdruzen + " " + " - " + novi + "\r";
    }
    nap = true;
 }

\r is appended to create a line break, but it does not generate a line break like I expect. I would like to generate an output similar to this:
- 213
- 232
- 1321

How can I add a line break in my string?
Comment: have you tried '\n'? for os dependent new line you ca use String osNewLine = System.getProperty("line.separator");
Comment: i try \n is the same and \r\n too. It is not like enter button
Comment: Are you talking about paragraph breaks in microsoft word, done by pressing the enter key?
Comment: \r is carriage return and \n is linebreak. Clearly you need both to advance to the next line and be in the first position.
Answer: you could use this:
public static String newline = System.getProperty("line.separator");

Comment: Awesome! Works in Android dialog windows ;)
Comment: thanks, good to know, Java seems to consequently follow this on all platforms :)
Comment: Works for me too! Thanks. When is text hardcoded in project \n works well, but when coming from Retrofit needs of System.getPrope....
Answer: New line character combinations vary between OS. Windows is \r\n, Unix-like systems such as Linux, FreeBSD, Android and so on is \n and MacOS is \r.
Try whichever suits your development environment.
Answer: Try this:
if (delanaloge.equals(stari)) {
    if (novi.equals("-")) {
        zdruzen = " -";
    } else {
        zdruzen = zdruzen + "  - " + novi + System.getProperty("line.separator");
    }
    nap = true;
}

Comment: this is good idea but - and then new line is not the same as if you in word click labeling. I try to make labeling
Answer: try to use \r\n, in some cases \n will work (or every case) .. just try both :)
Comment: i try \n is the same and \r\n too. It is not like enter button
Answer: In JTextPane and other text components \n suffices and seems a good choice. On Windows the document internally stores \r\n so document positions and getText() indices are not equal. System.getProperty("line.separator") is more correct, but \n is so universal.
Answer: Use \ n for line breaking in printing the String.
if (delanaloge.equals(stari)) {
if (novi.equals("-")) {
       zdruzen = " -";
} else {
   zdruzen = zdruzen + " " + " - " + novi + "\n";
}
nap = true;
}

Answer: A bit from the typing machines age -

\r is the carriage return and should go back to the line origin.
\n is the new line feed on and does create the new line.

For Windows systems \r\n is a typical new line - and works as on the typing machine - carriage return, then new line.
For Linux based systems it was shorten to just \n. But '\n' is normally recognized by most programs.

\r does not generate a line break


Can I call a PHP script in an Apache configuration block?

Question: I'm using PHP as an Apache module, not CGI. Every request made to a particular virtual host should result in a PHP script's execution ('/srv/web/init.php'), and I do this like so:
<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /srv/web/

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/init\.php$
    RewriteRule .* /init.php [L]
</VirtualHost>

This virtual host serves no other purpose besides executing init.php and returning its output to Apache for the response. My question is whether there is a cleaner way to do this - ie. bypassing Apache's filesystem emulation so that a "public" folder isn't required and so mod_rewrite isn't necessary. Much like calling a CGI script, it would go like this:
<VirtualHost *:80>
    ServerName example.com

    PHPScript /srv/web/init.php
</VirtualHost>

I've removed the DocumentRoot directive above since what I'm proposing would render it useless. Am I just trying to turn the Apache module into CGI, and should I just use CGI?
Answer: No, you can't directly call a PHP script. What you can do is something like:
<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /srv/web/
    DirectoryIndex init.php
</VirtualHost>

Answer: No,
PHPScript isn't an Apache Directive you can use.
http://httpd.apache.org/docs/2.2/mod/directives.html
You have to make that file default index or mod_rewrite to it.
Answer: You need to make that php file the default index file that then operates as a front controller to everything else on that site, so that all url's would then be example.com/index.php/whatever - you could make a rewrite that hides the index.php part to end users, but it would still be there directing things.


Why is the travis badge not assigned to the role in ansible galaxy?

Question: According to this documentation it should be possible to add a travis badge to an ansible role in galaxy:

Push the changes to your GitHub repo. This will kick-off a Travis
  build. When the build completes, Travis will notify Galaxy, and your
  role will be automatically imported into Galaxy with a Travis badge

Although the steps were followed:

.travis.yml added to repo that contains the notification part
access token from travis profile added to ansible galaxy
role imported manually as it was not pushed automatically

the badge does not appear.
Discussion
The build itself does not show the notification. Other roles that have a travis badge do not show this notification either.
Questions

What is causing the issue?
Why does travis not say anything regarding the notification part?
How to debug it?
Answer: It looks like your repository is structured correctly, and Travis builds are operating correctly. One thing to check: in Ansible Galaxy's settings, make sure you have added your Travis token to the role in Ansible Galaxy (instructions).
I'm guessing you've done this, but it never hurts to ask!
Two other suggestions:

Make sure you complete the rest of the README, as that's the entry point for your role on GitHub and on Galaxy. At least describe what your role does, and consider listing an example of how to use it, some available variables, etc.
If you still don't get the badge to show up, maybe there's a bug with your role (with a username like 030... maybe it's a bug in the code that grabs the role—strings that begin with numbers can be interpreted in funny ways in languages like Python!). Consider posting a bug report to the ansible-galaxy issues repository on GitHub.
Comment: I have created [an issue](https://github.com/ansible/galaxy-issues/issues/176) and an issue has been created to address the documentation improvement. Regarding the token: I have copied it from travis and pasted to the ansible galaxy. Thank you for the feedback. If the numbers in the username are causing the issue, then I will accept the answer.
Comment: @030 - It looks like the rabbit hole goes deeper—it's a Travis CI issue with their webhooks sending the wrong `Authorization` header! See [comment](https://github.com/ansible/galaxy-issues/issues/176#issuecomment-238707055) and [Travis CI issue](https://github.com/ansible/galaxy-issues/issues/176#issuecomment-238707055).


Postfix is rejecting some incoming emails ("Client host rejected: cannot find your hostname")

Question: Our postfix sometimes rejects emails. I see this error in our postfix log (/var/log/mail.log):
Feb  9 16:16:33 sd-15xxx postfix/smtpd[1972]: NOQUEUE: reject: RCPT from
    unknown[x.x.x.x]: 450 4.7.1 Client host rejected: cannot find your hostname,
    [x.x.x.x]; from=<firstname.lastname@example.com> to=<email@example.com>
    proto=ESMTP helo=<smtp.sender.com>

Here is my postconf -n :
append_dot_mydomain = yes
biff = no
config_directory = /etc/postfix
disable_vrfy_command = yes
inet_interfaces = all
mydestination = localhost, localhost.localdomain, sd-15xxx.dedibox.fr
mydomain = my-domain.com
myhostname = my-domain.com
mynetworks = 127.0.0.0/8 192.168.0.0/24 y.y.y.y <our server IP address>
relayhost =
smtpd_banner = $myhostname ESMTP (Debian/GNU)
smtpd_client_restrictions = reject_unknown_client,
    permit_mynetworks
smtpd_helo_required = yes
smtpd_recipient_restrictions = permit_mynetworks,
    reject_unauth_destination,
    reject_unknown_recipient_domain,
    reject_non_fqdn_recipient
smtpd_sender_restrictions = permit_mynetworks,
    reject_unknown_sender_domain,
    warn_if_reject reject_unverified_sender
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual_aliases.cf,mysql:/etc/postfix/mysql-virtual_aliases_mailbox.cf
virtual_gid_maps = static:5000
virtual_mailbox_base = /var/spool/vmail/
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual_domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual_mailboxes.cf
virtual_uid_maps = static:5000

It doesn't occur often, but it could have serious consequences if we missed an important email.
Do you see where this problem comes from? Is it a problem of configuration or a reverse DNS problem (as I read somewhere)?
Here is the result of nslookup x.x.x.x :
126.96.36.199.in-addr.arpa  name = Smtp16.sender.com.

Authoritative answers can be found from:
180.106.89.in-addr.arpa nameserver = dns2.iland.com.
180.106.89.in-addr.arpa nameserver = dns3.iland.com.
180.106.89.in-addr.arpa nameserver = dns1.iland.com.
dns1.iland.com  internet address = 188.8.131.52
dns2.iland.com  internet address = 184.108.40.206
dns3.iland.com  internet address = 220.127.116.11

and the result of dig x.x.x.x :
; <<>> DiG 9.5.1-P3 <<>> x.x.x.x
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 5920
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;x.x.x.x.           IN  A

;; AUTHORITY SECTION:
.           10800   IN  SOA a.root-servers.net. nstld.verisign-grs.com. 2010020901 1800 900 604800 86400

;; Query time: 227 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Feb 10 13:45:54 2010
;; MSG SIZE  rcvd: 106

I don't even know if the problem comes form our side or from the sender side.
Comment: Providing un-anonymized output would really help to determine the issue.  If you feel like you can do that, please do.
Answer: This is caused by the reject_unknown_client instruction ( http://www.postfix.org/postconf.5.html#reject_unknown_client_hostname )
Comment: How about when the reverse DNS lookup clearly is returning the correct response (that is ANSWER SECTION), what could be the reason?
Comment: So I should comment the 'reject_unknown_client' in smtpd_client_restrictions of /etc/postix/main.cf, that's it? But why isn't it a sender restriction?
Comment: Ok, I commented it and the email who was being rejected continuously has been accepted. I hope this security restriction wasn't too sensitive.
Comment: Also the `permit_mynetworks` should appear first in`smtpd_client_restrictions = reject_unknown_client, permit_mynetworks` — otherwise you could be blocking your own computers!
Answer: That's because the ip address sending the email (x.x.x.x in your case) isn't returning a valid reverse dns entry - either because there isn't a ptr record on their name server giving a valid hostname or because your dns lookups are failing.  The first thing to try is 'nslookup x.x.x.x' to see what you get.
Comment: nslookup gives :
Non-authoritative answer:
41.180.a.b.in-addr.arpa name = smtp16.sender.com.

Authoritative answers can be found from:
180.106.89.in-addr.arpa nameserver = dns2.iland.com.
180.106.89.in-addr.arpa nameserver = dns1.iland.com.
180.106.89.in-addr.arpa nameserver = dns3.iland.com.
dns1.iland.com internet address = 65.57.a.b
dns2.iland.com internet address = 63.211.d.e
dns3.iland.com internet address = 64.154.f.g

Is it ok?
Comment: Can you show the output of "dig x.x.x.x"?  Edit your question and put it there instead of as a comment so that formatting can be retained.


Marginal Effect for Poisson Model

Question: I am using package marginaleffects for calculating the AME of an exposure variable on a count dependent variable. I am hence using Poisson (and Negative Binomial as robustness). The dependent variable in this case maps the number of days that pass from the request for a license to the approval, while the exposure is "prior_conviction", measuring whether the person asking for the license was previously convicted for a felony.
If I fit the model via glm using a matched dataset, I use:
model_matched <- glm(days_to_license ~
                      prior_conviction + age +
                      sex+
                      prio_experience+
                      decade+
                      premises_type,
                    family=poisson, data = matched_dataset, weights=weights)

Let's assume these are all the confounders I need to control for. Then, to obtain the IRR, I use:
summ(model_matched, exp = TRUE, robust=TRUE, digits=3)

After this, I get that the coefficient is 1.059, meaning that having a prior conviction leads to an increase by 5.9% in the number of days needed to get the license.
I would also like to compute the AME, and hence I use:
ame_matched<-comparisons(model_matched, variables = "prior_conviction",
                           newdata = subset(matched_dataset, prior_conviction == 1)) |>summary()

Once I compute this; I get that the effect is 1.986. Is it correct then to conclude that for those having prior convictions, it takes on average 1.99 more days to receive the license, compared to those who do not have a prior conviction?
Thanks in advance for your help!
Answer: Negative binomial is not more robust than Poisson, so don't use it. You should be using a quasi-Poisson regression, which can be requested using family = quasipoisson. Negative binomial requires the model for the mean and (over-dispersed) variance to be correct; quasi-Poisson is consistent if just the mean function is correct specified. You need to use a robust standard error with quasi-Poisson (but you should be using that anyway).
If your matched sample size is large, you should include interactions between the treatment and covariates. This is also required if you don't achieve good balance after matching (though if that is the case, you should respecify the match).
If you are trying to estimate the marginal IRR, you can use essentially the same code as you would the the ATT. This code is below:
#ATT
avg_comparisons(model_matched, variables = "prior_conviction",
                newdata = subset(matched_dataset, prior_conviction == 1),
                vcov = ~subclass)

#ATT IRR
avg_comparisons(model_matched, variables = "prior_conviction",
                newdata = subset(matched_dataset, prior_conviction == 1),
                vcov = ~subclass,
                comparison = "lnratioavg",
                transform = exp)

You need to make sure you adjust the standard errors for pair membership if you performed pair or full matching.
Comment: Hi Noah. Thanks for your continuous support with marginaleffects. Your work is tremendously important.

Some questions: 1) the code I used for the AME in my post is hence not correct? 2) why do I need to include interactions between the exposure and the covariates? I used marginaleffects for Logit before and never used it. 3) I performed exact matching with substitution, do I need to adjust the standard errors as well? If so, how would you do it? Ps: agree on the NB comment, I have to do it nonetheless due to advisor's request.

Marginal Effect for Poisson Model


Lévy's Characterization of Brownian Motion Proof

Question: I am trying to understand the proof of Levy's characterization: we define the process $Y$ by $Y_t = \exp(iuM_t+\frac{1}{2}u^2t)$ where $u\in\mathbb{R}$ arbitrary and $M_t$ a continous local martingale starting at $0$ with quadratic variation $t$.
Now it should hold by applying Ito's formula, that $Y_t = 1+iu\int_0^t Y_s dM_s$, which I don't understand. To apply Ito's formula we need a twice differentiable function, in our case $f(x,t)=\exp(iux+\frac{1}{2}u^2t)$. Since $f:\mathbb{R}^2\longrightarrow \mathbb{C}$ we use the generalized Ito formula, which says:
$$f(X_t) = f(X_0) + \sum_{i=1}^d \int_0^t \frac{d}{dx_i} f(X)dX_i+\frac{1}{2}\sum_{i,j=1}^d\int_0^t\frac{d^2}{dx_idx_j}f(X)d\langle X_i,X_j\rangle,$$
where $X$ is a $d$-dimensional vector of semimartingales (I have already shown that the formula holds if $f$ maps to $\mathbb{C}$). We then get
\begin{align}
Y_t &= 1+iu\int_0^t Y_s dM_s+\frac{1}{2}u^2\int_0^tY_sds + \frac{1}{2}\left(-u^2\int_0^t Y_sds + \frac{1}{4}u^4\int_0^tY_sds + iu^3\int_0^t Y_sd\langle M,t\rangle_s \right)\\
&= 1 + iu\int_0^t Y_sdM_s + \frac{1}{8}u^4\int_0^tY_sds + iu^3\int_0^t d\langle M,t\rangle_s
\end{align}
if everything is correct. From this point I dont't know how to go on. I tried to calculate the quadratic covariation $\langle M,t\rangle$ but wasn't able to or maybe there was a mistake in the previous equation? Any help is much appreciated.
Comment: You mean $Y_t=1+iu\int_0^tY_sdM_s$?
Comment: yes, i will edit it, thanks
Answer: We suppose $\langle M,M\rangle_t=t$ so we have
$$df(M_t,t)=f_t(M_t,t)dt+f_x(M_t,t)dM_t+\frac{1}{2}f_{xx}(M_t,t)\underbrace{d\langle M,M\rangle_t}_{dt}$$
and
$$\begin{aligned}&f(x,t)=e^{iu x+\frac{1}{2}u^2t}\\
&f_t(x,t)=u^2f(x,t)/2\\
&f_x(x,t)=iuf(x,t)\\
&f_{xx}(x,t)=-u^2f(x,t)\end{aligned}$$
so if $Y_t=f(X_t,t)$ we get
$$dY_t=\frac{1}{2}u^2Y_tdt+iu Y_tdM_t+\frac{1}{2}(-u^2)Y_tdt=iuY_tdt\implies Y_t=1+iu\int_0^tY_sdM_s$$
Comment: Thank you for the answer. I don't understand where the first equation comes from. $f_tdt+f_xdM_t$ on the right handside are coming from the first sum of the generalized ito formula. But i don't understand how the second sum reduces to $1/2f_{xx}dt$
Comment: @bumbummath you may note $t \mapsto t$ is a continuous process with bounded variation, thus a semimartingale; we consider $(M_t,t)$. Also, the quadratic covariation of a semimartingale and of a continuous process with bounded variation is zero.
Comment: @bumbummath if you want a direct reference for the formula: Karatzas, Shreve; Th.3.6. p.  153

Lévy’s Characterization of Brownian Motion Proof


How to alias folders for use with IIS?

Question: I have several websites that use the same base files, other than a couple off images and stylesheets.
Instead of having the same DLL's repeated all over the place, I would like to have a bin alias in each of the folders, pointing to another, central location.
I realize I could write deployment scripts to duplicate the reused folders, but hoping for another solution.
Thanks.
Comment: this belongs on server fault.
Answer: I recommend putting your DLLs in the global assembly cache

How to alias folders for use with IIS?


How to test statistically whether my network (graph) is a "small-world" network or not?

Question:
A small-world network is a type of mathematical graph in which most
  nodes are not neighbors of one another, but most nodes can be reached
  from every other by a small number of hops or steps. Specifically, a
  small-world network is defined to be a network where the typical
  distance L between two randomly chosen nodes (the number of steps
  required) grows proportionally to the logarithm of the number of nodes
  N in the network, that is
$$ L \approx \log(N) $$

This relationship between L and N is a "thumb-rule". I'm looking for a more professional determination of small-world graphs for my research. How can I test whether my graph is a small-world graph or not?

The small-world experiment comprised several experiments conducted by
  Stanley Milgram and other researchers examining the average path
  length for social networks of people in the United States. The
  research was groundbreaking in that it suggested that human society is
  a small-world-type network characterized by short path-lengths. The
  experiments are often associated with the phrase "six degrees of
  separation", although Milgram did not use this term himself.

Thank you in advance.
Comment: I don't know what is the purpose of your papar or your background. Do you have an actual graph you want to test? You could take basic descriptive measures of your graph, any graph library would do (e.g. networkx in python or igraph in R). Just check if your network is connected, what is the diameter, the average shortest path, etc. If you are generating the graph or your context is different, I would say more info is needed in order to answer to your question.
Comment: To assess the presence of this logarithmic relationship, I think you'd need *series* of values. For instance, a sequence of snapshots of your graph evolving through time. Or a collection of different graphs corresponding to similar (comparable) systems (eg. the computer networks of several firms of various sizes).
Answer: TL;DR:
You can't.
What is typically done
The current "state of the art" in determining whether a network is a small world uses the following approach:

Calculate the mean shortest path length $L$ and the clustering coefficient $C$ of your network.
Generate an appropriate ensemble of null-model networks, such as Erdős–Rényi random graphs, or Maslov–Sneppen random graphs.
Calculate the average of the mean shortest path length $L_\text{r}$ over this ensemble of null-model networks; calculate $C_\text{r}$ analogously.
Calculate the normalised shortest path $λ := L/L_\text{r}$. and $γ := C/C_\text{r}$.
If $λ$ and $γ$ fulfil certain criteria (e.g., $λ≈1$ and $γ>1$), call the network a small-world network.

The idea behind this is that:

Small-world networks should have some spatial structure, which is reflected by a high clustering coefficient. By contrast, random networks have no such structure and a low clustering coefficient.
Small-world networks are efficient in communicating and similar and thus have a small shortest path length, comparable to that of random networks. By contrast, purely spatial networks have a high shortest path length.

Where the problems are

This does not say anything about how the mean shortest path scales with the network size. In fact, for real networks, the entire definition you quoted cannot be applied, as there is no such thing as the same network with a different number of nodes.
Suppose, we take some other definition of a small world that is not directly based on the values of $λ$ and $γ$, e.g.:

A small-world network is a spatial network with added long-range connections.

Then we still cannot make robust implications as to whether such a definition is fulfilled just using $λ$ and $γ$ (or in fact other network measures). The interpretation of many studies assumes that all networks are a realisation of the Watts–Strogatz model for some rewiring probability, which is not justified at all: We know many other network models, whose realisations are entirely different from the Watts–Strogatz model.
The above method is not robust to measurement errors. Small errors when establishing a network from measurements suffice to make, e.g., a lattice look like a small-world network, see e.g., Bialonski et al., Chaos (2010) and Papo et al., Front. Hum. Neurosci. (2016). In fact, I am not aware of a single study that claims that some empirical network is not a small-world network.

Sidenote: What would you gain?
I am not aware of any useful insight that can be derived from some network being a small world. The claim that some type of network is well described by a certain network model (e.g., the Watts–Strogatz model) may be useful for modelling studies, but that's going much further than just claiming small-world-ness.
Full disclaimer: One of the above papers is from my direct academic vicinity.
Comment: Also, do you know of any paper where the methodology you have mentioned in this answer is listed. Creating an ensemble of networks, calculating its average etc
Comment: @TheLastWord: *Also, do you know of any paper where the methodology you have mentioned in this answer is listed.* – The paper by Bialonski et al summarises this approach and should contain relevant references. Also see [this paper of mine](//doi.org/10.1103/PhysRevE.84.026103).
Comment: Thanks for the detailed answer.
I just wonder how the equivalent random graphs are generated? I assume we can choose the same number of nodes as the original graph, but what about the edges?  may be G(n, M)?
Comment: @lenhhoxung: See the links in Point 2. In brief, some popular options are to just keep the number of edges (or edge density) (Erdős–Rényi) or to preserve the degree of all nodes (Maslov–Sneppen).
Answer: A Small-Worldness Index can be computed in "R" using the function smallworldness in the package qgraph.
This is based on:
Humphries, M. D., & Gurney, K. (2008). Network "small-world-ness": a quantitative method for determining canonical network equivalence. PLoS One, 3(4), e0002051
From the paper:

"A network is now deemed a 'small-world' if S>1 - an assertion which
  may be tested statistically."


Start a program that is in Program Files folder

Question: I want to start an exe with java.
This exe is in the Program Files (x86) folder and when I try :
Runtime.getRuntime().exec("C:\\Program Files (x86)\\CodFiscExtractor\\MySQLServer\\MySqlStart.exe");

the console displays me this error :
CreateProcess error=740, The requested operation requires elevation

What I should do?
EDIT : this is not a duplicate of this, because i'm asking java
Comment: Did you try elevation?
Comment: @RobertColumbia no, how i can?
Comment: Possible duplicate of [Redirect standard output and prompt for UAC with ProcessStartInfo](https://stackoverflow.com/questions/18660014/redirect-standard-output-and-prompt-for-uac-with-processstartinfo)
Comment: @JeffreySamarziya that is not a duplicate as this is a Java question and that one is WPF. It's certainly related and could be helpful, but not a dupe.
Answer: I resolved, simply I writed like this :
Runtime.getRuntime().exec("cmd /c \"C:\\Program Files (x86)\\CodFiscExtractor\\MySQLServer\\MySqlStart.exe\"");

Now I don't have error, but I am insterested to don't show UAC window, because MySqlStart.exe starts with admin privileges.


Return JSON response

Question: I'm pulling in XML data and I need to return it to the front end as JSON.
I'm processing user input via AJAX like this:
$.ajax({ url: '/process.php',
         data: {category: 'sportingGoods'},
         type: 'post',
         success: function(output) {
                      console.log(output);
                  }
});

This is sent to process.php
if(isset($_POST['category']) && !empty($_POST['category'])){
    $category = $_POST['category'];
    //echo $category;

    switch($category){
        case 'automotive':
            $amazon->automotive;
            break;
        case 'sportingGoods':
            echo $amazon->sportingGoods();
            break;

    }
}

Then, I access a method in a class. In this case, $amazon->sportingGoods()
Now, sportingGoods() does a bunch of stuff, then returns a result set like this:
    $xml = simplexml_load_file($signedUrl);
    $json = json_encode($xml);
    $products = json_decode($json,TRUE);
    return $products;

The XML and JSON data is there. I can print_r($products) and print_r($xml) and see the results in the console. However, when I try and return it, I don't get anything. So, am I not returning an object? How can I gain access to the result?
Comment: You need to echo out the $products
Comment: @Maxxi doesn't work. I just get `Array`
Comment: Why 2 uses of `json_encode()` in `sportingGoods()`? jQuery will likely decode one round, but you're probably left needing to decode the other -- `console.log($.parseJSON(output));`.
Comment: Sorry I didn't notice you were decoding your JSON object before echoing it. You need to echo out the JSON object. Then as Jonathan says, parse the JSON with $.parseJSON() in the client
Comment: using json_encode you should also add to your ajax request that: dataType: "json", so that you can work with objects. In any case, **return** isn't enough, you have **echo** what you want to send to the client.
Comment: @briosheje There is an `echo` already before the call to `sportingGoods()`, within the `switch..case`.
Comment: Isn't a `return` statements outside a function a syntax error?
Comment: @FelixKling the only return I see is within his class function (from what he has put in the question anyways...)
Comment: @FelixKling that was a code snippet. It was part of a method
Comment: @FelixKling 2 uses? There is one encode and one decode. I guess my mistake was decoding it at that point
Answer: You need to echo out your json and then stop the script. From there, you'll use parseJSON to convert the json response into a js array.
Try this:
Your $.ajax({:
success: function( output ) {
    var response = $.parseJSON( output );
    // do something with your js array
},

and in sportingGoods():
return json_encode( $xml );

Comment: There already is an echo made from the return of that function (sportingGoods), though not for automotive.
Comment: Thanks! That helps. I'm now seeing the object in the console.
Comment: Welcome. Don't forget to use `die()` or `exit()` after you `echo` the response
Comment: @Jon Is your point that I should be able to return a result from `sportingGoods` and echo it with the switch? That was my intention at first. Not sure why that doesn't work.
Comment: @PaulDessert Yes, though, you return the decoded json (ie a php array) from your function, and when you just `echo` an array, all you will get is `Array`, so you should have your function return the `json_encode`'d version.  ie `return $json;` rather than `return $products;`

Return JSON response


How to print out each index in a 2D list without brackets and empty lines between the index?

Question: Here is my code:
menu=[['1.PEPPERONI $ ' , 8.50],
['2.SIMPLY CHEESE $ ' , 8.50],
['3.GARLIC CHEESE $ ' , 8.50],
['4.HAM & CHEESE $ ' , 8.50],
['5.VEG TRIO ' ,  8.50],
['6.BEEF & ONION $ ' , 8.50],
['7.HAWAIIAN $ ' , 8.50],
['8.APRICOT CHICKEN $ ' , 13.50],
['9.MEATLOVERS $ ' , 13.50],
['10.PERI-PERI CHICKEN $ ' , 13.50],
['11.PHILLY STEAK AND CHEESE $ ' , 13.50],
['12.CHICKEN & CRANBERRY $ ' , 13.50]]
print(menu)

When printed out, the menu will include brackets and the menu looks hard to read. Is there any way to print out menu without brackets and each pizza with its price will be on 1 same line. The next pizza and its price will be on the next line below. They should be all vertically aligned and text-based. In short, the printed menu should look easy to read and the price can be seen easily like a real menu.
Answer: You can iterate through the list and print the pizza along with its price to make it look nicer.
for item in menu:
    print(f"{item[0]}, Price: {item[1]}")
    print("\n")

Answer: If you want some more "alignment" than in the other answer you could try something like the following:
import re

menu = ...

re_pizza = re.compile(r'^(\d+\.)([^$]+)')
max_length = max(len(choice.split('.')[1]) for choice, _ in menu) - 1
new_menue = ''
for choice, price in menu:
    no = re_pizza.search(choice).group(1)
    choice = re_pizza.search(choice).group(2).strip()
    new_menue += (no.ljust(4)
                  + choice.ljust(max_length)
                  + f'{price:.2f}$\n'.rjust(7))

print(new_menue)

This can be refined. But it would be good if the input menu would be completely regular (in the entry for VEG TRIO the $ is missing).


Problema na criação de faturas ao usar o projecto do GitHub

Question: Depois de implementar as alterações mencionadas, consegui resolver os problemas dos restantes campos porém surgiu um novo problema. Após modificar o código para o seguinte...
private static InvoiceResource CreateSampleInvoice()
        {
            return new InvoiceResource
            {
                Company = "GRG",
                Customer = "ALCAD",
                Lines = new List<InvoiceLineResource>
                    {
                        new InvoiceLineResource
                        {
                            Item = "0001",
                            Quantity = 1,
                            Description = "Item 0003 custom description.",
                            Price = new MoneyResource { Value = 50 }
                        }
                    }
            };
        }

Surgiu-me este erro:

Tenho de adicionar o campo "Warehouse" manualmente no ficheiro "InvoiceLineResource.cs" e neste campo também?
Comment: @Fábio esses dados "Empresa" e "entidade" não estão correctos, é isso que ele está a dizer.
Comment: @Fábio, acabei d testar com o exemplo que estás a usar csharp-createinvoice-sample e consegui criar a fatura sem problema. Claro que tive de ajustar os meus dados da empresa e cliente para poder validar.
Comment: @SérgioSereno podia por favor fazer-me chegar onde foi buscar no próprio software jasmin, estes campos?
Comment: Os campos são a abreviatura (da empresa), o artigo (do artigo) e a entidade(do cliente).
Comment: @Fábio Isto é uma nova questão. Não deves alterar o conteudo de questões porque se não as respostas deixam de fazer sentido.
Comment: Repoe a questão original por favor.
Answer: para criar uma fatura via webapi numa aplicação de faturação tens de cumprir com alguns requisitos, a ver:

Criar uma empresa (todas as transações estão no ambito de uma empresa)
Criar a entidade para quem vai faturar e e mercadoria/serviço que vai faturar.
Ter uma serie activa e valida.

Para criar uma empresa.

Configuração | Geral | Empresas | Criar. O código que deres a empresa tens de associar á propriedade Company.

Para a Entidade

Vendas | Clientes. O código que deres ao cliente tens de associar á propriedade Customer.

Para a artigo

Vendas | Artigos de Venda. O código que deres ao cliente tens de associar á propriedade Item.

No meu caso.
private static InvoiceResource CreateSampleInvoice()
{
    return new InvoiceResource
    {
        Company = "default",
        Customer = "0001",
        Lines = new List<InvoiceLineResource>
            {
                new InvoiceLineResource
                {
                    Item = "0003",
                    Quantity = 2,
                    Description = "Item 0003 custom description.",
                    Price = new MoneyResource { Value = 50 }
                }
            }
    };
}


Logic (or possibly general production) terminology - what does 'recorded box' mean?

Question: I'm a singer and have been talking with a producer via email in regards to exchanging ideas/melodies on Logic. I just need to clarify what he means when he said 'Just some basic ideas with recorded box are cool.'
I haven't ever studied music so am not familiar with these phrases.
Can anyone help? I'm trying to act like I know what I'm doing ;)
Thanks
Comment: Seems like it must be. Best bet is to ask the producer what they meant.
Comment: I'm afraid I don't understand what a "recorded box" is either - but I'm not a Logic user. I do wonder if it's a typo though?
Answer: Given the proximity of the "b" and "v" keys on a qwerty keyboard, this is almost surely an "autocorrect" or typo for "vox" which is a common abbreviation of "vocals" (vocals -> vocs -> vox).
Answer: Drum box perhaps?  Or B/trax  short for backing tracks.


pylab not found - networkx python 2.7

Question: I am trying to run a simulator (developed by someone else) and make it work. I don't know Python but have started learning it. Could someone please look at the error below and advice me if it could be fixed or what it means. It should generate an image file at the end but it doesn't.
The error is:

Comment: if you simply run python and try `import pylab` what happens?  It looks to me like it's not installed, so I expect an error here even without networkx.
Comment: thanks for your reply but after running the command i get: >>> import pylab
Traceback (most recent call last):
  File "", line 1, in
ImportError: No module named pylab
Comment: Is there any way I could do a clean installation of Python (windows) with all these packages installed. I need this in Python 2
Comment: @user2119807 you can't just edit the question with a newer question, mark the answer that helped you as accepted and ask a new question about your new error independently. I rolled back your last edit.
Answer: You probably don't have the six Python module installed in your python version 2.6. You can find it on pypi.
To install it:
<code>$ easy_install six
</code>
if 2.6 is not your default version, use instead:
<code>$ easy_install-2.6 six
</code>
Comment: Still gets the same errors; install pip didn't help
Comment: you should install `six` not `pip`
Comment: after running easy_install six, I got: Searching for six
Best match: six 1.10.0
Processing six-1.10.0-py2.7.egg
six 1.10.0 is already the active version in easy-install.pth

Using c:\python27\lib\site-packages\six-1.10.0-py2.7.egg
Processing dependencies for six
Finished processing dependencies for six---------------------------(which means (I think) I installed it.
Comment: actually you installed it in the version 2.7 while you need it in the version 2.6. so try: `easy_install-2.6 six`
Comment: thanks for your reply but I am running 2.7 then why to install it on 2.6. OR are you suggesting suggesting to use 2.6 instead
Comment: @user2119807 because your paylab and matplotlib are installed in pythobn 2.6... check the error
Comment: I have now installed everything on 2.5 as the software was developed in 2.5. I managed to install the corresponding version for networkX and matplotlib. The application seems to working a part from generating the output image. I now get the error (please click on the link above in the original post) .. many thanks

pylab not found - networkx python 2.7


Why is there often more additional time in the second half versus the first half?

Question: In football (at least in Europe), the second half of a football match almost always gets a longer additional time (seems to be 3 minutes on average) than the first half (seems to be 1 minute on average).
Why is that?
Answer: Generally teams make more substitutions in the second half, which means more stoppage time. Very rarely is a substitution made in the first half, while most teams use all 3 subs in the second half.
Comment: Furthermore, referees *do what they can* to avoid handing out cards in the first half to keep play as fair for both teams as possible (i.e. players with cards have to be more conservative). Simple fouls rarely slow up play as teams just take the free kicks quickly (unless of course it's in a dangerous position where a kick is optimal). Since cards tend to get distributed more heavily in the second half, this leads to Player(s) v. Referee confrontations, as well as Team v. Team confrontations -- all of which causes delays in play, and since the clock never stops, this equates to stoppage time.


How to add an ascending row number (using some token) in front of each row in Views?

Question: I can't figure out how to make a soccer league table that would look like this: http://prntscr.com/8va7h7
This is how the table looks now: http://prntscr.com/8va8eu
Everything works but I don't know how to show the team position on the table. Is there a way to make this work using tokens so they count the number of rows?
Comment: You have to include a lot more info... for example, how are you creating the table, thru views? which fields are you sorting by etc... what have you tried so far?
Answer: In your View add a new Field, Filter by Global and select:

Global: View result counter
Displays the actual position of the view result

Click the Apply button and if you want change the output select Rewrite the output of this field in the Rewrite results section, and in the Replacement patterns section you will see the <code>[counter]</code> token as:

[counter] == Global: View result counter


Is p-value a point estimate?

Question: Since one can calculate confidence intervals for p-values and since the opposite of interval estimation is point estimation: Is p-value a point estimate?
Comment: I don't believe one *can* calculate confidence intervals for a p-value; it's a statistic calculated from the data, not a parameter describing the data-generating process.  Of course you can still ask what a statistic estimates.
Comment: @Cliff That's not a confidence interval for the p-value *qua* property of a distribution: that's a confidence interval for a stochastic estimator of the p-value of a test for a particular sample.  Although they sound similar, and both are intervals, they are completely different things.
Comment: @amoeba: a confidence interval is about an unknown parameter, while your bootstrap interval is an approximation of a 95% region for a statistic.
Comment: @Scortchi: but if I were to apply e.g. bootstrapping to compute a distribution of p-values and then were to construct a 95% percentile interval of this bootstrapped distribution, then if it's not a confidence interval for the p-value -- *what is it*?
Comment: @Scorthci: I have seen software that prints CI's for p-values. In this case, the approximate p-values were calculated by permutation tests, so if the CI was too wide (i.e. p-value $\in [0, 0.05]$ and p-value $\in [0.05, 1]$), you would use more permutations before making inference.
Comment: @whuber: completely agree. But I believe it's not completely wrong interpretation to call this simply a "confidence interval for a p-value", as the OP stated. I think Scortchi interpreted what they had posted as stating that a p-value was a parameter based on the *population of interest in the study*, which doesn't really make sense. But considering a p-value as a parameter of interest based on *your sample and statistical model* does not seem wrong to me. Often this parameter is known exactly, but occasionally it is estimated.
Comment: Thinking of it this way is a different angle than standard statistics (we usually only think of parameters coming from populations and estimates coming from samples), but as I noted, this slightly twisted view is not purely theoretical; you can get outputs from published statistical software that will present a CI for a p-value.
Answer: Point estimates and confidence intervals are for parameters that describe the distribution, e.g. mean or standard deviation.
But unlike other sample statistics like the sample mean and the sample standard deviation the p-value is not an useful estimator of an interesting distribution parameter. Look at the answer by @whuber for technical details.
The p-value for a test-statistic gives the probability of observing a deviation from the expected value of the test-statistic as least as large as observed in the sample, calculated under the assumption that the null hypothesis is true. If you have the entire distribution it is either consistent with the null hypothesis, or it is not. This can be described with by indicator variable (again, see the answer by @whuber).
But the p-value cannot be used as an useful estimator of the indicator variable because it is not consistent as the p-value does not converge as the sample size increases if the null hypothesis is true. This is a pretty complicated alternate way of stating that a statistical test can either reject or fail to reject the null, but never confirm it.
Comment: (-1) I agree with both @Tim's common-sensical answer & whuber's recondite answer, but am struggling to make any sense of this one. (1) "But the p-value is not a population parameter since it is explicitly defined on sample level": this is doubtless worth pointing out, but the "but" makes it seem like you're saying that a p-value can't be an estimate of anything because it's a sample statistic, as if the sample mean couldn't be an estimate of anything because it's a sample statistic. ...
Comment: Most of the better accounts of statistical tests (Lehman, Kiefer, etc.) do not refer to "populations" at all, but instead frame the situation in terms of estimating parameters of *distributions.*  This does not require the randomness to be due solely to sampling, and thereby allows the theory more broadly to apply to situations where the randomness is part of a *model*.
Comment: But you have explicitly contradicted that with the statement there "are no probabilities associated with the population at all."  Please note, too, that *all* estimators are "explicitly defined on sample level."  It is therefore difficult to determine what distinction you are trying to make in this post.
Comment: Of course! But a distribution is not a population.
Comment: (2) "This is because there are no probabilities associated with the population at all, it is regarded as fixed but unknown": (a) The p-value isn't calculated from the sample *because* "there are no probabilities [...]"; (b) as @whuber's pointed out, sampling from a finite population is a special case; (c) in any case it just doesn't follow from what you've said that the p-value doesn't estimate anything about the population.
Comment: @Erik: I disagree with the final sentence since [we proved](http://projecteuclid.org/euclid.aos/1176348534) it can be an admissible estimator.
Comment: @Xi'an But that is an (admittedly interesting) decision theoretic viewpoint. An answer from that perspective would be helpful, so at least I would be happy if you decided to write one.
Comment: Well, I sort of regard distributions as populations of infinite size.
Comment: Even with a distribution, the probability comes in play when sampling from the distribution? And the estimators are defined on sample level, but what they estimate is defined on population level.
Comment: @Scortchi Fair enough and thanks for the detailed comment. I think saying that unlike other sample statistics it is not an useful estimator of any parameter of the distribution. Will try to reclarify that point.
Answer: Yes, it could be (and has been) argued that a p-value is a point estimate.
In order to identify whatever property of a distribution a p-value might estimate, we would have to assume it is asymptotically unbiased. But, asymptotically, the mean p-value for the null hypothesis is $1/2$ (ideally; for some tests it might be some other nonzero number) and for any other hypothesis it is $0$. Thus, the p-value could be considered an estimator of one-half the indicator function for the null hypothesis.

Admittedly it takes some creativity to view a p-value in this way.  We could do a little better by viewing the estimator in question as the decision we make by means of the p-value: is the underlying distribution a member of the null hypothesis or of the alternate hypothesis? Let's call this set of possible decisions $D$.  Jack Kiefer writes

We suppose that there is an experiment whose outcome the statistician can observe.  This outcome is described by a random variable or random vector $X$ ... . The probability law of $X$ is unknown to the statistician, but it is known that the distribution function $F$ of $X$ is a member of a specified class $\Omega$ of distribution functions. ...
A statistical problem is said to be a problem of point estimation if $D$ is the collection of possible values of some real or vector-valued property of $F$ which depends on $F$ in a reasonably smooth way.

In this case, because $D$ is discrete, "reasonably smooth" is not a restriction at all.  Kiefer's terminology reflects this by referring to statistical procedures with discrete decision spaces as "tests" instead of "point estimators."
Although it is interesting to explore the limits (and limitations) of such definitions, as this question invites us to do, perhaps we should not insist too strongly that a p-value is a point estimator, because this distinction between estimators and tests is both useful and conventional.

In a comment to this question, Christian Robert brought attention to a 1992 paper where he and co-authors took exactly this point of view and analyzed the admissibility of the p-value as an estimator of the indicator function.  See the link in the references below.  The paper begins,

Approaches to hypothesis testing have usually treated the problem of testing as one of decision-making rather than estimation.  More precisely, a formal hypothesis test will result in a conclusion as to whether a hypothesis is true, and not provide a measure of evidence to associate with that conclusion.  In this paper we consider hypothesis testing as an estimation problem within a decision-theoretic framework ... .

[Emphasis added.]

References
Jiunn Tzon Hwang, George Casella, Christian Robert, Martin T. Wells, and Roger H. Farrell, Estimation of Accuracy in Testing.  Ann. Statist. Volume 20, Number 1 (1992), 490-509.  Open access.
Jack Carl Kiefer, Introduction to Statistical Inference.  Springer-Verlag, 1987.
Comment: The question does not ask whether the p-value is a *good* estimator, @Erik. As an estimator, it has obvious deficiencies.  For instance, its asymptotic variance for the null hypothesis is nonzero. Please note that the bias of almost *every* unbiased estimator depends on sample size. Although you are correct that an independent random number could be viewed as an estimator, it would be an estimator of something different: it would estimate its own mean (by definition). Thus your objections appear not to have any relevance to the question at hand.
Comment: I don't think we differ on any of those points, @Erik, except perhaps the "unhelpful" part. As Nick Cox points out in a comment elsewhere in this thread, it is nevertheless *interesting* to contemplate the sense in which a p-value could be considered an estimator and what, exactly, it could possibly be estimating. That can help us understand a little better just what a p-value is (and is not). Many would view that as a *helpful* exercise.
Comment: In a [1992 paper](http://projecteuclid.org/euclid.aos/1176348534), we study the $p$-value as an estimator of the indicator function $\mathbb{I}_{\Theta_0}(\theta)$ and demonstrate that it can be an admissible estimator for one-sided hypothesis and cannot be admissible for two-sided hypotheses.
Comment: Hmm. I am not sure if this view is helpful. For one in this sense the p-value is not a good estimator, since it is not consistent if the null hypothesis is true. And in the some cases (you mention that) it has a sample-size dependent bias as well. It might be technical true, but any random number could be (terrible) estimator for any parameter as well.
Comment: @Xi'an I see we're only 23 years behind you... .  Thank you for the reference!
Comment: "Thus, the p-value could be considered an estimator of one-half the indicator function for the alternate hypothesis." Shouldn't that read "the indicator function for the null hypothesis"?
Comment: @whuber: thanks for bringing Jack Kiefer's views back to life! And for including our AoS reference. You have my vote for this being _the_ answer!
Comment: What the estimator estimates is part of the definition. You can't say that the random number would by definition estimate the own mean. There is no reason why I can't define e.g. the sample standard deviation as an estimate of the mean or vice versa. It's just a bad estimator, like the p-value for the indicator function. What I am trying is to express that seeing the p-value as a point-estimate might be correct on some technical level, but that it is not helpful. When speaking of estimators for a specific parameter at least consistency is implicitly assumed unless stated otherwise.
Comment: BTW I still upvoted the answer as it provides a helpful additional perspective from a technical point of view.
Comment: Maybe I was imprecise. I agree that is an helpful and interesting view when thinking about estimators. But I don't think it adds much intuition or understanding when thinking about p-values and I saw the focus of the question more on p-values than on estimators.
Comment: @Andrew You're correct--I mixed up the language.  I'll fix that.  Thank you for noticing this!
Answer: $p$-values are not used for estimating any parameter of interest, but for hypothesis testing. For example, you could be interested in estimating population $\mu$ based on the sample you have, or you could be interested in interval estimate of it, but in hypothesis testing scenario you would rather compare the sample mean $\overline x$ with population mean $\mu$ to see if they differ. In fact in hypothesis testing scenario you are not interested in their particular values, but rather if they are below some threshold (e.g. $p < 0.05$). With $p$-values you are not that much interested in their point values, but rather you want to know if your data provides enough evidence against null hypothesis. In hypothesis testing scenario, you would not be comparing different $p$-values to each other, but rather use each of them to make separate decisions about your hypotheses. You don't really want to know anything about the hull hypothesis, as far as you know if you can reject it or not. This makes their values inseparable from the decision context and so they differ from point estimates, because with point estimates we are interested in their values per se.
Comment: Your initial statement correctly echoes how things are often explained, but nevertheless it does not go deep enough. A basic fact here is sampling variation, the variability from sample to sample. Take a different sample, and your P-value will be different. It takes a little ingenuity to see precisely what it is estimating, and it is not (as far as I know) **conventional** to explain it as estimating an parameter, but that point of view makes perfect sense. See @whuber's interesting answer. (The entire territory is littered with muddy paraphrases based on the need to simplify for teaching.)
Comment: This question intersects with many others, most of which are highly controversial. One is the idealisation that the purpose of a test is to make a decision yes or no, which doesn't match all problems at all. Another key fact is that use of threshold levels was for decades a matter that people used published tables from printed tables and exact P-values were out of reach while people did not use computers.
Comment: @Tim, I think this claim (from your last comment) is almost always not true, at least in biology. People are very much interested in the value of p-values, marking $p<0.05$, $p<0.01$, $p<0.001$ with one, two, or three stars on the figures, writing about something being "highly significant", etc. The usual recommendation is also to report exact p-values, e.g. $p=0.003$, and not $p<0.05$. Only very rarely do people adhere to the strict Neyman-Pearson framework, choose $\alpha$ in advance and report all p-values as $p<\alpha$.
Comment: @00schneider: If you do ever see an interval given for p-values, it's very unlikely to be a confidence interval for the population parameter defined by whuber. Tim's point is that there's no need to consider them as *estimating* anything at all, interesting though it may be to do so.
Comment: How terms are used is interesting and important (and a personal preoccupation, by the way). The question remains what a P-value **is**. This too is pointed out [inevitable pun here] elsewhere in this thread. It's a helpful convention to regard parameters as those unknowns which appear in a model specification, but there are other unknowns too.
Comment: is this comment referring to Tim or to my inital question?
Comment: It's referring to Tim's answer. (Comments on your question would belong under your question.)
Comment: @NickCox p-values are point estimates but we are not interested in their point values, my answer refers to their *usage*. They are not used and are useless as point estimates. Those cases were already discussed in other answers and comments.
Comment: @Tim why are they useless as point estimators? I almost never see an interval for them, so I guess the usual reported p-value is a point estimate and it's used as you described.

Is p-value a point estimate?


NFL team "getting rid" of a player

Question: NFL teams can cut or trade players they're no longer interested in. However, if the player is under a guaranteed contract, the team may have to pay him for as many years as his contract is valid.
In a recent move, the Houston Texans traded Brock Osweiler to the Cleveland Browns and gave up a 2nd round 2018 draft pick. This is unusual since instead of gaining a draft pick or another player in return the Texans gave up a draft pick. They essentially gave the Browns their draft pick so that they could get rid of Osweiler (and make salary space to pursue Tony Romo). Has this happened before that a team was willing to gave up a draft pick purely to get out paying a player?
Comment: So note, the trade was Osweiler + 2nd round 2018 draft pick + 6th round 2017 pick for a 4th round 2017 draft pick.  So they're giving up better picks... but in the future, such that they have an alternate explanation.  The article really points out well how it's quite obvious to everyone that it's a dump, but allows them an excuse to evade absolute proof.  And that such a dump like this hasn't happened before, and likely will be cracked down upon sharply in the future, but that they snuck through by using an opportunity of a grey area in the rules.
Comment: http://www.espn.com/nfl/story/_/id/18865828/making-sense-unprecedented-brock-osweiler-trade-nfl provides great background to the nature of the trade for those trying to understand it.
Answer: It is not allowed for an NFL team to simply "give up" a player; the formal language in the CBA is that a trade may not be for "nominal considerations" - a team cannot simply give Player X and a draft pick to another team and receive nothing in return, or even receive a lower draft pick in return.
So, the question now is what makes the Osweiler trade legal? The answer is that the Texans are giving a 2018 draft pick, and receiving a 2017 draft pick in return. Future draft picks have a lower value than current draft picks as they don't add any value for the team until a future year, so the Browns and Texans can argue they both "win" from this trade. However, there are suggestions that the NFL and NFLPA may look at tightening the rules around this sort of trade.
Comment: Yeah the trade itself is fishy. Notice the quotes around "getting rid" on the question title. In practice the deal was done purely to get Osweiler out of Houston. The Texans got a 4th round pick from Browns, and gave up a 6th round pick, a draft pick for next year & shipped Osweiler to Browns. The swap of 4th and 6th round pick was done to make the trade legitimate under the current CBA. As you have mentioned teams can't just give up a player like that. But for a team to ship away a starting QB who's making $18M for the next 2 seasons, this is as close as you could come an not break CBA rules.
Comment: Although this adds a lot more insight to Osweiler's trade, it doesn't answer my question. I wanna know if other teams have done something similar in the past.
Comment: The trouble is that your question is based on a false premise: the Texans did not give up a draft pick to get out of paying Osweiler - they traded a 2018 draft pick + Osweiler to get a 2017 pick. The trade would not have been allowed if the Browns were getting a 2017 pick.

NFL team "getting rid" of a player


Adding values to multi-value field and displaying them

Question: I have 3 multi-value fields and I have already inserted values in them. All of the fields are Text type, edible. What I'm trying to do is that I want to add functionality in xpages, so that I can add new values to those fields.
Here's what I got so far:
The code that triggers on the save button:
var statuss = document1.getItemValue("statuss");
var stat_vec:java.util.Vector = document1.getItemValue("statuss_update");
stat_vec.add(statuss);
document1.replaceItemValue("statuss_update", stat_vec);

var vards = session.getEffectiveUserName();
var vards_vec:java.util.Vector = document1.getItemValue("name_update");
vards_vec.add(vards);
document1.replaceItemValue("name_update", vards_vec);

var laiks = session.createDateTime("Today");
var laiks_vec:java.util.Vector = document1.getItemValue("time_update");
laiks_vec.add(laiks);
document1.replaceItemValue("time_update", laiks_vec);

document1.save();

The code that I have atteched to the computedField, where the values are displayed from the 3 multi value fields + it refreshes when I insert new values:
var x = document1.getItemValue("statuss_update");
    var y = document1.getItemValue("name_update");
    var z = document1.getItemValue("time_update");

    var html = "<link rel=\"stylesheet\" type = \"text/css\" href=\"test.css\">
";

    for (i = 0 ; i < x.size()-1; i++){
        html= html + "
" + x[i] +  "	" + y[i] + "	" +z[i] + "
";
        }
    html = html + "
";

I can insert the values and they get displayed in the HTML table but the problem is with saving the edits. Whenever I try to save the document (I have a save button that has save document event attached to it) I get the error:

Could not save the document 1B06 NotesException: Unknown or
  unsupported object type in Vector

As far as I understand I'm trying to savesomething in a field, where the values type is not supported. Can anyone give me a hint what am I doing wrong or where to look for the problem? Been stuck with this for a pretty long time.
Answer: Is it this part?
var statuss = document1.getItemValue("statuss");
var stat_vec:java.util.Vector = document1.getItemValue("statuss_update");
stat_vec.add(statuss);

It looks like you're getting the statuss item's values (potentially a Vector??) and adding it to the Vector for statuss_update. If it's definitely just one value, getItemValueString() would work better.
I'm nnot sure if this is right, but you mention all fields are Text type, but it looks like you're passing a DateTime to the third one.
It might be worth analysing the contents of the Vectors before it's doing the save, just to make sure they contain what you expect.
Comment: Hello Paul

I replaced the .getItemValue with .getItemValueString

About the date- i created a lib and used "import *libname*" in to the code, which gives me a string of the date.

Also- is there some kind of debbuger that I could use to see what each vector contains?
Comment: Just fixed the problem, thank you. It was because of the date, I didn't realize that I didn't get a string value, which caused the error. But i'd still like to know is there a way to debug the code?
Comment: Methods like that only throw the error on the save() method, not the replaceItemValue(). Even with Reader access you can call replaceItemValue() as much as you want and it won't throw an error until you call save() - and developers have used this to their benefit. As part of the OpenNTF Domino API team, we've discussed benefits / impacts of doing those kinds of checks, but haven't agreed to make a change to how the core Domino API does things as yet.


Swapping terms using Assignment de-structuring wont work inside a function

Question: let a = 'alpha', b = 'beta';
[a,b] = [b,a];

This swaps the values of a and b as intended;
but when placed inside a function it doesn't work
let c = 'charlie', d = 'delta';
swapVar = (x,y) => [x,y] = [y,x]
swapVar(c,d);

What am I missing here?
Comment: I don't think those are the same variables.  They are scoped only to the arrow function and then die.  How are you testing that they have actually been swapped?
Comment: Parameters are passed by value in Javascript, not by reference. Assigning to the variables inside the function has no effect on the caller's variables.
Answer: When you do
let a = 'alpha', b = 'beta';
[a,b] = [b,a];

You're swapping the values of a and b.
When you do
let c = 'charlie', d = 'delta';
swapVar = (x,y) => {
   // x and y are separate variables scoped within this block
   [x,y] = [y,x]
   console.log(x,y); // it is swapped alright but isn't reflected on c and d
   c = x;
   d = y;
   // Now the value will have been reflected.
}
swapVar(c,d);

So, within the function the values are swapped but aren't reflected outside. You could modify the program like this:
swapVar = (x,y) => [y,x]
[c, d] = swapVar(c, d); // now you're reflecting the swapped values on the outside

To have the intended effect.
Comment: @PatrickRoberts I added that to prove that assignment destructuring can indeed be done within the function but you've to use the return value. The title seemed specific to it.
Comment: `swapVar` in your final example becomes completely useless. Better to just `[c, d] = [d, c];`, the extra level of indirection has no benefit, not even readability, and actually makes the return value of the function misleading (as it simply returns an array with the values reversed, which is not "swapping".
Answer: You are doing the swap in a scope where the variables aren't being "exported".
In the first example, you act on the actual variables a and b in the scope they are defined in.
However, in the second example, you are acting on the variables x and y which are the same value as c and d but aren't the actual c and d since they are primitives so the c and d outside the scope of the arrow function is not affected.

{
  let a = 'alpha',
    b = 'beta';
  console.log("Test 1");
  console.log(`before a: ${a} b: ${b}`);
  [a, b] = [b, a];
  console.log(`after a: ${a} b: ${b}`);
}

{
  let c = 'charlie',
    d = 'delta';
  console.log("Test 2");
  console.log(`before c: ${c} d: ${d}`);
  swapVar = (x, y) => [x, y] = [y, x]

  /*
  function swapVarExpanded(x, y) {
    const tmp = [y, x];
    x = tmp[0];
    y = tmp[1];
    // Doesn't actually matter
    // because x and y die at the next closing curly brace due to scope
  }
  */

  swapVar(c, d);
  console.log(`after c: ${c} d: ${d}`);
}


Application of Luca's theorem

Question: Let, $p$ be a polynomial in $1$-complex variable. Suppose all zeros of $p$ are in the upper half plane $H=\{z\in \mathbb C|\Im(z)>0\}. $ Then , which are corrct ?

$\Im\left\{\frac{p'(z)}{p(z)}\right\}>0$ for $z\in \mathbb R$.
$\Re \left\{i\frac{p'(z)}{p(z)}\right\}<0$ for $z\in \mathbb R$.
$\Im\left\{\frac{p'(z)}{p(z)}\right\}>0$ for $z\in \mathbb C$ with $\Im (z)<0$.
$\Im\left\{\frac{p'(z)}{p(z)}\right\}>0$ for $z\in \mathbb C$ with $\Im (z)>0$.

I know that , since all roots of $p(z)$ lie in the upper half plane so, all roots of $p'(z)$ lie in the same upper half plane , from Luca's theorem.
But from there how we can say about real part or imaginary part of $\frac{p'(z)}{p(z)}$ ?
Answer: By the Fundamental Theorem of Algebra, we have $p(z)=a(z-z_1)\dots(z-z_n)$ where $a\neq 0$ and $n$ is the degree of $p$. (Clearly $p(z)$ cannot be identically zero.) By the chain rule, we have
$$
p'(z)=a\left(\prod_{i\neq 1}(z-z_i)+\dots+\prod_{i\neq n}(z-z_i)\right)
$$
and thus
$$
\frac{p'(z)}{p(z)} = \sum_{k=1}^n\frac{\prod_{i\neq k}(z-z_i)}{\prod_{i=1}^n(z-z_i)}
=\frac{1}{z-z_1}+\dots+\frac{1}{z-z_n}=\sum_{i=1}^n\frac{\overline{z}-\overline{z_i}}{|z-z_i|^2}
$$
This explains why 1, 2, and 3 are all true; can you see why? For 4, you can construct an easy counterexample using $p(z)=z-i$.
Comment: @AkashPatalwanshi oops--thanks for pointing it out!
Comment: Yes...all are clear..But where the condition ' All zeros of $p$ are in the upper half plane $H=\{z\in \mathbb C|\Im(z)>0\}$. '   is used ?
Comment: This means that $\Im z_i>0$, so $\Im(\bar{z_i})<0$. Consider the sign of the imaginary part of each contribution to $\frac{p'(z)}{p(z)}$ (written above).
Comment: Sir, beautiful answer but it contains little typo. When you had written $p'(z)=a(∑ +... + ∑)$ But, it is not correct!! It must be $p'(z)=a(∏ +... +∏)$ and further, in $\frac{p'(z)}{p(z)}$ the  summation symbols which used inside must be product symbol.
Comment: Welcome sir, now it's correct... :-)

Application of Luca's theorem


Pandas: apparent type mismatch using apply

Question: Say I want to apply a function to user_location
df.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 4139 entries, 2020-12-20 06:06:44 to 2021-01-13 04:45:10
Data columns (total 15 columns):
 #   Column            Non-Null Count  Dtype
---  ------            --------------  -----
 0   id                4139 non-null   int64
 1   user_name         4139 non-null   object
 2   user_location     3282 non-null   object
....

Why am I getting a TypeError (argument of type 'float' is not iterable) doing
def get_country(s):
    for country in pycountry.countries:
        if country.name in s:
            return country.name

d = df["user_location"].apply(get_country)

while get_country('Some text about Canada') works like a charm
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-89-50fde3ed5073> in <module>
      6 countries = [country.name for country in pycountry.countries]
      7
----> 8 d = df["user_location"].apply(get_country)
      9
     10 df["user_location"]

~/.local/lib/python3.7/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
   4106             else:
   4107                 values = self.astype(object)._values
-> 4108                 mapped = lib.map_infer(values, f, convert=convert_dtype)
   4109
   4110         if len(mapped) and isinstance(mapped[0], Series):

pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

<ipython-input-89-50fde3ed5073> in get_country(s)
      1 def get_country(s):
      2     for country in pycountry.countries:
----> 3         if country.name in s:
      4             return country.name
      5

TypeError: argument of type 'float' is not iterable

If apply really apply get_country element wise, why is it complaining about float not being iterable? I tried to set convert_dtype=False just in case but it did not change a thing.
Comment: Please share some sample data for this.
Comment: Object is a container that holds many things. `NaN` is a float, perhaps you have that to deal with missing values. If that's the case you'll need to add logic to deal with those null values since it's a float and won't have the same methods as say, a list
Answer: Maybe some of user_location got mixed with numbers?
Just force them "if country.name in str(s):"
Comment: This would be the most likely explanation. OP you could write a loop to check through the data frame and see which of its values are floats.


Não consigo enviar parâmetro com Curl

Question: Estou tentando fazer uma requisição POST para poder cadastrar um produto usando Curl mas quando eu executo ele me retorna uma string vazia
$param_POST = array(
    "IdProduct"=> "000001",
    "Name"=> "Caixa de Som",
    "Code"=> "125241",
    "Brand"=> "JBL",
    "NbmOrigin"=> "11111",
    "NbmNumber"=> "",
    "WarrantyTime"=> "0",
    "Active"=> true,
    "Categories"=> array(
        "Id"=> "1",
        "Name"=> "teste",
        "ParentId"=> ""
    ),
    "Attributes"=> array(
        "Name"=> "Protecao",
        "Value"=> "resistente a agua"
    )
);

$GetMarketplace = Integra_POST('/api/Product',$param_POST);
var_dump($GetMarketplace);

Esse é o array que eu envio para a minha função com o endpoint e o array.
function Integra_POST($endpoint, $params = array()){
    //Execução de POST
    $url = $_SESSION['url'];
    $url .= $endpoint;

    $data = json_encode($params);

    $ch_opts = integra_GetCurlOpts();
    $ch_opts[CURLOPT_CUSTOMREQUEST] = "POST";
    $ch_opts[CURLOPT_POSTFIELDS]    = $data;
    $ch_opts[CURLOPT_HTTPHEADER]    = array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data)
    );

    echo $data;

    $ch = curl_init($url);
    curl_setopt_array($ch, $ch_opts);
    $result = curl_exec($ch);

    return $result;
}

Answer: Fiz algumas modificações no envio dos dados pelo CURL e funcionou perfeitamente no meu servidor local. Veja abaixo as alterações:
<?php
...

$GetMarketplace = Integra_POST('/api/Product',$param_POST);
var_dump($GetMarketplace);

function Integra_POST($endpoint, $params = array()){

  $url = $_SESSION['url'];
  $url .= $endpoint;

  $curl = curl_init();

  curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => http_build_query($params),
    CURLOPT_HTTPHEADER => array(
      "Content-Type: application/x-www-form-urlencoded"
    ),
  ));

  $response = curl_exec($curl);

  curl_close($curl);

  return $response;
}

Comment: meu Curl já tem esses parâmetros mas em outra página php porq eu não estou usando só uma função então o principal eu deixei separado, ainda assim tentei colocar no mesmo arquivo e ainda não funcionou

Não consigo enviar parâmetro com Curl


convergence rate of sample covariance matrix

Question: I have a question about deriving the rate of convergence of sample covariance matrix. For the sake of simplicity, we can assume that our sample $\{ X_i\}_{i=1}^{n}$ is i.i.d. (I known we can relax this assumption). I have found that many papers mentioned that it is a $\sqrt{n}-$consistent estimator of true covariance matrix. My questions are
i)  Is the consistency result obtained under the Frobenius norm? I have found that many matrix consistency used this norm;
ii) How to prove that $\hat{\Sigma} = \frac{1}{n-1} \sum_{i=1}^{n} (X_i - \bar{X})(X_i-\bar{X})'= O_p(\frac{1}{\sqrt{n}})$.
Additional request:
I have learned advanced probability theory, mathematical statistics, and so on. However, I am not familiar with the classical methods for proving large sample results and determining the rate of convergence of some estimators in some classical statistical models, such as linear model, factor model and so on, which caused me a lot of trouble to read some cutting-edge papers.
Any related posts and materials will be appreciated. Thank you in advance!
Comment: Hi: I don't remember if it's explained as clearly as Thomas's explanation below, but Halbert White's "asymptotic theory for econometricians" has some of that material in it.  If the relevant material that you're looking for is not in there, then I'm sure that the references in there will be helpful.
Comment: @mlofton Thank you, and I'll read this book.
Answer: Start with
$$S=\frac{1}{n}\sum_i (X_i-\mu)(X_i-\mu)'$$
This is an iid mean. Assuming the summands $(X_i-\mu)(X_i-\mu)'$ have two finite moments, the central limit theorem says that
$$\sqrt{n}(S-E[S])\stackrel{d}{\to} N(0, V)$$
where $V=\mathrm{var}[(X_i-\mu)(X_i-\mu)']$.
This means $S-E[S]=O_p(1/\sqrt{n})$.
This is for the Frobenius norm, but it's also true for the spectral norm.
Now, $n/(n-1)=1+O(1/n)$, so
$$\tilde S=\frac{1}{n-1}\sum_i (X_i-\mu)(X_i-\mu)'$$
also converges at $\sqrt{n}$ rate, and clearly $\bar X$ converges to $\mu$ at $\sqrt{n}$ rate, so $\hat \Sigma$ is also $\sqrt{n}$-consistent.
So, basically, it's true for the same reasons that everything else is $\sqrt{n}$-consistent.
Comment: Thank you. Your helpful answer provides the basic framework for solving most questions. Further, do you know how to get the rate of convergence in the non-i.i.d case? By some theorems similar to central limit theorem or some probability inequalities?
Comment: Yes, there are central limit theorems for many kinds of non-iid data, but they can be hard to find so it's sometimes easier to work out the rate at which the variance of the variance decreases with increasing $n$ and then just use Chebyshev's inequality to show convergence in probability at the square root of that rate.
Comment: What is $p$ in your answer? i.e. $O_p$
Comment: I'm confused by what $S - E[S] \rightarrow N$ means. If I understand correctly, $S - E[S]$ is a matrix. What does it mean to say that this matrix follows a normal distribution; does this mean a matrix normal distribution?
Comment: Also, what is the variance of a matrix i.e $(X_i - \mu)(X_i - \mu)^{\prime}$?
Comment: @RylanSchaeffer it means it's multivariate Normal, equivalently, that any linear combination of the elements has a Normal distribution. And the variance is the covariance matrix of the entries of $S$, which is a $(p\times p)\times (p\times p)$ matrix if $S$ is $p\times p$.


Dividir data frame pela primeira linha dele mesmo

Question: Estou tentando criar um número índice a partir de um data frame. Gostaria de dividir cada coluna pelo primeiro número sem precisar fazer a divisão coluna a coluna.
Apenas como exemplo, o df seria:
DF1 <- data.frame(Name = c("Aaron", "Blake"), Jan = c(2, 5), Feb = c(4, 6), Mar = c(3, 4))

Fazendo coluna a coluna, por exemplo:
library(tidyverse)
DF1$Fev/first(DF1$Fev)*100

o resultado é o esperado:
[1] 100 150

Porém fazendo
DF1[,-1]/first(DF1[,-1])*100

obtenho
  Jan Fev Mar
1 100 200 150
2 100 120  80

O adequado seria
   Name Jan Fev      Mar
1 Aaron 100 100 100.0000
2 Blake 250 150 133.3333

Alguém pode me ajudar? Vou trabalhar com um data frame com muitas colunas em breve.
Answer: Há várias maneiras de fazer o que quer. Vou usar duas delas.

Com o tidyverse.
Só com R base.

Em ambas vou trabalhar com cópias de DF1.
Primeiro tidyverse.
library(tidyverse)

DF2 <- DF1
DF2[-1] <- DF2[-1] %>%
  mutate_all(funs(./first(.)*100))

DF2
#   Name Jan Feb      Mar
#1 Aaron 100 100 100.0000
#2 Blake 250 150 133.3333

Agora R base.
DF3 <- DF1
DF3[-1] <- lapply(DF3[-1], function(x) x/x[1]*100)

DF3
#   Name Jan Feb      Mar
#1 Aaron 100 100 100.0000
#2 Blake 250 150 133.3333

Verificação final.
identical(DF2, DF3)
#[1] TRUE


Infinity in ZFC vs infinity in the metatheory

Question: I was reading about different ways to formalize the notion of infinity in ZFC. The classic axiom is of course to have the existence of an inductive set, but you can also assert the existence of a Dedekind infinite set, and it turns out it is equivalent. (This question shows this: How can I define $\mathbb{N}$ if I postulate existence of a Dedekind-infinite set rather than existence of an inductive set?)
They both give a notion of infinity internal to the theory. However, I am not quite sure how much this coincides with a "metatheoretic" understanding of infinity. For instance, let $L=\{=,\in\}$ and let $T$ be the $L$-theory consisting of all axioms of ZFC except for the axiom of infinity. Define a new language $L'=L\cup\{c\}$ with a single additional constant symbol, and define a new theory $$T'=T\cup\{\exists x_1\dots\exists x_n\bigwedge_{1\leq i<j\leq n}x_i\neq x_j\wedge\bigwedge_{i=1}^n x_i\in c:n\in\mathbb{N}\}.$$ This seems to be a very natural way to capture the notion of infinity, but I don't know whether we could prove that the realization of $c$ in a model of $T'$ is Dedekind-infinite in the sense of ZFC. Therefore, in light of the question I put a link to, my question is: is $T'$ equivalent to ZFC?
Answer: Not in any sense. $T'$ is in fact a conservative extension of $\mathsf{ZF}$-$\mathsf{Inf}$; this is a consequence of the compactness theorem.
Now any well-founded model (or even $\omega$-model) of $T'$ restricts to a model of $\mathsf{ZF}$, but in the absence of such a semantic restriction $T'$ is no better than $\mathsf{ZF}$.
Comment: @Andyjames An $\omega$-model is just a model all of whose finite ordinals are well-founded. Every well-founded model is an $\omega$-model, but not conversely. The point is that $\omega$-model-ness means exactly that there are no "fake finite sets," which is exactly what we need here to get from your $c$ to an internally-infinite set.
Comment: oh! I see thank you sir. please could you add some more detail in your second paragraph? what is an $\omega$-model? and how does it give this? thank you!!!!
Answer: No; in fact, $T'$ is conservative over $T$ (that is, it does not prove any theorems in $L$ that $T$ does not prove).  Indeed, every finite fragment of $T'$ is satisfied in every model of $T$, by letting $c$ denote some set with enough elements to satisfy all of the finitely many axioms you include.  Every theorem of $T'$ is proved from only finitely many of its axioms, so this means it can't prove anything over $L$ that isn't true in every model of $T$.