I am trying to run a model selection anlysis (with MuMIn and AICc) based on a set of mixed effects models with a binomial distribution family.
My data looks like this (sorry for not posting it more elegantly)
head of data
And the saturated model (out of 38 combinations) is this:
model1 <-glmer( occ~Habitat*NDVI_centre+Dist_Paths+Dist_Power_Lines+Dist_relocation + (1 | Individual) , family=binomial , data=g.hab, control=glmerControl(optimizer="bobyqa"),nAGQ=10)
Some of the models run smoothly but about half of the models give me this error:
Error in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GHrule(0L), compDev = compDev, :
(maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate
I wasn't able to find a solution for this and will appreciate any guidance.
hopefully useful info :
all variable were centered
the same parameters (indp var) were used in a model with a different binomial response variable and worked fine.
the dataset is large (44000 observations)
In some more details:
The full dataset can be found here
The following models showed no error (just a couple examples):
`model38<-glmer( occ~Habitat + (1 | Individual) , family=binomial , data=g.hab, control=glmerControl(optimizer="bobyqa"),nAGQ=10)
model33 <-glmer( occ~Habitat+Dist_Paths + (1 | Individual) , family=binomial , data=g.hab, control=glmerControl(optimizer="bobyqa"),nAGQ=10)
model8 <-glmer( occ~Habitat+Dist_Paths+Dist_Power_Lines+NDVI_centre + (1 | Individual) , family=binomial , data=g.hab, control=glmerControl(optimizer="bobyqa"),nAGQ=10)
`
But these showed the above error :
model3 <-glmer( occ~Dist_Paths+Dist_Power_Lines+Dist_relocation+NDVI_centre + (1 | Individual) , family=binomial , data=g.hab, control=glmerControl(optimizer="bobyqa"),nAGQ=10)
model1 <-glmer( occ~Habitat*NDVI_centre+Dist_Paths+Dist_Power_Lines+Dist_relocation + (1 | Individual) , family=binomial , data=g.hab, control=glmerControl(optimizer="bobyqa"),nAGQ=10)
`
Thank you very much
Related
im working on export the import export data from excell sheet to sequlize mysql. im facing the issue during extract the data from one column of excell sheet.
im getting this data
let str = [
'CABBAGE - Approx 800g - 1.3Kg * 1 ₹44.55\r\n' +
"LADY'SFINGER/BHENDI - 1Kg * 1 ₹61.20\r\n" +
'BRINJAL LONG/ BAIGAN - 500g * 1 ₹23.24\r\n' +
'LEMON - 6 pieces * 1 ₹24.00\r\n' +
'KIRA / CUCUMBER GREEN - 1Kg * 1 ₹35.00\r\n' +
'CARROT - 500g * 1 ₹41.65\r\n' +
'Amrutanjan Strong Pain Balm Double Power - 50ml * 1 ₹118.75\r\n' +
'Pediasure 7',
' Specialized Nutrition Drink Powder for Growing Children- Chocolate Flavour - 200g * 1 ₹223.10'
]
let str1 = JSON.parse(str)
console.log( str1)
how can i upload thes all details into mysql defrent defrent column ??
Is there a way to have the where clausule inside a different column with Kusto Language. I am aware of the "Pivot" syntax that is also used with SQL to create columns based on unique value. But don't think this will help in my case. There is also another SO question who almost has the same question as me. But his solution Didn't work either.
Context of my query: This query gets the runtime of each machine for every month. You may be wondering why I used such a long query to achieve this. Any opnions and adjustments are welcome. I am very new to the language. And I already use the top query to get the start and stop times of each VM in another project.
Original query :
AzureActivity
| where ResourceProvider == "Microsoft.Compute"
and ActivityStatus == "Succeeded"
and OperationName == "Deallocate Virtual Machine"
| project DeallocateResource=Resource
,DeallocatedDate=format_datetime(EventSubmissionTimestamp, 'yyyy-MM-dd')
,DeallocatedTime=format_datetime(EventSubmissionTimestamp, 'HH:mm:ss')
| join kind=fullouter (AzureActivity
| where ResourceProvider == "Microsoft.Compute"
and ActivityStatus == "Succeeded"
and OperationName == "Start Virtual Machine"
| project StartupResource=Resource
,StartDate=format_datetime(EventSubmissionTimestamp, 'yyyy-MM-dd')
,StartTime=format_datetime(EventSubmissionTimestamp, 'HH:mm:ss')
) on $right.StartupResource == $left.DeallocateResource
| where StartDate == DeallocatedDate
| project Resource=coalesce(StartupResource, DeallocateResource) ,
Runtime = round(todouble(datetime_diff('minute', todatetime(strcat(StartDate , " " , DeallocatedTime )) , todatetime(strcat(StartDate , " " , StartTime )))) / 60)
| summarize sum(Runtime) by Resource
Now the query above will get the sum of the running time with the time range you specifically set in the portal.
To get the sum of the running time for each month (Log analytics is set for 90 days so 3 months ago) I add these where statements. in 3 Different queries. The work gets done And I got 3 different tables with the running time of each month being (month1, month2, month3 ).
| where TimeGenerated > ago(30d)
| where TimeGenerated between(ago(30d) .. ago(60d) )
| where TimeGenerated between(ago(60d) .. ago(90d) )
But these are 3 different queries and 3 different tables. My Goal is to get this look where you have the 3 different (timegenerated where statements inside one Table)
Tried the SO question solution but that didn't go as planned (got an Failed to resolve scalar expression named 'TimeGenerated' error while adding these lines of code to my original query)
| summarize sum(Runtime) by Resource , bin(TimeGenerated, 1m)
| summarize Fistmonth = TimeGenerated > ago(30d),
SecondMonth = TimeGenerated between(ago(30d) .. ago(60d)) ,
ThirdMonth = Runtime_,TimeGenerated between(ago(60d) .. ago(90d) ) by Resource
Does anyone knows what I am missing or overseeing here. Is this possible with kusto ?
And do I use an overhead of query for something that can be done in a couple of lines.
if I understand your scenario correctly, you could potentially achieve that using sumif, assuming you know the months you're targeting in advance.
Here's an example:
datatable(Resource:string, Runtime:double, TimeGenerated:datetime)
[
"A", 13.4, datetime(2019-01-01 11:11:11),
"B", 1.34, datetime(2019-01-01 10:10:10),
"C", 0.13, datetime(2019-01-01 12:12:12),
"A", 12.4, datetime(2019-02-01 11:11:11),
"B", 1.24, datetime(2019-02-01 09:09:09),
"B", 2.24, datetime(2019-02-01 09:10:09),
"B", 3.24, datetime(2019-02-01 09:11:09),
"C", 0.12, datetime(2019-02-01 08:08:08),
"A", 14.4, datetime(2019-03-01 07:07:07),
"B", 1.44, datetime(2019-03-01 05:05:05),
"C", 0.14, datetime(2019-03-01 06:06:06),
]
| summarize Month1 = sumif(Runtime, TimeGenerated between(datetime(2019-01-01)..datetime(2019-02-01))),
Month2 = sumif(Runtime, TimeGenerated between(datetime(2019-02-01)..datetime(2019-03-01))),
Month3 = sumif(Runtime, TimeGenerated between(datetime(2019-03-01)..datetime(2019-04-01)))
by Resource
This question already has answers here:
Surpassing MySQL's TIME value limit of 838:59:59
(7 answers)
Closed 4 years ago.
I am trying to sum time values and have it in the format of hours:minutes:seconds i.e. 100:30:10.
SEC_TO_TIME(SUM(TIME_TO_SEC(ActualHours))) AS Hours
But I'm having a problem because time's max value is 838:59:59.
So if summing the time is over this value it won't show i.e. if it equals 900 hours it will show as 838:59:59 which is wrong.
How do I the display the total hours if it is over 838:59:59?
If I had to do this conversion in SQL, I would do something like this:
SELECT CONCAT( ( _secs_ DIV 3600)
, ':'
, RIGHT(CONCAT('0',( _secs_ DIV 60 ) MOD 60 ),2)
, ':'
, RIGHT(CONCAT('0',( _secs_ MOD 60)),2)
) AS `h:mm:ss`
We can just replace the _secs_ with the expression that returns the number of seconds we want to convert. Using the expression given in the question, we get something like this:
SELECT CONCAT( ( SUM(TIME_TO_SEC(ActualHours)) DIV 3600)
, ':'
, RIGHT(CONCAT('0',( SUM(TIME_TO_SEC(ActualHours)) DIV 60 ) MOD 60 ),2)
, ':'
, RIGHT(CONCAT('0',( SUM(TIME_TO_SEC(ActualHours)) MOD 60)),2)
) AS `h:mm:ss`
DEMONSTRATION
The syntax provided in this answer is valid in MySQL 5.6. As a demonstration, using a user-defined variable #_secs as the expression number of seconds:
Set user-defined variable for demonstration:
SELECT #_secs_ := ( 987 * 3600 ) + ( 5 * 60 ) + 7 ;
returns
#_secs := ( 987 * 3600 ) + ( 5 * 60 ) + 7
-----------------------------------------
3553507
demonstrating the query pattern:
SELECT CONCAT( ( #_secs_ DIV 3600)
, ':'
, RIGHT(CONCAT('0',( #_secs_ DIV 60 ) MOD 60 ),2)
, ':'
, RIGHT(CONCAT('0',( #_secs_ MOD 60)),2)
) AS `hhh:mm:ss`
returns
hhh:mm:ss
---------
987:05:07
Here is one way we can do this:
SELECT
CONCAT(CAST(FLOOR(seconds / 3600) AS CHAR(50)), ':',
CAST(FLOOR(60*((seconds / 3600) - FLOOR(seconds / 3600))) AS CHAR(50)), ':',
CAST(seconds % 60 AS CHAR(50))) AS time
FROM yourTable;
For an input of 10,000,000 (ten million) seconds, this would generate:
2777:46:40
Demo
Use some simple math to concat a time period from seconds,replace 35000 with your column.
SELECT CONCAT(FLOOR(35000/3600),':',FLOOR((35000%3600)/60),':',(35000%3600)%60)
A fiddle to play with
I need to split data within a cell separated by - (dash) and put into separate columns. The problem I am having is there may be more than one -.
So using the table below with the original data coming from sic_orig, I need to put everything before the first - in sic_num and everything after the first - in sic_desc. I'm sure this is really easy, but I can't seem to find anything clear on this.
This is what my table should look like with sic_orig being the source and sic_num and sic_desc being data pulled from sic_orig:
sic_orig | sic_num | sic_desc
---------------------------------------------------------------------------
509406 - Jewelers-Wholesale | 509406 | Jewelers-Wholesale
--------------------------------------|-----------|------------------------
506324 - Burglar Alarm Systems | 506324 | Burglar Alarm Systems
--------------------------------------|-----------|------------------------
502317 - Picture Frames-Wholesale | 502317 | Picture Frames-Wholesale
This code works, but only works right if there are two -'s and some cells may have 1, 2 or 3 -'s
UPDATE test_tbl_1
SET sic_num = SUBSTRING_INDEX(`sic_orig`, '-', 1),
sic_desc = SUBSTRING_INDEX(`sic_orig`, '-', -2);
How do I split everything before first - and everything after first -?
One method is to use the length of the first part and use that for substr():
UPDATE test_tbl_1
SET sic_num = SUBSTRING_INDEX(`sic_og`, '-', 1),
sic_desc = SUBSTR(sig_og, CHAR_LENGTH(SUBSTRING_INDEX(`sic_og`, '-', 1)) + 1) ;
You can use a combination of SUBSTR() and LOCATE() function to help you slice the string:
UPDATE test_tbl_1
SET sic_num = SUBSTR(sig_orig, 1, LOCATE('-', sig_orig) - 1),
sic_desc = SUBSTR(sig_orig, LOCATE('-', sig_orig) + 1) ;
Click here for MySQL string functions.
Another alternative is to get a count of the dashes in the string. We can get a count of the number of dash characters by doing a replacement of all dash characters with an empty string, and then subtracting the length from the length of the original string.
As a demonstration:
SELECT `sic_orig`
, CHAR_LENGTH(`sic_orig`)-CHAR_LENGTH(REPLACE(`sic_orig`,'-','')) AS cnt_dashes
FROM ( SELECT '509406 - Jewelers-Wholesale ' AS sic_orig
UNION ALL SELECT '506324 - Burglar Alarm Systems'
UNION ALL SELECT '502317 - Picture Frames-Wholesale'
UNION ALL SELECT ' la di dah no dashes '
) t
returns:
sic_orig cnt_dashes
------------------------------------- ----------
509406 - Jewelers-Wholesale 2
506324 - Burglar Alarm Systems 1
502317 - Picture Frames-Wholesale 2
lots-of - -dashes- --everywhere-- -- 10
zero dashes 0
We can use the expression that returns the count of dashes as the third argument of SUBSTRING_INDEX, multiplying by negative 1 to get a a negative value...
SELECT `sic_orig`
, TRIM(
SUBSTRING_INDEX(`sic_orig`,'-'
, 1
)
) AS before_first_dash
, TRIM(
SUBSTRING_INDEX(`sic_orig`,'-'
, -1*(CHAR_LENGTH(`sic_orig`)-CHAR_LENGTH(REPLACE(`sic_orig`,'-','')))
)
) AS after_first_dash
FROM ( SELECT '509406 - Jewelers-Wholesale ' AS sic_orig
UNION ALL SELECT '506324 - Burglar Alarm Systems'
UNION ALL SELECT '502317 - Picture Frames-Wholesale'
UNION ALL SELECT 'lots-of - -dashes- - -every-where-'
UNION ALL SELECT ' zero dashes '
) t
returns:
sic_orig before_first_dash after_first_dash
--------------------------------- ----------------- ----------------------
509406 - Jewelers-Wholesale 509406 Jewelers-Wholesale
506324 - Burglar Alarm Systems 506324 Burglar Alarm Systems
502317 - Picture Frames-Wholesale 502317 Picture Frames-Wholesale
lots-of - -dashes- - -every-where- lots of - -dashes- - -every-where-
zero dashes zero dashes
The extra line breaks and formatting is intended to make deciphering the expressions easier, making sure parens balance, etc.
I always test my expressions with a SELECT statement first, before I put those expressions into an UPDATE statement.
I want to convert feet and inches to centimeters format
Format in my DB is:
4'6" (4 feet, 6 inches)
Formula for converting into centimeters
4*30.48 = 121.92 (convert feet to centimeters = multiply by 30.48)
6*2.54 = 15.24 (convert inches to centimeters = multiply by 2.54)
So Result = 121.92 + 15.24 = 137.16 cm
eg:
Actual Table: inches
SELECT * FROM inches
id height
1 4'6"
2 4'7"
3 5'8"
4 5'9"
I expect the following result as centimeters when I do SQL query
id height
1 137.16
2 139.7
3 172.72
4 175.26
Thanks in advance :)
Probably far easier to do on the application level, but if you really had to, you could do it in SQL like this, using the SUBSTR and INSTR functions, and some basic math:
SET #height = '4''6"';
SELECT
SUBSTR(#height, 1, INSTR(#height, '''') - 1) * 12 * 2.54 +
SUBSTR(#height, INSTR(#height, '''') + 1, INSTR(#height, '"') - INSTR(#height, '''') - 1) * 2.54;
-- yields 137.16
Or, applied to your table structure:
SELECT id,
SUBSTR(height, 1, INSTR(height, '''') - 1) * 12 * 2.54 +
SUBSTR(height, INSTR(height, '''') + 1, INSTR(height, '"') - INSTR(height, '''') - 1) * 2.54 AS height
FROM inches;
Application side process will be better,
However,
SELECT
(CAST(SUBSTR(height,1, LOCATE("'",height)-1) AS UNSIGNED) * 30.48) +
(CAST(SUBSTR(height, LOCATE("'",height)+1) AS UNSIGNED) * 2.54 ) AS cm
FROM
inches;