How to fix the 'expected right parenthesis' happening in the 4th line : tau0*(t[j+1]-t[j]) in winbugs - parentheses

I need to estimate four parameters using winbugs: tau[i], mu1[i],mu2[i]and tau0[i].
When I click check the model, it shows expected right parenthesis between tau0* and (t[j+1]-t[j]) in the 4th line.
When I delete the (t[j+1]-t[j]), it shows the same expected right parenthesis between c and <-(1-step( tau[i]-t[j]))
model
{
#likelihood
for(i in 1:n){
for(j in 1:m){
x[i,j]~ dnorm( mu[i,j], tau0*(t[j+1]-t[j]))
mu[i,j]<- mu1*(t[j+1]-t[j])*a+mu1*(tau[i]-t[j])*b+mu2*(t[j+1]-tau[i])*b+mu2*(t[j+1]-t[j])*c
sigma <-1/sqrt(tau0)
a<-step( tau[i]-t[ j+1] )
b<-(step(tau[i]- t[j])-(step(tau[i]- t[j+1]))
c<-(1-step( tau[i]-t[j]))
}
#prior
tau[i]~dnorm(mutau,tautau)
mutau~dorm(0, 0.001)
tautau~dgamma(0.01, 0.01)
sigmatau<-1/sqrt(tautau)
mu1[i]~dnorm(mumu1, tau1)
mumu1~dorm(0, 0.001)
tau1~dgamma(0.01,0.01)
sigmatau1<-1/sqrt(tau1)
mu2[i]~dnorm(mumu2, tau2)
mumu2~dorm(0, 0.001)
tau2~dgamma(0.01,0.01)
sigmatau2<-1/sqrt(tau2)
tau0[i]~dgamma(alpha,beta)
sigmatau0<-1/tau0
}
}
DATA
list(n=5, m=16, mutau=0, tautau=1, mumu1=0, tau1=1, mumu2=0, tau2=1, alpha=0.01, beta=0.01 )
I expected the right model syntax

b<-(step(tau[i]- t[j])-(step(tau[i]- t[j+1]))
(
step(
tau[i]- t[j]
)
-
(
step(
tau[i]- t[j+1]
)
)
4 brackets opening, 3 brackets closing.
First bracket is not closed.

Related

Performance enhancement in DAX query

I have Power BI DAX query used in a measure. It takes longer time to execute. Can anyone please help me with this?
MEASURE FACT_CONSOL_BALANCE_OL[Measure 4] =
SWITCH (
TRUE (),
CONTAINS (
DIM_ANALYTIC_STRUCT_ACCOUNT,
DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)], "1 - CURRENT ASSETS"
), SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),
CONTAINS (
DIM_ANALYTIC_STRUCT_ACCOUNT,
DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)], "2 - NON - CURRENT ASSETS"
), SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),
SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) * -1
)
Performance Result on DAX Studio:
Can you please try this code, see if It solves your problem. I tried to write it without contains() function.
MEASURE FACT_CONSOL_BALANCE_OL[Measure 4] =
SUMX (
FACT_CONSOL_BALANCE_OL,
VAR Balance =
SWITCH (
RELATED ( DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)] ),
"1 - CURRENT ASSETS", FACT_CONSOL_BALANCE_OL[BALANCE],
"2 - NON - CURRENT ASSETS", FACT_CONSOL_BALANCE_OL[BALANCE],
FACT_CONSOL_BALANCE_OL[BALANCE] * -1
)
RETURN
Balance
)

SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: double precision > interval

So I'm using Laravel with GraphQL and PostgreSQL database.
My query is very long, but more specifically this line
selectRaw('(CASE
WHEN (COALESCE(((NULLIF((project_members.hourly_rate - last_known_user_costs.cost), 0)/NULLIF(project_members.hourly_rate, 0)) * 100),0) > (
SELECT value :: INTERVAL FROM "configuration" WHERE "key" = \'Gross Margin Per Resource Yellow\'
)) THEN \'red\'
WHEN (COALESCE(((NULLIF((project_members.hourly_rate - last_known_user_costs.cost), 0)/NULLIF(project_members.hourly_rate, 0)) * 100),0) > (
SELECT value :: INTERVAL FROM "configuration" WHERE "key" = \'Gross Margin Per Resource Green\'
)) THEN \'green\'
ELSE \'red\'
END) AS status')
when added, throws the following error:
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: double precision > interval\nLINE 2: ...t), 0)/NULLIF(project_members.hourly_rate, 0)) * 100),0) > (\n ^\nHINT: No operator matches the given name and argument types. You might need to add explicit type casts.
I don't know if I'm writing the sentence properly

What is the number after the second colon on a Google Apps Script error?

I have a Google Apps Script linked to a Sheet that takes Form responses. I'm getting this error:
I've figured out that 104 is the line number where the error occurs. What does 14 represent? Both numbers are the same every time the error occurs. For context's sake, here's some of the code:
if (Renaming) {
Debug("Renaming Began")
var Section = Values[4]
var Name = Values[5].replace(/\//g, "-").concat(" ", Values[3], "-", Values[2].substring(0, 1)) // Date, space, last name, hyphen, first initial
Debug("Renaming Files...")
DriveApp.getFileById(Documents[0]).setName(Section.concat(" Session Plan ", Name)) // Session plan naming (this is line 104)
Debug("Session Plan Renamed")
DriveApp.getFileById(Documents[1]).setName(Section.concat(" Sign-in ", Name))
Debug("Sign-in Sheet Renamed")
if (Documents.length > 2) {
Debug("Worksheets Detected")
Debug(Documents.length)
for (i = 2; Documents.length; i++) {
if (i > 13) {break}
Debug(("Began ").concat(i))
if (!Documents[i]) {continue}
Debug(("Exists ").concat(i))
DriveApp.getFileById(Documents[i]).setName(Section.concat(" Worksheet #", i - 1, " ", Name))
Debug(("Renamed ").concat(i))
}
Debug("Worksheets Renamed")
}
Debug("Renaming Completed")
} else {
Debug("Renaming Disabled")
}
Explanation:
From this expression: 104:14:
104: represents the row where the error occured.
14: represents the column where the error occured.
Column is defined as the position of each character in the document on the horizontal axis. Each symbol/space/letter/number occupies one column of space.
Example:
the error here is in the 2nd row and there are 2 spaces (columns) before the word error.
But the error starts at the letter e of the word error. So you have 2 spaces (columns) before error plus a letter which is the position where the error started. Two spaces and one letter equals to 3 columns. Therefore, you have an error that is located in the 3rd column.
In your case, the error is located at the row 104 and there are 13 symbols/spaces/letters or numbers before the command that introduces the error. Everything before column 14 is correct. The error starts at column 14.

Read and write tab-delimited text data

I have an excel output in the tab-delimited format:
temperature H2O CO2 N2 NH3
10 2.71539E+12 44374931376 7410673406 2570.560804
20 2.34216E+12 38494172272 6429230649 3148.699673
30 2.04242E+12 33759520581 5639029060 3856.866413
40 1.75491E+12 29172949817 4882467457 4724.305292
.
.
.
I need to convert these numbers to FORMAT(1X,F7.0,2X,1P4E11.3) readable for another code.
This is what I've come up with:
program fixformat
real temp, neuts(4)
integer i,j
character header
open(11,file='./unformatted.txt',status='old')
open(12,file='./formatted.txt',status='unknown')
read(11,*) header
write(12,*) header
do i = 1, 200
read(11,*) temp, (neuts(j),j=1,4)
write(12,23) temp, (neuts(j),j=1,4)
end do
23 FORMAT(1X,F7.0,2X,1P4E11.3)
close(11)
close(12)
return
end
I keep getting this error:
Fortran runtime error: Bad real number in item 1 of list input
Is there any other way to convert the data to that format?
You need a character string, not a single character for the header
character(80) header
other than that you program works for me. Make sure you have the right number of lines in your loop
Do i=1,200
Adjust 200 to the real number of your data lines.
If for some reason you still cannot read even a single line, you can also use the format:
read(11,'(f2.0,4(1x,f11.0))') temp, (neuts(j),j=1,4)
because the tab is just a character you can easily skip.
Notes:
Unformatted and formatted means something completely different in Fortran. Unformatted is what you may know as "binary".
Use some indentation and blank lines for your programs to make them readable.
There is no reason to explicitly use status=unknown. Just don't put anything there. In your case status=replace may be more appropriate.
The FORMAT statement is quite obsolete, in modern Fortran we use format strings:
write(12,'(1X,F7.0,2X,1P4E11.3)') temp, (neuts(j),j=1,4)
There is absolutely no reason for your return before the end. Returns is for early return from a procedure. Some put stop before the end program, but it is superfluous.
To read tab delimited data, I'd use a simple algorithm like the one below. NOTE: This is assuming that there is no tab character in any of your fields.
integer :: error_code, delim_index, line_index
character*500 :: data_line, field_data_string
double precision :: dp_value
Open(Unit=1001,File="C:\\MY\\PATH\\Data.txt")
DO
Read(UNIT=1001,End=106, FMT='(A)' ) data_line
line_length = LEN(TRIM(data_line))
delim_index = SCAN(data_line, achar(9) )
line_index = 0
DO WHILE ( delim_index .NE. 0 )
line_index = line_index + delim_index
IF (delim_index .EQ. 1 ) THEN ! found a NULL (no value), so skip
GOTO 101
END IF
field_data_string = data_line( (line_index-delim_index+1) : line_index )
READ( field_data_string, FMT=*, ERR=100) dp_value
PRINT *, "Is a double precision ", dp_value
GOTO 101
100 Continue
PRINT *, "Not a double precision"
101 Continue
IF ( (line_index+1) .GT. line_length ) THEN
GOTO 104 ! found end of line prematurely
END IF
delim_index = SCAN( data_line( line_index + 1 : ), achar(9) )
END DO
field_data_string = data_line( line_index + 1 : )
READ( field_data_string, FMT=*, ERR=102) dp_value
PRINT *, "Is a double precision ", dp_value
GOTO 103
102 Continue
PRINT *, "Not a double precision"
103 Continue
PRINT *, "Is a double precision ", dp_value
104 Continue
END DO
104 Continue
PRINT *, "Error opening file"
105 Continue
Close(1001)

Speed up the analysis

I have 2 dataframes in R for example df and dfrefseq.
df<-data.frame( chr = c("chr1","chr1","chr1","chr4")
, start = c(843294,4329248,4329423,4932234)
, stop = c(845294,4329248,4529423,4935234)
, genenames= c("HTA","OdX","FEA","MGA")
)
dfrefseq<-data.frame( chr = c("chr1","chr1","chr1","chr2")
, start = c(843294,4329248,4329423,4932234)
, stop = c(845294,4329248,4529423,4935234)
, genenames= c("tra","FGE","FFs","FAA")
)
I want to check for each gene in df witch gene in dfrefseq lies closest to the selected df gene.
I first selected "chr1" in both dataframes.
Then I calculated for the first gene in readschr1 the distance between start-start start-stop stop-start and stop-stop sites.
The sum of this calculations say everything about the distance. My question here is, How can I speed up this analyse? Because now I tested only 1 gene against a dataframe, but I need to test 2000 genes.
readschr1 <- subset(df,df[,1]=="chr1")
refseqchr1 <- subset(dfrefseq,dfrefseq[,1]=="chr1")
names<-list()
read_start_start<-list()
read_start_stop<-list()
read_stop_start<-list()
read_stop_stop<-list()
for (i in 1:nrow(refseqchr1)) {
startstart<-abs(readschr1[1,2] - refseqchr1[i,2])
startstop<-abs(readschr1[1,2] - refseqchr1[i,3])
stopstart<-abs(readschr1[1,3] - refseqchr1[i,2])
stopstop<-abs(readschr1[1,3] - refseqchr1[i,3])
read_start_start[[i]]<- matrix(startstart)
read_start_stop[[i]]<- matrix(startstop)
read_stop_start[[i]]<- matrix(stopstart)
read_stop_stop[[i]]<- matrix(stopstop)
names[[i]]<-matrix(refseqchr1[i,4])
}
table<-cbind(names, read_start_start, read_start_stop, read_stop_start, read_stop_stop)
sumtotalcolumns<-as.numeric(table[,2]) + as.numeric(table[,3])+ as.numeric(table[,4]) + as.numeric(table[,5])
test<-cbind(table, sumtotalcolumns)
test1<-test[order(as.vector(test$sumtotalcolumns)), ]
Thank you!
The Bioconductor package GenomicRanges is designed to work with this type of data
source('http://bioconductor.org/biocLite.R')
biocLite('GenomicRanges') # one-time installation
then
library(GenomicRanges)
gr <- with(df,
GRanges(factor(chr, levels=paste("chr", 1:4, sep="")),
IRanges(start, stop), genenames=genenames))
grrefseq <- with(dfrefseq,
GRanges(factor(chr, levels=paste("chr", 1:4, sep="")),
IRanges(start, stop), genenames=genenames))
and
> nearest(gr, grrefseq)
[1] 1 2 3 NA
You can merge the two separate data.frames together to form one table and then use vectorized operations. The key to merge is to specify the common column(s) between the data.frames and to tell it what to do when there are cases that do not match. Specifying all = TRUE will return all rows and fill in NAs if there is no match in the other data.frame, i.e. ch2 and ch4 in this case. Once the data.frames have been merged, then it's a simple exercise in subtracting the different columns from one another and then summing the four columns of interest. I use transform to cut down on the typing needed to do the subtraction.
zz <- merge(df, dfrefseq, by = "chr", all = TRUE)
zz <- transform(zz,
read_start_start = abs(start.x - start.y)
, read_start_stop = abs(start.x - stop.y)
, read_stop_start = abs(stop.x - start.y)
, read_stop_stop = abs(stop.x - stop.y)
)
zz <- transform(zz,
sum_total_columns = read_start_start + read_start_stop + read_stop_start + read_stop_stop
)
Here's one approach get the row with the minimum distance. I'm assuming you want to do this by chr and genenames. I use the plyr package, but I'm sure there are base solutions if you'd prefer one of those. Maybe someone else will chime in with a base solution.
require(plyr)
ddply(zz, c("chr", "genenames.x"), function(x) x[which.min(x$sum_total_columns) ,])

Resources