How to interpret glm and ols with offset

Question: I ran a few glm and linear models with an offset. Each row in the dataset is a healthcare user. The data contains medical payments and icu days of each user between 2000 to 2007. As the number of years with institute contact differs between user (e.g. some came to the medical institute in 2001-2003 whereas there some who came on all years), I thought I should offset the number of years to account for "observation period". And it is common sense that the longer the years with contact the higher is the payment and icu days.
Gamma:
    Call:
    glm(formula = payment_amt ~ offset(log(years)) +
        as.factor(gender) + age,
        family = Gamma(link = "log"), data = pm, control = glm.control(maxit = 50))

    Deviance Residuals:
        Min       1Q   Median       3Q      Max
    -3.8787  -1.2142  -0.5339   0.1904  15.1442

    Coefficients:
                                       Estimate Std. Error z value Pr(>|z|)
    (Intercept)                       4.6718536  0.0134132   348.3   <2e-16 ***
    as.factor(gender)M 0.7800695  0.0024625   316.8   <2e-16 ***
    age           0.0642834  0.0001908   337.0   <2e-16 ***
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

    (Dispersion parameter for Gamma family taken to be 1.238685)

        Null deviance: 1520252  on 852449  degrees of freedom
    Residual deviance: 1251859  on 852447  degrees of freedom
    AIC: 20497443

    Number of Fisher Scoring iterations: 8

OLS:
    Call:
    lm(formula = payment_amt ~ offset(years) +
        as.factor(gender) + age,
        data = pm)

    Residuals:
        Min      1Q  Median      3Q     Max
    -170257  -53628  -23808   15835 8808825

    Coefficients:
                                        Estimate Std. Error t value Pr(>|t|)
    (Intercept)                       -206943.18    1425.83  -145.1   <2e-16 ***
    as.factor(gender)M   48794.00     261.77   186.4   <2e-16 ***
    age              3547.31      20.28   174.9   <2e-16 ***
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

    Residual standard error: 118300 on 852447 degrees of freedom
    Multiple R-squared:  0.07811,   Adjusted R-squared:  0.0781
    F-statistic: 3.611e+04 on 2 and 852447 DF,  p-value: < 2.2e-16

Poisson:

    Call:
    glm(formula = icu_days ~ offset(log(years)) + as.factor(gender) +
        age, family = poisson(link = "log"),
        data = pm)

    Deviance Residuals:
       Min      1Q  Median      3Q     Max
    -56.95  -15.11   -7.11    3.22  747.64

    Coefficients:
                                        Estimate Std. Error z value Pr(>|z|)
    (Intercept)                       -5.518e-01  9.058e-04  -609.2   <2e-16 ***
    as.factor(gender)M  6.357e-01  1.341e-04  4738.9   <2e-16 ***
    age            6.395e-02  1.246e-05  5130.9   <2e-16 ***
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

    (Dispersion parameter for poisson family taken to be 1)

Negative binomial:
    Call:
    glm.nb(formula = icu_days ~ offset(log(years)) +
    as.factor(gender) +
    age, data = pm, init.theta = 0.9279403178,
    link = log)
    Deviance Residuals:
    Deviance Residuals:
            Min       1Q   Median       3Q      Max
         -2.7720  -1.0788  -0.4652   0.1641  17.2095

        Coefficients:
                                        Estimate Std. Error z value Pr(>|z|)
        (Intercept)                       -1.0038131  0.0126237  -79.52   <2e-16 ***
        as.factor(gender)M  0.5977179  0.0023017  259.69   <2e-16 ***
        age            0.0708916  0.0001795  394.97   <2e-16 ***
        ---
        Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

        (Dispersion parameter for Negative Binomial(0.9279) family taken to be 1)

May I know how do i interpret the coefficients?
Answer: You show four models, one of them is strange (the one marked OLS) so I will first discuss the three others. What is common is that a response variable (amount of pay for the Gamma, a count of days for the others) is modeled as a function of covariates, but what is modeled is value pr year, that is:
$$ \DeclareMathOperator{\E}{\mathbb{E}}
   \frac{\E Y}{\text{years}} = \exp(\beta^T x) = \exp(\eta), \qquad \text{say}
$$
(as you are using a log link function).  Taking logarithms (natural) on both sides give:
$$
   \log \E Y - \log\text{years} = \eta
$$
and moving one term above over on the right hand side:
$$
  \log \E Y = \log\text{years} + \eta
$$
and that answers your question: the combination of a log link function, a non-negative response and offset of log of exposure means that you are modeling the ratio of total amount divided into exposure, that is, payment per year or number of days per year.  The interpretation of the other variables (linear parameters in the linear predictor $\eta$ should then be clear, it is interpreted as usual in regression models.
Please note that the exact choice of distribution family in the explanation above do not play any role!
Your fourth model do not make much sense to me, you can of course use a gaussian model for a non-negative response, that in itself is not a problem.  But, the use of identity link function together with offset of log exposure is meaningless, as far as I can see.  Let us try to mimic the logic above:
$$
   \frac{\E Y}{\text{years}} = \beta^T x = \eta, \qquad \text{say}
$$
Note we changed to identity link function.  But now taking logs doesn't work as above, that worked above only because we had a log link function.  So I would not try to interpret the parameters in your OLS model, they are meaningless.   But you could try a gaussian family, but with log link!  For a more extensive discussion of the arguments above, see Goodness of fit and which model to choose linear regression or Poisson
EDIT

To the additional question in comments:  So does that mean offset only works for log links?  No, but log link and rate modeling is the major use case.  Most posts on this site mentioning offset is this case.  A few posts discussing other uses:  Binary Models (Probit and Logit) with a Logarithmic Offset   , Using offset in binomial model to account for increased numbers of patients    , Offset in Logistic regression: what are the typical use cases?
Comment: That is correct, yes.
Comment: So does that mean offset only works for log links?
Comment: Probably not, there are other use cases, but log link is the main use
Comment: Thanks for the clear explanation. For gamma model, am I right to say that I can interpret the gender effect as 'Males are expected to have 2.18 times higher payment per year than females given that every else remain fixed.'? Similar interpretation applies for poisson and negative binomial?
Comment: Just a follow up question, you mentioned that the offset for OLS model does not make sense. So what is the correct way to operationalize offset in a linear regression model?
Answer: Your OLS model:
lm(formula = payment_amt ~ offset(years) +
    as.factor(gender) + age,
    data = pm)

Is the same as:
lm(formula = payment_amt - years ~ as.factor(gender) + age,
   data = pm)

With a log-link, you can use offsets to model rates because of how math works with logarithms, but for an identity link there's really no point to using an offset.


How to create a new column in dataframe A, based on multiple conditions in dataframe B

Question: I guess I don´t see the forest through the trees... Thus, I would like to ask for help.
Data: for dput() output see at the end of the question.

-Dataframe dfA with the columns: ID; ts. ts being POSIXct

-Dataframe dfB with the columns: ID; start; end; state_id. ID (corresponding to the ID in dfA), start (POSIXct), end (POSIXct), state_id.

The task:
I would like to create a new column in dfA with values 1/0 based on a condition. The condition in words: If the ID in dfA and dfB matches, and if the timestamp dfA$ts is in between or equal to dfB$start and dfB$end, then the value 1 should be written into dfA$x, otherwise a 0 should be there.
I think the code should look somewhat like this:

dfA$x <- iflese( dfA$ID == dfB$ID & dfA$ts >= dfB$start & dfA$ts <= dfB$end, 1, 0)

Thanks for the help already in advance.
dput(dfB):

structure(list(ID = c(1151L, 1151L, 1150L, 1150L, 1150L, 1150L,
1152L, 1152L, 1152L, 1345L), start = structure(c(1443142500,
1443144600, 1442934900, 1442942400, 1442944800, 1442946300, 1443103500,
1443132600, 1443137400, 1443389400), class = c("POSIXct", "POSIXt"
)), end = structure(c(1443143400, 1443145500, 1442935500, 1442943000,
1442945400, 1442950200, 1443106200, 1443134100, 1443140100, 1443392400
), class = c("POSIXct", "POSIXt")), state_id = c(1L, 2L, 1L,
2L, 3L, 4L, 1L, 2L, 3L, 1L)), row.names = c(NA, -10L), class = "data.frame")

dput(dfA):

structure(list(ID = c(1151L, 1151L, 1151L, 1151L, 1151L, 1151L,
1151L, 1151L, 1151L, 1151L, 1151L, 1151L, 1151L, 1151L, 1151L,
1151L, 1151L, 1151L, 1151L, 1151L, 1150L, 1150L, 1150L, 1150L,
1150L, 1150L, 1150L, 1150L, 1150L, 1150L, 1150L, 1150L, 1152L,
1152L, 1152L, 1152L, 1152L, 1152L, 1152L, 1152L, 1152L, 1152L,
1152L, 1152L, 1152L, 1152L, 1152L, 1152L, 1345L, 1345L, 1345L,
1345L, 1345L, 1345L, 1345L, 1345L, 1345L, 1345L), ts = structure(c(1443141300,
1443141600, 1443141900, 1443142200, 1443142500, 1443142800, 1443143100,
1443143400, 1443143700, 1443144000, 1443144300, 1443144600, 1443144900,
1443145200, 1443145500, 1443145800, 1443146100, 1443146400, 1443146700,
1443147000, 1442934900, 1442935200, 1442935500, 1442935800, 1442936100,
1442936400, 1442936700, 1442937000, 1442937300, 1442937600, 1442937900,
1442938200, 1443103500, 1443103800, 1443104100, 1443104400, 1443104700,
1443105000, 1443105300, 1443105600, 1443105900, 1443106200, 1443106500,
1443106800, 1443107100, 1443107400, 1443107700, 1443108000, 1443369300,
1443369600, 1443369900, 1443370200, 1443370500, 1443370800, 1443371100,
1443371400, 1443371700, 1443372000), class = c("POSIXct", "POSIXt"
))), row.names = c(NA, -58L), class = "data.frame")
Answer: You can use data.table, conditional replacement with :=:
data.table::setDT(dfA)
dfA[,value := 0L]
dfA[(get('ID') == dfB$ID) & (get('ts') >= dfB$start) & (get('ts') <= dfB$end), value := 1L]

Note that I put column names from dfA in a get call to avoid confusion with dfB columns.
In this situation dfA and dfB must have the same number of rows. If they don't, use a merge based on ID column
Comment: dfA and dfB don´t have the same number of rows. Merging by ID doesn´t solve the problem, as there is multiple rows in dfA as well as in dfB which would be merged. This means duplicate values in ID in dfA and dfB.
Answer: We can left_join dfA and dfB by 'ID', group_by each ID and ts and check if any value lies in the range for that group.
library(dplyr)

dfA %>%
  left_join(dfB, by = 'ID') %>%
  group_by(ID, ts) %>%
  summarise(x = +any(ts >= start & ts <= end))

#      ID ts                      x
#   <int> <dttm>              <int>
# 1  1150 2015-09-22 23:15:00     1
# 2  1150 2015-09-22 23:20:00     1
# 3  1150 2015-09-22 23:25:00     1
# 4  1150 2015-09-22 23:30:00     0
# 5  1150 2015-09-22 23:35:00     0
# 6  1150 2015-09-22 23:40:00     0
# 7  1150 2015-09-22 23:45:00     0
# 8  1150 2015-09-22 23:50:00     0
# 9  1150 2015-09-22 23:55:00     0
#10  1150 2015-09-23 00:00:00     0
# … with 48 more rows

Comment: Your solution is working for a small example dataset as the one I gave here. Yet, with the whole dataset I get the following error: Error: std::bad_alloc. . I think it must be due to the size of my data.frame. It was also the supposed issue for others with this error:  https://github.com/tidyverse/readxl/issues/150
Comment: @RasK I am not sure about that. It works for the data shared here so I cannot test it for other datasets.
Answer: This is an updating non-equi join:
library(data.table)

setDT(dfA); setDT(dfB)

dfA[dfB, match := 1, on=.(ID=ID, ts>=start, ts<=end)][, match:=ifelse(is.na(match), 0, match)]

      ID                  ts match
 1: 1151 2015-09-25 07:35:00     0
 2: 1151 2015-09-25 07:40:00     0
 3: 1151 2015-09-25 07:45:00     0
 4: 1151 2015-09-25 07:50:00     0
 5: 1151 2015-09-25 07:55:00     1
 6: 1151 2015-09-25 08:00:00     1
 7: 1151 2015-09-25 08:05:00     1
 8: 1151 2015-09-25 08:10:00     1
 9: 1151 2015-09-25 08:15:00     0
10: 1151 2015-09-25 08:20:00     0
...

Comment: Your solution works best as I am using large datasets. Also very fast (0.16 sec)...       Yet, a follow up question. If I would like to add the state_id column as well, I figured it should work through: dfA[dfB, state_ID := state_id, on=.(ID=ID, ts>=start, ts<=end)]     For the small example dataset it is working. For the real dataset I get the wrong numbers. Any ideas?
Comment: Maybe check again carefully. If you're 100% sure that the numbers are not matching correctly, then you'll have to provide a minimal dataset for me (or others) to test. I know your dataset is large, but perhaps subset the ids that are not working? Also, check for duplicates on ID + ts (dfA) and ID+start (dfB).


Can I use enter as an input?

Question: I am trying to allow the user to either enter a string or just hit enter, and in that case I would use a default string.
cout << "Where should I save the exam (default (./)exam.txt): " ;
cin >> exam_filename;

But right now you can enter a string and it works fine, but if you hit enter it just keeps waiting for the user to type something.  Any suggestions??
Okay so when I do this:
string exam_filename;
getline(cin, exam_filename);
if (exam_filename.empty())
  // set to default string

now it always sets the string to the default string.  It never gives me a chance to enter anything it just moves on the next part of the program autmoatically.
Answer: You really want to read a line. Just do it:
string exam_filename;
getline(cin, exam_filename);
if (exam_filename.empty())
  // set to default string

Comment: When I put in that code though it just skips over letting the user input.  Like it just moves on to the next part of the program and sets the filename to the default string no matter what?
Comment: @user1852078, Search on SO for "[c++] getline skipping". There are *tons* of hits.

Can I use enter as an input?


How to modify term reference field in Drupal 7 custom content type?

Question: I am using a term reference field in a content type in Drupal 7 which is a long hierarchical list of categories. In the input form, I want to show them as checkboxes and it gets displayed as a flat list of around 100 items and that of course is not user friendly at all. What hook do I use or where do I manipulate the code of the generated field so that I can display them in a hierarchical way and at the same time use some jQuery to show hide the sub categories. I guess I can intercept it in the theme preprocess and modify the field but I believe theres a better way?
Answer: Try the Taxonomy Term Reference Tree Widget.

This module provides an expandable tree widget for the Taxonomy Term Reference field in Drupal 7. This widget is intended to serve as a replacement for Drupal's core Taxonomy Term Reference widget, which is a flat list of radio buttons or checkboxes and not necessarily fit for medium to large taxonomy trees.

Sounds like it would be perfect for your needs, but if not it's fully themable and already has the jQuery functionality built in so would be a very good place to start.
Comment: This is exactly what I needed. Its not compatible with conditional fields but thats something that can easily be coded. Thanks a lot.


What does this Q-Q plot indicate about my data?

Question:
Q-Q plot of residuals for data set

Graph showing the relationship between length of dogwhelk shell and distance from the low tide mark, with linear regression line, 95% confidence interval lines and 0 gradient line (red).
Does the Q-Q plot mean that there are are less 'smaller dogwelks' than 'larger dog whelks',
Comment: I wish there were more information available.  could you use the "qqPlot" from the 'car' package in 'R'?  It puts confidence intervals for normality.  Can you tell me what your data is, what it is from, and what you are trying to use it to do?  Understanding the problem is really (really really) important before saying "data means x".  Also, you need more text in your question.  What did you think it meant or didn't?
Comment: The scatter plot of the original data is most helpful. One graph implies that the response is height; the other length of shell. Can you confirm that the graphs are for the same analysis? I am see a very weak relationship overall: considering whether model assumptions are satisfied for an unconvincing model is not worth much time. If the model is good, whether the residuals are normal is secondary; if it's poor, normality is immaterial. I see also a longer tail of smaller organisms, which may reflect a mixture situation, e.g. damaged shells??? immature organisms???
Comment: @NickCox Thank you for making the link to other post with my answer.
Comment: Our answers came before the regression plot with the dogwelk data added and a new question was added with it.  I think it should have been a separate post. @MrGD Did you add this?
Comment: Also it is confusing because the second qqplot is for data completely separate from the original plot given by the OP.
Answer: The shape of the plot is consistent with a left-skew, possibly bimodal distribution (with a small mode on the left).
It is possible that there are two groups with similar spread (such as a mixture of two normals with about the same standard deviation, the smaller subpopulation having a lower mean than the rest). This would suggest the possibility of a missing predictor -- which would correspond to the two groups).
However, the following discussion relies on the regression assumption that the conditional mean and spread of errors is zero and constant respectively, so that we can interpret the QQ plot of residuals as conveying information about the conditional distribution of errors. [Note that interpreting the marginal distribution of the residuals this way makes little sense if the residuals actually come from several different distributions. Other diagnostics - including those relating to other possible predictors - must be considered first]
Note that there's a "steep part" between the two less steep sections at the left and right, but either side of that steep part the slope is similar:

This suggests a reasonably normal-ish looking in the center and on the right and also in the left tail, but that there's a "gap" between with fewer points (in the ballpark of -1.3).
So the distribution is probably bimodal - (with the second peak being a pretty small bump on the left). You can get a similar appearance by generating data from a normal distribution and leaving out a substantial proportion of points in an interval near -1.3.
Like so:

This is ten sets of simulated data of (originally) 400 values each from a standard normal with points near -1.3 then having some chance of being omitted; resulting in on average 349 points with a somewhat bimodal appearance and whose qq plots typically having something like the appearance of your own -- with points at the left and at the center-and-right seeming to lay near roughly parallel lines, and in between a steeper section (indicating the lower density)
Comment: I am surprised at your characterization of the left tail: it looks consistent with a Normal distribution that has a comparable variance (as represented by the slope of the fitted line in the QQ plot) but a median that is substantially *less* (as represented by uniform drop). This shows up clearly in the OP's second plot, where we can see those low "stragglers" that appear to lie 10 units below where one might expect. One description is a mixture of two normals of equal variance--which could be explained with a homoscedastic model in which one binary explanatory variable has been omitted.
Comment: @whuber yes, that's a good point, though we have to beware reading too much into details of the plots since they show random variation in the tails even at the larger sample size - having generated more plots using different ways of reducing the density, at similar sample sizes to the original you sometimes see things that look very similar to the original plot and sometimes you don't. You sometimes see things like what you're saying about the upper tail and sometimes you don't. I'll try to make some edits soon. (Edit: I have now done so)
Comment: While you were working on this answer I was preparing mine and referencing your answer in an earlier post.
Comment: @whuber That shift can just be a natural consequence of the area with lower density. See my second plot, which shows that same sort of shift in the left side of the qq-plot - I created my second plot by generating 400 observations from a standard normal and then simply reducing the density in an interval around -1.3 (omit some points); we see a very similar "shift" in that far left tail. The lower density region alone is enough to push the rest of the line down. There may be no need to suppose that there's any additional effect beyond a region with lower density to see something like that.
Comment: @whuber There *might* be two groups with such a shift in median, of course, but we can see this sort of effect even when there isn't anything but a reduced density in a small interval. In part this is why there are caveats at the start of my post - we should only interpret this QQ plot of residuals in relation to the density of *errors* when the conditional mean and variance of residuals are consistent with the regression assumptions, because otherwise the density of residuals is not telling us about the density of errors. I may have to refine / expand on that to clarify this issue
Comment: Glen, your image differs importantly from the one in the question: its points at the left never return to the fitted line, whereas yours do.  Thus your description is appropriate for your example, but not for the one in the question.
Comment: @whuber That's mostly random variation. I have added a plot with 4000 points (rather than 400) generated the same way -- generate from a standard normal and omit some points in an interval ... there's no "return to the line". Again, I say there's no need to invoke two groups with a shift in mean. If the regression assumptions of independent errors with zero  conditional mean and constant conditional variance hold, then you can still see this sort of pattern simply by reducing the density in a small region.
Comment: Thank you -- that's interesting.  It shows that removing some points from the tail of a Gaussian can be very close to being the same thing as forming a mixture. The main distinction is that the point removal process retains a more extended upper tail than the mixture does--and this is now evident (although of small magnitude) in your QQ plot.  There is no hint of such behavior in the OP's plot. In a non-regression setting there would be little reason to choose between the two mechanisms, but it seems to me it might be difficult to explain how certain small *residuals* just disappeared.
Answer: There are many ways to formally or informally take a sample and check to see if it is approximately normal. The pp or qq plots are usually used as exploratory tools. If that is your intent I would not worry much about error bars. The graph should look like a straight line roughly for normality to be considered a reasonable model. From the circles on the plot, it looks like you have a reasonably large sample size.  It would help to tell us what that sample size is. Regarding your data you should at least believe that it behaves like a random sample from a population preferably continuous. Departures from the straight line at the extreme ends of the plot can indicate skewness (asymmetry) or kurtosis (heavy tails).
The eye test suggests that there is a big departure from normality in the lower tail. In the body and the right tail, the behavior appears to be close to what you would expect from a normal distribution.
You should check out the CV post How to interpret a qq plot. Glen_b has a nice answer with several plots and their interpretation. Also I like the University of Virginia Library article with the title How to interpret a qq plot that you can find it with a Google search under qq plot.


Maximum connections on pusher

Question: I'm trying to understand Pusher.
If I have maximum of 100 connections (Boostrap) does that means that one user can open 100 connections and other also 100. Or first user can open, let's say, 50 and second one also 50 connections, so third cannot open any?
Comment: possible duplicate of [How Pusher Connection is calculated?](http://stackoverflow.com/questions/18254062/how-pusher-connection-is-calculated)
Answer: Pusher uses a model of subscribing to channels within a connection. A single user would only need one connection, but could be subscribed to as many channels as you want on that connection.

Maximum connections on pusher


I'm having trouble grabbing an html input value using BeautifulSoup

Question: I need to grab the value of the attribute value inside this HTML element
<option value="1129070-040" data-size="US9.5" data-stock="In_Stock" data-morecomingsoon="true">

I can't seem to find a way in bs4 documentation
Comment: Can you provide the entire HTML or a link to a page?
Comment: Is the problem that you don't know how to find that specific element, or that you don't know how to access the `value` attribute?
Comment: I don't how to find a specific value of an attr
Comment: Once you have the element, it should just be `element['value']`.
Comment: @PeterSutton I want to find "1129070-035" in ``````
Comment: could you please provide what you have already done? example of your code or something.
Comment: Possible duplicate of [Extracting an attribute value with beautifulsoup](https://stackoverflow.com/questions/2612548/extracting-an-attribute-value-with-beautifulsoup)
Comment: @VladimirSemashkin
```product_page = requests.get('https://www.net-a-porter.com/de/en/product/1129070')
soup = BeautifulSoup (product_page.content, "lxml")
product_id = soup.find(here i need to find that value)```.
The value is inside this html element ``````
Answer: Based on what you included in your question you can get the value of the value attribute using this code:
from bs4 import BeautifulSoup

html = """<option value="1129070-040" data-size="US9.5" data-stock="In_Stock" data-morecomingsoon="true">"""
soup = BeautifulSoup(html,"lxml")
value = soup.find("option")["value"]

print(value)

hope this helps
Comment: almost @fozoro
 ```product_page = requests.get('https://www.net-a-porter.com/de/en/product/1129070')
soup = BeautifulSoup (product_page.content, "lxml")
product_id = soup.find(here i need to find that value)```

The value is inside this html element ``````
Comment: what if there's more ("option")["value"] in the webpage, how to find a specific one with exact elements that i gave you like data_size and, data_stock and data_morecomingsoon
Comment: hmmmm it seems that the website is rendered using Javascript. Which makes it nearly impossible to scrap using `requests`
Comment: not a problem i can use selenium, just wanna know how to find that specific value
Comment: do you want to get one or all of them?
Comment: let's say just one, with data_size="US7'' and data_stock="InStock"
Comment: in this case replace my `value` variable with `value = soup.find("option",{"data_size":"US7","data_stock"="InStock"})["value"]`
Comment: Thanks man! do you recommend using node,js/cheerio for a webpage that's rendered in js or stick with py/sb4 and use selenium? I wan parsing to be fast though.
Comment: never used node.js/cheerio I think selenium is a solid choice in your case though I can't really give any tips on it (I hardly ever use it myself). Thanks for accepting the answer, best of luck!


VueJS Router-View e Axios

Question: Eu tenho uma página com 2 estruturas usando router-view. Menu e Content. o no meu Menu eu tenho uma página chamada "Lojas", nessa página "Lojas" possui uma tabela, eu dou um Axios.Get na minha API e ela me retornar um JSON que joga pra tabela de "Lojas".
Problema: Se minha API tem um dado novo, eu tenho que recarregar a view.
Solução que gostaria: Quando eu clicar lá no menu no item "Lojas", eu queria que a view atual (no caso "Lojas") recarregasse para que o Axios desse o Get de novo e a Tabela trouxesse os dados atuais.
@EDIT
Lojas.vue
<template>

             {{item.Name}}

</template>

Menu.vue

      <router-link :to="{ name: 'lojas' }">Lojas</router-link>

routes.js
import lojas from './Lojas.vue'

const routes = [{
        path: '/Content',
        component: Content,
        children: [
            {
                name: "lojas",
                path: '/Lojas',
                component: lojas
            }
        ]
    }
]

Obrigado!
Answer: Usa um dos métodos que o vue-router implementa no componente, o beforeRouteEnter.
Esses hooks/ ganchos pré defenidos como o beforeRouteEnter são chamados antes da rota ser rederizada, e neste caso passanto uma função à callback next essa função é chamada quando o componente tiver sido instanciado e fica disponível dentro dessa função.
Nesse momento podes chamar os métodos da função.
Exemplo:
import axios from 'axios'
export default {
  data: () => ({
    dataItem: [],
    errors: []
  }),
  methods: {
    atualizarLoja() {
      axios.get(`http://localhost:8090/API/Lojas`)
        .then(response => {
          this.dataItem = response.data.Data
          $('#dataTable').DataTable(datatableConfigBR)
        })
        .catch(e => {
          this.errors.push(e)
        })
    }
  },
  beforeRouteEnter(to, from, next) {
    next(vm => vm.atualizarLoja())
  }
}

jsFiddle: http://jsfiddle.net/Sergio_fiddle/Ly4eaeyq/
Se queres forçar o update do componente estando já na view desse componente o router não te ajuda. Se não há navegação o router não faz nada.
Nesse caso a melhor possibilidade é criar um botão de update, ou mudar o botão de click no menu para um componente que chama o método.
Essa ultima ideia seria assim: http://jsfiddle.net/Sergio_fiddle/Ly4eaeyq/1/
Comment: Sergio, fiquei na duvida de como funciona esse codigo, poderia explicar? sempre aprendendo com você rs
Comment: @RafaelAugusto editei a rersposta com um exemplo. A minha resposta inicial seguia [uma resposta](https://forum.vuejs.org/t/vue-router-beforeenter-access-vue-apps-methods/4056/3) de um dos core-developers mas que não consegui implementar, acho que seria da versão `1.x`. Agora corrigi e dei um exemplo. Obrigado pelo pedido de explicações, assim corrigi a minha resposta :)
Comment: @Sergio entendi o que fez! mas caio no mesmo problema que o exemplo do Rafael, A chamada da Axios API está no **Lojas.vue**, e este Method de Click teria que ficar no meu **Menu.vue**. Como faço nesse problema? Obrigado!!
Comment: @Jackson esse método que atualiza a loja é chamado sempre que abres essa página. Não é isso que queres?
Comment: Sim, ele já funciona na propriedade Created(). Eu queria chamar de novo o method do axios quando eu clicar na página do menu. Como se fosse um Refresh da página. É como se eu estivesse no Lojas.vue, e fosse no Menu e clicasse no "Lojas" para trazer os dados. Hoje eu tenho que ir para outra view, e voltar para "Lojas" para o Axios dar o Get de novo
Comment: @Jackson ok. Editei a resposta. Dá uma olhada e testa o segundo jsFiddle
Comment: Entendi @Sergio! Obrigado pela ajuda. Foi bem claro =)
Answer: Você não precisa recarregar o view, basta ter um method e chama-lo sempre que clicar, ou mesmo, recarrega-lo em x minutos. Ex:

e ai em um link <button @click="api">Atualizar</button>
Ou mesmo em X tempo

Comment: Gostei muito da sua alternativa, mas o problema é que a chamada da Axios API está no **Lojas.vue**, e este Method de Click teria que ficar no meu **Menu.vue**.

VueJS Router-View e Axios


Branch Points of the function $z^{(1 + i)}$

Question: I don't seem to understand what branch points and branch cuts are. Can anyone tell me the concepts by finding the branch points and the branch cuts of the following funcition. $$z^{(1 + i)}$$
Comment: I would start with simpler functions, if you're trying to get the hang of branches (branch points/cuts) of analytic functions. Do you know about branches of $\sqrt z$? of $\log z$?
Comment: Yes, for these function, the modulus of the function doesn't depend on the argument of $z$. But in case of $z^{(i + 1)}$, it does. This is what is confusing me. Intuitively I think z = 0 is a branch point. But I am not able to prove it.
Comment: $|\log z|$ definitely does depend upon the argument of $z$, even if you've already fixed a branch. What is $|\log 1|$? What is $|\log i|$?
Comment: Oh! That clears the confusion I guess. So for $log z$ there is a change in magnitude on the change in argument. Thus one rotation in the $z$ plane containing the origin results in a different mapping to the $w$ plane, hence making in multiple valued ($f(z)$ maps $z$ to $w$). Thank you :D.
Comment: Indeed, that is a second reason that the magnitude changes. One fact about $\log z$ worth remembering is that the real part of $\log z$ is just $\log |z|$ (this is the usual logarithm of a real number), whlie the imaginary part of $\log z$ is the argument of $z$ (which, as you point out, is multivalued). In particular, the real part of $\log z$ doesn't depend on the argument of $z$ (nor the branch you choose), but the imaginary part and hence the magnitude definitely do (as well as on the branch you choose).
Answer: Take any $z,a\in\Bbb{C}.$ Then usually $z^a$ is defined as $e^{a\log z},$ where $\log z=\ln |z|+\arg z$ is the complex logarithm of $z.$ Therefore $$z^{1+i}=e^{(1+i)\ln|z|+(-1+i)\arg(z)}.$$ Obviously, once we travel along a closed path enclosing the origin in
the counterclockwise direction $$\arg(z)\to 2\pi+\arg(z).$$
Hence $z=0$ is a branch point of $z^{1+i}.$
Also changing the variable $z\to\dfrac1z,$ we can see that there is another branch point at $z=\infty.$
These are the only branch points of this function.
Comment: $z^a=\exp(z\log a)$?  How strange, I always thought it was  $z^a=\exp(a\log z)$.  I'd check that.
Comment: Oh. It is my mistake. Thank you for pointing out it.


ListBox items return string, when DataTemplate is Button

Question: I am creating a WP 8.1 Silverlight app.
I have an ObservableCollection of string names, that is set to the ItemsSource of a ListBox. Which are the names of buttons in the ListBox. I then want to extract the buttons from the ListBox, but the return value is of type string.
The xaml code is:
<ListBox x:Name="Game_ScrollViewer_online" Margin="41,104,128,6" SelectedValuePath="Current_game_button">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Button x:Name="Current_game_button" Content="{Binding}"
                    HorizontalAlignment="Center" Height="80" Margin="-14,6,-15,0"
                    VerticalAlignment="Top" Width="210" Template="{StaticResource Button_CurrentLayout1}"
                    RenderTransformOrigin="0.5,0.5" Foreground="#FFCBECCB" FontFamily="Times New Roman"
                    Click="LoadGame_online" FontSize="16">
            </Button>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

I then want to extract the button element:
for (int i = 0; i < Game_ScrollViewer_online.Items.Count; i++)
{
     var tempType = Game_ScrollViewer_online.Items[i].GetType();
     Button tempBut = (Game_ScrollViewer_online.Items[i] as Button);
     //Do stuff with button
}

But as said the return type is string.
Why is it not button ? And is there a way to access the button?
Answer: EDIT:
Game_ScrollViewer_online.ItemContainerGenerator.ContainerFromIndex(i) is dprecated, read here.
Use Game_ScrollViewer_online.ContainerFromIndex(i) instead, read here

You need FrameworkTemplate.FindName Method (String, FrameworkElement) for this purpose:
private childItem FindVisualChild<childItem>(DependencyObject obj)
where childItem : DependencyObject
{
        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
        {
            DependencyObject child = VisualTreeHelper.GetChild(obj, i);
            if (child != null && child is childItem)
                return (childItem)child;
            else
            {
                childItem childOfChild = FindVisualChild<childItem>(child);
                if (childOfChild != null)
                    return childOfChild;
            }
        }
        return null;
}

Then:
for (int i = 0; i < Game_ScrollViewer_online.Items.Count; i++)
{
     ListBoxItem GameListBoxItem = (ListBoxItem)(Game_ScrollViewer_online.ItemContainerGenerator.ContainerFromIndex(i));
     ContentPresenter contentPresenter = FindVisualChild<ContentPresenter>(GameListBoxItem);
     DataTemplate myDataTemplate = contentPresenter.ContentTemplate;
     Button tempBut = (Button) myDataTemplate.FindName("Current_game_button", contentPresenter);
     //Do stuff with button
}

To solve missing FindName use FindDescendant like this:
public T FindDescendant<T>(DependencyObject obj) where T : DependencyObject
{
    if (obj is T)
        return obj as T;

    int childrenCount = VisualTreeHelper.GetChildrenCount(obj);
    if (childrenCount < 1)
        return null;

    for (int i = 0; i < childrenCount; i++)
    {
        DependencyObject child = VisualTreeHelper.GetChild(obj, i);
        if (child is T)
            return child as T;
    }

    for (int i = 0; i < childrenCount; i++)
    {
        DependencyObject child = FindDescendant<T>(VisualTreeHelper.GetChild(obj, i));
        if (child != null && child is T)
            return child as T;
    }

    return null;
}

Comment: Awesome That works perfectly !. After extracting the listitem as you did and then just using `FindDescendant` it works. Update your answer and I'll mark it as solved :)


im getting correct time in the local system. but after uploading application in the server i'm getting incorrect datetime

Question: im getting incorrect time in the remote server.i'm getting the correct datetime in the local system.our server may be in other country, how to get correct datetime which is im getting in the local system.
Local application date time - 23/05/2018 06:40:20 PM
time after deploy in server - 23/05/2018 09:10:20 AM
timestamp - 2018-05-23T10:56:12.730Z
getting output
23/05/2018 09:10:20 AM

Expected Output
23/05/2018 06:40:20 PM

Code
string time = con.PayloadsUl.Timestamp.ToString();
onem2m.time = Convert.ToDateTime(time).ToString(string.Format("dd/MM/yyyy hh:mm:ss tt"));

data type
public class onem2m {
    public string dataFrame{ get; set; }
    public string time { get; set; }
}

Comment: Why do you expect an output that starts with `MM` when you are explicitly passing `dd` as the beginning of the format?
Comment: im least bother about the mm in the starting , im looking for correct time which im not getting
Answer: Something like this?
string time = con.PayloadsUl.Timestamp.ToString();
DateTime utcdate = DateTime.ParseExact(time, "M/dd/yyyy
                                           h:mm:ss tt",CultureInfo.InvariantCulture);

    var istdate = TimeZoneInfo.ConvertTimeFromUtc(utcdate,
    TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));

Comment: String was not recognized as a valid DateTime. my time value - 23/05/2018 12:20:57 +00:00
Answer: Try Using SimpleDateFormat class and
TimeZone.getTimeZone("IST")

Comment: @Camilo Seems to be a java answer to a C# question :-(
Comment: @john I imagined, but I don't know enough Java to point that out
Comment: Even if this were Java, use of the `SimpleDateFormat` class is strongly discouraged, that class is long outdated and notoriously troublesome. And you should never rely on a three letter time zone abbreviation like IST. You cannot know whether Java gives you Irish Summer Time, Israel Standard Time or India Standard Time.
Comment: What `SimpleDateFormat`/`TimeZone` class? That does not exist on the .NET Framework.


Proof that if $R_{1};R_{2}=R_{2};R_{1}$ is a relation on a set $S$, then $R_{1}$ and $R_{2}$ are bijective maps

Question: For the surjectivity part, I believe I have managed to prove the claim. And for Injectivity, I've tried to show that if $aR_{1};R_{2}c$ and $bR_{2};R_{1}c$, then $a=b$ but I am not entirely sure what $a=b$ means in this context. Do I have to show that there is an equivalence relation containing (a,b)?
Comment: Yes, I believe they want me to prove that if $f \circ g=g \circ f $ then $f$ and $g$ are bijective but from a more general point of view namely the functions as relations.
Comment: What do your assumptions men? (the part after "if" in the title)
Comment: It denotes a composition of two relations $R_{1}$ and $R_{2}$
Comment: So each semicolon ; means composition? [Usual notation for that is a circle like $R_1 \circ R_2$]
Comment: Sei-- why did you already ask this (see reference to "exact duplicate) and then post the question again?
Answer: Something is missing in the question. Take $S=\{a,b\}$ and take $R_1$ and $R_2$ to be the relations defined by the function $f:x\mapsto a$.
Then, $R_1;R_2=f\circ f=R_2;R_1$, but $f$ is not injective nor surjective.
Comment: Well, it makes all the difference, on the contrary.
Comment: I believe it makes no difference but the exact wording of the question was "Suppose $R_{1}$ and $R_{2}$ are relations on a set S with $R_{1};R_{2} = I $ and $R_{2};R_{1} = I$.
Prove that both $R_{1}$ and $R_{2}$ are bijective maps"
Comment: Hint: first prove injectivity of $R_1$: if $xR_1z$ and $yR_1z$, let $w$ be such that $zR_2w$. Then $xR_1;R_2w$ and $yR_1;R_2w$, but $R_1:R_2=1$, so $x=w=y$. Similarly, $R_2$ is injective. Now, prove that $R_1$ and $R_2$ are actually applications and finally that they are surjective.
Comment: what do you mean by $R_{1}: R_{2}=1$? Is $:$ different from $;$? and how is it equal to 1?
Comment: This is a typo. : is ; and 1 is $I$.
Comment: I still don't see how that implies $x=w=y$


How Download Github Repo Filled with CSV Files on Github using Python?

Question: I'm trying to do some exploratory data analysis on the data that is provided by CSSE at Johns Hopkins University. They have it on Github at this link https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_daily_reports
I'm trying to download the entire file using python that will save it to my current directory. That way I'll have all the up to date, data and can reload it to use. I'm using two functions fetch_covid_daily_data() that will go to the website and download all the CSV files. Then ill have a load_covid_daily_data() that will go in the current repo and read the data so I can process it with pandas.
I'm doing this way because if I go back to my code I can call the function fetch_covid_daily_data() and it will download all the new changes made such as another daily CSV added.
Answer: You can read data directly from online CSV to Pandas DataFrame:
Examples:
import pandas as pd

CONFIRMED_URL = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv'

df = pd.read_csv(CONFIRMED_URL)

# df now contains data from time of call.

You can also create a class to get and manipulate all data

import pandas as pd

class Corona:

    def __init__(self):

        BASE_URL = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series'

        self.URLS = {'confirmed': f'{BASE_URL}/time_series_covid19_confirmed_global.csv',
                'deaths': f'{BASE_URL}/time_series_covid19_deaths_global.csv',
                'recovered':f'{BASE_URL}/time_series_covid19_recovered_global.csv',
        }

        self.data = {case:pd.read_csv(url) for case, url in self.URLS.items()}

    # create other useful functions to work with data
    def current_status(self):
        # function to show current status
        pass

To get current data:
# returns data as dictionary with DataFrames as Values
corona = Corona()
confirmed_df = corona.data['confirmed']

# If you want to save them to csv
confirmed_df.to_csv('confirmed.csv', index=False)

# show first five rows
print(corona_df.head())

# check other DataFrame
print(corona.data.keys())

Comment: Hi yes, I have done your first example multiple times but my problem is that I want to collect all those csv in the daily reports and join them together myself. I want to know if theres an easy way to do this in case I come across data that's in multiple csv files and ill need to join them. Im trying to do this on google colab so I don't want to download the data
Comment: I also love your idea of using a class!
Comment: You can easily do that too. What I love about classes is that they help organise your code. To answer your multiple csv, if there is a pattern in csv names, you can still use the class above with list comprehension to get all csvs and the merge/concat/join then to one. I am happy to help if you provide a sample url if csvs and what you will like to do. See https://stackoverflow.com/questions/20906474/import-multiple-csv-files-into-pandas-and-concatenate-into-one-dataframe
Answer: Assuming you have git installed, you need to clone the repository from your terminal
git clone https://github.com/CSSEGISandData/COVID-19

hope this helps!


Wondering what this bean plot analysis chart means

Question: How does one interpret and generate bean plot charts. Here is one example taken from Walkes et al. 2010.  What kind of data is it most useful for?

(source: biomedcentral.com)
Comment: "A beanplot is an alternative to the boxplot for visual
comparison of univariate data between groups. In a beanplot, the individual observations are shown as small lines in a one-dimensional scatter plot. Next to that, the estimated
density of the distributions is visible and the average is shown." Extract taken from [here](http://www.jstatsoft.org/v28/c01/paper).
Comment: For those who don't know: this is a near relative of violin plot (vioplot).
Answer: Boxplots were really designed for normal data, or at least unimodal data. The Beanplot shows you the actual density curve, which is more informative.
The shape is the density, and the short horizontal lines represent each data point. This combines the best of a boxplot, density plot, and rug plot all in one and is very readable.
Unfortunately, the example that you've chosen decided to add a bunch of longer lines which clutter the graph beyond recognition (for me). [snip]
EDIT: Having now worked with beanplot a bit more, the longer thick lines are the mean (or optionally median) for each bean. The longer thin lines are the data, with a sort of "stacking" where wider lines indicate more duplicate values. (You can also jitter them, which I prefer, but at least the "normal" category already has a fair density of points that jittering might make worse.)
I still think the example you chose is a rather cluttered, which could perhaps be cleared up by using jittering instead of stacking.
The paper that describes the R package for making bean plots is a nice read.
Comment: +1 - reading the bean plot article now. I would also suggest a working paper by Hadley Wickham, [40 years of boxplots](http://vita.had.co.nz/papers/boxplots.pdf). It goes through a description of a variety of plots with more of less the same goals as bean plots.
Answer: Without having read the whole paper, it appears to be essentially a variant of the boxplot.  As such, you could use it where you would have otherwise used a boxplot, such as comparing the univariate distributions of several groups.  It displays a line for each point and overlays a kernel density estimate.  From looking at it, I would think it might be more informative with small amounts of data, but be too cluttered with more data.  It doesn't seem very Earth-shaking to me, at first blush.  If you want to know something more, elaborate your question.


trying to pull from multiple tables and displaying the different information

Question: So I have been searching and doing trial and error for several days now, and Im turning to here for help.
I have created a page on my website that pulls a schedule information from a table on a database and displays it to the webpage. I am trying to pull a color scheme from a second table in the same DB, when the name on the first table matches the name on the second table, only that name will be displayed in the different color assigned to it. MY tables look as follows:
TBL1:
id    time    timeframe   Mon     Tues    Wed     Thur    Fri     Sat     Sun
1      12a     00:00:00   Name1   Name2   Name3   Name2   Name5   Name6   Name7
2      1a      01:00:00   Name1   Name2   Name3   Name2   Name5   Name4   Name3
3      2a      02:00:00   Name1   Name2   Name4   Name2   Name2   Name6   Name2
4      3a      03:00:00   Name2   Name2   Name4   Name2   Name3   Name3   Name2
ect
TBL2:
id    Name    Color
1     Name1   #hexcolor
2     Name2   #hexcolor2
3     Name3   #hexcolor3
ect
    $query = array('select' => "*",
               'tbl' => "Schedule");
$query2 = array('select' => "name, color",
               'tbl' => "dj_colors");

$name = "select t1.*, Monday.color, Tuesday.color, Wednesday.color, Thursday.color, Friday.color, Saturday.color, Sunday.color

FROM Schedule t1
     JOIN dj_colors Monday
     ON t1.Monday = Monday.name,
     JOIN dj_colors Tuesday
     ON t1.Tuesday = Tuesday.name,
     JOIN dj_colors Wednesday
     ON t1.Wednesday = Wednesday.name,
     JOIN dj_colors Thursday
     ON t1.Thursday = Thursday.name,
     JOIN dj_colors Friday
     ON t1.Friday = Friday.name,
     JOIN dj_colors Saturday
     ON t1.Saturday = Saturday.name,
     JOIN dj_colors Sunday
     ON t1.Sunday = Sunday.name";
$DB = new DB();
$result = $DB->select_multi($query);

foreach ($result as $arrayLoop) {
    $printout .= "
";
    foreach ($arrayLoop as $field => $data) {
        if ($field == 'id' || $field == 'TimeFrame') continue;
        if ($data === $name) $printout .= "".$data."	";
        else $printout .= "".$data."	";
    }
    $printout .= "
";
}

EDIT* This is what I've come up with and trying, but I think I am still missing something as its still not working like I want it to. I went a head and gave the names of the actual tables that I'm using in proper format. Still not pulling colors, but I'm not getting any errors. Please bear with me, I am still learning. I'm not asking for the answer, just where to look and some helpful tips.
Comment: why dont you fetch the data in one result joining tables?
Answer: I think you need to learn about joins.  You can return the colors in the same query as the names, by joining them in:
select t1.*, mon.color, tue.color, . . . sun.color
from table1 t1 join
     table2 mon
     on t1.name = mon.name join
     tale2 tue
     on t1.tue = tue.name
     . . .
     table2 sun
     on t1.sun = sun.name

The expression:
SELECT color FROM tbl2 WHERE name

Will probably return no rows.  With no comparison, name will be converted to an int, based on the initial digits at the front.  If it starts with an alpha character, it will be transformed to 0, which is false, so no rows are returned.
Comment: I told you it was probably something basic. I'm teaching myself php at the same time of writing code. Off to learn the join functions. Thank you very much.
Comment: @Chad . . . I don't see a from clause in your revised question.
Comment: I fixed the format to show all the code, I wasnt paying attention yesterday when editing my post.
Comment: @Chad . . . I think you want to give the different colors different aliases:  `Monday.color as MondayColor, Tuesday.color as TuesdayColor, . . . `.  MySQL likes for columns to have different names.
Comment: The days are not supposed to be in colors, only the names for the staff member. Like, I have a staffer that works Monday 1a-3a and Thursday 4p-7p. I want his name to show up in a specific color, regardless of where he actually is in the schedule.


How Do You Show That There Exist Infinitely Many Organic Tautologies?

Question: This question takes inspiration from this question.
A tautology is organic if none of it's proper sub-formulas are tautologies.  In other words, if all of the sub-formulas excluding the formula itself are not tautologies.
For example, C C p q C C q r C p r is organic, but C p C q C r q is not, since C q C r q is a tautology.
I suspect that there exist infinitely many organic tautologies which are not substitution instances of other tautologies.  How might that get proved?
Comment: @PyRulez Polish notation.  http://plato.stanford.edu/entries/lukasiewicz/polish-notation.html
Comment: What notation are you using? I don't recognize it.
Answer: Can't you just expand your first formula by adding more variables? For instance
$$ (a\to(b\to c))\to((a\to d)\to((b\to d)\to(c\to d)) $$
or CCaCbcCCadCCbdCcd in Polish notation, should be an organic tautology if I'm not wrong.
Comment: @DougSpoonwood: I'm not sure I really know what a "substitution instance" is, but is $$ (a\to(b\to c))\to((a\wedge b)\to c)$$ allowed?
Comment: You're right that this would work for what I asked.  I've edited the question to preclude using such substitution instances.
Comment: CCaCbcCCadCCbdCcd is not a tautology.  Let a = 0, b = 0, c = 1, and d= 0.  Then CaCbc = 1.  But, CCadCCbdCcd = CC00CC00C10 = CC00CC000 = CC00C10= CC000= C10 = 0.  A substitution instance **I** of a tautology **T** is simply a wff that we can obtain from **T** by substitution alone (*uniform* replacement of variables by formulas throughout the formula).  Your example is incorrect, but your idea works!  You just prefix the conditionals instead of what you did.  More like C CaCpq C CaCqr CaCpr, C CbCaCpq C CbCaCqr CbCaCpr, C CcCbCaCpq C CcCbCaCqr CcCbCaCpr...
Comment: The pattern there goes that you have Ca...CoCpq as the antecedent, Ca...CoCqr as the antecedent of the consequent, and Ca...CoCpr as the consequent of the consequent.  Since the consequent of the consequent has form Ca...CoCpr, we could assume Ca...CoCpq and Ca...CoCqr, and all variables in a ... p.  Then we have q, and finally r following.  Discharging all assumptions yields the formula as a tautology.  It's not organic, since the antecedent is not a tautology (nor does it contain any) and neither is the consequent of the consequent, nor the antecedent of the consequent.
Comment: And the consequent itself is not a tautology either, so none of the sub-formulas are tautologies, rendering all tautologies of this form organic.
Comment: Oh and extended forms of importation and exportation like you've suggested with your last comment should work also.


Change a single value in R?

Question: I would like to change the "finals" to the number 4. I have tried indexing df[4, "round"] = 4, but that hasn't worked.  I have also tried df[4, 2] = 4 but that hasn't worked either.  A tidyverse solution would be great if possible.  Any help is appreciated.
Some reproducible code:
rating <- c(1000, 900, 945, 990, 952)
round <- c(1, 2, 3, "finals", 1)

df <- data.frame(rating, round)

Comment: It is working fine for me.  Can you show the `str(df)`  Is it a `factor` or `character` class?  From `R 4.0`, `stringsAsFactors = FALSE` is by default when you create the data.frame
Comment: If it is a `factor`, then convert to `character` before doing the assignment i.e. `df$round <- as.character(df$round)`
Answer: Like this?
rating <- c(1000, 900, 945, 990, 952)
round <- c(1, 2, 3, "finals", 1)

df <- data.frame(rating, round)
df$round[4] <- 4
df$round <- as.numeric(df$round)

df
#>  rating round
#>1   1000     1
#>2    900     2
#>3    945     3
#>4    990     4
#>5    952     1

Answer: This could be an issue based on the class of the column i.e. a factor class instead of character.  From the R 4.0, the default option stringsAsFactors = TRUE is changed to FALSE in data.frame.  Thus, if the OP is using an older R version, the column could change to factor.  It can be reproduced with
df <- data.frame(rating, round, stringsAsFactors = TRUE)

in R 4.0.3
Now, if we do
df[4, "round"] = 4

returns a warning and it gets converted to NA

Warning message:
In [<-.factor(*tmp*, 4, value = c(1L, 2L, 3L, NA, 1L)) :
invalid factor level, NA generated

This can be corrected by first converting the column to character class
df$round <- as.character(df$round)

and then using the OP's code

Or as the OP mentioned about tidyverse, we can directly recode with fct_recode on the factor/character column and then change the type (if needed)
library(dplyr)
library(forcats)
df1 <- df %>%
    mutate(round = fct_recode(round, '4' = 'finals')) %>%
    type.convert(as.is = TRUE)

-output
df1
#  rating round
#1   1000     1
#2    900     2
#3    945     3
#4    990     4
#5    952     1

Change a single value in R?


How to show the image of $h : (0, 1) \rightarrow \mathbb{R}$ defined by $h(x) = 1/(x^2 + 8x)$ is equal to $(1/9, \infty)?$

Question:
How to show the image of $h : (0, 1) \rightarrow \mathbb{R}$ defined
  by $h(x) = 1/(x^2 + 8x)$ is equal to $(1/9, \infty)?$

Hi, I want to show that the image of $h : (0, 1) \rightarrow \mathbb{R}$ defined by $h(x) = 1/(x^2 + 8x)$ is equal to $(1/9, \infty)$. Is there a quick way to do this? Maybe one can first prove that $h$ is injective on this domain, or that it's strictly decreasing. I don't know what the best way is.
Comment: The fast way is probably: $h(x)$ is strictly decreasing; $h(x)$ is continuous; $h(1) = \frac19$; and $h(x)$ tends to infinity as $x$ tends to zero. Each of these facts individually (assuming you have the mechanism of continuous functions set up) should be easy to prove.
Answer: $\frac{1}{x}$ is convex on $\mathbb{R}^+$, hence $\frac{1}{x}-\frac{1}{x+8}$ is positive and decreasing on $\mathbb{R}^+$.
It follows that the range of $h$ over $(0,1)$ is just $\left(\lim_{x\to 1^-}h(x),\lim_{x\to 0^+}h(x)\right)$.
Comment: Hi, could you please help me figure out how to prove the image using element-chasing technique? (e.g. choose an arbitrary $y$ from the image of $h$ and show that it is in the set $S = \{x \mid 1/9 < x < \infty\}$. Then do the same for the other direction so we can conlude the image equals $S$. I've been trying this for 2h, but cannot progress.
Answer: Since for $x\in (0,1)$ we have $$0<x^2+8x<9\implies {1\over x^2+8x}>{1\over 9}$$
Since $h$ is continuous and $\displaystyle \lim _{x\to 0}h(x)=\infty$ and $\displaystyle \lim _{x\to 1}h(x)={1\over 9}$ we have the range $({1\over 9},\infty)$
Comment: Hi, could you please help me figure out how to prove the image using element-chasing technique? (e.g. choose an arbitrary $y$ from the image of $h$ and show that it is in the set $S = \{x \mid 1/9 < x < \infty\}$. Then do the same for the other direction so we can conlude the image equals $S$. I've been trying this for 2h, but cannot progress.


Model to be used with only median data and weights

Question: I am finding a decent method to demonstrate if there is trend in the median age at diagnosis of multiple cancers. I do not have a breakdown of individual ages though, all I have is only (1) Median age at diagnosis by year, (2) Number of Cases and Population by year. (One of the cancer sites as below)

What statistics methodology I can use to prove or disprove the trend of median age? Thanks.
Answer: First off, you can neither prove nor disprove anything in statistics.
Second, because you have median data, you can use quantile regression to model the median age of diagnosis as a function of time using the number of patients in each year diagnosed as a weight.  Here is an R script to do so
library(quantreg)

year = 2009:2017 - 2009
age = c(53,53,54,54,54,55,56,56,57)
w = c(2945,3014, 3419, 2508, 3524, 3868, 3900, 4108, 4373)

d=data.frame(year=year, age=age, w=w)

model = rq(age ~ year, data = d, weights = w)
summary(model)

This yeilds
Call: rq(formula = age ~ year, data = d, weights = w)

tau: [1] 0.5

Coefficients:
            coefficients lower bd upper bd
(Intercept) 52.50000     51.70021 53.10151
year         0.50000      0.39485  0.595

There definitely appears to be an increase in the age of diagnosis.  quantreg spits out lower bd and upper bd.  The documentation for quantreg says that lower bd and upper bd are confidence intervals.  Thus, it appears that the data are consistent with a non-zero effect of year, so I think you can confidently say that every two years, the median age of diagnosis increases by a year.
Comment: Thank you for your advice. How can we vigorously show that using median in the first hand does not affect the model fitting (or else, how does it affect the model and how can we justify that it is not problematic for the fit)?
Comment: @AaronLei Quantreg models the median of the data as opposed to the mean. You don't have to worry about using the median since we are using tools which deal with the median.
Answer: For something like this, I would probably ignore the changes in Cases and Population, and just use a robust or nonparametric method to determine if there is a slope of Age over Year, and to estimate that slope.  It's simple and easy for the audience to interpret.  It's probably also not worth it to try something more complex like auto-regressive time series.
One method is Sen's slope, which is nonparametric, and is often used in time series data. Another nonparametric test of trend is Mann-Kendall.  Alternately, you could use something like correlation or robust regression.
In the following R code, for the function I used for Sen's slope, the data are first transformed into a time series object.  But this isn't necessary for some other functions that calculate Sen's slope.
Note that the output gives you Sen's slope (0.5), a p value (0.001), and a 95% confidence interval for the slope.
if(!require(trend)){install.packages("trend")}

Data = read.table(header=TRUE, text="
Year Age Cases Population
2009  53  2945 3.69
2010  53  3014 3.73
2011  54  3419 3.82
2012  54  3508 3.85
2013  54  3524 3.85
2014  55  3524 3.89
2015  56  3868 3.93
2016  56  4108 3.96
2017  57  4373 4.00
")

TS = ts(Data$Age, frequency=1, start=2009)

library(trend)
sens.slope(TS)

   ### z = 3.2287, n = 9, p-value = 0.001243
   ### 95 percent confidence interval:
   ###  0.3333333 0.6666667
   ### sample estimates:
   ### Sen's slope
   ###         0.5

You may not want to be too quick though, in reaching conclusions for this relationship.  For example, it is also the case that the incidence of cancer (Prop below, cases per 1000) increases over Year.  I don't know what to make of this.  Perhaps we are testing older people more over time, and so also are finding more incidents of cancer?
Data$Prop = round(Data$Cases / Data$Population / 1000, 3)

Data

   ###   Year Age Cases Population  Prop
   ### 1 2009  53  2945       3.69 0.798
   ### 2 2010  53  3014       3.73 0.808
   ### 3 2011  54  3419       3.82 0.895
   ### 4 2012  54  3508       3.85 0.911
   ### 5 2013  54  3524       3.85 0.915
   ### 6 2014  55  3524       3.89 0.906
   ### 7 2015  56  3868       3.93 0.984
   ### 8 2016  56  4108       3.96 1.037
   ### 9 2017  57  4373       4.00 1.093

cor.test(~ Age + Prop, data=Data)

   ### Pearson's product-moment correlation
   ### t = 9.1506, df = 7, p-value = 3.829e-05
   ###       cor
   ### 0.961

As to the concern you raised in the answer by Demetri Pananos, I think the reality is that you can only work with the data you have.  If you have the median age, you can only report what you can determine about the median age.  You can't know if using the median was the best way to summarize the raw data.


Which fundamental problem is solved by application of panel data methodology?

Question: I know that the panel data accounts for both heterogeneity across individuals or groups for dynamic effects that are not visible in cross sections, but should this be the answer to this question?
Answer: The main feature would be dealing with some types of heterogeneity/omitted variable problems. Dynamic adjustment is another. There are at least two more:

Since panel data have variation across units and across time, so
more efficient estimation is possible, at least sometimes. There's
also more variability, less collinearity, and more degrees of
freedom.
Some problems can only be dealt with in a panel setting. Consider the problem of distinguishing between returns to scale (compare costs of firms of different size) from that of technological change.
Comment: Yes, I had a feeling about the endogeneity problem as well.


Proving that an orthonormal system close to a basis is also a basis

Question: Let $\mathcal{H}$ be a Hilbert space and $(e_n)_{n \in \mathbb{N}} \subseteq\mathcal{H}$ be an orthonormal basis and $f_n$ be an orthonormal system such that
$(f_n)_{n \in \mathbb{N}} \subseteq\mathcal{H}$ and $$\sum_{n \in \mathbb{N}}\|e_n-f_n\|^2 <1.$$ Prove that $f_n$ is also a basis.
I am kind of stuck and can't figure out how to prove that $(f_n)_{n \in \mathbb{N}}$ is a basis.
I tried to prove by contradiction that if $(f_n)_{n \in \mathbb{N}}$ is not  a basis then $\exists   x \neq0 \in \mathcal{H}$ such that $\langle x,f_n \rangle=0 \forall n \in \mathbb{N}$.
I also know that $\|e_n-f_n\|^2 \to 0 \implies Re(\langle e_n,f_n \rangle) \to 1$
I then tried to write $x=\sum_{n=1}^{\infty} \langle x,e_n \rangle e_n$ from which I get that
$\sum_{k=1}^{\infty} \overline{ \langle x,e_k \rangle} \langle e_k,f_n \rangle \forall n \in \mathbb{N}$
But I do not know how to proceed. Any hints would be highly appreciated
Answer: Let $x \in \mathcal{H}$ with $\lVert x\rVert = 1$. Show that $x$ cannot be in the orthogonal complement of $\operatorname{span} \{ f_n : n \in \mathbb{N}\}$.
Since $\{ e_n : n \in \mathbb{N}\}$ is a Hilbert basis of $\mathcal{H}$, we can write
$$x = \sum_{n = 0}^\infty c_n\cdot e_n.$$
Consider now
$$y = \sum_{n = 0}^\infty c_n \cdot f_n.$$
Then we have
$$\lVert x-y\rVert^2 \leqslant \Biggl(\sum_{n = 0}^\infty \lvert c_n\rvert\cdot \lVert e_n - f_n\rVert\Biggr)^2 \leqslant \sum_{n = 0}^\infty \lvert c_n\rvert^2\cdot \sum_{n = 0}^\infty \lVert e_n - f_n\rVert^2 < 1.$$
It follows that
$$\left\lVert x - \sum_{n = 0}^\infty \langle x,f_n\rangle f_n\right\rVert^2 \leqslant \lVert x-y\rVert^2 < 1 = \lVert x\rVert^2,$$
so some $\langle x, f_n\rangle$ must be nonzero.

In fact, we have something much stronger: It already follows that $(f_n)_{n \in \mathbb{N}}$ is also an orthonormal basis when
$$\sum_{n\in \mathbb{N}} \lVert e_n - f_n\rVert^2 < +\infty.\tag{1}$$
Proof: Choose $\varepsilon \in (0,1)$. By $(1)$, there is an $N \in \mathbb{N}$ such that
$$\sum_{n \geqslant N} \lVert e_n - f_n\rVert^2 < \varepsilon^2.$$
Let $E = \overline{\operatorname{span} \{ e_n : n \geqslant N\}}$ and $F = \overline{\operatorname{span} \{ f_n : n \geqslant N\}}$. Define
\begin{gather}
A \colon E^{\perp} \to F^{\perp},\quad x \mapsto x - P_F x,\\
B \colon F^{\perp} \to E^{\perp},\quad x \mapsto x - P_E x,
\end{gather}
where $P_E,\,P_F$ are the orthogonal projections to $E$ resp. $F$.
By $(1)$, we have
$$\lVert P_F x\rVert^2 = \Biggl\lVert \sum_{n \geqslant N} \langle x,f_n\rangle f_n\Biggr\rVert^2 = \sum_{n\geqslant N} \lvert \langle x, f_n\rangle\rvert^2 = \sum_{n\geqslant N} \lvert \langle x, f_n - e_n\rangle\rvert^2 \leqslant \lVert x\rVert^2\sum_{n\geqslant N} \lVert f_n - e_n\rVert^2 < \varepsilon^2\lVert x\rVert^2$$
for all $x \in E^{\perp}$, and similarly
$$\lVert P_E x\rVert^2 = \sum_{n \geqslant N} \lvert\langle x, e_n\rangle\rvert^2 = \sum_{n\geqslant N} \lvert\langle x, e_n - f_n\rangle\rvert^2 < \varepsilon^2\lVert x\rVert^2$$
for all $x\in F^{\perp}$.
For $x \in E^{\perp}$ we have
\begin{align}
BA x &= B(x - P_F x) = (x - P_F x) - P_E(x - P_F x)\\
&= x - P_F x + P_E P_F x = x - (I - P_E)P_F x\\
&= x - P_{E^{\perp}} P_F x
\end{align}
since $P_E x = 0$, and hence $\lVert (I_{E^{\perp}} - BA) x\rVert = \lVert P_{E^{\perp}} P_F x\rVert \leqslant \lVert P_F x\rVert < \varepsilon \lVert x\rVert$. It follows that $BA$ is an automorphism of $E^{\perp}$, in particular that $A$ is injective, and hence $\dim E^{\perp} \leqslant \dim F^{\perp}$.
In the same way, for $x \in F^{\perp}$ we have
\begin{align}
AB x &= A(x - P_E x) = (x - P_E x) - P_F(x - P_E x)\\
&= x - P_E x + P_F P_E x = x - (I - P_F)P_E x\\
&= x - P_{F^{\perp}} P_E x,
\end{align}
and consequently $\lVert I_{F^{\perp}} - AB\rVert < \varepsilon$. So $AB$ is an automorphism of $F^{\perp}$, in particular $B$ is injective and hence $\dim F^{\perp} \leqslant \dim E^{\perp}$.
Since $(e_n)_{n \in \mathbb{N}}$ is by assumption a Hilbert basis of $\mathcal{H}$, it follows that $(e_n)_{n < N}$ is a basis of $E^{\perp}$, whence $\dim E^{\perp} = N$ (we assume $0 \in \mathbb{N}$, the dimension would be $N-1$ otherwise). By the orthonormality of $(f_n)_{n\in\mathbb{N}}$, the $N$-element family $(f_n)_{n < N}$ is linearly independent and contained in $F^{\perp}$. Since $\dim F^{\perp} = N$, it is a basis of $F^{\perp}$, and thus $(f_n)_{n \in \mathbb{N}}$ is total in $\mathcal{H}$.
Comment: If the closure of $\operatorname{span} \{ f_n : n \in \mathbb{N}\}$ were not all of $\mathcal{H}$, then there would be an $x_0 \in (\operatorname{span} \{ f_n : n \in \mathbb{N}\})^\perp$ with $\lVert x_0\rVert = 1$. Then we would have $$\Biggl\lVert x_0 - \sum_{n = 0}^\infty \langle x_0,f_n\rangle f_n\Biggr\rVert^2 = \lVert x_0\rVert^2 = 1.$$ But we have shown that $$\Biggl\lVert x - \sum_{n = 0}^\infty \langle x,f_n\rangle f_n\Biggr\rVert^2 < 1$$ for **every** $x\in \mathcal{H}$ with $\lVert x\rVert = 1$.
Comment: I somehow didnt see the solution. Now that I read it I don't understand your argument. I see why the whole  x cannot be in the orthogonal complement of the span of $\{f_n\}_{n=1}^{\infty}$ but how does that imply that $x$ is in the span of  $\{f_n\}_{n=1}^{\infty}$. I mean if that were true wouldn't the following be true?
$$\left\lVert x - \sum_{n = 0}^\infty \langle x,f_n\rangle f_n\right\rVert^2 = 0$$
Comment: Ah Thank you. I should have thought of that !! :(
Comment: what if it is finite instead of less than 1 in the problem
Comment: @89085731 Thanks, that was an interesting question. I didn't know whether it would suffice to merely require finiteness of the sum at the beginning. Turns out it does, see the updated answer.
Comment: In the first part of your answer, why $$\left\lVert x - \sum_{n = 0}^\infty \langle x,f_n\rangle f_n\right\rVert^2 \leqslant \lVert x-y\rVert^2 $$?
Comment: This seems incorrect. If we take $(e_n)$ to be the standard basis of $\ell^2$ and $(f_n) = (0, e_2, e_3, e_4, \ldots)$, then the sum of the squared distances is finite, but $(f_n)$ is not an orthonormal basis.
Answer: Consider the mapping $T: H \to H, \sum_{n=1}^{\infty} \lambda_n e_n \mapsto \sum_{n=1}^{\infty} \lambda_n f_n$.
Then we have, for $x \in H$:
$$
\| x - T x \|^2 = \left\| \sum_{n=1}^{\infty} \lambda_n (e_n - x_n) \right\|^2 \overset{\text{Hölder}}{\leq} \left( \sum_{n=1}^{\infty} |\lambda_n|^2 \right) \left( \sum_{n=1}^{\infty} \| e_n - x_n \|^2 \right) = \| x \|^2 \sum_{n=1}^{\infty} \| e_n - x_n \|^2
$$
Therefore, $\|\operatorname{id} - T \| \leq \sqrt{\sum_{n=1}^{\infty} \| e_n - x_n \|^2} < 1$, so by the Neumann series, $T$ is invertible, hence surjective, and hence $\operatorname{span}\{f_n\}$ is dense in $H$.


Tradução de linguagens de programação

Question: Sempre que pesquiso sobre "tradução de linguagem de programação no Google" só me aparecem tutoriais de como reescrever de uma linguagem para outra, e nunca o que realmente quero saber: Existe alguma linguagem de programação que foi traduzida para o português?
Vejo isso por que me intriga o fato de haverem várias linguagens de programação em inglês e pouquíssimas (Conheço apenas BIRL e Portugol*) em português ou em outros idiomas.
Por exemplo o Python, uma linguagem simples e poderosa. Existe legalmente algo que impede a tradução da linguagem para se tornar uma linguagem de apresentação para iniciantes na área?
Existe alguma barreira que proíbe isso que vá além da simples tradução das palavras reservadas?
Comment: Não, inclusive conheço pessoas que estão trabalhando em uma versão do Python em português.
Comment: Existe um fator importante sobre não existir em tantos outros idiomas: público alvo. Sejamos sinceros, a língua franca após a Segunda Guerra Mundial se tornou o inglês, e muita coisa na computação começou com pessoas cuja língua mãe era o inglês ou em instituições que estavam em países cuja língua principal era o inglês, fazendo disso, portanto, um legado sociológico linguístico importante na área
Answer: Não, não existe uma barreira. Um compilador é apenas mais um peça de software. Nada impede alguém de fazer um fork  de um compilador / interpretador qualquer, traduzir palavras reservadas e eventualmente localizar a liguagem.
O Excel por exemplo possui fórmulas localizadas. Inclusive, até onde vai meu conhecimento, não é possível mudar a língua das fórmulas sem instalar um Language Pack. Bem, a Microsoft ao menos teve a decência de matar o VBA localizado nos anos 90. O problema com macros em Alemão, Francês, etc seria com certeza muito pior do que o problema das fórmulas.
As perguntas subentendidas são: Então por que essa não é uma prática mais popular? Por que não traduzimos e adotamos linguagens em Português?
Ao meu ver as desvantagens não justificam as vantagens de localização. Voltando ao Excel: Tente parear com um colega Francês e usar o Excel no laptop dele (sim, eu vivi isso). Mesmo que seu ambiente de trabalho não seja tão globalizado há desvantagens na localização. Após se acostumar com o Excel em Português, tente abrir uma planilha no Excel em Inglês e editar as fórmulas (ou vice-versa)... Não, não é divertido.
O Inglês é a língua franca da computação, assim como o Italiano é a língua franca da música e o Latim é ainda hoje fortemente usado em nomenclatura científica.
Enquanto traduzir "if" para "se", "while" para "enquanto", "or" para "ou", etc pode facilitar - até certo ponto - a vida de um lusófono, me pergunto se essa é uma barreira cognitiva tão significativa assim...
Na data que escrevi essa resposta o Java possui 57 palavras reservadas, Python possui 33. Quando consideramos tudo o que um programador tem que aprender, o uso dessas palavras reservadas em Inglês me parece um problema menor. Eu trabalhei e estudei por muitos anos com programadores muito bons que não falam Inglês.
As palavras reservadas também são só o começo do problema. O que fazer com toda a biblioteca padrão da linguagem? Devemos traduzir também?  E o que fazer com nomes de variáveis (que inclusive podem conflitar com palavras reservadas)? O que fazer com literais (separadores decimais, datas, etc)? Devemos portar e traduzir todas as bibliotecas e frameworks?
A tradução de uma linguagem resulta em... bem... outra linguagem. Uma linguagem talvez mais acessível para a comunidade local; porém incompatível, quando não totalmente inacessível para a comunidade original. O resultado final são ecossistemas separados, reinvenção da roda e um esforço enorme para portar software entre duas linguagens.
O lado positivo da localização é a inclusão (vide Stackoverflow PT). O lado negativo é a fragmentação.
Pense em uma realidade alternativa em que a linguagem Lua tivesse sido criada usando palavras reservadas em Português. Ela talvez tivesse encontrado um nicho, ao menos temporariamente, na Petrobrás e nas atividades de pesquisa da PUC do Rio. Quem sabe Lua teria até um pézinho em outras empresas e Universidades nacionais. Hoje porém muito provavelmente Lua seria uma relíquia do passado. Esse mundo hipotético teria perdido muito... Instituições como Adobe, Blizzard, Mozilla, NASA, etc não teriam a chance de fazer coisas fantásticas com uma linguagem criada aqui no Brasil.

Fonte: SOEn - Do there exist any compilers with localized versions of programming languages?
Comment: Eu usei o Dialog, também conhecido como dBase pirateado na caruda e traduzido para o português, e que fez muito dinheiro vendendo pra estatais que eram obrigadas comprar o "similar" nacional. Era "lindo".
Comment: @Breno, sobre o primeiro ponto, vejo o Portugol mais como uma ferramenta de ensino. Um pseudocódigo que ganhou alguns compiladores e ferramentas derivados, ainda primariamente para suporte de atividades acadêmicas (Visualalg, Portugol Studio, etc). Sobre o segundo ponto, minha resposta é um categórico sim. Não só deveríamos, já o fazemos. Uso várias ferramentas, bibliotecas, frameworks e APIs de código aberto inicialmente desenvolvidas por brasileiros (e.g., htop, VRaptor e várias APIs do Java que nasceram em JSRs lideradas por experts Brasileiros).
Comment: Hmm, seria essa a razão da "morte" do Portugol? (Pelo menos na minha região parece ter desaparecido um pouco).
Comment: Concluindo, num mundo do rei inglês, devemos criar algo universal. Por esse ponto, quando nós, brasileiros, resolvemos criar uma biblioteca, _frameworks_, e até mesmo "softwares que podem receber acessos mundiais", deveríamos escrever em inglês?

Tradução de linguagens de programação


No module named hyppo._utils when importing models

Question: My issue is when trying to import the DCSBM model:
Code:
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import hyppo

from hyppo.time_series import _utils as _utils
from graspy.embed import AdjacencySpectralEmbed
from graspy.models import DCSBMEstimator
from graspy.models import EREstimator
from graspy.models import SBMEstimator

from graspy.models.sbm import _block_to_full, _get_block_indices
from graspy.simulations import er_np, sbm

Error:
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-33-287386449480> in <module>()
      8 from hyppo.time_series import _utils as _utils
      9 from graspy.embed import AdjacencySpectralEmbed
---> 10 from graspy.models import DCSBMEstimator
     11 from graspy.models import EREstimator
     12 from graspy.models import SBMEstimator

2 frames
/usr/local/lib/python3.7/dist-packages/graspy/inference/latent_distribution_test.py in <module>()
     26 from sklearn.metrics.pairwise import PAIRWISE_KERNEL_FUNCTIONS
     27 from hyppo.ksample import KSample
---> 28 from hyppo._utils import gaussian
     29
     30 _VALID_DISTANCES = list(PAIRED_DISTANCES.keys())

ModuleNotFoundError: No module named 'hyppo._utils'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.

I think hyppo._utils doesn't exist and has been replaced by hyppo.time_series and inside that folder there exists the required _utils package.
How do we fix this?
I was just trying to run the tutorial: https://docs.neurodata.io/notebooks/pedigo/graspologic/2020/09/24/latent_model_tutorial.html
Run on Google colab
This line
from hyppo.time_series import _utils as _utils   was added from me trying to fix the issue, but doesn't work.
Answer: Looks like you're using an old version of the package - it's called "graspologic" now. If you pip install graspologic, from graspologic.models import DCSBMEstimator should work fine. Just replace everything in that code that says "graspy" with "graspologic".
we're happy to answer questions on github issues as well! (I'm one of the people who contributes to the package)


How do I prevent flickering on CListCtrl?

Question: I'm using a CListCtrl/CListView report view (LVS_REPORT) in virtual mode (LVS_OWNERDATA) with LVS_EX_DOUBLEBUFFER enabled and I encounter ugly flickering. Double buffer have a real effect but it doesn't stop all flickering (without it very slow).
I'm not looking for switching to other controls that would require a high amount of rework (like ObjectListView)
How does the flickering behaves:

on column resize - the background is first clean using lightgray and after this is displayed the text (background is white)
on mouse scroll (animated) - for a very short time there is lightgray-bar displayed in the area where new lines are to be displayed.

It looks like it does clean the background using the default window background color (lightgray) for the area where it has to redraw.
How do I solve the flickering problem?
Answer: Try to do the following:
- Set Clip Children and Clip Sibling for paremt dialog of List Control.
- Make dirived from CListCtrl class. In this class overwrite OnEraseBkgnd. In the OnEraseBkgnd fill with background color area around of visible items of the list.
The OnEraseBkgnd can look like:
BOOL CListCtrlEx::OnEraseBkgnd(CDC* pDC)
{
    CBrush  br;
    CRect   rcCli;
    CRect   rcItemsRect(0, 0, 0, 0);
    int     nHeadHeight = 0;
    int     nItems      = GetItemCount();

    GetClientRect(&rcCli);

    CHeaderCtrl* pHeadCtrl = GetHeaderCtrl();
    if (pHeadCtrl)
    {
        CRect  rcHead;
        pHeadCtrl->GetWindowRect(&rcHead);
        nHeadHeight = rcHead.Height();
    }
    rcCli.top += nHeadHeight;

    if (nItems > 0)
    {
        CPoint  ptItem;
        CRect   rcItem;

        GetItemRect(nItems - 1, &rcItem, LVIR_BOUNDS);
        GetItemPosition(nItems - 1, &ptItem);

        rcItemsRect.top    = rcCli.top;
        rcItemsRect.left   = ptItem.x;
        rcItemsRect.right  = rcItem.right;
        rcItemsRect.bottom = rcItem.bottom;

        if (GetExtendedStyle() & LVS_EX_CHECKBOXES)
            rcItemsRect.left -= GetSystemMetrics(SM_CXEDGE) + 16;
    }

    br.CreateSolidBrush(GetBkColor());

    if (rcItemsRect.IsRectEmpty())
        pDC->FillRect(rcCli, &br);
    else
    {
        if (rcItemsRect.left > rcCli.left)     // fill left rectangle
            pDC->FillRect(
                CRect(0, rcCli.top, rcItemsRect.left, rcCli.bottom), &br);
        if (rcItemsRect.bottom < rcCli.bottom) // fill bottom rectangle
            pDC->FillRect(
                CRect(0, rcItemsRect.bottom, rcCli.right, rcCli.bottom), &br);
        if (rcItemsRect.right < rcCli.right) // fill right rectangle
            pDC->FillRect(
                CRect(rcItemsRect.right, rcCli.top, rcCli.right, rcCli.bottom), &br);
    }

    return TRUE;
}

Answer: I know only way to have flicker free is using double buffering or MemDC.
have found this article: Flicker-free-drawing-of-any-control
This article explains it well how to quickly perform Non Flickering drawing on your CListCtrl.
And it works excellent.
PS: VS 2005 doesn't have CMemDC class you will need to implement it your self, or use the following code:
//
// CMemDC.h header file
//
#pragma once

class CMemDC
{
public:
    CMemDC(CDC& dc, CWnd* pWnd);
    CMemDC(CDC& dc, const CRect& rect);

    virtual ~CMemDC();

    CDC& GetDC() { return m_bMemDC ? m_dcMem : m_dc; }
    BOOL IsMemDC() const { return m_bMemDC; }
    BOOL IsVistaDC() const { return m_hBufferedPaint != NULL; }

  void EraseBkClip();
protected:
    CDC&     m_dc;
    BOOL     m_bMemDC;
    HANDLE   m_hBufferedPaint;
    CDC      m_dcMem;
    CBitmap  m_bmp;
    CBitmap* m_pOldBmp;
    CRect    m_rect;
};

//
// CMemDC.cpp source file
//
#include "CMemDC.h"

CMemDC::CMemDC(CDC& dc, CWnd* pWnd) :
    m_dc(dc), m_bMemDC(FALSE), m_hBufferedPaint(NULL), m_pOldBmp(NULL)
{
    ASSERT_VALID(pWnd);

    pWnd->GetClientRect(m_rect);
    m_rect.right += pWnd->GetScrollPos(SB_HORZ);
    m_rect.bottom += pWnd->GetScrollPos(SB_VERT);
    if (m_dcMem.CreateCompatibleDC(&m_dc) &&
      m_bmp.CreateCompatibleBitmap(&m_dc, m_rect.Width(), m_rect.Height()))
    {
        m_bMemDC = TRUE;
        m_pOldBmp = m_dcMem.SelectObject(&m_bmp);
    }
}

CMemDC::CMemDC(CDC& dc, const CRect& rect) :
    m_dc(dc), m_bMemDC(FALSE), m_hBufferedPaint(NULL), m_pOldBmp(NULL), m_rect(rect)
{
    ASSERT(!m_rect.IsRectEmpty());
    if (m_dcMem.CreateCompatibleDC(&m_dc) &&
      m_bmp.CreateCompatibleBitmap(&m_dc, m_rect.Width(), m_rect.Height()))
    {
        m_bMemDC = TRUE;
        m_pOldBmp = m_dcMem.SelectObject(&m_bmp);
    }
}

CMemDC::~CMemDC()
{
    if (m_bMemDC)
    {
        CRect rectClip;
        int nClipType = m_dc.GetClipBox(rectClip);

        if (nClipType != NULLREGION)
        {
            if (nClipType != SIMPLEREGION)
            {
                rectClip = m_rect;
            }
            m_dc.BitBlt(rectClip.left, rectClip.top, rectClip.Width(), rectClip.Height(), &m_dcMem, rectClip.left, rectClip.top, SRCCOPY);
        }

        m_dcMem.SelectObject(m_pOldBmp);
    }
}

void CMemDC::EraseBkClip()
{
  CRect clip;
  m_dcMem.GetClipBox(&clip);
  m_dcMem.FillSolidRect(clip, GetSysColor(COLOR_WINDOW));
}

Answer: There is an ultra simple way I found that worked for me:

Turn off redraw with m_List1.SetRedraw(false)
Reset contents with m_List1.ResetContents()
Add new strings in loop with m_List1.AddString()
Then finalize by turning back on redraw and a m_List1.UpdateWindow().


How can I enable search on parts of a word and autocomplete suggestions?

Question: I'm using Search API in Drupal 8.
I tried with Search API pages and even views, but I didn't find <code>%like%</code> function query
Can I do %like% in Search API or Views?
Answer: Click in "Edit" this Database server, and navigate to the end of that page:


Is the explained variance of a model invariant to the presence of multicollinearity?

Question: I have fitted two different binomial logistic regression models A and B. Model A contains only one predictor variable. Model B contains a different set of predictor variables, none of which is the predictor included in model A. There is a notable degree of multicollinearity between the predictors in model B. I want to compare how well the two models can account for the variation in my data.
Usually, when discussing the consequences of multicollinearity in linear regression models, most authors focus on the effect on the predictors. For example Dormann et al (2012) point out that the standard errors of collinear coefficients will be inflated, which leads to "inaccurate tests of significance for the predictors, meaning that important predictors may not be significant, even if they are truly influential" (p. 29).
However, what is less clear to me is the effect of multicollinearity on the overall performance of the model. This question asks whether multicollinearity affects the performance of the model as a classifier, with reference to the Wikipedia article on Multicollinearity which says that "multicollinearity does not reduce the predictive power or reliability of the model as a whole, at least within the sample data set". In his answer to the question, @EdM seems to confirm that multicollinearity does not affect model reliability unless it is used to predict a data set different from the one used to fit it.
My case is somewhat different because I don't want to use the models as classifiers on new data. Instead, I want to compare how well they can explain my data set. So, that answer still leaves me with the following questions:

Is it valid to say that the explained variance of a model is invariant to the presence of multicollinearity?
Can I use still measures such as AIC or AUROC to compare the performance of my models A and B even though the predictors of model B are strongly correlated?
Is there a quotable reference that discusses the effect of multicollinearity on the explained variance of models and on measures such as the AIC or AUROC?
Comment: @Schmuddi You mean a reviewer said that? It could be helpful to quote his or her comment exactly so we can help you decide on a reply.
Comment: As shown at https://stats.stackexchange.com/questions/447684, in *any* model that is fit by optimizing some function of a linear combination of the variables, it doesn't matter how you express the variables: all that matters is the *vector space* they generate.  That instantly answers your question: multicollinearity is irrelevant.  What might be relevant is the possibility that future data could vary so much from the data you have that your predictions become gross extrapolations.  https://stats.stackexchange.com/a/507178/919 is also relevant.
Comment: What a dynamite question.  btw I'll say Yes to the first 2 questions.  I am curious, though, why within-sample performance is all you care about here.
Comment: @rolando2: There's a claim made by one author that his novel predictor is as good as the established predictors discussed by other authors. My data set comes from an experiment specifically designed to test the effect of the novel predictor in comparison to the combined effect of the established predictors. The point of the analysis is not to tease apart the effect of the established predictors, or to verify that they actually work, the point is only to see whether the model using the novel predictor performs as good as the model using the established predictors.
Comment: Thanks....A predictor requires a coefficient  :-)   How will anyone know that the within-sample results give the best, most reliable estimates of this novel predictor's coefficient...standardized coefficient...standard error...or, generally, performance?
Comment: The concept of explained variance has no clear application to logistic regression, the way it does to linear regression. Are you sure "explained variance" is what you mean?
Comment: @Kodiologist: You're right, of course. What I mean in my first question is probably "Is it valid to say that the capability of a logistic regression model to correctly predict the probabilities of the values of the dependent variable is invariant to the presence of multicollinearity?" – Is there a more concise way of putting that? I'd gladly correct my question to be more accurate.
Comment: @Schmuddi Yes, but then I don't understand what your concern is. The notion of predictive accuracy only makes sense when we consider performance on unseen data, and you've said that you only care about performance in a fixed sample.
Comment: @Kodiologist: Let me try to rephrase my concern. When remapping the predicted probabilities of model A to a binary response, model A makes the correct predictions for say 70% of the observations. When doing the same for model B, model B makes correct predictions for say 75% of the observations. Is it still valid to say that model B can account better for the values of the observations than model A even though there is multicollinearity among the predictors used in model B? Or does the multicollinearity invalidate any comparison between A and B?
Comment: @Schmuddi Multicollinearity indeed doesn't make the agreement between model outputs and actual observations any less useful as a measure of model fit, as far as I can see. I mean, I don't know why anybody would think that.
Comment: @Kodiologist: "I don't know why anybody would think that" – unfortunately, I'm in a less than ideal position to ask that one particular reader of my manuscript who raised this issue what he was thinking, if you get my drift...
Answer: From the comments, it is evident that you mean some kind of predictive accuracy measurement, any of which would be a function of the predictions and the true observations.
Multicollinearity cannot affect the true observations, since they are the observations even if you don't do any modeling, so for multicollinearity to influence the predictive accuracy, multicollinearity must influence the predictions.
Let's do a simulation where we do a logistic regression on two correlated variables, regress on a transformation of those variables that retains all of the information while removing the correlation, and comparing predictions.
<code>library(MASS)
set.seed(2022)
N <- 25
X <- MASS::mvrnorm(N, c(0, 0), matrix(c(1, 0.9, 0.9, 1), 2, 2))
y <- rbinom(N, 1, 0.5)
L_correlated <- glm(y ~ X, family = binomial)
predictions_correlated <- predict(L_correlated)
PCs <- X %*% prcomp(X)$rotation # Do PCA to remove correlation
L_uncorrelated <- glm(y ~ PCs, family = binomial) # Take all PCs to
                                                  # retain all information
predictions_uncorrelated <- predict(L_uncorrelated)
round(predictions_correlated - predictions_uncorrelated, 14)
</code>
Aside from floating point arithmetic issues out past the $14^{\text{th}}$ decimal place, the predictions are the same.
In GLMs, multicollinearity can affect interpretations, p-values, and confidence intervals, but multicollinearity does not affect the predicted values. Some people also dislike multicollinearity because they think they can drop some variables and retain most of the information while lowering the parameter count. As much as that makes sense, it is not perfect and might even be fairly problematic.
Comment: I have to admit that by now, I completely forgot about my question, and I had to re-read everything to understand my own problem back then. But this is exactly the type of argument that I could've needed back then – thanks!


How can i move a button in a UINavigation bar to the right

Question: im trying to move the right button in my navigation bar to the right to align it with buttons on a table view here is what is currently looks like
i made a button like this:
<code>let allButton = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
    allButton.layer.borderColor = Constants.AppColor.cgColor
    allButton.layer.borderWidth = 1
    allButton.layer.backgroundColor = UIColor.white.cgColor
    allButton.addTarget(self, action: #selector(selectAllContacts), for: .touchUpInside)
    allButton.layer.cornerRadius = 10
</code>
and im adding it to my nav bar like this:
<code>        navigationItem.rightBarButtonItems = [UIBarButtonItem(customView: allButton), importButton]
</code>
I have tried adding image insets, content insets and it doesn't work.
Any idea on what else i can try?
Answer: Will this do?
navigationItem.rightBarButtonItem = UIBarButtonItem(
    title: "Menu >",
    style: .plain,
    target: self,
    action: #selector( rightNavTap )
)
Comment: i don't think this would solve my issue, i just need to move my button to the right by a few pixels
Answer: I was able to solve this by adding
<code>    let negativeSpacer:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: nil, action: nil)
    negativeSpacer.width = -10
</code>
and appending that to my array of buttons
<code>        navigationItem.rightBarButtonItems = [negativeSpacer, UIBarButtonItem(customView: allButton), importButton]
</code>
If anyone finds a better solution let me know.


Why won't RDP accept my stored credentials, and makes me manually enter it every time?

Question: Trying to log in to an Amazon EC2 instance (running Windows Server 2012 R2) via RDP.  It works, and I can connect, but having saved the credentials that worked, they never seem to be accepted on subsequent logins, always rejecting them and requiring me to reenter the password part manually.

Nothing about why it didn't work, just that it didn't — "Your credentials did not work" and "The logon attempt failed".  Then I type in the same password as always and it works.
I can see that the credentials are in fact saved in the Credential Manager, and the right name is always filled in trying to log on.  I can also see it trying the saved credentials for a split second before being presented with this dialog.
After googling around for an answer, I've tried several things, including using an IP address vs. a FQDN, doing that thing with the Group Policy editor ("Allow Delegating Saved Credentials with NTLM-only Server Authentication"), and checking the Group Policy on the remote side for anything unusual-looking.  No dice.
How do I get it to accept the credentials it saved and not prompt me each time?
Answer:
To be able to use saved credentials in this situation you need to do
  the following:

Open Group Policy Editor via cmd -> gpedit.msc
Navigate to Local Computer Policy\Computer    Configuration\Administrative Templates\System\Credentials Delegation\
Open Setting Allow Delegating Saved Credentials with NTLM-only Server    Authentication, set it to Enabled click on button Show...
  and in Show    Contents window add Value TERMSRV/* Close all windows
  by pressing OK.
Run cmd and enter gpupdate command to update your policy.

Now you should be able to use your saved credentials.

Source: http://answers.microsoft.com/en-us/windows/forum/windows_7-security/remote-desktop-connection-not-using-saved/13a17d84-b008-4767-95fb-b891e9e6bc66?auth=1
or try the solution from link below:
https://superuser.com/questions/604483/windows-7-remote-desktop-connection-save-credentials-not-working
Comment: This worked for me.
Answer: On Windows 10:
In Credential Manager, within the Windows Credentials section, try deleting the credentials from the Windows Credentials sub-section and instead re-creating them in the Generic Credentials section.
Comment: connection to win server 2019 repaired once and forever, thx!
Comment: thank you so much. tried so many different things and this fixed it. Seems to be a Windows 10 bug though.


circles in a square

Question: N circles of maximum possible equal radius are contained in a square of side 1 with no overlap among the circles. What is the % of the area of the square outside the circle for N=3? (would appreciate a way of thinking about solving this for the general case; also, is there an easy way to extrapolate this into higher dimensions? i.e. spheres of maximum possible equal radius inside a cube of side 1).
This is similar to the question here, but I am looking for a generalized way of thinking about this, for circles and cubes:
Maximum area of $2$ circles in a square
Thank you.
Comment: Does the Wikipedia article help somewhat at least?  https://en.wikipedia.org/wiki/Circle_packing_in_a_square
Comment: No you cannot generally extrapolate to higher dimension. You should search for packing spheres in a cylinder for example.
Answer:
Hint: This figure is drawn with condition that all three circles are mutually tangent.
As can be seen maximum r is when three circle are symmetric about DB. In this case DB bisects $\angle SPT$ which is $60^o$. BD makes $45^o$ angle with PQ which is parallel with AD. Therefore:
$\angle QPS=45-30=15^o$
You can use this figure to find the ratio.
$AD=2 r +2r(1+ \cos (\angle QPS)=2r(1+ \cos (\angle QPS)$;
With $\angle (QPS)=15^o$  we get  $r=0.25435$
Can do the rest?
Comment: I would propose some edits: 1. Your image only shows that the bounding box of circles is strictly contained in a square with parallel sides. But what if the circles do not touch each other pairwise and what happens when not two of them share the same $x$-value? I think there are some details missing here... 2. What does $4r=1=0.25$ mean?
Comment: @PrudiiArca, This is not specified. I considered the conditions like in two circles as in OP reference. I edited my answer.
Comment: @DanielMathias, You are right , I edited my answer.
Comment: +1, though there seems to be a typo in your equation. Also, the result should be $r\approx 0.254333$

circles in a square