I am not sure what to do when R tells me it can't find a package that has been installed. Any suggestions?
model1 = glm( RESPONSE ~ AGE + as.factor(SEX) + SYSBP +
as.factor(DIABETES) + LDLC + as.factor(BPMEDS) +
as.factor(CURSMOKE) + HDLC + HEARTRTE + TIME,
data=trVal, family=binomial(link=logit))
glm.predict has been installed successfully
library(glm.predict)
glm.predict(model1)
Error: could not find function "glm.predict"
glm.predict is the package's name, not a function. What you are looking for is probably the function discrete.changes() from the glm.predict package.
Related
I'm new to Mathematica I was hoping that this is a functionality built in. I am calculating the conditional entropy of a table and have the following 4 variables:
a = 1/8*Log[(1/8)/(1/2)] + 1/16*Log[(1/16)/(1/2)] + 1/16*Log[(1/16)/(1/2)] + 1/4*Log[(1/4)/(1/2)]
b = 1/16*Log[(1/16)/(1/4)] + 1/8*Log[(1/8)/(1/4)] + 1/32*Log[(1/32)/(1/4)] + 0
c = 1/32*Log[(1/32)/(1/8)] + 1/32*Log[(1/32)/(1/8)] + 1/16*Log[(1/16)/(1/8)] + 0
d = 1/32*Log[(1/32)/(1/8)] + 1/32*Log[(1/32)/(1/8)] + 1/32*Log[(1/32)/(1/8)] + 0
Then the final calculation is:
a + b + c + d
I was hoping there was a way to display the expanded a + b + c + d as a output so I can right-click/copy as latex to past into a document so I don't have to type it out. I can't figure out how to do it though. I'm guessing there is a way to expand those variables in the output to show the full calculation but maybe it is not possible. Thanks for any help.
I'm not sure how expanded you wanted the mathematical expression to be. See if the following expression is in the form you want to convert to LaTeX: (1/16 Log[1/(16/4)]+1/8 Log[1/(8/4)]+1/32 Log[1/(32/4)]+0)+(1/32 Log[1/(32/8)]+1/32 Log[1/(32/8)]+1/16 Log[1/(16/8)]+0)+(1/32 Log[1/(32/8)]+1/32 Log[1/(32/8)]+1/32 Log[1/(32/8)]+0)+(1/8 Log[1/(8/2)]+1/16 Log[1/(16/2)]+1/16 Log[1/(16/2)]+1/4 Log[1/(4/2)]).
You can get that by using HoldForm on the right-hand side of your assignments. Then use TeXForm[a+b+c+d] to convert:
a = HoldForm[
1/8*Log[(1/8)/(1/2)] + 1/16*Log[(1/16)/(1/2)] +
1/16*Log[(1/16)/(1/2)] + 1/4*Log[(1/4)/(1/2)]];
b = HoldForm[
1/16*Log[(1/16)/(1/4)] + 1/8*Log[(1/8)/(1/4)] +
1/32*Log[(1/32)/(1/4)] + 0];
c = HoldForm[
1/32*Log[(1/32)/(1/8)] + 1/32*Log[(1/32)/(1/8)] +
1/16*Log[(1/16)/(1/8)] + 0];
d = HoldForm[
1/32*Log[(1/32)/(1/8)] + 1/32*Log[(1/32)/(1/8)] +
1/32*Log[(1/32)/(1/8)] + 0];
TeXForm[a + b + c + d]
I would like to fire a function as soon as a trade was closed (= the OrdersHistoryTotal increased by at least 1).
Is there any handler in MQL4 for such scenarios?
In my particular setup I have the following function pushSocket which should only push data in case the OrdersHistoryTotal changed.
int i,hstTotal=OrdersHistoryTotal();
string historical_trades = "";
for(i=0;i<hstTotal;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue;
historical_trades = historical_trades +
"historical_trades|" +
version + "|" +
DID + "|" +
AccountNumber() + "|" +
IntegerToString(OrderTicket()) + "," +
TimeToString(OrderOpenTime(), TIME_DATE|TIME_SECONDS) + "," +
TimeToString(OrderCloseTime(), TIME_DATE|TIME_SECONDS) + "," +
IntegerToString(OrderType()) + "," +
DoubleToString(OrderLots(),2) + "," +
OrderSymbol() + "," +
DoubleToString(OrderOpenPrice(),5) + "," +
DoubleToString(OrderClosePrice(),5) + "," +
DoubleToString(OrderStopLoss(),5) + "," +
DoubleToString(OrderTakeProfit(),5) + "," +
DoubleToString(OrderCommission(),2) + "," +
DoubleToString(OrderSwap(),2) + "," +
DoubleToString(OrderProfit(),2) + "," +
"<" + OrderComment() + ">|";
}
pushSocket.send(StringFormat("%s", historical_trades, true));
I tried to insert a counter to compare it but the counter is deleted every time on memory clean-up.. The above function is nested in a onTick function which executes every second.
There is a function OnTradeAction() in MQL5 that is called every time some trading action is done. But unfortunately this function is not available in MQL4. On the other hand, you can implement a function inside OnTick() that will check that HistoryTraderTotal() increased compared to the previously saved value, and do all the steps you like in that case. A bit more work but almost the same.
OnTimer(){
Mt4OnTradeAction();
otherLogic();
}
Mt4OnTradeAction(){
static int historyTradesTotal=0;
if(HistoryTradesTotal()==historyTradesTotal) return;
historyTradesTotal = HistoryTradesTotal();
processingTrade();
}
I am searching for a solution to just and only consider real forex pairs in my loop. I don't want CFDs, commodities, silver, gold, etc. to be included because they have a complete different logic when it comes to calculating pips etc. etc. (I want to use the data for a FX dashboard).
How can I implement a filter to do so without building if-statements for every FX pair existing?
If possible, the solution should be independent of the broker used (since the offered FX pairs might be different from broker to broker, so a common approach would be the all-in solution).
This is my current code that doesn't seperate between fx and non fx:
/*
2.) Create a string format for each pending and running trade
*/
int live_orders = OrdersTotal();
string live_trades = "";
for(int i=live_orders; i >= 0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)==false) continue;
live_trades = live_trades +
"live_trades|" +
version + "|" +
DID + "|" +
AccountNumber() + "|" +
IntegerToString(OrderTicket()) + "|" +
TimeToString(OrderOpenTime(), TIME_DATE|TIME_SECONDS) + "|" +
TimeToString(OrderCloseTime(), TIME_DATE|TIME_SECONDS) + "|" +
IntegerToString(OrderType()) + "|" +
DoubleToString(OrderLots(),2) + "|" +
OrderSymbol() + "|" +
DoubleToString(OrderOpenPrice(),5) + "|" +
DoubleToString(OrderClosePrice(),5) + "|" +
DoubleToString(OrderStopLoss(),5) + "|" +
DoubleToString(OrderTakeProfit(),5) + "|" +
DoubleToString(OrderCommission(),2) + "|" +
DoubleToString(OrderSwap(),2) + "|" +
DoubleToString(OrderProfit(),2) + "|" +
"<" + OrderComment() + ">|";
}
This is probably the easiest way. Prefix symbols might be a problem (e.g. mEURUSD) but easily solved by shifting the StringSubstr values by the prefix size. Suffix is not a problem as we take the first 6 chars of the symbol string.
const string FX_CURRENCIES[]={"EUR","GBP","USD","NZD","AUD","CHF","CAD","JPY"};//add other currencies if needed
bool isFxPair(const string symbol){
return StringLen(symbol)>=6 && getCurrencyIdx(StringSubStr(symbol,0,3))>=0 &&
getCurrencyIdx(StringSubStr(symbol,3,3))>=0;
}
int getCurrencyIdx(const string smb){
for(int i=ArraySize(FX_CURRENCIES)-1;i>=0;i--){
if(FX_CURRENCIES[i]==smb)
return i;
}
return -1;
}
Use of CStringArray and caching FX symbols might be another good idea that may potentially work faster, but it seems to use the similar logic as above(but you'll have to sort the cache every time you add something in order to have CStringArray collection to work fast).
There is no direct method to ask whether a symbol is FX, CFD, Stock, Crypto or anything else.
Here is my code:
if (amount != -1)
returnJson.Add("<p style=\"color: black;\">" + double.Parse(res_q.Replace(",", ".")) * amount + " " + res_i + "</p>");
else
returnJson.Add("<p style=\"color: black;\">" + res_q + " " + " ") + res_i + "</p>");
And no matter if the execution of the program goes to if or the else, if res_q="1,5", this returns 15 on server, and 1.5 locally.
Why is this happening?
The problem was in the comma.
I want to apply globalization in my program. Using CultureInfo.InvariantCulture was the answer I needed. Or simple replcing the comma with dot.
Here is expression that we have to minimize with boolean algebra:
y = /A/B/C/D + /A/B/CD + /AB/CD + A/B/C/D + A/B/CD + A/BC/D + A/BCD.
I know little bit about that, please help!!!
The answer is /A/CD + /B/C + A/B
You need to put those minterms on a Karnaugh Map and find the minimized form after grouping.