Understanding Discrete Fourier Transform based on continuous Fourier Transform

Question: I'm reading a PDF that starts like this:

It sees the Discrete Fourier Transform as a "partitioning" of the continuous case, I guess. That's what I'm trying to understand.
The Fourier transform of $f(t)$ is
$$F(jw) = \int_{-\infty}^{\infty}f(t)e^{-jwt}\ dt$$
If we concentrate on a signal of finite time, I guess, we only have to integrate on this finite time, since the rest would be $0$. At first I thought he was breaking the integral
$$\int_{o}^{(n-1)T}f(t)e^{-jwt}\ dt$$
as lots of integrals with the 'size', but then I saw that it is in fact doing some other things, it's like the $e^{-jwt}$ weren't integrated at all.
Could somebody explain to me what's happening? I'm very lost.
Comment: Consider it is not true. The discrete Fourier transform is analogous to a Fourier series $\sum_n c_n e^{2i \pi n x}$ with finitely many terms, in that case knowing it for finitely many values of $x$ is enough. In practice, the DFT (of size $N$) is just an unitary matrix $W \in \mathbb{C}^{N \times N}, WW^* = W^* W = Id$. **It is true** that the Fourier series is the limiting case of the DFT. It is much less true that the Fourier transform is the limiting case of the Fourier series.  You'll need the Fourier transform of distributions (with Dirac deltas) to unify everything.
Comment: It is not completely wrong neither that the FT is the limiting case of the DFT, but it is also true it is quite hard to prove.
Answer: The idea is the following: I will try to use notation similar to what was used in the picture provided.  (I will use $i$ instead of $j$ for the canonical complex root of unity.)
Often in signal processing our discrete signal $\{s[0],s[1],\dots,s[N -1]\}$ was obtained by sampling a continuous signal $s : [0,(N- 1)T] \to \mathbb{R}$ with, say, $s[n] = s(nT)$.
An apparently naive but actually fairly natural way of representing the samples $\{s[0],s[1],\dots,s[N - 1]\}$ is as a measure on $[0,(N - 1)T]$ via the formula
$$s_{d} = \sum_{j = 0}^{N - 1} s[j] \delta_{jT},$$
where $\delta_{x}$ denotes the Dirac mass at $x$.  This is what the author means by "regarding each sample as an impulse having area ..."  In fact, if one "integrates" $s[j] \delta_{jT}$ over $[0,(N - 1)T]$, one gets $s[j]$ back.  (What I mean by "integrates" should be clear if you have enough real analysis background, but, if not, I can try to explain further.)  In the electrical engineering literature, "impulse" means Dirac or Kronecker delta depending on the context so this is what the author means, whether or not he wants to write it (or even thinks about it) in a mathematically rigorous way.
Now take the Fourier transform of $s_{d}$.  $s_{d}$ isn't a function, it's a measure.  Nonetheless, we have a notion of Fourier transforms of measures and it gives us
$$\hat{s}_{d}(\omega) = \sum_{j = 0}^{N - 1} s[j] \int_{-\infty}^{\infty} e^{-i \omega t} \delta_{jT}(dt) = \sum_{j = 0}^{N - 1} s[j] e^{-i \omega j T}$$
which is what the article claims.
Comment: I'd like to get a better understanding of this dirac thing, I don't get this integral of a function times the dirac function
Comment: The Dirac mass $\delta_{x}$ centered at $x$ is a measure, not a function.  Do you have any background in measure theory?  If not, the easiest way to play with a Dirac mass is to use think of it as a linear functional that takes (sufficiently nice) continuous functions and spits out the value at $x$, i.e. $\int_{\mathbb{R}} \varphi(y) \delta_{x}(dy) = \varphi(x)$.
Answer: I guess that you missed the fragment "regard each sample as an impulse", which means (reading between lines) that the signal is a sum of Dirac deltas of amplitude $f[k]$.
A Dirac delta is an infinitely short signal of infinite amplitude, such that the area under its "curve" is one. When you integrate such a delta in an interval that contains it, you get one. If you integrate the product of a delta and a function, you get the value of the function at the delta. https://en.wikipedia.org/wiki/Dirac_delta_function
Hence a Dirac delta replaces an integral by an instantaneous value. This is how you trade a continous signal for a discrete one.


How come the Bayes Theorem formula results in different probabilities that are verifiable using manual counting?

Question: I assume Baye's Theorem is expressed as either:
$P(B|A) = \frac{P(A|B)*P(B)}{P(A)}$
or
$P(A|B) = \frac{P(A) * P(B|A)}{((P(A) * P(B|A)) + (P(A') * P(B|A'))}$
The tutorial problem was:

Assume ten children have the following ages (years) and heights (inches):

I interpreted events A and B as:
P(A): Age x = 9 yr., 4/10
P(B): Height y = 49 in., 3/10
P(B|A): 3/4
The probability of a child being nine years old and exactly forty-nine inches tall is three out of ten. When I use the cumulative probabilities in Baye's Theorem, the result is 0.4 or 0.3999... I have to add one to the number of children 49 inches tall and nine years old to make the result 0.3. When I use the correct probabilities, I get 1. Did I misinterpret the results of the correct formula? Maybe Baye's Theorem is saying that all children 49 inches tall are nine-year-olds. Maybe Baye's Theorem is not the right theorem to use in estimating the probability of getting a nine-year-old who is forty-nine inches tall, $P(A ∩ B)$. I think that is a joint distribution. Is Baye's Theorem referring to a conditional distribution, where I have to assume a "prior" event?
Given $P(A|B) = \frac{P(A)*P(B|A)}{P(B)}$:
<code># Formula using the wrong probabilities.
print(f'P(A|B) = {((4/10)*(3/10))/(3/10)}')
print(f'P(A|B) = {((4/10)*(3/10))/((4/10)*(3/4)+((6/10)*(0/6)))}')
# Output: 0.4, 0.3999...

# Formula with P(B)+1 to force the known correct answer.
print(f'P(B) + 1, P(A|B) = {((4/10)*(3/4 * 4/10))/ ( (3+1) /10)}')
print(f'P(B|A\') + 1, P(A|B) = {((4/10)*(3/10))/(( (3+1) /10)*(3/4)+((6/10)*(1/6)))}')
# Output: 0.3, 0.3

# Formula for what I thought was the correct interpretation.
print(f'P(A|B) = {((4/10)*(3/4))/(3/10)}')
print(f'P(A|B) = {((4/10)*(3/4))/((4/10)*(3/4)+((6/10)*(0/6)))}')
# Output: 1.000...2, 1
</code>
Comment: Your formula at the start is incorrect, carefully check where each $A$ and $B$ goes. You seem to confuse conditional ($P(A|B)$ or prob. of A *given B is true*) an joint probability ($P(A\cap B)$, prob. of A and B both true). Bayes' theorem is used mostly to shuffle around conditional probability and says less about joint, it usually requires the latter to be known up to some integrating constant. Still, you seem to want $P(A|B)$ or the chance of being 9yo *given* being 49in; how many children of 49in that aren't 9yo are there?
Comment: From your picture table $P(A \mid B)=1$ is correct: everybody 49 inches tall is also 9 years old.  This is consistent with  $P(B \mid A)=\frac34$ since $\frac{P(A)}{P(B)}=\frac43$
Comment: @PBulls Which formula is incorrect, the formula in the question text or the Python code? The first two groups of Python code separated by comments are meant to be wrong. I thought the correct code implementation was the last two lines of code that return 1. Also, all children 49 in. tall are nine years old.
Comment: Sorry, I mixed up parsing the formula myself - I meant the very first one in your post but it's correct (should teach me not to comment from phone). I still don't follow where the mismatch lies though or what you're trying to do in those bottom calculations; you have $P(A)=0.4$, $P(B)=0.3$, $P(B|A)=0.75$, and $P(A|B)=\frac{P(B|A)P(A)}{P(B)}=\frac{0.75*0.4}{0.3}=1$? Everything in Bayes' theorem holds?
Comment: You're right. Baye's Theorem does hold. I was using it to answer the question of how many children in the entire sample are 49 in. tall and 9 yo. That is a misuse of Baye's Theorem.
Answer: The first two Python code groups that display either 0.4 or 0.3 are wrong. They do not implement Baye's Theorem. The third group is correct. I was just using Baye's Theorem the wrong way. I wanted to confirm that $P(A∩B) = 0.3$ according to the problem. That is the proportion of the sample children who are nine years old and forty-nine inches tall. Baye's Theorem does not answer that question. It answers the probability of an event given some prior event's probability. For example, it could answer the likelihood or proportion of children who are nine years old ($P(A)$) if/given they are forty-nine inches tall ($P(B)$). This is exactly $P(A|B) = \frac{P(A)∗P(B|A)}{P(B)}$ Refer to the comments of PBulls and Henry:


How can i increment int number in leading zero number?

Question: I am unable to increment a number in leading zero numbers.
a = 2
a = ('%02d' % a) #02

a = a + 1
print(a)

Code Error:
TypeError: can only concatenate str (not "int") to str

Expected Result:
02

03

04

05

Can anyone tell me best possible solution.
Comment: Still not using a `for` loop?
Answer: By the time you do:
a = a + 1

a is of type string. By adding 1 you are combining string and int types, which is not allowed in this sense.
What you can do is this (while keeping the same structure for clairity)
a = 2
b = ('%02d' % a) #02
print(b)

a = a + 1
b = ('%02d' % a) #02
print(b)

#etc.

Consider using a for loop (as the others mentioned) if you don't want to write all the separate cases.
Answer: You're mixing types. By doing a = a + 1 you're trying to add an int to a string.
Just divide to 2 variables:
a = 2

for i in range(4):
    a_str = ('%02d' % a)
    a = a + 1
    print(a_str)

or even save one variable if you simply want to print:
a = 2

for i in range(4):
    print('%02d' % a)
    a = a + 1

Answer: If it is just a printing issue and the leading zero is insignificant, then you can use print formatting like below (the "02" is the width):
for a in range(1, 12):
    print(format(a, "02"))

# output
01
02
03
04
05
06
07
08
09
10
11

Answer: Here is the answer:
Take an example 'i' and it starts with 0001 and I am incrementing the 'i' but python implicitly removes the zero's
I'm using the for loop to increment the 'i' values
length = 4  # number of digits like 0001
for i in range(1,15):
    print('0' * (length - len(str(i))) + str(i))

the output will be :
0001, 0002, 0003....0010 and so on

Answer: x = 2
x = ('%02d' % x)
print(str(int(x) + 1).zfill(len(x)))
>> '03'

you will have to keep it in a string as once you convert it to int, it strips away the leading 0's as having those will use more space to store the object.
Answer: If you want to print a number with a leading zero if the number is lesser than 10, then you can just do this:
a = 2
print(('0' if a < 10 else '') + str(a))  # 02


Adjusting confounders

Question: I'm conducting a case-control study consisted of 32 males and 35 females matched by age and gender with controls. Do I have to control for gender when I do the statistical analysis?
Answer: If you are analyzing each matched pair, then no, you should not include the matching variables in the regression model, but you should be using conditional logistic regression.
If, instead, you are using matching just to ensure a "balance" of covariates between cases and controls, you can help address some additional residual confounding by including those matching variables in the model. You do not have to do so, but it protects against failures in the matching process.
You may find much of this presentation helpful: http://www.teachepi.org/documents/courses/fundamentals/Pai_Lecture8_Confounding_Part2.pdf
Comment: thank you very much your answer is very helpful! what i understood is that when i'm conducting  linear regression analysis for the full cohort i have to control for gender. And i have to use conditional logistic regression to obtain OR?-@Fomite
Comment: @ReemM.AlHaj You should be doing *one or the other*, not both. I'd use conditional logistic regression and keep the matched pairs together, personally.
Comment: @Fomite- actually I'm new to statistics! I want to examine the effect of several biomarkers on insulin resistance among obese and non-obese (cases and controls) and if the association is independent or not so I've conducted multiple linear regression for the full cohort. do i have to conduct logistic regression OR between cases and controls? what do you think! and please if you have a useful reference for conducting a conditional logistic regression using SPSS I would be grateful! thanks again

Adjusting confounders


Is there an easier way to print taxonomies in the tpl? I get this working code, but it should be a "shorter" way!

Question: After a painful day and a half I get this code, that prints out in my node.tpl.php the taxonomy terms associated to that particular node that the user is viewing.
It works just fine. As it is quite long I´ll just put the whole thing inside a module and into a variable, to just print that.
The thing is that it should get an easier, better way to do this!
Any ideas?
<?php
$vid = 11; //vocabulary id
$nid = $node->nid; //it looks for the current loaded node
$query = "SELECT tid, name
FROM (
SELECT td.tid AS tid, name
FROM taxonomy_term_data AS td
JOIN taxonomy_index AS tn
  ON td.tid = tn.tid
JOIN node AS n
  ON n.nid = tn.nid
WHERE td.vid = ". $vid ."
  AND n.status = 1
  AND n.nid = ".$nid."
GROUP BY td.tid
) AS t
ORDER BY name ASC";
$result = db_query($query);
foreach($result as $term) {
      echo l($term->name, "taxonomy/term/$term->tid") . ', ';
}
 ?>

UPDATE:
This is devel output:
(I´ve used (dpm($node);) because it let me print the result here without losing the indentation)
(object) array(
  'vid' => '5178',
  'uid' => '1',
  'title' => 'PROYECTO',
  'log' => '',
  'status' => '1',
  'comment' => '2',
  'promote' => '0',
  'sticky' => '0',
  'nid' => '155',
  'type' => 'jornadas',
  'language' => 'und',
  'created' => '1095048000',
  'changed' => '1360589684',
  'tnid' => '0',
  'translate' => '0',
  'revision_timestamp' => '1360589684',
  'revision_uid' => '1',
  'taxonomy_vocabulary_4' => array(),
  'taxonomy_vocabulary_6' => array(
    'und' => array(
      array(
        'tid' => '33',
        'taxonomy_term' => (object) array(
            'tid' => '33',
            'vid' => '6',
            'name' => 'Jornadas Gratuitas',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_6',
          ),
      ),
    ),
  ),
  'taxonomy_vocabulary_7' => array(
    'und' => array(
      array(
        'tid' => '40',
        'taxonomy_term' => (object) array(
            'tid' => '40',
            'vid' => '7',
            'name' => 'Para PH',
            'description' => '',
            'format' => NULL,
            'weight' => '-10',
            'vocabulary_machine_name' => 'vocabulary_7',
          ),
      ),
    ),
  ),
  'taxonomy_vocabulary_11' => array(
    'und' => array(
      array(
        'tid' => '262',
        'taxonomy_term' => (object) array(
            'tid' => '262',
            'vid' => '11',
            'name' => 'colegios',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_11',
          ),
      ),
      array(
        'tid' => '543',
        'taxonomy_term' => (object) array(
            'tid' => '543',
            'vid' => '11',
            'name' => 'derecho',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_11',
          ),
      ),
    ),
  ),
  'body' => array(
    'und' => array(
      array(
        'value' => "

Answer: Few things here:

Your SQL is open to injection
You're running a query that has already been run, and for which data has already been returned by the core field system. Drupal already runs way too many queries in a page load, adding another unnecessary one should be avoided wherever possible.
Your code should be in a template preprocess function (or module file as you've mentioned). But that's not because of the length of the code. It's because you should maintain a good separation of logic and display.
Drupal has already prepared the display of the field for you, so it would be preferable to use that instead of building up from scratch again.

With those in mind, try simply adding:
<?php echo render($content['field_name_of_term_ref_field']); ?>

in place of your code.
To control how those field items come out (e.g. as links), navigate to admin/structure/types/manage/TYPE/display, and choose appropriate settings for the display widget.
Comment: Are you sure it's set to display on the "Manage Display" tab of your content type?
Comment: Ahhh ok. I remember seeing questions of yours before using D6 so I did wonder :) I can't think why the field isn't showing, but if you want to force it you can try `print render(field_view_field('node', $node, 'taxonomy_vocabulary_11'));`...
Comment: On the Devel tab for the node there's a sub-tab called 'Render'...you should be able to see whats being passed through in there. If you can dump that output to pastebin or something I can take a look
Comment: Sorry, By mistake I´ve deleted the comment! I´ll check that out now.
Comment: Yes, they all should display, I´ve just checked the "Manage display" tab. And no, sadly that code doesn´t print out anything. This was the link being referenced by me in my accidentally deleted comment: http://stackoverflow.com/questions/14835303/printing-all-array-results-in-a-themable-way-using-php
Comment: The only way they get printed is with this: print render($content['taxonomy_vocabulary_11'][0]['#title']); (I need to print out each one [0], [1], [2], etc). And even when they should get printed like links (in Manage Display I´ve set them that way), they are printed out in plain text.
Comment: Hmm is this a custom content type or one provided by a contrib module? If you've added the field yourself it should definitely start with `field_`
Comment: Thanks for your answer. It´s a custom content type. And the machine name is taxonomy_vocabulary_11 (this is a ported D6 site, and that was the taxonomy attached to that node type). I´ve tried also: field_vocabulary_11 and field_taxonomy_vocabulary_11, with no luck.
Comment: Here´s the devel output: http://stackoverflow.com/questions/14835303/printing-all-array-results-in-a-themable-way-using-php
Comment: Yes, I´m stuck with this froma  while now :). I´ve printed out this, but it won´t print. I´ve tried other options: $links, wich didn´t worked out either. $terms won´t work because (in any theme) shows notice error: Notice: Undefined variable: term... It´s pretty weird...
Comment: Thanks for your reply! I´ve pasted it here: http://pastebin.com/tGir5EbF


How is a jazz bass different from a normal bass guitar?

Question: I'm trying to get a jazz bass guitar (active) and I've been looking at the Ibanez range. The only problem is that it doesn't quite say whether it is jazz bass or not for most of them. For example, how do I know this Ibanez bass guitar is a jazz bass?
The question is what makes a jazz bass guitar a jazz bass?
Comment: This question will probably be disallowed. Have a look at SGC Nanyo Bass collection, I use several, and have never heard a bad word about them. From late '80s/ 90s. If you pay £300 it'll be a little more than average for a much greater than average bass.
Answer: Generally, the Jazz Bass refers to the Fender Jazz Bass.
Per the above link, it was named 'Jazz Bass' because the creator, Leo Fender, thought that jazz bassists would feel more comfortable playing this kind of bass. This is a characteristic jazz bass:

Notice the pickups. Two singlecoil ones. There are similar basses from other companies, but they aren't names as such. If you see a bass like this, you might be able to refer to as jazz bass, but unless it's a fender bass, it would be technically wrong.
Comment: in addition he intended it to be played when sitting down.


Why does $b^{\log_bx} = x$?

Question: Why does $b^{\log_bx} = x$?
Can someone break this down by showing me the steps as to why this is true?
Comment: It's probably the definition of logarithm; or did you have a different definition in mind?
Answer: It's the definition of the base-$b$ logarithm.
$\log_b c=d \Leftrightarrow b^d=c$.
So putting $y=\log_b x$ we have $b^y=x$.  That is $b^{\log_b x}=x$.
Comment: @Michael Hardy: Thanks for the clean up!
Answer: Another way to think of this is to define a family of functions for any $b > 0$:  $$f_b(x) = b^x.$$  Then there is an inverse function $$f_b^{-1}(x)$$ such that $$f_b^{-1}(f_b(x)) = x$$ for all real $x$, and $$f_b(f_b^{-1}(x)) = x$$ on the domain of the inverse function, which happens to be for $x > 0$.  The inverse function is the logarithm:  $$f_b^{-1}(x) = \log_b x.$$  Thus, $\log_b x^b = x$ and $b^{\log_b x} = x$ are consequences of the above and merely use different notation to express the same concept.
Another way to think about the base-$b$ logarithm is that logarithms are exponents.  That is to say, $\log_b x$ is the exponent or power to which $b$ must be raised in order to obtain $x$.
Answer: $$b^{\log_b(x)}=b^{\frac{\ln(x)}{\ln(b)}}=\sqrt[\ln(b)]{b^{\ln(x)}}=\sqrt[\ln(b)]{x^{\ln(b)}}=x^{\frac{\ln(b)}{\ln(b)}}=x^1=x$$

Why does $b^{\log_bx} = x$?


Using lmrob for repeated measures; warning message: S-estimated scale == 0: Probably exact fit; check your data

Question: I'm trying to run the lmrob() function in the R package robustbase, using data from a mixed factorial design study. My dependent variable is repeated (pre+ post) and I have two independent variables. I'm entering the post-measurement as the dependent variable, and controlling for the pre-measurement.
The function I'm trying to run is basically:
lmrob(Post ~ pre +IV1 + IV2, setting = "KS2014", data=mydataframe)

When I run this, I get an error message saying:
S-estimated scale == 0:  Probably exact fit; check your data.

When I don't control for the pre-measurement, I don't get this warning message. So I assume it has something to do with the repeated measures being correlated? Does anyone have any idea what might be causing the issue and how to resolve it?
This is the first time I'm posting here so please bear with me if I've not included enough detail or my question isn't clear enough, I will provide clarification if needed! I've copied in the output from the console, the session info, and the relevant extract from the dataset below.

Call:
lmrob(formula = Post_Intention ~ TPB_vs_no_TPB + Tailored_vs_Untailored +
    Pre_Intention, data = dfa, setting = "KS2014")
 \--> method = "S"
Residuals:
   Min     1Q Median     3Q    Max
   -80      0      0     10     90

Exact fit detected

Coefficients:
                                 Estimate Std. Error t value Pr(>|t|)
(Intercept)                             0          0      NA       NA
TPB_vs_no_TPBNo TPB                     0          0      NA       NA
Tailored_vs_UntailoredUntailored        0          0      NA       NA
Pre_Intention                           1          0      NA       NA

Robustness weights:
 88 observations c(1,5,10,13,16,19,21,25,27,28,29,31,32,34,36,40,42,50,53,56,57,61,66,68,75,79,83,86,87,93,98,104,108,112,116,119,124,125,128,134,135,136,138,139,144,145,148,153,156,161,164,165,171,173,175,176,177,179,182,184,190,193,197,198,199,203,213,215,216,217,218,219,220,226,232,233,235,236,239,241,242,243,245,246,247,250,251,252)
     are outliers with |weight| = 0 ( < 0.0004);
 165 weights are ~= 1.
Algorithmic parameters:
      tuning.chi1       tuning.chi2       tuning.chi3       tuning.chi4                bb       tuning.psi1       tuning.psi2
       -5.000e-01         1.500e+00                NA         5.000e-01         5.000e-01        -5.000e-01         1.500e+00
      tuning.psi3       tuning.psi4        refine.tol           rel.tol         solve.tol       eps.outlier             eps.x
        9.500e-01                NA         1.000e-07         1.000e-07         1.000e-07         3.953e-04         1.819e-10
warn.limit.reject warn.limit.meanrw
        5.000e-01         5.000e-01
     nResample         max.it       best.r.s       k.fast.s          k.max    maxit.scale      trace.lev            mts
          1000            500             20              2           2000            200              0           1000
    compute.rd fast.s.large.n
             0           2000
              setting                   psi           subsampling                   cov compute.outlier.stats
             "KS2014"                 "lqq"         "nonsingular"             ".vcov.w"                "SMDM"
seed : int(0)
> source('~/R scripts/lmrob.R')
re-encoding from UTF-8
Warning message:
In lmrob.S(x, y, control = control, mf = mf) :
  S-estimated scale == 0:  Probably exact fit; check your data
> sessionInfo
function (package = NULL)
{
    z <- list()
    z$R.version <- R.Version()
    z$platform <- z$R.version$platform
    if (nzchar(.Platform$r_arch))
        z$platform <- paste(z$platform, .Platform$r_arch, sep = "/")
    z$platform <- paste0(z$platform, " (", 8 * .Machine$sizeof.pointer,
        "-bit)")
    z$locale <- Sys.getlocale()
    if (.Platform$OS.type == "windows") {
        z$running <- win.version()
    }
    else if (nzchar(Sys.which("uname"))) {
        uname <- system("uname -a", intern = TRUE)
        os <- sub(" .*", "", uname)
        z$running <- switch(os, Linux = if (file.exists("/etc/os-release")) {
            tmp <- readLines("/etc/os-release")
            t2 <- if (any(startsWith(tmp, "PRETTY_NAME="))) sub("^PRETTY_NAME=",
                "", grep("^PRETTY_NAME=", tmp, value = TRUE)[1L]) else if (any(startsWith(tmp,
                "NAME"))) sub("^NAME=", "", grep("^NAME=", tmp,
                value = TRUE)[1L]) else "Linux (unknown distro)"
            sub("\\"(.*)\\"", "\\\\1", t2)
        } else if (file.exists("/etc/system-release")) {
            readLines("/etc/system-release")
        }, Darwin = {
            ver <- readLines("/System/Library/CoreServices/SystemVersion.plist")
            ind <- grep("ProductUserVisibleVersion", ver)
            ver <- ver[ind + 1L]
            ver <- sub(".*<string>", "", ver)
            ver <- sub("</string>$", "", ver)
            ver1 <- strsplit(ver, ".", fixed = TRUE)[[1L]][2L]
            sprintf("%s %s %s", ifelse(as.numeric(ver1) < 12,
                "OS X", "macOS"), switch(ver1, `6` = "Snow Leopard",
                `7` = "Lion", `8` = "Mountain Lion", `9` = "Mavericks",
                `10` = "Yosemite", `11` = "El Capitan", `12` = "Sierra",
                `13` = "High Sierra", ""), ver)
        }, SunOS = {
            ver <- system("uname -r", intern = TRUE)
            paste("Solaris", strsplit(ver, ".", fixed = TRUE)[[1L]][2L])
        }, uname)
    }
    if (is.null(package)) {
        package <- grep("^package:", search(), value = TRUE)
        keep <- vapply(package, function(x) x == "package:base" ||
            !is.null(attr(as.environment(x), "path")), NA)
        package <- .rmpkg(package[keep])
    }
    pkgDesc <- lapply(package, packageDescription, encoding = NA)
    if (length(package) == 0)
        stop("no valid packages were specified")
    basePkgs <- sapply(pkgDesc, function(x) !is.null(x$Priority) &&
        x$Priority == "base")
    z$basePkgs <- package[basePkgs]
    if (any(!basePkgs)) {
        z$otherPkgs <- pkgDesc[!basePkgs]
        names(z$otherPkgs) <- package[!basePkgs]
    }
    loadedOnly <- loadedNamespaces()
    loadedOnly <- loadedOnly[!(loadedOnly %in% package)]
    if (length(loadedOnly)) {
        names(loadedOnly) <- loadedOnly
        pkgDesc <- c(pkgDesc, lapply(loadedOnly, packageDescription))
        z$loadedOnly <- pkgDesc[loadedOnly]
    }
    z$matprod <- as.character(options("matprod"))
    es <- extSoftVersion()
    z$BLAS <- as.character(es["BLAS"])
    z$LAPACK <- La_library()
    class(z) <- "sessionInfo"
    z
}
<bytecode: 0x0000000017538350>
<environment: namespace:utils>

Dataset
dput(dfa)
structure(list(Pre_Intention = c(50, 10, 50, 100, 80, 100, 10,
0, 100, 50, 90, 100, 50, 100, 100, 50, 100, 100, 30, 0, 10, 0,
60, 10, 0, 0, 0, 0, 40, 10, 50, 0, 70, 50, 50, 20, 0, 50, 0,
70, 50, 60, 0, 100, 50, 100, 100, 100, 0, 50, 0, 10, 0, 60, 0,
50, 50, 20, 100, 100, 50, 100, 100, 0, 60, 20, 100, 10, 50, 100,
100, 100, 0, 50, 10, 0, 80, 50, 30, 100, 100, 80, 40, 100, 0,
10, 20, 100, 100, 100, 100, 0, 50, 100, 70, 100, 40, 20, 100,
100, 100, 100, 0, 50, 100, 100, 0, 50, 50, 90, 20, 50, 10, 40,
50, 20, 50, 0, 0, 100, 100, 10, 10, 80, 10, 100, 80, 50, 100,
10, 100, 100, 90, 50, 50, 50, 100, 50, 40, 100, 100, 40, 20,
10, 10, 20, 100, 20, 100, 0, 100, 0, 30, 0, 10, 10, 40, 0, 40,
0, 50, 0, 0, 30, 0, 0, 50, 0, 0, 0, 0, 10, 0, 0, 10, 10, 20,
50, 20, 100, 50, 20, 90, 20, 100, 70, 20, 90, 10, 20, 80, 100,
90, 100, 100, 100, 10, 10, 20, 0, 60, 0, 10, 100, 100, 100, 10,
10, 0, 20, 0, 0, 40, 0, 30, 0, 40, 70, 0, 0, 30, 40, 0, 10, 20,
20, 50, 10, 10, 0, 0, 10, 0, 50, 0, 40, 0, 20, 0, 0, 20, 100,
0, 100, 30, 0, 50, 70, 10, 0, 0, 30, 10), Post_Intention = c(70,
10, 50, 100, 0, 100, 10, 0, 100, 90, 90, 100, 100, 100, 100,
80, 100, 100, 70, 0, 30, 0, 60, 10, 10, 0, 40, 20, 70, 10, 80,
40, 70, 40, 50, 30, 0, 50, 0, 100, 50, 100, 0, 100, 50, 100,
100, 100, 0, 60, 0, 10, 40, 60, 0, 100, 80, 20, 100, 100, 90,
100, 100, 0, 60, 30, 100, 0, 50, 100, 100, 100, 0, 50, 20, 0,
80, 50, 100, 100, 100, 80, 50, 100, 0, 0, 30, 100, 100, 100,
100, 0, 60, 100, 70, 100, 40, 30, 100, 100, 100, 100, 0, 100,
100, 100, 0, 100, 50, 90, 20, 70, 10, 40, 50, 50, 50, 0, 10,
100, 100, 10, 10, 20, 40, 100, 80, 80, 100, 10, 100, 100, 90,
80, 70, 70, 100, 80, 50, 100, 100, 40, 20, 100, 50, 20, 100,
30, 100, 0, 100, 0, 60, 0, 10, 20, 40, 0, 40, 0, 60, 0, 0, 10,
10, 0, 50, 0, 0, 0, 30, 10, 30, 0, 0, 30, 10, 50, 80, 100, 50,
50, 90, 0, 100, 70, 20, 90, 10, 30, 80, 100, 100, 100, 100, 100,
20, 20, 40, 0, 60, 0, 90, 100, 100, 100, 10, 10, 0, 20, 0, 0,
60, 0, 50, 20, 70, 80, 20, 20, 30, 40, 0, 10, 20, 40, 50, 10,
10, 0, 0, 20, 60, 50, 10, 60, 0, 20, 50, 0, 60, 70, 10, 100,
40, 30, 100, 70, 10, 30, 20, 40, 10), TPB_vs_no_TPB = structure(c(1L,
2L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L,
2L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L,
2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L,
2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L,
2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L,
2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L,
2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L,
1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L,
2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L), .Label = c("TPB",
"No TPB"), class = "factor"), Tailored_vs_Untailored = structure(c(2L,
2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L,
1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L,
1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L,
1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L,
1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L,
1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L,
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L,
2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L,
1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L), .Label = c("Tailored",
"Untailored"), class = "factor")), .Names = c("Pre_Intention",
"Post_Intention", "TPB_vs_no_TPB", "Tailored_vs_Untailored"), class = "data.frame", row.names = c(NA,
-253L))
Comment: There is of course a logical problem here as if the pre and post are so closely related your other variables have little to predict and what they do have may be mostly measurement error.
Comment: It looks like your pre and post measurements are perfectly correlated. Is that true? If not then more details are needed about your data-set.
Comment: No they are not perfectly correlated; the correlation is r=0.895. Does that help? If not let me know what further details you need to know about the dataset.
Comment: What happens if you fit the model just with the pre-score as the sole predictor?
Comment: Thanks for the response. I just ran the function again with only the pre-score as a predictor, and got the same error message... Is it possible R can't handle when the two scores are highly correlated (even if not quite perfect)?
Comment: They may not be perfectly correlated if you do linear regression but I suspect some feature of the robust algorithm is down-weighting the few observations which are discrepant. You may have to ask on an R specific mailing list where people may be more familiar with the internals of the function.
Comment: Thanks for your reply - yes I suspect what you suggest is the case! I'll try to find some R savvy people who might know more about the function. Cheers!
Answer: The initial  S  estimate is based on random sampling.  It has itself quite a few tuning parameters,  see  help(lmrob.control) and probably  ?lmrob.S .  As @mdewey was also thinking, it could be that too many subsamples (of the random sample) gave perfect fits. I (as maintainer of robustbase) would be happy to investigate in more detail (when back at work), but for that I (or others helping) need to be able to get your data (or subset of your data which gives the same error).  If it's small enough, you could use to dput(<dataframe>) and paste the result here.
Even before that you could try to use the currently most recommended  setting="KS2014" and see if it helps (it already tries to use "better" S estimate tuning).   Last but not least:  Are you using the most current version of robustbase?
Comment: Thanks very much for your response. Regarding your queries/suggestions: I am using robustbase version 0.92-7, which I believe is the most up to date version. Also, I added the setting="KS2014" but this did not resolve the issue.  I've copied in the output from dput() into my question above; if you are able to have a look at this once you are back at work, that would be great! I appreciate it. Many thanks.
Answer: Note you did not get an error, but a warning... and that's why you did get a result on which you could call summary(*)  and got what you did show as output.
As a matter of fact that is already sufficient: You got 88 robustness weights == 0, and a perfect fit for the remaining observations (which had weights == 1: You can find that by using   weight(fm, type = "robustness")  where fm denotes the fitted model, i.e.,  fm <- lmrob(Post.. ~ Pre + .., dfa)`.
Your summary(fm) output indeed shows that the estimated coefficients are '1' for Pre  and 0 for all other "predictors" (including the intercept).
If you look more closely you can notice that from a total of 253 observations, in 165 cases, pre == post, identically, and hence a model where you reject 88 observations as outliers and use the remaining 165 ones gives a perfect prediction.
--- all clearly no error, and  'Ok'  actually.
Now if you are more interested you can do the following,
fm1 <- lmrob(Post_Intention ~ ., setting = "KS2014", data = dfa)

Warning message:
In lmrob.S(x, y, control = control, mf = mf) :
S-estimated scale == 0:  Probably exact fit; check your data

Robustness weights, directly:
table(rw <- weights(fm1, type = "robustness"))
0   1

88 165          #total: 253 observations
Model if we only look at the 88 cases that were weighed down to 0 (aka "thrown away"):
fms <- lmrob(Post_Intention ~ ., setting = "KS2014", data = dfa,
         subset = rw == 0)
summary(fms)

Call:
lmrob(formula = Post_Intention ~ ., data = dfa, subset = rw == 0, setting = "KS2014")
 \--> method = "SMDM"
Residuals:
Min      1Q  Median      3Q     Max
-97.494  -9.791  -2.203  11.692  70.635

Coefficients:
                 Estimate Std. Error t value Pr(>|t|)
(Intercept)                      26.26067    4.98925   5.263 1.07e-06 ***
Pre_Intention                     0.96748    0.09624  10.053 4.56e-16 ***
TPB_vs_no_TPBNo TPB              -6.57097    4.45877  -1.474    0.144
Tailored_vs_UntailoredUntailored  0.40615    4.52753   0.090    0.929
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Robust residual standard error: 20.6
Multiple R-squared:  0.5511,    Adjusted R-squared:  0.535
Convergence in 12 IRWLS iterations

Robustness weights:
 66 weights are ~= 1. The remaining 22 ones are summarized as
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
 0.0956  0.6930  0.8942  0.7596  0.9297  0.9981
Algorithmic parameters:
   .........
   .........
>

This may (or may not) be interesting: Even for these cases, only the pre_intention has a significant effect.
Comment: Thank you for your helpful and detailed response. Could you help me understand why the model excludes the 88 responses? I understand that the model views them as outliers but in this case I don't think they should be excluded. A little background info: I was looking into ways to increase participants' intention to seek help from a doctor. It looks like for the majority (n=165), there was no change in intention. However for 88 participants, the intention changed: In only 10 cases it decreased, whereas in 78 cases it increased. I think this indicates that these weren't random outliers.


How can I clear the Menu cache after saving some configuration?

Question: I'm in the process of creating my first D7 module, partly based on the tutorial found here. My module creates (among other things) a public page to show some content, and it also has a configuration page (in the Drupal admin) that allows the user to choose the path at which this page must be displayed (e.g. "mypage" or "content/mymodule" etc).
My problem is that saving this value through the configuration form is not enough: you also have to clear the Menu cache, otherwise the old path remains active, and the new one gives you a "page not found" error.
I need that to occur automatically every time this value is changed (or every time the form is submitted). I tried using menu_rebuild() in my validation function, but it's obviously not the right place, because it is triggered before the new data is saved, and so the menu is rebuilt with the obsolete data.
How should I proceed if I want the Menu cache to be automatically cleared after the data has been validated and saved?
Here's my implementation of the pages, via hook_menu:
<?php

/**
 * Implements hook_menu().
 */
function mymodule_menu() {
  $items = array();

  // config page
  $items['admin/config/services/mymodule'] = array(
    'title' => 'mymodule',
    'description' => 'Configuration for the mymodule module',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('mymodule_form'),
    'access arguments' => array('access administration pages'),
    'type' => MENU_NORMAL_ITEM,
  );

  // public page
  $m_title = variable_get('mymodule_title', 'Mymodule');
  $m_title = $m_title ? $m_title : 'Mymodule';

  $m_path = variable_get('mymodule_path', 'mymodule');
  $m_path = $m_path ? $m_path : 'mymodule';

  $items[$m_path] = array(
      'title' => $m_title,
      'page callback' => '_mymodule_page',
      'access arguments' => array('access mymodule content'),
      'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

/**
 * Page callback: mymodule settings
 *
 * @see mymodule_menu()
 */
function mymodule_form($form, &$form_state) {
  $form['mymodule_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title displayed on the mymodule public page'),
    '#default_value' => variable_get('mymodule_title', 'Mymodule'),
    '#required' => TRUE,
  );
  $form['mymodule_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path for the mymodule public page'),
    '#default_value' => variable_get('mymodule_path', 'mymodule'),
    '#required' => TRUE,
  );
  $form['#submit'][] = 'mymodule_form_submit';

  return system_settings_form($form);
}

/**
 * Add a submit handler/function to the form.
 */
function mymodule_form_submit($form, &$form_state) {
  drupal_set_message(t('TEST: The form has been submitted.'));
  menu_rebuild();
}

/**
 * Implements validation from the Form API.
 *
 * @param $form
 *   A structured array containing the elements and properties of the form.
 * @param $form_state
 *   An array that stores information about the form's current state
 *   during processing.
 */
function mymodule_form_validate($form, &$form_state) {
  // page path validation
  $m_path = $form_state['values']['mymodule_path'];
  $m_path_db = variable_get('mymodule_path', '');
  if ($m_path_db != $m_path) {

    if (drupal_lookup_path('source', $m_path) || menu_get_item($m_path)) {
      form_set_error('mymodule_path', t('This path is already used.'));
    } else {

      // attempting to validate path value
      // see: http://drupal.stackexchange.com/questions/167923
      $m_path_parts = explode('/', $m_path);
      $has_invalid_chars = false;
      foreach ($m_path_parts as $key => $part) {
        if (urlencode($part) != $part) {
          $has_invalid_chars = true;
        }
      }
      if ($has_invalid_chars) {
        form_set_error('mymodule_path', t('This path contains invalid characters.'));
      }
    }
  }
}

?>

Edit: more code provided.
Comment: Just a note, `variable_get`'s second parameter (e.g. 'Mymodule') is the default value to return if the variable is not set. You don't need the other line immediately after it: `$m_title = $m_title ? $m_title : 'Mymodule';` because variable_get already does it for you.
Comment: Right. Actually I was aware of that, I just wasn't sure if a variable could be defined with an empty value (""), so I added this check to make sure the title or path was never empty.
Answer: Your form code would be helpful to see here to determine if you are using a system_settings_form() function (which seems likely since you are creating a module configuration form) or just a simple form. Regardless, the answer for both is to add a submit_handler to your form.
Basic Form with Submit Handler: https://www.drupal.org/node/717740
If you are not using system_settings_form, than you can add your post-submit actions to a function named after your form definition function, or
/**
 * Add a submit handler/function to the form.
 */
function my_form_submit($form, &$form_state) {
  <YOUR menu_rebuild STUFF HERE>
}

and Form API will automatically find it. If you are using system_settings_form() for your admin form, than you can add your submit handler by adding this before calling system_settings_form()
$form['#submit'][] = 'my_form_submit';

Comment: Oh, I see. So it seems the only thing I was missing was the `my_form_submit` function. I'll have to wait until Monday before I can test that out, but thanks for your answer already. ^^
Comment: OK I tested your suggestion. The submit function is called (I used a `drupal_set_message()` to make sure of that), but with the same problem as when I tried clearing the cache during validation: after the menu cache is cleared, the menu still uses the values from *before* the form was submitted, instead of using the updated values. So if I save the form twice in a row (by clicking the submit button), then the new path is recognized. But not if I save the form only once. Any idea how to solve that? I've edited my question to include more of my code.
Comment: Never mind, problem solved. :)
Comment: Mind sharing what it was that resolved the problem?
Comment: Sure. The trick was to use `variable_set('menu_rebuild_needed', TRUE);` in order to let Drupal know that it needed to rebuild the menu cache later on. I was able to put that in my validation function, so that the clearing only occurs when really needed. You can check the accepted answer and my comment after it for more details.
Answer: This is to do with the order of execution.
mymodule_form_submit is being called earlier than system_settings_form_submit because you're adding your own submit handler into the form array before calling system_settings_form which will add it's own submit handler (system_settings_form_submit) after your submit handler.
Essentially, your submit handler does a menu rebuild with the old variables, and then the new variables get saved to the database.
There's couple ways you can fix it as far as I know. These aren't tested.
First method is using a variable in your submit handler instead of directly rebuilding the menu:
/**
 * Add a submit handler/function to the form.
 */
function mymodule_form_submit($form, &$form_state) {
  drupal_set_message(t('TEST: The form has been submitted.'));
  // Set a variable to let menu_execute_active_handler() know that menu rebuild is required
  variable_set('menu_rebuild_needed', TRUE);
}

Or alternatively, you can add your own submit handler after system_settings_form has done its thing:
/**
 * Page callback: mymodule settings
 *
 * @see mymodule_menu()
 */
function mymodule_form($form, &$form_state) {
  $form['mymodule_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title displayed on the mymodule public page'),
    '#default_value' => variable_get('mymodule_title', 'Mymodule'),
    '#required' => TRUE,
  );
  $form['mymodule_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path for the mymodule public page'),
    '#default_value' => variable_get('mymodule_path', 'mymodule'),
    '#required' => TRUE,
  );

  $form = system_settings_form($form);
  // Add custom submit handler after system_settings_form_submit
  $form['#submit'][] = 'mymodule_form_submit';

  return $form;
}

Hope this helps.
Comment: Thanks for your help. First I tried the second solution you suggested: it worked, but it caused the *"The configuration options have been saved"* message to appear twice, which made me feel it was not optimal. So I canceled this change and then tried your first solution: it works perfectly as far as I can tell (no double message this time). (I actually moved the `variable_set('menu_rebuild_needed', TRUE);` line in the validation function, so it only executes if the updated values are different than the ones stored in the database. No need to clear the cache if those values haven't changed. :))
Answer: Drupal 7
for Drush using
drush eval 'menu_rebuild();'

memcached
If you are using memcached, you have to restart it.
On Linux: /etc/init.d/memcached restart

On OS X: killall memcached


NX: How to create a NX workspace in an existing empty git repository instead of creating it under a workspace name?

Question: I have an existing repository. I have cleared all the unwanted files as I wanted to start a new NX-integrated project. But, I want to continue using the same repository as there are some files which I would prefer to be present in the root directory.
If I run npx create-nx-workspace@latest --preset=next --packageManager=yarn, it will ask a bunch of questions and create the project under the workspace name. I want the files to reside directly under the existing current directory rather than creating a new directory with the workspace name under the current directory.
For example, instead of
my-project
--nx-workspace-name
----package.json
----lib

I want the files to be under
my-project
--package.json
--lib

I went through all the create work space flags but didn't find a relevant flag which could resolve this issue. At present, I copy all the files and place them in the root directory. Then, I delete the folder with the workspace name.
An example would be to use something like the --flat flag while creating the NX react component which creates the files in the same directory without nesting the files under any new directory.
Is it possible to avoid this extra step?
Answer: I had the same issue and it seems create-nx-workspace command do not have any build-in flag to ignore hidden ".git" directory.
I tried to use "--skipGit=true" flag but still it complains about hidden ".git" directory.
What worked for me is to do things from scratch by using local git repo and then connecting it to remote git repo.
Steps:

Empty your existing repository on remote/server and make sure there
are no files or folders in the "main" branch and there are no other branches.
Delete other branches as it might cause inconsistency.
Delete your existing git repository folder. For e.g. say your
existing repository name was "my-org-repo" then delete "my-org-repo"
folder
Go to the parent directory in terminal/cmd inside which you want to create the new nx-workspace folder and run "create-nx-workspace" command
"create-nx-workspace" initializes the new git repo for you if you
need to initialize manually and provide specific branch name you can
pass the "skipGit" flag
Now cd inside newly created directory cd my-org-repo and run git remote add origin [your-git-repo-url]
Check if the remote is successfully added by running git remote -v.
It should show something like origin [your-git-repo-url] (fetch)
origin [your-git-repo-url] (push)
Push your local repo changes to remote repo branch by running git push --set-upstream origin main. Replace main with your branch name
in case it's different
Now you have new repo setup with Nx at root level
Answer: I ran into the same situation and I just moved the resulting files one directory up.
Answer: I think you need to install nx in an existing repo/workspace. Run the following command in your root folder:
npx nx@latest init

Check out more here: https://nx.dev/getting-started/installation
Answer: (No) Solution:
Looks like this cannot be done at the moment so I opened an issue here.
Workaround:
Step 1.
Clone your project (let's say it's called urproject)
git clone urproject

Step 2.
Enter the cloned directory.
cd urproject

Step 3.
Create the workspace via the wizard as normal. FOR THE DIRECTORY INPUT ENTER ANY NAME (like urproject)
npx nx create-nx-workspace

Step 4.
Move the created project from the created subdirectory to the current one.
It's important to match the .gitignore and other dotfiles as well.
mv ./urproject/* /urproject/.* .

Step 5.
Remove the temporary directory created by the wizard.
rm -rf ./urproject


Standard deviation of game results about predictions from a rating system

Question: I'm very in to Sports analysis and am keen to look at finessing my analysis models that I have worked up  (I don't have a great maths background, I've just done a little bit of reading).
Standard deviation of Game Results about prediction from a Ratings system (in this case least squares regression with a few tweaks) equals the stochastic element in a normal distribution function where:
x = the margin of victory that you are trying to get a % against (e.g. it could be a point spread e.g. % to cover)
the mean = the predicted margin of victory derived in this case from my least squares regression to create power ratings for teams
sigma = standard deviation of error on the difference between the predicted margin of victory and actual margin of victory based on past results.
Based on the above I would treat in Excel terms a win % for team A as:
1-NORMDIST(0.5,mean,sigma,true) - with the mean and sigma having values obviously.
Based on Stern "The Probability of Winning an American Football Game" American Statistician (August 1991) - the sigma value (stochastic element? - sorry this isn't my usual thing) is approximately 13.86. How would you go about refining this for other sports? - e.g. Australian Rules Football. I said this could be done for any sport (and I believe it can within reason unless the results or the sport doesn't lend itself to this type of analysis).
Looking at past AFL results from the end of the season point of view the standard deviations are as follows (have only started looking at these in the last two days):
2009: 31.34 (150+ results)
2010: 33.44 (150+ results
2011: 34.91 (150+ results)
2012: 25.62 (only approximately 70 results so far as it is mid season)
As you feed more data into the model for 2012 it will build up a more accurate picture but looking at past data I'm putting the sigma value for AFL at around 33.5 (above the 25.62 value). Is there anyway of defining a best fit value? Where I don't have a great background in this kind of thing, if someone could give me some gentle nudges in the right direction in terms of where I should be looking or what I could be applying I would be grateful.
I believe this can definitely be applied to other sports as well e.g.:
English Premiership:
2008/2009: 1.45 (Season with over 300+ results)
2009/2010: 1.52
2010/2011: 1.54
2011/2012: 1.64 (but when looking over the last 100 results around the 1.50 mark)
I've also looked at the percentages that this then gives for home wins, away wins and draws and they are virtually identical to the percentages for bookmakers odds (except they work to 105-106% instead of 100% so they have an edge which accounts for the small differences).
NBA:
2008/2009: 11.30 (Season with 1000+ results)
2009/2010: 11.56
2010/2011: 10.88
2011/2012: 11.36
Thanks in advance for any advice,
Answer: It is common in sports to predict outcomes using logistic regression or if you want to predict a continuous response linear regression.
In logistic regression the response Y has 2 values (win or lose in the case of a sporting event outcome) So the outcome is usually coded as 0 for loss and 1 for win.
The model is y=a1 X1 + a2 X2 +a3 X3 +....+ e.  The response y=log(p/1-p)  where p is the unknown probability of success and X1, X2, X2,... are the vsrisble that are used to predict y. In linear regression you have the same form as with logistic regression except that y is the response rather than a function of it. e is the random component or stochastic element.  It is there to express error (sometimes measurement error in determining y).  In these models the error term is assumed to be additive.  Also the Xi are assumed to be determined without error. Using the model and data for the Xis and the corresponding ys the regression parameters a1, a2,a3, ... are estimated (usually by least squares).  Often the error term e is assumed to be normally distributed with me an 0.  They are independent of the Xis and independent of each other. The variability of the error term is defined by the standard deviation sigma which is assumed to be constant (i. e. the same for each sample).  For the normal distribution the mean and standard deviation uniquely determine the distribution.  These models are general and the technique can be applied in any sport.  The covariate and response variables can differ from sport to sport.  It is important to keep the modeling assumptions in mind and if they don't seem to apply alternative approaches may need to be considered.
The American Statistical Association has a section on Statistics in Sports. Hal Stern whose article you cited is a member of that section. He has written substantially on sports. other members Jim Albert and Michael Schell have written books specifically on baseball. You might want to consider joining the association and the section. On the ASA website there is an eGroup for the section where questions like yours are discussed. I am a member but haven't actively done research in it. Many members of the section have though.
Other prominent members that I have not yet mentioned are Carl Morris and Scott Berry.
What is the sample size and do you have bins with fewer than 5 observations? I ask these questions because very small departures from normality can be detect in large samples. Also the chi square test is approximate and doesn't work well when there are bins with fewer than 5 observations. The median seems a lot larger than the mean which would indicate high skewness. But that doesn't show up in the skewness statistic.The standard deviation is large but the standard error is small which indicate a large sample size.
Since the ratio of the standard deviation tio the standard error should be the sqaure root of n, your sample size must be close to 600. I calculated 576 and looking at our data again I see count =567 is probably your sample size and that would make sense. I would like to see a histogram and a Q-Q plot. The conclusion is non-normal but it is not yet clear to me that the departure from normality is large enough to worry about.
Comment: Q-Q stands for quantile vs quantile.  It is like log paper for normal distributions.  Things are scaled so that normally distributed data will fall close to a straight line. It provides an informal graphical check.  I think redefining the bins will help with the validity of the chi square test.
Comment: I think I have definitely have got this being normally distributed now around the 33.2 mark in terms of standard deviation/the stochastic element. I've added links in to screenshots from an Excel workup I've done on a KS Test which suggests normal distribution and a QQ plot which again suggests normal distribution (I have corrected the link above). http://img42.imageshack.us/img42/7521/aflkstestresult.jpg - is the ks and http://img641.imageshack.us/img641/7367/aflnormalprobability.jpg is what I think is the QQ. If this matches what you were thinking I'm happy to accept an answer.
Comment: sorry I meant to ping you on the above (I hope this makes sense). The nudges you've provided me in the right direction I think have resolved this and I would be happy to accept an answer on that basis.
Comment: @user8812: If writing a comment under an answer or a question, the author of the post (and most recent editor) will *automatically* get a notification (even if you don't address them using @). For example, Michael is going to get pinged in addition to you when this comment gets posted. :)
Comment: @Cardinal thanks for the advice re: pinging - I didn't realise and couldn't figure why when I tried to add at MichaelC it didn't show. From the screenshots above does my logic appear sound that this is normal distributed? (sorry for asking I just have close to no relevant background in this kind of thing and am not 100% sure on this).
Comment: Thanks for the information - it's helpful to get a better understanding (we did this kind of thing at school but there was never a practical application so it was difficult to see where it was relevant). I would say what I am doing is essentially logistic but instead of coding 0 and 1, I am using actual games scores (which does affect the ratings as they are skewed by one-sided results). I am definitely keen to try and get a general approximation for e (if there is such a things as best fit for stochastic elements) and the given the past data you can get access to I think this achievable.
Comment: The American Statistical Association has a section on Statistics in Sports.  Hal Stern whose article you cited is a member of that section.  He has written substantially on sports.  other members Jim Albert and Michael Schell have written books specifically on baseball. You might want to consider joining the association and the section.  On the ASA website there is an eGroup for the section where questions like yours are discussed.  I am a member but haven't actively done research in it.  Many members of the section have though.
Comment: Other prominent members that I have not yet mentioneed are Carl Morris and Scott Berry.
Comment: Thanks for the heads up. I'm keen to improve the models generally (side interest) and I'm just keen to refine the AFL one (hence why I worked up the last three years data to get a clearer idea of the e value as I figured the 2012 one was wrong or there wasn't enough data yet most likely). I know the model is generally solid though as it has gone 11/21 on general bet-able outcomes (so far this weekend - one game remaining) and 6 out of 7 on totals (which these models seem sharp on - 10% return off of my German Ice Hockey model  - or the totals are badly handicapped).
Comment: I went away and looked into the Chi Square test, and carried out a Chi Square test on the error of my prediction against the result:
Comment: DESCRIPTIVE STATISTICS
Mean 0.00000160
Standard Error 1.395945948
Median 0.393745022
Standard Deviation 33.2399324
Sample Variance 1104.893106
Kurtosis 0.030249713
Skewness 0.081407243
Range 221.2779953
Minimum -104.080249
Maximum 117.1977463
Sum 0.000908841
Count 567
Confidence Level(95.0%) 2.741866796, Chi Squared Statistic = 223.79, df=21 (24 filled bins, 2 parameters), p=0 (so I reject the null hypothesis but I'm not sure what this means). I can provide further information if it helps (e.g. the histogram) but any nudges in the right direction would be appreciated.
Comment: What is the sample size and do you have bins with fewer than 5 observations?  I ask these questions because very small departures from normality can be detect in large samples. Also the chi square test is approximate and doesn't work well when there are bins with fewer than 5 observations. The median seems a lot larger than the mean which would indicate high skewness.  But that doesn't show up in the skewness statistic.The standard deviation is large but the standard error is small which indicate a large sample size.
Comment: Since the ratio of the standard deviation tio the standard error should be the sqaure root of n, your sample size must be close to 600.  I calculated 576 and looking at our data again I see count =567 is probably your sample size and that would make sense.  I would like to see a histogram and a Q-Q plot.  The conclusion is non-normal but it is not yet clear to me that the departure from normality is large enough to worry about.
Comment: The sample size is 567 - and I do have bins with fewer than 5 observations, I'll try and post the histogram but I don't know if the formatting will work in a comment: Bin Frequency
-120 0
-90 2
-70 5
-50 31
-40 31
-30 38
-25 27
-20 19
-15 24
-10 47
-5 35
0 21
5 35
10 38
15 23
20 34
25 26
30 26
40 43
50 26
70 25
90 8
120 3
More 0 - I don't know what a Q-Q plot is but I will find out and come back with the info. I've done the Chi Squared in Excel and had it verified by someone. I intend to try and do a K-S test on this next. Bin number starts at -120 with 0, -90 with 2, etc.
Comment: Incidentally the sample size of 567 is the last 3 full years of AFL data (in the same way the Stern study went with 3 full years of NFL data) I just wanted to make sure there was enough data in there to make a reasonable study.
Comment: I tried to figure out what I needed to do for a QQ plot in Excel but I don't think that I could quite figure it out but I think I've managed a normal probability plot. I've posted a jpeg of the plot here: http://imageshack.us/photo/my-images/641/aflnormalprobability.jpg/ - from my very basic understanding of this the fact that it is approximately in a straight line would suggest a normally distributed data set? Providing I'm on the right lines I will redefine the bins and post fresh Chi Squared data.


Por que a tag  do HTML5 não está redimensionando as imagens?

Question:

<!DOCTYPE html>

<picture>
   <source media="(min-width: 490px)" srcset="img/smartphone.jpg"/>
   <source media="(min-width: 650px)" srcset="img/bola.jpg"/>

</picture>

Comment: O código que colocou nem tem essa tag
Answer: OBS: Primeiramente acredito que vc tenha se confundido no título da pergunta, pois falou de
, mas no código vc colocou <picture>, de qq forma, seu problema é com a ordem das tags...
Seu problema é simples, quando se usa min-width o maior valor sempre tem que vir primeiro
Primeiro 650px e depois 490px, se nao for nessa ordem o valor de 490px vai sobrescrever tudo que vier após
<source media="(min-width: 650px)" srcset="http://placecage.com/300/100" />
<source media="(min-width: 490px)" srcset="http://placecage.com/200/100" />

Segue o código da imagem acima

<picture>
    <source media="(min-width: 650px)" srcset="http://placecage.com/300/100" />
    <source media="(min-width: 490px)" srcset="http://placecage.com/200/100" />

</picture>


Embedding of affine space in vector space

Question: Let $E$ be an affine space over a field $k$ and let $V$ its vector space of translations. Denote by $X=\operatorname{Aff}(E,k)$ the vector space of all affine-linear transformations $f:E\to k$, that is, functions such that there is a $k$-linear form $Df:V\to k$ satisfying
$$
f(x+v) = f(x) + Df(v) \quad \text{for all } x\in E, v\in V,
$$
and let $X^*=\operatorname{Aff}(E,k)^*$ its dual space. Consider the following $k$-linear map:
$$
\varepsilon:V\to X^*, \quad v\mapsto \varepsilon(v),
$$
where $\varepsilon(v):X\to k$ is given by evaluation of $Df$ at $v$, that is
$$
\varepsilon(v)(f) = Df(v) \quad \text{for all } f\in X.
$$
Clearly $\varepsilon$ is injective. The claim is that $\varepsilon$ embeds $V$ as a (linear) hyperplane of $X^*$. This is obvious if $E$ is of finite dimension. For arbitrary dimension I defined
$$
\alpha:X^* \to k, \quad \varphi \mapsto \alpha(\varphi)=\varphi(1),
$$
where $1:E\to k$ is the constant function taking the constant value $1\in k$. Then it is clear that
$$
\varepsilon(V)\subseteq \ker(\alpha).
$$
I believe that equality holds but I don't know how to prove it. This will prove the claim.
Is this the right approach? Is there a better one?
Context: I know this has to be a basic fact, so to be honest I feel a bit ashamed for asking this question. I'm reading Macdonald's Affine Hecke Algebras and Orthogonal Polynomials; this claim is stated without comments on page 1.
Answer: The claim is false if $E$ is not assumed to be finite dimensional: Take $E$ to be of infinite dimension and fix $x_0\in E$. Consider the linear map
$$
\theta:F\to k, \quad f\mapsto f(x_0).
$$
Then the map $D:\ker(\theta)\to V^*$ given by $f\mapsto Df$ is easily seen to be a $k$-linear isomorphism. Thus as $\ker(\theta)$ is of codimension one in $F$, the first isomorphism theorem implies that $\dim F = \dim V^* +1$. But as $V$ is of infinite dimension, then $\dim F = \dim V^*$. But, because the algebraic dual space is strictly larger than the original space, we have the following inequality of infinite cardinals:
$$
\dim V < \dim V^* = \dim F < \dim F^*.
$$
This shows that $\varepsilon(V)$ cannot be of codimension one in $F^*$, but $\ker(\alpha)$ is, so the inclusion $\varepsilon(V)\subseteq \ker(\alpha)$ is strict in this case.


Getting EL variable properties in eclipse

Question: I'm using Eclipse/Spring source to edit JSP tags and EL. If I want to check what all the properties of a variable are is there a way to do this? Or even find out which file is generating the variable that's passed in. I'm thinking something along the lines of firebug for Javascript, where you can select an object and drill-down to get it's properties.
Answer: Eclipse doesn't support EL autocomplete yet. It isn't that smart yet. IntelliJ Ultimate Edition supports it and MyEclipse supports it as well, but both are not free (when talking about JSP/EL development).
The JBoss Tools Eclipse plugin supports it to a certain degree, only for implicit/predefinied EL objects, but not for custom ones which you've put as attribute in request/session/application scope yourself.
Comment: Now that it's 4 years later, is Eclipse smart enough yet?  :)
Comment: @Matt: Yep. It's even much better when you install JBoss Tools. Check this answer for an how to: http://stackoverflow.com/a/4057346
Comment: Sweet. Once JBoss is installed, what do I need to do within my JSP to tell content assist what the class of my bean is that I'm referencing with EL? I can't find documentation on this...


Evaluate $\int_{0}^{\pi}x\ln[b^{2a}+2b^a\cos(ax)+1]dx$

Question: How to evaluate this integral?
Let $(a,b)\ge2$
$$I=\int_{0}^{\pi}x\ln[b^{2a}+2b^a\cos(ax)+1]\mathrm dx$$
$u=\ln[b^{2a}+2b^a\cos(ax)+1]$
$u^{'}=\frac{2ab^a\sin(ax)}{b^{2a}+2b^a\cos(ax)+1}$
$v=\int x=\frac{x^2}{2}$
$$I=\frac{x^2}{2}\cdot \ln[b^{2a}+2b^a\cos(ax)+1]-\int\frac{ab^ax^2\sin(ax)}{b^{2a}+2b^a\cos(ax)+1}\mathrm dx$$
$$I=\pi^2\cdot \ln(b^a+1)-\int_{0}^{\pi}\frac{ab^ax^2\sin(ax)}{b^{2a}+2b^a\cos(ax)+1}\mathrm dx$$
$w=b^a\cos(ax)$
$$J=\int_{0}^{\pi}\frac{ab^ax^2\sin(ax)}{b^{2a}+2b^a\cos(ax)+1}\mathrm dx$$
$$J=-\int \frac{x^2}{b^{2a}+2w+1}\mathrm dw$$
$$J=-\frac{1}{a}\int \arccos^2\left(\frac{w}{b^a}\right)\frac{1}{b^{2a}+2w+1}\mathrm dw$$
Comment: yeah a and b are integers
Comment: The case  when $a$ is even is quite trivial ($\pi^2 a\ln b$) whereas the other case looks quite hard.
Comment: I am very interested if you can evaluate for the other case.
Comment: So, you just need a special case of $$j(s;p,q)=\int_0^\pi x\ln\left(p+q\cos(sx)\right)\ dx$$
Answer: Let $w=b^a.$  Then there exists a closed form in terms of polylogarithms for the integral
$$ I=\int_0^\pi x \log\big(w^2+2\,w\,\cos{(a\,x)}+1 \big) dx = \pi^2\,\log{w} + \frac{i\,\pi}{a} \Big( \text{Li}_2\big(-\frac{e^{i\,a\,\pi}}{w} \big) -
\text{Li}_2\big(-\frac{e^{-i\,a\,\pi}}{w} \big) \Big)+$$
$$+\frac{1}{a^2}\Big(2\, \text{Li}_3(-1/w) - \Big( \text{Li}_3\big(-\frac{e^{i\,a\,\pi}}{w} \big) +
\text{Li}_3\big(-\frac{e^{-i\,a\,\pi}}{w} \big) \Big) \Big). $$
The proof consists of factoring the argument of the logarithm as
$(w+\exp{(i\,\pi\,a)})(w+\exp{(-i\,\pi\,a)}),$ using the additive property of the log to get a sum of two integrals, and let Mathematica do the integral.  In the comments it was said that it can be assumed that $a$ can be an integer greater than two.  For this case we have
$$ I = \pi^2\,\log{w} + (1 - (-1)^a)/a^2 \Big( \text{Li}_3\big(-\frac{1}{w} \big) -
\text{Li}_3\big(\frac{1}{w} \big) \Big) .$$
The special case for even $a,$ as mentioned by Zachy, is easily recovered.


android webview video is not playing full screen mode

Question: i have to develop one android application.here the webvicw video is playing well..but if i have to click full screen mode means the video is crashes...how can i resolve these error...
How can i play video on full screen mode ??? or how can i play the video using youtube player ??? pls give me any suggestions ???
I have using below code:
<code>content.setWebChromeClient(new WebChromeClient());
final Activity activity = this;
    content.setWebChromeClient(new WebChromeClient(){
    public void onProgressChanged ( WebView view , int progress ){
        activity.setProgress(progress * 1000);
    }
});

content.setWebViewClient(new WebViewClient(){
    public void onReceivedError ( WebView view , int errorCode , String description , String failingUrl ){
        Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
    }

});

content.setWebChromeClient(new WebChromeClient());

content.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
content.getSettings().setJavaScriptEnabled(true);
content.getSettings().setDomStorageEnabled(true);
content.getSettings().setPluginState(PluginState.ON);
content.loadDataWithBaseURL(null, full_content, "text/html", "utf-8", null);
</code>
Answer: I did it use youtube player API...these is easy one for android developer.it is played well on fullscreen mode.
Comment: And what exactly did you do? Can you elaborate a bit please?
Comment: yes already youtube app is downloading on ur device which means its working well on our app also...


Why are extreme correlations so common in this Monte Carlo simulation?

Question: Consider the following simple Monte Carlo:
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import pearsonr
r = np.arange(3)+1
R = [pearsonr(np.random.normal(0,1,3), r)[0] for i in range(5009)]
plt.hist(R, bins=100)
plt.xlabel('Pearson\'s Correlation Coefficient')
plt.ylabel('Frequency')
plt.show()

Which gives a diagram similar to the following:

In words, 5009 IID standard normal variables are sampled in triplicate (n=3) and are paired to the values (1,2,3). The code above computes the Pearson's product-moment correlation coefficient between the triplicate standard normal variable measures and the sequence (1,2,3). I am curious about the distribution that results, which appears to my surprise to be non-uniform. I suspect there is a mathematical reason behind this reproducible effect.
Is there a mathematically formal reason why the extreme correlations of $\pm 1$ are more common than the less extreme correlation scores?
Comment: The shape closely resembles the [exact density](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#Using_the_exact_distribution) of the sample correlation coefficient for $\rho = 0$ and $n=3$ for bivariate normal distributions. Plot the density $f(r) = 1/(\pi\sqrt{1-r^2})$ on top of your histogram and compare.
Answer: Vector length seems to be too small, $n$, trying $30$. Minor changes to your sample code:
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import pearsonr
r = np.arange(30)+1
R = [pearsonr(np.random.normal(0,1,30), r)[0] for i in range(5009)]
plt.hist(R,bins=100)
plt.xlabel('Pearson\'s Correlation Coefficient')
plt.ylabel('Frequency')
plt.show()

Also, if we think that a noise should be uncorrelated, so correlations should look like normal centred at zero, not uniform:. This is the consequence of law of large numbers, intuitively.
Edit: Good point from @user20160. The length argument can be thought in terms of Autocorrelation Functions in time-series. Because observation is valid for two random variates too. So increasing length will decrease ACF to 0, mean value in the simulation. For small n=2, it is all fully correlated then it decays with increasing length.
Comment: This shows that the results change with greater $n$, but doesn't seem to answer the OP's question about why large correlations are so common when $n=3$
Comment: @user20160 Thank you for your thoughtful comment. You are right, the answer should be more explicit. Added additional information, intuition of thinking in terms of autocorrelations.
Answer:
Is there a mathematically formal reason why the extreme correlations of ±1 are more common than the less extreme correlation scores?

COOLSerdash gives in the comments the exact distribution of the sample distribution of the correlation coefficient. But this does not directly answer why we get so often values close to the extremes.

Intuition in terms of geometry of fitting
For an intuition why the correlation is so extreme you might consider the distribution of $R^2$.
You can regard correlation as a linear fit which splits the random variable $y$ into a linear model part and a noise part. This has a geometric interpretation of a perpendicular projection of the n-dimensional datapoonts $y$ onto a surface spanned by two vectors $a \cdot \vec{1} + b \vec{x}$. See for instance the illustration from this question

The value of $R^2$ is the ratio of the variance in these two components, the ratio of the variance in the model part and the variance in the total.
The variance of these model and noise components (which, by the way, are independent) are $\chi^2(\nu)$ distributed with the model part one degree of freedom $\nu=1$ and the noise $\nu=n-2$ degrees of freedom. So the distribution of $R^2$ is similar to
$$\frac{X_{model}}{X_{noise} + X_{model}} \quad \text{with $X_{model} \sim \chi^2(1)$ and $X_{noise} \sim \chi^2(n-2)$}$$
when $X_{noise}$ is small this ratio is relatively more often close to $1$.
We can also express $$1/R^2 = 1 + \frac{X_{noise}}{X_{model}}$$
which is similar to a F-distributed variable shifted by 1. When the degrees of freedom in the noise are low then this $1 + \frac{X_{noise}}{X_{model}}$ will be close to 1.


Svg - realtime scrolling chart

Question: Is it possible to create a realtime scrolling chart with svg in java android?
I found java salamander to display svg, but I don't know how to refresh the contained data on the chart...
Answer: Firstly, I doubt Salamander will work on Android.
The Android WebView supports SVG from Honeycomb onwards.  You could try that.
There are also a few standalone SVG libraries for Android, but none of them support animation or the type of DOM manipulation you are after.
SVG may not be the best solution for this use case.  Drawing the chart yourself with the Android Canvas API would probably be a better approach.

Svg - realtime scrolling chart


For $0<t\leq 1$ show that: $ \text{ln}(t)\geq \frac{t-1}{2t+2}\left(1+\sqrt{\frac{2t^2+5t+2}{t}}\right)$

Question: For $0<t\leq 1$ show
$$ \text{ln}(t)\geq \frac{t-1}{2t+2}\left(1+\sqrt{\frac{2t^2+5t+2}{t}}\right)$$
On a side note, I've been taking this summer class on inequalities. The professor told us that his main source are all sorts of  math olympiads. Given that I'm gonna take Calc 3 next semester and Real Analysis afterwards, are those types of inequalities really as essential as my prof suggests? As you can tell, I'm not really capable of proving most of them by myself yet...
Comment: In real analysis you will need to do several estimates while proving things. They are very rearly as tight as the contest questions on the theme. But some themes (AM-GM, Young, Jensen, Hölder) are very important.
Comment: Have you tried simple thing like $x=(0.5y-2)$? or use exponential ?
Comment: Can't really make anything of you substitution. I have tried using expponential but it didn't lead me to anything
Comment: Let $0<x\leq 1 $ and $n$ a positive  natural number then define $f\left(x\right)=\left(x^{2}-1\right)\ln\left(x^{n}\right)-2nx^{2}$ the second derivative is positive so using a tangent line we have better result with $$\frac{\left(f'\left(1\right)\left(x^{\frac{1}{n}}-1\right)+f\left(1\right)+2nx^{\frac{2}{n}}\right)}{\left(x^{\frac{2}{n}}-1\right)}$$ more than $n(x^{1/n}-1)$
Comment: Then we can make the substitution $y=1/x$ and see what's happend ...
Comment: @Octot Hey, I wrote an answer some days ago but there is no response. Please see if it is correct and  helps you with the basic methodology. Thanks!
Answer: My try .
here (Which is greater $\frac{13}{32}$ or $\ln \left(\frac{3}{2}\right)$)  Michael Rozenberg show :
let $0<x\leq 1$ :
$$\ln{x}\geq(x-1)\sqrt[3]{\frac{2}{x^2+x}}$$
Now we need to show :
$$(x-1)\sqrt[3]{\frac{2}{x^2+x}}\geq \frac{x-1}{2x+2}\left(1+\sqrt{\frac{2x^{2}+5x+2}{x}}\right)$$
or :
$$\sqrt[3]{\frac{2}{x^2+x}}\geq \frac{1}{2x+2}\left(1+\sqrt{\frac{2x^{2}+5x+2}{x}}\right)$$
I'm stuck here .Hope someone can achieve this .
Edit :
In fact using Wolfram Alpha we can conclude quicly see this logarithmic derivative link
Just some remarks for another proof :
We have the inequality :
$$\sqrt{\frac{\left(2x^{2}+5x+2\right)}{x}}\geq \frac{3}{2}\left(\sqrt{\frac{1}{x^{a}}}+\sqrt{x^{a}}\right)$$
Where :
$$a=\frac{2\sqrt{2}}{3}$$
So we need to show :
$$\left(\frac{3}{2}\left(\sqrt{\frac{1}{x^{a}}}+\sqrt{x^{a}}\right)+1\right)\left(x-1\right)\cdot\frac{1}{\left(2x+2\right)}-\ln\left(x\right)\leq 0$$
Or $x\to x^{\frac{2}{a}}$ :
$$\left(\frac{3}{2}\left(\frac{1}{x}+x\right)+1\right)\left(x^{\frac{2}{a}}-1\right)\cdot\frac{1}{\left(2x^{\frac{2}{a}}+2\right)}-\frac{\ln\left(x\right)2}{a}\leq 0$$
Now we substitute $\ln(x)=y$ and then we can use derivative .
Answer: Consider only strict inequality by dropping off the equal sign (because equality can be proven easily by putting t = 1).
Let $A$ = ${\frac{(t-1)}{2(t+2)}}$= $(1/2)- 1/(t+1)$
Now, t∈ (0,1) . Hence,
$A = (1/2)- 1/(t+1)∈ (-1/2,0)$
Let $B$  = $\left(1+\sqrt{\frac{2t^2+5t+2}{t}}\right)$
Now, we know that ;
$t + (1/t)  >2$
$2[t + (1/t)] >4$
$2[t + (1/t)] + 5 >9$
$\sqrt{2[t + (1/t)] + 5} >3$
$\sqrt{2[t + (1/t)] + 5} + 1 >4$
Hence,
$B$ $> 4$ because
$\sqrt{2[t + (1/t)] + 5} + 1 = \left(1+\sqrt{\frac{2t^2+5t+2}{t}}\right)$
Hence, your inequality reduces to ;
$ln(t)  > AB$
where $A∈ (-1/2,0)$ and $B ∈ (4,∞)$
Can you proceed further?
Answer: Fact 1: If $x \in (0, 1]$, then
$$\ln x \ge \frac{(x - 1)(1 + x^{1/3})}{x + x^{1/3}}.$$
(See [1], page 272. This inequality is due to Karamata.)
By Fact 1, it suffices to prove that
$$\frac{(t - 1)(1 + t^{1/3})}{t + t^{1/3}}
\ge \frac{t-1}{2t+2}\left(1+\sqrt{\frac{2t^2+5t+2}{t}}\right)$$
or
$$\frac{1 + t^{1/3}}{t + t^{1/3}}
\le \frac{1}{2t+2}\left(1+\sqrt{\frac{2t^2+5t+2}{t}}\right).$$
Letting $t = u^3$, it suffices to prove that, for all $u\in (0, 1]$,
$$\frac{1 + u}{u^3 + u}
\le \frac{1}{2u^3+2}\left(1+\sqrt{\frac{2u^6+5u^3+2}{u^3}}\right)$$
or
$$\frac{2u^4 + u^3 + u + 2}{u^3 + u} \le \sqrt{\frac{2u^6+5u^3+2}{u^3}}$$
or
$$\left(\frac{2u^4 + u^3 + u + 2}{u^3 + u}\right)^2
\le \frac{2u^6+5u^3+2}{u^3}$$
or
$$\frac{2(u^2 + u + 1)(u^2 - u + 1)(1 + u)^2(1 - u)^4}{u^3(u^2 + 1)^2} \ge 0$$
which is true.
We are done.
Reference.
[1] D. S. Mitrinovic, P. M. Vasic, "Analytic Inequalities," 1970.


what matters MTA's IP or hostname or both

Question: There is no proper single article or I haven't researched properly, to find what does matters most for MTA's reputation IP or the hostname of the MTA or both matters equally.
I am asking this question because I am facing a situation, where I am changing my hosting of prod servers, which require changing the public IPs of the platforms and MTAs, so for the updated IPs of platform, I need to inform clients through my whitelisting page, so that they can update their network for our IPs.
But for mail servers there's one more thing, that is the IPs should be warmed up to use it in production so that it can send emails in large numbers.
So, my question is, if I create new MTAs with the same existing hostnames but of course the IPs would be different, will it require warming or it is good to go live.
and whether the IP or hostname is warmed up or not, where does this affects? just only the public email providers like yahoo, google, outlook, etc. or does this affects the private MTAs of some clients too.
one more thing, I have seen many RBLs they just show reputation based on only IPs but the hostname, so is it, that only the IPs reputation matters, and that I would have to warm up my new MTAs with new IPs?
some clearance on this would be of great help thanks!
Answer: Basically SMTP require your hostname and IP being resolved properly and this requirement is checked during connect and HELO phase of any connection. Your hostname (which is delivered to other party via HELO) should have DNS A record with the address your MTA is connecting from. And this IP address should have PTR record leading to this hostname as well. Other party MTA will not trust your hostname if one of those checks have failed.
So the answer is yes - you can prepare DNS records and wait they distribute across internet and your MTA can go live.
Although, there are some other checks like SPF domain records which should allow your MTA sending e-mails from specified domain, this should be checked too.
As for RBL question - most of RBLs have their databases build about IP's, not domainnames or hostnames. The only thing you have to do here is to check new IP address history and you can use it immediately if the history is clean.
Comment: but whom does the warming of the IP affects, like public email providers
Comment: In common it will affect any server sending e-mails to your domain. Not every MTA in the world conform to standards in the same way so it is barely predictable which service will be affected. The standard says your DNS should be fine. Any MTA will reject sending mail to your new server if it is not fine. They will retry delivery when DNS records would be cleaned up. World MTA would re-request your DNS records after they expire and this time is set in TTL record of your DNS zone.


If $\frac{(z+w)^2}{zw}$ is real, then $z, w$ and the origin of the complex plane are either colinear or vertext of triangle

Question: I need to prove that if $\frac{(z+w)^2}{zw}$ is real, then $z, w$ and the origin of the complex plane are either colinear or vertex of an isosceles triangle.
I first tried some computations with the real part, like this:
$$Re\left(\frac{(z+w)^2}{zw}\right) = Re\left(\frac{z^ 2+2zw+w^2}{zw}\right) = \frac{z_1^2-z_2^2+2(z_1w_1-z_2w_2)+w_1^2-z_2^2}{z_1w_1-z_2w_2}$$
but them I remembered that I must set the imaginary part to $0$, because I'm not just intersted in the real part, I must also deal with the imaginary part neing $0$, so this is the equaiton:
$$\frac{z^2+2zw+w^2}{zw} = \frac{(z_1^2+2z_1z_2i-z_2^2)+2(z_1w_1+iz_1w_2+iz_2w_1-z_2w_2)+w_1^2+2w_1w_2-w_2^2}{z_1w_1+iz_1w_2+iz_2w_1-z_2w_2}=$$
$$\frac{z_1^2-z_2^2+2z_1w_1-2z_2w_2+w_1^2-w_2^2}{\cdots}+\cdots$$
Ok, I just realized that I'll also have to multiply by the conjugate below, and this will result in more squared terms. This is getting heavy, so I don't think this is the way to do it. Could somebody give me a help?
Comment: Hint: look at arguments, not real parts.
Answer: If $\frac{(z+w)^2}{zw}$, $z\ne 0$, $w\ne 0$, is a real number, then its imaginary part is zero.  Therefore, we are seeking a relationship between $z=\rho e^{i\phi}$ and $w=re^{i\theta}$ such that
$$\begin{align}
0&=\text{Im}\left(\frac{(z+w)^2}{zw} \right)\\\\
&=\text{Im}\left(\frac{z}{w}+2+\frac{w}{z} \right)\\\\
&=\text{Im}\left(\frac{\rho}{r}e^{i(\phi-\theta)}+2+\frac{r}{\rho}e^{-i(\phi-\theta)} \right)\\\\
&=\left(\frac{\rho}{r}-\frac{r}{\rho}\right)\sin(\phi-\theta)\tag 1
\end{align}$$
This is true if either $\rho =r$ or $\phi = \theta\pm n\pi$.
If $\rho =r$, then $0$, $z$, and $w$ form a triangle (unless $\phi =\theta \pm n\pi$ also).
If $\phi =\theta \pm n\pi$, then $0$, $z$, and $w$ lie on the same line.
Answer: I think the computation is easier in polar notation. Let $z=ae^{i\theta}, w=be^{i\phi}$, where $a,b>0$. Then $$\frac{(z+w)^2}{zw}=\frac{a}{b}e^{i(\theta-\phi)}+\frac{b}{a}e^{i(\phi-\theta)}+2$$ and we want the imaginary part of this to be zero, that is $$\sin(\theta-\phi)(\frac{a^2}{b^2}-1)=0.$$ From this you get either $a=b$ (so that $|z|=|w|$, i.e. isosceles triangle) or $\theta=\phi, \theta=\phi+\pi$ (so that $0,z,w$ are on a line).
Comment: How is this different from mine?  ;-))
Comment: I only realised there was another answer after I wrote it and sent it
Comment: No worry.  That has happened a number of times to me.


Numerical Analysis-Proof That Sum of Lagrange Interpolating Polynomials is One

Question: I am having trouble proving that given interpolation nodes $x_0, x_1, \ldots, x_n$ and function values $f_0, f_1, \ldots, f_n$ that $\sum\limits_{i=0}^n l_i(x) = 1$.
Our Lagrange interpolation formula is given by: $p_n(x) = \sum\limits_{i=0}^n f(x_i) l_i(x) $
I was able to find a proof online here: http://sepwww.stanford.edu/sep/sergey/128A/answers4.pdf
It is listed as problem number 1. However, this proof does not make sense to me because it assumes that we may set  $f_0, \ldots ,f_n = 1$. I would like to know how to prove that $\sum\limits_{i=0}^n l_i(x) = 1$ when we are given arbitrary $f_0, \ldots ,f_n$.
Answer: Note that the basis polynomials $l_i(x)$ depend only on the nodes and are therefore the same for any function values.
Also, the n-degree interpolating polynomial through n+1 points is unique, this is just "the Lagrange form" of that unique polynomial.
Apply the Lagrange interpolation formula to the polynomial $p(x)=1$


Proof of convergence of series

Question: How would you prove that the following series converges?
$$\sum_{k=1}^\infty \frac{3+k \sin (k^2)}{5^k}$$.
using the comparison test and relating to the geometric series
Answer: Hint
Use this inequality
$$\vert3+k\sin(k^2)\vert\le 3+k$$
and then prove by the ratio test that the series $\sum \frac{3+k}{5^k}$ is convergent and use comparison to conclude.
Comment: the ratio test is not allowed to be used in this question. Alternatively, the comparison test is asked to be used. Sorry for not making this clear
Answer: As already suggested in another answer, you have that $|3 + k \sin k^2| \le 3 + k$.
Notice that it can be proven by induction that $3 + k \le 2^k, \ k \ge 3$: for $k = 3$ it is true that $6 < 8$ and the jump from $k$ to $k+1$ is obtained by $3 + (k+1) = (3+k) + 1 < 2^k + 1 < 2^k + 2^k = 2^{k+1}$.
We can say then that
$$\left| \sum \limits _{k=1} ^\infty \frac {3 + k \sin k^2} {5^k} \right| \le \left| \frac {3 + \sin 1} 5 \right| + \left| \frac {3 + 2 \sin 4} {25} \right| + \sum \limits _{k=3} ^\infty \frac {2^k} {5^k}$$
and the last series is obviously convergent being a geometric series of ratio $\frac 2 5$.

Proof of convergence of series


Adding to bidirectional ManyToMany collection retrieves all entries already in relation

Question: I have User entity mapped by users in UserGroup entity
USER.java
@ManyToMany(mappedBy = "users")
private Set<UserGroup> userGroups;

public void addGroup(UserGroup userGroup){
this.userGroups.add(userGroup);
userGroup.addUser(this);
}

UserGroup.java
@ManyToMany
@JoinTable(name = "group_users", joinColumns = @JoinColumn(name = "group_id"),
        inverseJoinColumns = @JoinColumn(name = "user_id"))
private Set<User> users;

public void addUser(User user) {
   this.users.add(user);
}

I have a method to add Group to User in UserService:
@Transactional
public void addGroupsToUser(UserAddGroupsCommand userAddGroupsCommand, String username) {
    User user = userRepository.findByUsername(username);
    if (user != null) {
        List<UserGroup> userGroupList = userGroupRepository.findAllById(userAddGroupsCommand.getId());
        for (UserGroup userGroup : userGroupList) {
            user.addGroup(userGroup);
        }
        userRepository.save(user);
    }
}

The problem is that when I iterate through groups and add user to each group, for some reason Hibernate selects All users in that group (from join table).
Hibernate:
select
    users0_.group_id as group_id1_3_1_,
    users0_.user_id as user_id2_3_1_,
    user1_.id as id1_7_0_,
    user1_.email as email2_7_0_,
    user1_.firstname as firstnam3_7_0_,
    user1_.is_admin as is_admin4_7_0_,
    user1_.lastname as lastname5_7_0_,
    user1_.password as password6_7_0_,
    user1_.username as username7_7_0_
from
    group_users users0_
inner join
    user user1_
        on users0_.user_id=user1_.id
where
    users0_.group_id in (
        select
            usergroup0_.id
        from
            user_group usergroup0_
        where
            usergroup0_.id in (
                ? , ?
            )
    )

How to avoid that? Any option to do avoid this without writing own query, just with annotations and JPA Repository methods?
Answer: When adding group there are 2 selects:
for fetching groups in user calling user.getUserGroups().add(group)
select usergroups0_.user_id as user_id2_0_0_, usergroups0_.group_id as group_id1_0_0_, usergroup1_.id as id1_8_1_
from group_users usergroups0_
inner join UserGroup usergroup1_ on usergroups0_.group_id=usergroup1_.id
where usergroups0_.user_id=?

for fetching users in group calling group.addUser(user)
select users0_.group_id as group_id1_0_0_, users0_.user_id as user_id2_0_0_, user1_.id as id1_7_1_
from group_users users0_
inner join User user1_ on users0_.user_id=user1_.id
where users0_.group_id=?

users field needs to be initialized, either way you load it lazy or eagerly.
Comment: Yes, but why Hibernate selects all users from every group I want to add that user to. I mean why not just insert user_id group_id into join table group_users instead of selecting all entries from group_users that have no relation to the user I try to insert?
Comment: Because you are accessing it. Hibernate does not know what do you want to do with that collection. This is how it works. You can still do a native SQL insert to that table if you want. JPA is not good to use if you want to have full control over queries.
Comment: Understand now. But is Entity Graph solution for this?
Comment: No. If a fetch graph is used, only the attributes specified by the entity graph will be treated as FetchType.EAGER
Comment: Thank you, Peter. So what would be you suggestion on this? Should I write Query? As far as I know I can not insert entries into join table.
Comment: Peter. Sure I will. I just did not understand the part with group.addUser(user). I see that when I add user to group it fetch all users in that group. My user holds like 50+ groups which has 1000+ users each and every time it fetches all users from every group I add user to. Is it standard behavior that hibernate selects all data from join table when actually I just need to have one entry inserted? The reason I ask is that when I add multiple group to user I can see significant lag in execution and checking console show me that delay comes because hibernate selects all users from all groups.
Comment: Solution depends on use case. Create a new question for it. I can answer it there. Consider also marking as correct your previous questions. Stackoverflow is driven by this.


How can I add a DepdensOn attribute between CfnEndpoint and SecretTargetAttachment?

Question: I'm creating a database cluster and a DMS in the same stack. I'm using SecretsManager to pass the connection properties of the DB Cluster to the Endpoint. I've added a dependency between the endpoint and DB Cluster, but when I try to deploy the stack I get a problem like this:
11/14 | 10:08:49 AM | CREATE_COMPLETE      | AWS::RDS::DBCluster                         | FooDBCluster
 11/14 | 10:08:51 AM | CREATE_IN_PROGRESS   | AWS::DMS::Endpoint                          | fooendpoint
 11/14 | 10:08:51 AM | CREATE_IN_PROGRESS   | AWS::SecretsManager::SecretTargetAttachment | FooDBSecretAttachment (FooDBSecretAttachmentE2E5F50F)
 12/14 | 10:08:52 AM | CREATE_FAILED        | AWS::DMS::Endpoint                          | fooendpoint Could not find a value associated with JSONKey in SecretString

The same does not happen if I have complemented the deployment of the DB Cluster some time before starting to deploy the Endpoint. This implies the host & port are not present in the Secret right after the DB Cluster has been created. Indeed in CDK they are declared after the DB Cluster.
However, I cannot add a dependency between the Endpoint and SecretTargetAttachment as SecretTargetAttackment is not a CfnResource type expected by the CfnEndpoint addDependencyOn method.
Answer: You can add the dependency if you access the underlying node, like so.
if (secretsAttachment.node.defaultChild) {
      endPoint.node.addDependency(secretsAttachment.node.defaultChild);
}