How to automate plotting a certain set of values after simulation in OMEdit? - plot

I have built a fairly complex model using OMEdit. To post-process, I want to generate a set of plots (<5) with a different number of quantities (~5) plotted in each plot.
So far, I did this using the Plotting view in OMEdit. However, doing this time and time again, with the mouse, after every start of OMEdit, gets tedious very quickly, so I want to automate this.
Is there a way to programmatically define (e.g. with an experiment annotation) a set of plots belonging to a certain model, which get generated/refreshed after every simulation of said model, or at least by the click of one button or running of one script? Do I have to write a .mos script, and if yes, how do I best run that from within OMEdit?

There is no standard experiment annotation for it but we could have OpenModelica specific annotation to make it work.
But you don't have to select the plots every time. You only need to do it once.
- Simulate your model
- Select the plots
- Update your model
- Simulate again
- The existing plots will be automatically updated to the new values.

Related

perform calculation on more than one series using kibana TSVB

I using open distro kibana in order to show up some visuals,
I am using TSVB in order to perform some KPIs,
the issue that I wan to do some calculation on two indexes therefore I have created two series and done the calculation for each one like the below image
what I need is two get the average on those two series ... any idea or advice ...thanks in advance.

Tableau to R connection - script_real returning rounded fraction numbers

I'm pretty new to Tableau but have a lot of experience with R. Everytime I use SCRIPT_REAL to call an R function based on Tableau aggregates, I get back a number that seems to be like the closest fraction approximation. For example if raw R gives me .741312, Tableau will spit out .777778, and so on. Does anything have any experience with this issue?
I'm pretty sure this is an aggregation issue.
From the Tableau and R Integration post by Jonathan Drummey on their community site:
Using Every Row of Data - Disaggregated Data For accurate results
for the R functions, sometimes those R functions need to be called
with every row in the underlying data. There are two solutions to
this:
Disaggregate the measures using Analysis->Aggregate Measures->Off. This doesn’t actually cause the measures to stop their
aggregations, instead it tells Tableau to return every row in the data
without aggregating by the dimensions on the view (which gives the
wanted effect). Using this with R scripts can get the desired results,
but can cause problems for views that we want to have R work on the
non-aggregated data and then display the data with some level of
aggregation.
The second solution deals with this situation: Add a
dimension such as a unique Row ID to the view, and set the Compute
Using (addressing) of the R script to be along that dimension. If
we’re doing some sort of aggregation with R, then we might need to
reduce the number of values returned by filtering them out with
something like:
IF FIRST()==0 THEN SCRIPT_REAL('insert R script here') END
If we need to then perform additional aggregations on that
data, we can do so with table calculations with the appropriate
Compute Usings that take into account the increased level of detail in
the view.

Control number of cr.plot in one grid

I have some troubles with the function cr.plot.
Here I attach my problem:
-First I run glm model with one dependent variable (Slope) and three independent (CPUEintra, Max.T, and Depth)
MODEL1<-glm(Slope~CPUEintra+Max.T.+Depth,data = na.omit(wiser_perc))
-Second I run the command cr.plot() to obtain each graph related to independent variables
cr.plots(MODEL1,line=TRUE,smooth=FALSE,grid=FALSE,
col.lines="black",cex.lab=1.4,font.lab="2",cex.axis=1.5,ylab="Roach",lwd=3)
The output automatically show me three residual plots in accordance to number of independent variables.
What I want is to control the number of cr.plot in one grid but it seems that the command par() does not work in cr.plots. Do you know any other command or solution for handling the number of cr.plots?
Thank you very much for your time!
As mentioned above, cr.plots is depreicated in the car package. You may want to run update.packages("car") to get the latest version.
The "updated" version crPlots has a layout= parameter that allows you to control the number of rows and columns for the grid where the plots are drawn.

Setting options of runjags plots

I am trying to run JAGS using the runjags package and produce customized plots - change colors of the chains (the full model code is in the question https://stats.stackexchange.com/q/62006/5509):
require("runjags")
out2 <- run.jags("Poisson.OD.t.test.txt", params, win.data, nc, inits,
nb*4/5, ni, nb*1/5)
plot(out2, layout = c(4, 2))
But it seems impossible to change the plot parameters. In
?runjagsclass they write:
The plot method produces trace and density plots (note that these are
pre-plotted and stored inside the runjags object, so the usual options
to lattice or plot functions are not available).
This seems that the plots are already made in the run.jags call! But that does not seem to allow to change the plot options as well.
Questions:
How to change the plot parameters, like chain colors?
Why do they create plots in the run.jags already? Usually well designed application will separate the logic (model computation) and the outputs. Is there any special reason for that?
Usually the largest elements of a runjags class object are the data and RNG states required to continue the model as it is. Unless these are stored inside the class, there isn't a way to continue this where it left off without requiring additional arguments. However, when you have monitored a large number of variables, sometimes the pre-fabricated plots are also quite large - in these cases you can get rid of all the plots (and associated storage problems) by specifying plots=FALSE to the original run.jags() call. Or, you can strip the runjags object down to a bare-bones MCMC list object using (as you might expect) as.mcmc.list().
So to answer your questions:
1) Use as.mcmc.list() first and then use whatever specific plots on these chains you want to
2) The design decision I made at the time was to pre-create all of these plots (on thinned MCMC chains to minimise storage issues) so that the time required to print them was reduced, and so that the convergence diagnostic plots that I typically want to look at quickly are easily at hand. These weren't really (as stated in the help file) intended to be used for anything other than convergence diagnostics. In the future I may look at alternative ways of generating the plots on the fly (using the existing S3 methods), as the code that stores the plots is very old and probably outdated, but it will always be a compromise of speed vs storage. For my purposes, speed nearly always wins out (I'm impatient).

Shiny - Efficient way to use ggplot2(boxplot) & a 'reactive' subset function

I have a dataset with > 1000K rows and 5 columns. (material & prices been the relevant columns)
I have written a 'reactive' Shiny app which uses ggplot2 to create a boxplot of the price of the various materials.
e.g the user selects 4-5 materials from a list and then Shiny creates a boxplot of the price of each material :
Price spread of: Made of Cotton, Made of Paper, Made of Wood
It also creates a material combination data plot of the pricing spread of the combination of all the materials
e.g Boxplot of
Price spread of: Made of Cotton & Paper & Wood
It is working relatively quickly for the sample dataset (~5000 rows) but I am worried about scaling it effectively.
The dataset is static so I look at the following solutions:
Calculate the quartile ranges of the various materials (data <-
summary(data)) and then use googleViz to create a candle stick,
however I run into problems when trying to calculate the material combination plot as there are over 100 materials, so calculating
all the possible combinations offline is not feasible.
Calculate the quartile ranges of the various materials (data <- summary(data)) and then create a matrix which stores the row numberof the summary data (min,median,max,1st&3rd quartile) for each material. I can then use some rough calculations to establish the summary() data for the material combination plot,
and then plot using GoogleVIZ however I have little experience with this type of calculation using Shiny.
Can anyone suggest the most robust and scalable way to calculate & boxplot reactive subsets using Shiny?
I understand this a question related to method, rather than code, but I am new to the capabilities of R and am still digesting the different class capabilities, and don't want to 'miss a trick' so to speak.
As always thanks!
Please see below for methods reviewed.
Quartile Clustering: A quartile based technique for Generating Meaningful Clusters
http://arxiv.org/ftp/arxiv/papers/1203/1203.4157.pdf
Conditionally subsetting and calculating a new variable in dataframe in shiny
If you really have a dataset that has more than 1000K, which is 1M. It is probably in a flat file or in a database. You can always do some precalculations and store the result in a database table and use shiny app to call that table instead of loading everything into R every time people open up your shiny app.
I have built several shiny apps for internal use and the lesson I have learned is that: before you build your app, you need to carefully think about, how can I minimize the calculations for R and at the same time deliver the info to app user. Some of our data is 10billion+ and use Hive query will take more than 1 hour. Then I ended up precalculate result and put it on the crontab to update the result table every midnight.
I prefer, maybe your method2? or store the precalculation in a mysql database. (Maybe a Python script update the table once a day if you need some real-time feature later).

Resources