Re: [R] (no subject)

2018-07-10 Thread Werning, Jan-Philipp

Hi,

thanks a lot! Now it works.

Yours

Jan

Am 10.07.2018 um 09:00 schrieb PIKAL Petr 
mailto:petr.pi...@precheza.cz>>:

Hi

see in line

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Werning, Jan-
Philipp
Sent: Monday, July 9, 2018 9:42 PM
To: r-help@r-project.org<mailto:r-help@r-project.org>
Subject: [R] (no subject)

Dear all,


In the end I try to run a system dynamics simulation in R using the package
deSolve.
Therefore I need an auxiliary list (auxs) the model can refer to when it the
functions need an auxiliary value.

I used a manual list:

auxs <- c( aSplitSN=0.4 , aSplitLN=0.6, aSplitSR1=0 , aSplitLR1=1, aSplitSR2=0 ,
aSplitLR2=1, aSplitSR3=0 , aSplitLR3=1, aSalesNR=0.92, aSalesRR=0.08, […])

This is vector not list.
auxs <- c( aSplitSN=0.4 , aSplitLN=0.6, aSplitSR1=0 , aSplitLR1=1, aSplitSR2=0)
is.vector(auxs)
[1] TRUE
is.list(auxs)
[1] FALSE


this way everything worked well.

Now I want to use a matrix with different values for each of the auxiliaries in
order to run different scenarios. Therefore I created a csv document wich I read
in:

csv1  <- read.csv("180713_Taguchi Robust Design Test_180709_1745.csv", sep
= ";")

list_csv <- csv1[1,]

which is probably data frame

test<-vec[1,]
is.vector(test)
[1] FALSE
is.list(test)
[1] TRUE
is.data.frame(test)
[1] TRUE



namesauxs <- names(list_csv)

auxs1 <- as.numeric(list_csv)

names(auxs1) <- namesauxs

auxs <- auxs1


Looking at the global environment section in R studio, now both are the same,
in the value section as "Numed num"

I do not know rstudio but you could check two objects by
?identical


Yet, the model will not run using these values ultimately coming from the csv.

I wonder why do you use as.numeric in the first instance. You coud use

auxs1 <- unlist(csv1[1,])
and you should get named numeric vector. Maybe there are problems when reading 
numbers from csv file. You could check it e.g. by

str(auxs1)


What am I doing wrong here?

It would be great if you could help.

Thanks a lot in advance

Yours

Jan





[[alternative HTML version deleted]]

__
R-help@r-project.org<mailto:R-help@r-project.org> mailing list -- To 
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] (no subject)

2018-07-09 Thread Werning, Jan-Philipp
Dear all,


In the end I try to run a system dynamics simulation in R using the package 
deSolve.
Therefore I need an auxiliary list (auxs) the model can refer to when it the 
functions need an auxiliary value.

I used a manual list:

auxs <- c( aSplitSN=0.4 , aSplitLN=0.6, aSplitSR1=0 , aSplitLR1=1, aSplitSR2=0 
, aSplitLR2=1, aSplitSR3=0 , aSplitLR3=1, aSalesNR=0.92, aSalesRR=0.08, […])

this way everything worked well.

Now I want to use a matrix with different values for each of the auxiliaries in 
order to run different scenarios. Therefore I created a csv document wich I 
read in:

csv1  <- read.csv("180713_Taguchi Robust Design Test_180709_1745.csv", sep = 
";")

list_csv <- csv1[1,]

namesauxs <- names(list_csv)

 auxs1 <- as.numeric(list_csv)

 names(auxs1) <- namesauxs

 auxs <- auxs1


Looking at the global environment section in R studio, now both are the same, 
in the value section as "Numed num"

Yet, the model will not run using these values ultimately coming from the csv.

What am I doing wrong here?

It would be great if you could help.

Thanks a lot in advance

Yours

Jan





[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] DeSolve Package and Moving Average

2017-11-29 Thread Werning, Jan-Philipp
Dear all,


I am using the DeSolve Package to simulate a system dynamics model. At the 
problematic point in the model, I basically want to decide how many products 
shall be produced to be sold. In order to determine the amount a basic 
forecasting model of using the average of the last 12 time periods shall be 
used. My code looks like the following.

“ […]

# Time units in month
START<-0; FINISH<-120; STEP<-1

# Set seed for reproducability

 set.seed(123)

# Create time vector
simtime  <- seq(START, FINISH, by=STEP)

# Create a stock vector with initial values
stocks   <- c([…])

# Create an aux vector for the fixed aux values
auxs<- c([…])


model <- function(time, stocks, auxs){
  with(as.list(c(stocks, auxs)),{

[… “lots of aux, flow, and stock functions” … ]


aMovingAverage  <-  
ifelse(exists("ResultsSimulation")=="FALSE",1,movavg(ResultsSimulation$TotalSales,
 12, type = "s”))


return (list(c([…]))

  })
}

# Call Solver, and store results in a data frame
ResultsSimulation <-  data.frame(ode(y=stocks, times=simtime, func = model,
  parms=auxs, method="euler"))

[…]”

My problem is, that the moving average (function: movavg) is only computed once 
and the same value is used in every timestep of the model. I.e. When running 
the model for the first time, 1 is used, running it for the next time the 
total sales value of the first timestep is used. Since only one timestep 
exists, this is logical. Yet  I would expect the movavg function to produce a 
new value in each of the 120 timesteps, as it is the case with all other flow, 
stock and aux calculations as well.

It would be great if you could help me with fixing this problem.


Many thanks in advance!

Yours,

Jan





[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.