Carl Love

Carl Love

28035 Reputation

25 Badges

12 years, 321 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@Zeineb You must be using a Maple version from before when one-argument add was introduced. In the future, please put your Maple version in your Question headers using the pull-down provided for that purpose. Here's a retrofit for the add error:

ChiSqIndTest:= proc(O::Matrix, {method::identical(Pearson, G):= 'Pearson'})
description "Returns p-value for Pearson's or G chi-squared independence test.";
option
   author= "Carl Love <carl.j.love@gmail.com>, 25-Oct-2018",
   reference= (
      "https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test",
      "https://en.wikipedia.org/wiki/G-test"
   )
;
uses AT= ArrayTools, St= Statistics;
local 
   C:= AT:-AddAlongDimension(O,1), R:= AT:-AddAlongDimension(O,2), #column & row sums
   r:= numelems(R), c:= numelems(C), #count of rows & columns
   x, 
   #matrix of expected values under null hypothesis (independence):
   T:= Matrix((r,c), (i,j)-> R[i]*C[j], datatype= float) / add(x, x= R)
;
   #p-value by either method:
   1 - St:-CDF(
      ChiSquare((r-1)*(c-1)), 
      add(x, x= `if`(method='G', 2*O*~ln~(O/~T), (O-T)^~2 /~ T))
   )
end proc:

 

@Rohith 

As I've mentioned before, the whole point of making expressions into strings is to avoid automatic simplification. If an expression already exists as a mathematical expression (rather than as a string) in Maple's memory, then it's certain that automatic simplification has already occurred. If you must work with expressions that are already in Maple's memory, then it's impossible for this entire project to work exactly to your specifications. I'm sorry that this point was not made more clear to you earlier, but I did try.

It is not the module that changes a - c*d to -c*d + a; it's the automatic simplification.

To summarize and re-emphasize the key points:

  1. When you enter an expression into Maple other than as a string, that expression will very often be altered into a form that Maple views as mathematically equivalent but more convenient for it to store.
  2. Some automatic simplifications (such as rational-number arithmetic) will always happen and are easily predictable; others (such as ordering of polynomial terms or ordering of factors within terms) depend on what Maple already has stored for that session, and are more difficult to predict.
  3. You cannot stop or control this process: It is a fundamental part of how Maple works, and it always has been.

@Zeineb Yes, you are right about the denominator. Thank you for correcting. I have corrected the original.

@DEBA I can see a little link like a postage stamp in the lower left corner of your most-recent Reply, but it doesn't take me anywhere.

For part (d), you'll need a pair of differential equations, one for the sum of the signed horizontal (or x) forces (propulsion and drag) and one for the sum of the signed vertical (or y) forces (lift and weight). After you have these, getting Maple to do the Euler-method part is trivial (so don't worry about that part, I'll show you everything). So, can you enter those differential equations? If not, I can give some hints for that.

@Zeineb I don't know anything about that,  but if you can direct me to some reference material, I may be able to figure something out. Indeed, I don't recall ever seeing a functional recurrence before you brought up this one.

There are several ways to compute the p-value. (And they'll give slightly different results because most are approximations.) Do you know which you're supposed to use? The method that I've seen most often in first-year textbooks is Pearson's chi-squared test. In this test, the value of the chi-squared statistic can be computed simply with a four-function hand calculator: chi^2 = sum(sum((Obs[i,j] - T[i,j])^2/T[i,j], i= 1..R), j= 1..C), where Obs is the matrix of observed data, R is the number of rows, and C is the number of columns. Then we can have Maple compute the p-value from the chi-squared distribution with (R-1)*(C-1) degrees of freedom.

But given that we have a computer available, we can do Fisher's exact test or a G-Test.

Your final question "At what p-value can we reject H0?" is not really a mathematical question, it's more philosophical[*1]. How much risk of rejecting a true null hypothesis are you willing to accept? (p is the probability of doing that.) I suppose that if the drug were to be marketed based on this study, that risk is huge: hundreds of millions to billions of dollars. If you decide on a value of p that you will base the decision on, then that is represented by the letter alpha.

Please respond to my Answers to your previous two Questions that I gave Monday night / Tuesday morning! It is rude to not respond to Answers. I put a lot of effort into writing that general solver for functional recurrences.

[*1]Although I'd be willing to say with mathematical certainty that you should never reject the null hypothesis if p > 1/2.

I see no attached file on your Question. Please try again to upload it.

@mmcdara Actually, there are two (unrelated) small things wrong with your method:

1. The support of your distribution is {1, ..., K+1} (as clearly seen from the horizontal axis tickmarks of your histogram) whereas the OP wanted {0, ..., K}. You can correct this by using EmpiricalDistribution instead of ProbabilityTable. Indeed, the support of a distribution created with ProbabilityTable is always an initial segment of positive integers (minus any values that have probability explicitly set to 0 in the table).

2. The values returned by Sample are floats rather than integers. This is a nuisance that can be corrected with trunc.

@eggoodaire Of course, it is always risky to use single-letter global names as labels for anything. If you want to free up for whatever use, do

interface(imaginaryunit= ...);

where you fill in whatever symbol for ....

But, I recommend that you use strings.

You may not be aware that edge weights can be included in the original graph definition, and that when drawn with option style= planar, the results are pretty good. So, your example could be

restart;
GG:= GraphTheory:-Graph({
   [{1,2}, 7], [{1,7}, 8], [{1,8}, 5], [{2,3}, 8], [{2,8}, 4], [{2,9}, 3],   [{3,4}, 8],  [{3,9}, 5], [{4,5}, 4], 
   [{4,10}, 3], [{5,6}, 6], [{6,7}, 7], [{6,10}, 10], [{7,8}, 5], [{7,9}, 2], [{9,10}, 7]
});
HH:= GraphTheory:-RelabelVertices(GG, ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]);
GraphTheory:-DrawGraph(HH, style= planar);

Or you can use your custom vertex positioning, but allow DrawGraph to decide on the edge-weight positioning:

vp := [[0,0], [5,10], [20,17], [50,20], [70,0], [50,-10], [20,-10], [18,2], [35,10], [55,5]];
GraphTheory:-SetVertexPositions(HH, vp);
GraphTheory:-DrawGraph(HH);

It's not perfect, but it's a lot less work than you figuring out the positioning of the edge labels.

@ecterrab Thank you for the detailed explanation. I was aware of the use of differentiating wrt a function in analyzing differential equations, for example, as it is used in the "uniqueness" part of the standard existence and uniqueness theorem for 1st-order IVPs. I conflated this desired functionality with the command Physics:-Fundiff when it is actually provided by Physics:-diff.

@primogen The specindex(theta) tells indets (and thus also subsindets) to search for the symbol theta with any index. Since d is a single instance rather than a set of instances, it could be handled simply with subs, like this:

qdot:= diff~(subsindets(subs(d= d(t), MassMatrix), specindex(theta), T-> T(t)),t)

However, I think that this is more robust:

qdot:= diff~(subsindets(MassMatrix, {identical(d), specindex(theta)}, T-> T(t)),t)

and this even more robust:

qdot:= diff~(subsindets(MassMatrix, {'identical'(d), 'specindex'(theta)}, T-> T(t)),t)

although I'll admit that typing the identical and those quotes is annoying.

@Rohith 

1: I can't reproduce that behavior. When I do termExtract("a-c*d"), I get output {c*d}. Nonetheless, I may be able fix the problem anyway if I can see the internal representation of the expression on your computer. So, please do

lprint(kernelopts(version), InertForm:-Parse("a-c*d"));

and show me the output. My output is

`Maple 2018.1, X86 64 WINDOWS, Jun 8 2018, Build ID 1321769`, `%+`(a, -`%*`(c, d))

I suspect that the last part of your output might be `%+`(a, `%*`(-c, d)). If it is, I'd like to know why; but even if I don't know, I may be able to fix it. As we've discussed from the beginning of this project, the minus sign is handled differently than other operators by InertForm:-Parse in that it is always treated as an unary operator.

2: I need for you to make a list of all the expressions that we've handled so far. I need that so that when I modify the program I can test to make sure that all previous correct behavior is maintained.

3: Regarding OP: It is just a parameter in the short arrow expression OP-> foldl(op(0,OP), op(OP)). As such, it is local to that expression, and both its spelling and its meaning are entirely up to the author, me. It has no connection to op. The same is true of any name appearing on the left side of an arrow ->. Since this arrow expression appears as the third argument of subsindets, the values passed to OP are determined by the second argument, AssocOps, which is defined a few lines above as `%+` or `%*` with three or more arguments.

Why do you ask about this symbol OP in particular?

 

@Rohith You have List2 and List1 reversed.

That seq(assign(...), ...could also be done as

assign(List1=~ List2);

However, I share Acer's disdain of using the assign command in the context of your Question.

@Ronan Names built with indexing, such as Pedal[i], serve the same purpose programmatically as Pedal||i, but they share the same lexical level (local, global, in-between) as their parent Pedal. Just don't try to assign to the parent (unless you really know what you're doing); only make assignments to the indexed forms. The indices can be anything, even multiple things; they don't need to be numbers or even names.

To delve a bit into techical details, assigning to A[i] where has not been previously assigned turns into a table, which you can look up help for. Nonetheless,  you can go pretty far using indexed variables without knowing this detail.

First 298 299 300 301 302 303 304 Last Page 300 of 708