Re: [R] function doesn't exists but still runs.....

2023-01-19 Thread Bill Dunlap
Look into R's scoping rules.  E.g.,
https://bookdown.org/rdpeng/rprogdatascience/scoping-rules-of-r.html.

* When a function looks up a name, it looks it up in the environment in
which the function was defined.
* Functions in a package are generally defined in the package's environment
(although sometimes they are in a descendent of the parent's environment).
* When one searches an environment for a name, if it is not found in the
environment the search continues in the parent environment of that
environment, recursively until the parent environment is the empty
environment.

> with(environment(wdman::selenium), java_check)
function ()
{
javapath <- Sys.which("java")
if (identical(unname(javapath), "")) {
stop("PATH to JAVA not found. Please check JAVA is installed.")
}
javapath
}



-Bill

On Thu, Jan 19, 2023 at 2:28 PM akshay kulkarni 
wrote:

> dear members,
> I am using the RSelenium package which uses
> the function selenium() from the wdman package. The selenium function
> contains the function java_check at line 12. If I try to run it, it throws
> an error:
>
> >   javapath <- java_check()
> Error in java_check() : could not find function "java_check"
>
> Also:
>
> > exists("java_check")
> [1] FALSE
>
> But when I run selenium(), it works fine
>
> How do you explain this conundrum? You can refer to this link:
> https://github.com/ropensci/wdman/issues/15
>
> Specifically what concept of R explains this weird behaviour?
>
> Thanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
>
>
> [[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.
>

[[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] function doesn't exists but still runs.....

2023-01-19 Thread akshay kulkarni
dear members,
I am using the RSelenium package which uses the 
function selenium() from the wdman package. The selenium function contains the 
function java_check at line 12. If I try to run it, it throws an error:

>   javapath <- java_check()
Error in java_check() : could not find function "java_check"

Also:

> exists("java_check")
[1] FALSE

But when I run selenium(), it works fine

How do you explain this conundrum? You can refer to this link: 
https://github.com/ropensci/wdman/issues/15

Specifically what concept of R explains this weird behaviour?

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI


[[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.


Re: [R-es] Suma de datos de una tabla

2023-01-19 Thread David Camilo Gomez Medina
Muchas gracias Carlos y Manuel por el aporte, me ayudó bastante.

On Thu, 19 Jan 2023 at 04:12, Carlos Ortega 
wrote:

> Hola,
>
> Sí, he cambiado de forma de hacerlo, así lo tienes directo en un
> data.table...
> Y sale el 2000 que no sé porqué no salía antes.
>
> #-
> library(readxl)
> library(data.table)
> library(tidytable)
> library(lubridate)
>
> datos <- read_excel("PPT.xlsx") %>%
>   as.data.table() %>%
>   rename.(fecha = Fecha) %>%
>   mutate.( year = as.factor(year(ymd(fecha)) )) %>%
>   select.(-fecha) %>%
>   as.data.table()
>
> # Crear vectores con nombres de columnas y factores
> cols_to_sum <- datos %>% select.(where(is.numeric)) %>% names()
> resultado <- datos[, lapply(.SD, function(x) sum(x, na.rm = TRUE )),
> .SDcols = cols_to_sum, by = year]
> #
>
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>
> El mié, 18 ene 2023 a las 23:57, David Camilo Gomez Medina (<
> dcgome...@unal.edu.co>) escribió:
>
>> Hola Carlos, muchísimas gracias. Me sirvió muchísimo y me hiciste caer en
>> cuenta en que es mejor dejarlo en un dataframe y no en lista. Estoy
>> iniciando en esto porque manejar ese volumen de datos en Excel es muy
>> tedioso.
>>
>> Seguí tu código y lo apliqué, pero mira que no me está dando la suma de
>> manera correcta y también no me aparece el año 2000 y 2020. Adjunto una
>> captura del resultado, de cómo apliqué el código y también el archivo con
>> el que estoy trabajando.
>>
>> library(readxl)
>> library(tidyverse)
>>
>> ppt <- read_excel("PPT.xlsx")
>>
>> ppt <- transform(ppt, Fecha = as.Date(Fecha))
>>
>> ppt$year <- as.integer(format(as.Date(ppt$Fecha), "%Y"))
>>
>> result <- aggregate(. ~ year, data = ppt[, -1], sum, na.rm = T)
>>
>> Saludos,
>>
>> [image: image.png]
>>
>> On Wed, 18 Jan 2023 at 16:10, Carlos Ortega 
>> wrote:
>>
>>> Hola,
>>>
>>> De esta forma se aproxima bastante a lo que quieres...
>>>
>>> #-
>>> #--- Generar datos de forma sintética.
>>> library(dplyr)
>>>
>>> # número de sitios
>>> N <- 5
>>>
>>> # número de fechas
>>> num_dates <- 365
>>>
>>> # generar fechas para 2019, 2021 y 2022
>>> dates_2019 <- seq(as.Date("2019-01-01"), as.Date("2019-12-31"), by =
>>> "day")
>>> dates_2021 <- seq(as.Date("2021-01-01"), as.Date("2021-12-31"), by =
>>> "day")
>>> dates_2022 <- seq(as.Date("2022-01-01"), as.Date("2022-12-31"), by =
>>> "day")
>>> dates <-
>>> c(rep(dates_2019,num_dates),rep(dates_2021,num_dates),rep(dates_2022,num_dates))
>>>
>>> # generar nombres de columnas
>>> colnames <- c("fecha", paste0("Sitio_", 1:N))
>>>
>>> # generar dataframe vacío
>>> df <- data.frame(matrix(nrow = length(dates), ncol = N + 1))
>>> colnames(df) <- colnames
>>> df$fecha <- dates
>>>
>>> # generar valores aleatorios
>>> for (i in 2:(N + 1)) {
>>>   df[,i] <- rnorm(length(dates), mean = 50, sd = 10)
>>> }
>>>
>>> #- Cálculo como dataframe.
>>> df$year <- as.integer(format(as.Date(df$fecha), "%Y"))
>>> result <- aggregate(. ~ year, data=df[, -1], sum)
>>>
>>> #- Como lista...
>>> result_list <- list()
>>> # Aplicar aggregate() a cada columna de sitio
>>> agg_list <- lapply(df[,-1], function(x) aggregate(x ~ year, data =
>>> df[,-1], sum))
>>>
>>> # Aplicar split() a cada elemento de la lista de aggregate()
>>> result_list <- lapply(agg_list, function(x) split(x, x$year))
>>>
>>>
>>> Saludos,
>>> Carlos Ortega
>>> www.qualityexcellence.es
>>>
>>> El mié, 18 ene 2023 a las 20:14, David Camilo Gomez Medina (<
>>> dcgome...@unal.edu.co>) escribió:
>>>
 No sé si olvidé aclarar, pero quiero crear una lista para cada columna
 y así almacenar esos valores.

 On Wed, 18 Jan 2023 at 14:13, David Camilo Gomez Medina <
 dcgome...@unal.edu.co> wrote:

> Hola Carlos.
>
> Por ejemplo la segunda columna (16040050), quiero sumar todos los
> datos de esa columna correspondientes al año 2000 (quiero relacionarlos 
> con
> la primera columna donde está la fecha) y ese valor almacenarlo en una
> lista y así sucesivamente con los demás años y con las demás columnas.
>
> Tengo pensado una lista así:
>
> est_16040050
>
> [[2000]]
> [1] 2.3
>
> [[2001]]
> [1] 1.7
>
> [[2002]]
> [1] 4.8
>
> Quedo muy atento a sus sugerencias o guías.
>
> Saludos.
>
> On Wed, 18 Jan 2023 at 13:52, Carlos Ortega 
> wrote:
>
>> Hola,
>>
>> Por entenderlo mejor, quieres que para las filas, para cada año:
>>
>>1. se sumen las columnas y por tanto tengas tantas sumas como
>>columnas.
>>2. o sumar todas las columnas y obtener una única suma.
>>
>> Gracias,
>> Carlos Ortega
>> www.qualityexcellence.es
>>
>> El mié, 18 ene 2023 a las 19:29, David Camilo Gomez Medina (<
>> dcgome...@unal.edu.co>) escribió:
>>
>>> Hola, espero que se encuentren muy bien.
>>>
>>> Tengo una tabla de 

Re: [R] R emulation of FindRoot in Mathematica

2023-01-19 Thread Gabor Grothendieck
If the equations are in the form shown in your post then take the log of
both sides, expand the logs and replace log(whatever) with new variables so
now the equations are in linear form and are easy to solve.

__
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.


Re: [R] R emulation of FindRoot in Mathematica

2023-01-19 Thread Søren Højsgaard via R-help
Dear Troels,

Are you aware of the caracas package for computer algebra in R? The package 
provides an interface to the SymPy package in python via the reticulate package.

I have no idea if the package can be helpful in your connection, but please 
report succeses and failures back.

Best regards
Søren

-Original Message-
From: Troels Ring 
mailto:troels%20ring%20%3ctr...@gvdnet.dk%3e>>
To: Jeff Newmiller 
mailto:jeff%20newmiller%20%3cjdnew...@dcn.davis.ca.us%3e>>,
 r-help@r-project.org, "Ebert,Timothy Aaron" 
mailto:%22Ebert,timothy%20aaron%22%20%3cteb...@ufl.edu%3e>>, 
Valentin Petzel 
mailto:valentin%20petzel%20%3cvalen...@petzel.at%3e>>
Subject: Re: [R] R emulation of FindRoot in Mathematica
Date: Thu, 19 Jan 2023 16:18:57 +0100


Hi Jeff - that is definitely not fair, this is a highly respected

scientist but old me are probably not clever enough to explain problem

which I think is not too difficult. Basically, it is a series of

consecutive statements of H and Mg and K combining to ATP and ADP,

creatin and creatinP under assumption og known total inorganic phosphate

(pi), total ATP total ADP, creatin and creatinphosphate. It was written

in 1997 when R was less mature - and if we know how to do it in R so not

to depend on black box operations it would be fun. For the moment, I'm

not even sure I understand why there is now focus on the problem being

nonlinear, since I want to evaluate at given H or pH.  hatp <- 10^6.494

* H * ATP ?


BW Troels



Den 19-01-2023 kl. 15:54 skrev Jeff Newmiller:

But it is simultaneously an example of why some researchers like black box 
solvers... a system of dozens of nonlinear equations can potentially have many 
or even infinite solutions. If the researcher is weak in math, they may have no 
idea which solutions are possible and having a tool like FindRoot confidently 
return a solution lets them focus on other things. Sort of like ChatGPT.


TL;DR the author may have no idea about how to resolve this without relying on 
the opaque FindRoot.


On January 19, 2023 6:28:53 AM PST, "Ebert,Timothy Aaron" <



teb...@ufl.edu

> wrote:

This is a poster child for why we like open source software. "I dump numbers 
into a black box and get numbers out but I cannot verify how the numbers out 
were calculated so they must be correct" approach to analysis does not really 
work for me.

Tim


-Original Message-

From: R-help <



r-help-boun...@r-project.org

> On Behalf Of Troels Ring

Sent: Thursday, January 19, 2023 9:18 AM

To: Valentin Petzel <



valen...@petzel.at

>; r-help mailing list <



r-help@r-project.org

>

Subject: Re: [R] R emulation of FindRoot in Mathematica


[External Email]


Thanks,   Valentin for the suggestion. I'm not sure I can go that way. I

include below the statements from the paper containing the knowledge on the 
basis of which I would like to know at specified [H] the concentration of each 
of the many metabolites given the constraints. I have tried to contact the 
author to get the full code but it seems difficult.


BW Troels



hatp <- 10^6.494*H*atp

hhatp <- 10^3.944*H*hatp

hhhatp <- 10^1.9*H*hhatp

atp  <- 10*H*hhhatp

mgatp <- 10^4.363*atp*mg

mghatp <- 10^2.299*hatp*mg

mg2atp <- 10^1-7*mg*mgatp

katp <- 10^0.959*atp*k


hadp <- 10^6.349*adp*H

hhadp <- 10^3.819*hadp*H

hhhadp <- 10*H*hhadp

mgadp <- 10^3.294*mg*adp

mghadp <- 10^1.61*mg*hadp

mg2adp <- 10*mg*mgadp

kadp <- 10^0.82*k*adp


hpi <- 10^11.616*H*pi

hhpi <- 10^6.7*h*hpi

hhhpi <- 10^1.962*h*hhpi

mgpi <- 10^3.4*mg*pi

mghpi <- 10^1.946*mg*hpi

mghhpi <- 10^1.19*mg*hhpi

kpi <- 10^0.6*k*pi

khpi <- 10^1.218*k*hpi

khhpi <- 10^-0.2*k*hhpi


hpcr <- 10^14.3*h*pcr

hhpcr <- 10^4.5*h*hpcr

hhhpcr <- 10^2.7*h*hhpcr

pcr <- 100*h*hhhpcr

mghpcr <- 10^1.6*mg*hpcr

kpcr <- 10^0.74*k*pcr

khpcr <- 10^0.31*k*hpcr

khhpcr <- 10^-0.13*k*hhpcr


hcr <- 10^14.3*h*cr

hhcr <- 10^2.512*h*hcr


hlactate <- 10^3.66*h*lactate

mglactate <- 10^0.93*mg*lactate


tatp <- atp + hatp + hhatp + hhhatp + mgatp + mghatp + mg2atp + katp


tadp <- adp + hadp + hhadp + hhhadp + mghadp + mgadp + mg2adp + kadp


tpi <- pi + hpi + hhpi + hhhpi + mgpi + mghpi + mghhpi + kpi + khpi + khhpi


tpcr <- pcr + hpcr + hhpcr + hhhpcr + pcr + mghpcr + kpcr + khpcr + khhpcr


tcr <- cr + hcr + hhcr


tmg <- mg + mgatp + mghatp + mg2atp + mgadp + mghadp + mg2adp + mgpi + kghpi + 
mghhpi +

   mghpcr + mglactate


tk <- k + katp + kadp + kpi + khpi + khhpi + kpcr + khpcr + khhpcr


tlactate <- lactate + hlactate + mglactate


# conditions


tatp <- 0.008

tpcr <- 0.042

tcr <- 0.004

tadp <- 0.1

tpi <- 0.003

tlactate <- 0.005


# free K and Mg constrained to be fixed

#

mg <- 0.0006

k <- 0.12


Den 19-01-2023 kl. 12:11 skrev Valentin Petzel:

Hello Troels,



As fair as I understand you attempt to numerically solve a system of

non 

Re: [R] MLE Estimation of Gamma Distribution Parameters for data with 'zeros'

2023-01-19 Thread Ken Kleinman
There's at least one package that can do zero-inflated gamma regression
(Rfast2::zigamma).  I'm not sure it's ML, though.


On Thu, Jan 19, 2023 at 10:17 AM Jeff Newmiller 
wrote:

> Beware of adding a constant... the magnitude of the constant used can have
> an outsized impact on the answer obtained. See e.g.
> https://gist.github.com/jdnewmil/99301a88de702ad2fcbaef33326b08b4
>
> On January 19, 2023 3:49:29 AM PST, peter dalgaard 
> wrote:
> >Not necessarily homework, Bert. There's a generic issue with MLE and
> rounded data, in that gamma densities may be 0 at the boundary but small
> numbers are represented as 0, making the log-likelihood -Inf.
> >
> >The cleanest way out is to switch to a discretized distribution in the
> likelihood, so that instead of log(dgamma(0,...)) you use
> log(pgamma(.005,..) - pgamma(0,...)) == pgamma(.005,..., log=TRUE). (For
> data rounded to nearest .01, that is). Cruder techniques would be to just
> add, like, .0025 to all the zeros.
> >
> >-pd
> >
> >> On 10 Jan 2023, at 18:42 , Bert Gunter  wrote:
> >>
> >> Is this homework? This list has a no-homework policy.
> >>
> >>
> >> -- Bert
> >>
> >> On Tue, Jan 10, 2023 at 8:13 AM Nyasha 
> wrote:
> >>>
> >>> Please how can one go about this one? I don't know how to go about it.
> >>>
> >>>[[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-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.
> >
>
> --
> Sent from my phone. Please excuse my brevity.
>
> __
> 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.
>

[[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.


Re: [R] R emulation of FindRoot in Mathematica

2023-01-19 Thread Berend Hasselman


If you need to solve a nonlinear system of equations you could have a look at 
the 
CRAN Task View: Numerical Mathematics:   
https://cran.r-project.org/view=NumericalMathematics

Specifically look in the subsection "Root Finding and Fixed Points".


Berend Hasselman

> On 19 Jan 2023, at 10:41, Troels Ring  wrote:
> 
> Hi friends - I hope this is not a misplaced question. From the literature 
> (Kushmerick AJP 1997;272:C1739-C1747) I have a series of Mathematica 
> equations which are solved together to yield over different pH values the 
> concentrations of metabolites in skeletal muscle using the Mathematica 
> function FindRoot((E1,E2...),(V2,V2..)] where E is a list of equations and V 
> list of variables.  Most of the equations are individual binding reactions of 
> the form 10^6.494*atp*h == hatp and next 10^9.944*hatp*h ==hhatp describing 
> binding of singe protons or Mg or K to ATP or creatin for example, but we 
> also have constraints giving total concentrations of say ATP i.e. ATP + ATPH, 
> ATPH2..ATP.Mg
> 
> I have, without success, tried to find ways to do this in R - I have 36 
> equations on 36 variables and 8 equations on total concentrations. As far as 
> I can see from the definition of FindRoot in Wolfram, Newton search or secant 
> search is employed.
> 
> I'm on Windows R 4.2.2
> 
> Best wishes
> Troels Ring, MD
> Aalborg, Denmark
> 
> __
> 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-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.


Re: [R] MLE Estimation of Gamma Distribution Parameters for data with 'zeros'

2023-01-19 Thread Marc Girondot via R-help
Another situation for the presence of 0 is about dosage when 
concentration is below the detection limit. It is not necessary to 
discretize the data. We propose a method here:
Salvat-Leal I, Cortés-Gómez AA, Romero D, Girondot M (2022) New method 
for imputation of unquantifiable values using Bayesian statistics for a 
mixture of censored or truncated distributions: Application to trace 
elements measured in blood of olive ridley sea turtles from mexico. 
Animals 2022: 2919 doi 10.3390/ani12212919

with R code.
If the data has "true" 0, the gamma distribution is not the best choice 
as 0 is impossible with gamma distribution.


Marc

Le 19/01/2023 à 12:49, peter dalgaard a écrit :

Not necessarily homework, Bert. There's a generic issue with MLE and rounded 
data, in that gamma densities may be 0 at the boundary but small numbers are 
represented as 0, making the log-likelihood -Inf.

The cleanest way out is to switch to a discretized distribution in the 
likelihood, so that instead of log(dgamma(0,...)) you use log(pgamma(.005,..) - 
pgamma(0,...)) == pgamma(.005,..., log=TRUE). (For data rounded to nearest .01, 
that is). Cruder techniques would be to just add, like, .0025 to all the zeros.

-pd


On 10 Jan 2023, at 18:42 , Bert Gunter  wrote:

Is this homework? This list has a no-homework policy.


-- Bert

On Tue, Jan 10, 2023 at 8:13 AM Nyasha  wrote:

Please how can one go about this one? I don't know how to go about it.

[[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-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-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.


Re: [R] R emulation of FindRoot in Mathematica

2023-01-19 Thread Troels Ring
Hi Jeff - that is definitely not fair, this is a highly respected 
scientist but old me are probably not clever enough to explain problem 
which I think is not too difficult. Basically, it is a series of 
consecutive statements of H and Mg and K combining to ATP and ADP, 
creatin and creatinP under assumption og known total inorganic phosphate 
(pi), total ATP total ADP, creatin and creatinphosphate. It was written 
in 1997 when R was less mature - and if we know how to do it in R so not 
to depend on black box operations it would be fun. For the moment, I'm 
not even sure I understand why there is now focus on the problem being 
nonlinear, since I want to evaluate at given H or pH.  hatp <- 10^6.494 
* H * ATP ?


BW Troels


Den 19-01-2023 kl. 15:54 skrev Jeff Newmiller:

But it is simultaneously an example of why some researchers like black box 
solvers... a system of dozens of nonlinear equations can potentially have many 
or even infinite solutions. If the researcher is weak in math, they may have no 
idea which solutions are possible and having a tool like FindRoot confidently 
return a solution lets them focus on other things. Sort of like ChatGPT.

TL;DR the author may have no idea about how to resolve this without relying on 
the opaque FindRoot.

On January 19, 2023 6:28:53 AM PST, "Ebert,Timothy Aaron"  
wrote:

This is a poster child for why we like open source software. "I dump numbers into a 
black box and get numbers out but I cannot verify how the numbers out were calculated so 
they must be correct" approach to analysis does not really work for me.
Tim

-Original Message-
From: R-help  On Behalf Of Troels Ring
Sent: Thursday, January 19, 2023 9:18 AM
To: Valentin Petzel ; r-help mailing list 

Subject: Re: [R] R emulation of FindRoot in Mathematica

[External Email]

Thanks,   Valentin for the suggestion. I'm not sure I can go that way. I
include below the statements from the paper containing the knowledge on the 
basis of which I would like to know at specified [H] the concentration of each 
of the many metabolites given the constraints. I have tried to contact the 
author to get the full code but it seems difficult.

BW Troels


hatp <- 10^6.494*H*atp
hhatp <- 10^3.944*H*hatp
hhhatp <- 10^1.9*H*hhatp
atp  <- 10*H*hhhatp
mgatp <- 10^4.363*atp*mg
mghatp <- 10^2.299*hatp*mg
mg2atp <- 10^1-7*mg*mgatp
katp <- 10^0.959*atp*k

hadp <- 10^6.349*adp*H
hhadp <- 10^3.819*hadp*H
hhhadp <- 10*H*hhadp
mgadp <- 10^3.294*mg*adp
mghadp <- 10^1.61*mg*hadp
mg2adp <- 10*mg*mgadp
kadp <- 10^0.82*k*adp

hpi <- 10^11.616*H*pi
hhpi <- 10^6.7*h*hpi
hhhpi <- 10^1.962*h*hhpi
mgpi <- 10^3.4*mg*pi
mghpi <- 10^1.946*mg*hpi
mghhpi <- 10^1.19*mg*hhpi
kpi <- 10^0.6*k*pi
khpi <- 10^1.218*k*hpi
khhpi <- 10^-0.2*k*hhpi

hpcr <- 10^14.3*h*pcr
hhpcr <- 10^4.5*h*hpcr
hhhpcr <- 10^2.7*h*hhpcr
pcr <- 100*h*hhhpcr
mghpcr <- 10^1.6*mg*hpcr
kpcr <- 10^0.74*k*pcr
khpcr <- 10^0.31*k*hpcr
khhpcr <- 10^-0.13*k*hhpcr

hcr <- 10^14.3*h*cr
hhcr <- 10^2.512*h*hcr

hlactate <- 10^3.66*h*lactate
mglactate <- 10^0.93*mg*lactate

tatp <- atp + hatp + hhatp + hhhatp + mgatp + mghatp + mg2atp + katp

tadp <- adp + hadp + hhadp + hhhadp + mghadp + mgadp + mg2adp + kadp

tpi <- pi + hpi + hhpi + hhhpi + mgpi + mghpi + mghhpi + kpi + khpi + khhpi

tpcr <- pcr + hpcr + hhpcr + hhhpcr + pcr + mghpcr + kpcr + khpcr + khhpcr

tcr <- cr + hcr + hhcr

tmg <- mg + mgatp + mghatp + mg2atp + mgadp + mghadp + mg2adp + mgpi + kghpi + 
mghhpi +
   mghpcr + mglactate

tk <- k + katp + kadp + kpi + khpi + khhpi + kpcr + khpcr + khhpcr

tlactate <- lactate + hlactate + mglactate

# conditions

tatp <- 0.008
tpcr <- 0.042
tcr <- 0.004
tadp <- 0.1
tpi <- 0.003
tlactate <- 0.005

# free K and Mg constrained to be fixed
#
mg <- 0.0006
k <- 0.12

Den 19-01-2023 kl. 12:11 skrev Valentin Petzel:

Hello Troels,


As fair as I understand you attempt to numerically solve a system of
non linear equations in multiple variables in R. R does not provide
this functionality natively, but have you tried multiroot from the
rootSolve package:


https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcran
.r-project.org%2Fweb%2Fpackages%2FrootSolve%2FrootSolve.pdf=05%7C
01%7Ctebert%40ufl.edu%7C7cb98cd926b34284cd5f08dafa28026c%7C0d4da0f84a3
14d76ace60a62331e1b84%7C0%7C0%7C638097347110882622%7CUnknown%7CTWFpbGZ
sb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3
D%7C3000%7C%7C%7C=D9A3fwJ5x7GbEV4A01wncLUil7szTdSPul5vd0lsSBw%3D
=0


multiroot is called like


multiroot(f, start, ...)


where f is a function of one argument which is a vector of n values
(representing the n variables) and returning a vector of d values
(symbolising the d equations) and start is a vector of length n.


E.g. if we want so solve


x^2 + y^2 + z^2 = 1

x^3-y^3 = 0

x - z = 0


(which is of course equivalent to x = y = z, x^2 + y^2 + z^2 = 1, so x
= y = z = ±sqrt(1/3) ~ 0.577)


we'd enter


f <- function(x) c(x[1]**2 + x[2]**2 + x[3]**2 - 1, x[1]**3 - 

Re: [R] MLE Estimation of Gamma Distribution Parameters for data with 'zeros'

2023-01-19 Thread Jeff Newmiller
Beware of adding a constant... the magnitude of the constant used can have an 
outsized impact on the answer obtained. See e.g. 
https://gist.github.com/jdnewmil/99301a88de702ad2fcbaef33326b08b4

On January 19, 2023 3:49:29 AM PST, peter dalgaard  wrote:
>Not necessarily homework, Bert. There's a generic issue with MLE and rounded 
>data, in that gamma densities may be 0 at the boundary but small numbers are 
>represented as 0, making the log-likelihood -Inf. 
>
>The cleanest way out is to switch to a discretized distribution in the 
>likelihood, so that instead of log(dgamma(0,...)) you use log(pgamma(.005,..) 
>- pgamma(0,...)) == pgamma(.005,..., log=TRUE). (For data rounded to nearest 
>.01, that is). Cruder techniques would be to just add, like, .0025 to all the 
>zeros. 
>
>-pd
>
>> On 10 Jan 2023, at 18:42 , Bert Gunter  wrote:
>> 
>> Is this homework? This list has a no-homework policy.
>> 
>> 
>> -- Bert
>> 
>> On Tue, Jan 10, 2023 at 8:13 AM Nyasha  wrote:
>>> 
>>> Please how can one go about this one? I don't know how to go about it.
>>> 
>>>[[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-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.
>

-- 
Sent from my phone. Please excuse my brevity.

__
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.


Re: [R] R emulation of FindRoot in Mathematica

2023-01-19 Thread J C Nash

A crude but often informative approach is to treat the nonlinear equations as a
nonlinear least squared problem. This is NOT a generally recommended solution 
technique,
but can help to show some of the multiple solutions. Moreover, it forces some 
attention
to the problem. Unfortunately, it often does not fall into the "modeling" 
structure of
nls() or the numerically more stable nlsr of Duncan and I that tries to 
generate the
Jacobian by automatic differentiation.

JN


On 2023-01-19 09:54, Jeff Newmiller wrote:

But it is simultaneously an example of why some researchers like black box 
solvers... a system of dozens of nonlinear equations can potentially have many 
or even infinite solutions. If the researcher is weak in math, they may have no 
idea which solutions are possible and having a tool like FindRoot confidently 
return a solution lets them focus on other things. Sort of like ChatGPT.

TL;DR the author may have no idea about how to resolve this without relying on 
the opaque FindRoot.

On January 19, 2023 6:28:53 AM PST, "Ebert,Timothy Aaron"  
wrote:

This is a poster child for why we like open source software. "I dump numbers into a 
black box and get numbers out but I cannot verify how the numbers out were calculated so 
they must be correct" approach to analysis does not really work for me.
Tim

-Original Message-
From: R-help  On Behalf Of Troels Ring
Sent: Thursday, January 19, 2023 9:18 AM
To: Valentin Petzel ; r-help mailing list 

Subject: Re: [R] R emulation of FindRoot in Mathematica

[External Email]

Thanks,   Valentin for the suggestion. I'm not sure I can go that way. I
include below the statements from the paper containing the knowledge on the 
basis of which I would like to know at specified [H] the concentration of each 
of the many metabolites given the constraints. I have tried to contact the 
author to get the full code but it seems difficult.

BW Troels


hatp <- 10^6.494*H*atp
hhatp <- 10^3.944*H*hatp
hhhatp <- 10^1.9*H*hhatp
atp  <- 10*H*hhhatp
mgatp <- 10^4.363*atp*mg
mghatp <- 10^2.299*hatp*mg
mg2atp <- 10^1-7*mg*mgatp
katp <- 10^0.959*atp*k

hadp <- 10^6.349*adp*H
hhadp <- 10^3.819*hadp*H
hhhadp <- 10*H*hhadp
mgadp <- 10^3.294*mg*adp
mghadp <- 10^1.61*mg*hadp
mg2adp <- 10*mg*mgadp
kadp <- 10^0.82*k*adp

hpi <- 10^11.616*H*pi
hhpi <- 10^6.7*h*hpi
hhhpi <- 10^1.962*h*hhpi
mgpi <- 10^3.4*mg*pi
mghpi <- 10^1.946*mg*hpi
mghhpi <- 10^1.19*mg*hhpi
kpi <- 10^0.6*k*pi
khpi <- 10^1.218*k*hpi
khhpi <- 10^-0.2*k*hhpi

hpcr <- 10^14.3*h*pcr
hhpcr <- 10^4.5*h*hpcr
hhhpcr <- 10^2.7*h*hhpcr
pcr <- 100*h*hhhpcr
mghpcr <- 10^1.6*mg*hpcr
kpcr <- 10^0.74*k*pcr
khpcr <- 10^0.31*k*hpcr
khhpcr <- 10^-0.13*k*hhpcr

hcr <- 10^14.3*h*cr
hhcr <- 10^2.512*h*hcr

hlactate <- 10^3.66*h*lactate
mglactate <- 10^0.93*mg*lactate

tatp <- atp + hatp + hhatp + hhhatp + mgatp + mghatp + mg2atp + katp

tadp <- adp + hadp + hhadp + hhhadp + mghadp + mgadp + mg2adp + kadp

tpi <- pi + hpi + hhpi + hhhpi + mgpi + mghpi + mghhpi + kpi + khpi + khhpi

tpcr <- pcr + hpcr + hhpcr + hhhpcr + pcr + mghpcr + kpcr + khpcr + khhpcr

tcr <- cr + hcr + hhcr

tmg <- mg + mgatp + mghatp + mg2atp + mgadp + mghadp + mg2adp + mgpi + kghpi + 
mghhpi +
   mghpcr + mglactate

tk <- k + katp + kadp + kpi + khpi + khhpi + kpcr + khpcr + khhpcr

tlactate <- lactate + hlactate + mglactate

# conditions

tatp <- 0.008
tpcr <- 0.042
tcr <- 0.004
tadp <- 0.1
tpi <- 0.003
tlactate <- 0.005

# free K and Mg constrained to be fixed
#
mg <- 0.0006
k <- 0.12

Den 19-01-2023 kl. 12:11 skrev Valentin Petzel:


Hello Troels,


As fair as I understand you attempt to numerically solve a system of
non linear equations in multiple variables in R. R does not provide
this functionality natively, but have you tried multiroot from the
rootSolve package:


https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcran
.r-project.org%2Fweb%2Fpackages%2FrootSolve%2FrootSolve.pdf=05%7C
01%7Ctebert%40ufl.edu%7C7cb98cd926b34284cd5f08dafa28026c%7C0d4da0f84a3
14d76ace60a62331e1b84%7C0%7C0%7C638097347110882622%7CUnknown%7CTWFpbGZ
sb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3
D%7C3000%7C%7C%7C=D9A3fwJ5x7GbEV4A01wncLUil7szTdSPul5vd0lsSBw%3D
=0


multiroot is called like


multiroot(f, start, ...)


where f is a function of one argument which is a vector of n values
(representing the n variables) and returning a vector of d values
(symbolising the d equations) and start is a vector of length n.


E.g. if we want so solve


x^2 + y^2 + z^2 = 1

x^3-y^3 = 0

x - z = 0


(which is of course equivalent to x = y = z, x^2 + y^2 + z^2 = 1, so x
= y = z = ±sqrt(1/3) ~ 0.577)


we'd enter


f <- function(x) c(x[1]**2 + x[2]**2 + x[3]**2 - 1, x[1]**3 - x[2]**3,
x[1] - x[3])


multiroot(f, c(0,0,0))


which yields


$root

[1] 0.5773502 0.5773505 0.5773502


$f.root

[1] 1.412261e-07 -2.197939e-07  0.00e+00


$iter

[1] 31


$estim.precis

[1] 1.2034e-07


Best regards,

Valentin


Am Donnerstag, 19. Jänner 

Re: [R] R emulation of FindRoot in Mathematica

2023-01-19 Thread Jeff Newmiller
But it is simultaneously an example of why some researchers like black box 
solvers... a system of dozens of nonlinear equations can potentially have many 
or even infinite solutions. If the researcher is weak in math, they may have no 
idea which solutions are possible and having a tool like FindRoot confidently 
return a solution lets them focus on other things. Sort of like ChatGPT.

TL;DR the author may have no idea about how to resolve this without relying on 
the opaque FindRoot.

On January 19, 2023 6:28:53 AM PST, "Ebert,Timothy Aaron"  
wrote:
>This is a poster child for why we like open source software. "I dump numbers 
>into a black box and get numbers out but I cannot verify how the numbers out 
>were calculated so they must be correct" approach to analysis does not really 
>work for me.
>Tim
>
>-Original Message-
>From: R-help  On Behalf Of Troels Ring
>Sent: Thursday, January 19, 2023 9:18 AM
>To: Valentin Petzel ; r-help mailing list 
>
>Subject: Re: [R] R emulation of FindRoot in Mathematica
>
>[External Email]
>
>Thanks,   Valentin for the suggestion. I'm not sure I can go that way. I
>include below the statements from the paper containing the knowledge on the 
>basis of which I would like to know at specified [H] the concentration of each 
>of the many metabolites given the constraints. I have tried to contact the 
>author to get the full code but it seems difficult.
>
>BW Troels
>
>
>hatp <- 10^6.494*H*atp
>hhatp <- 10^3.944*H*hatp
>hhhatp <- 10^1.9*H*hhatp
>atp  <- 10*H*hhhatp
>mgatp <- 10^4.363*atp*mg
>mghatp <- 10^2.299*hatp*mg
>mg2atp <- 10^1-7*mg*mgatp
>katp <- 10^0.959*atp*k
>
>hadp <- 10^6.349*adp*H
>hhadp <- 10^3.819*hadp*H
>hhhadp <- 10*H*hhadp
>mgadp <- 10^3.294*mg*adp
>mghadp <- 10^1.61*mg*hadp
>mg2adp <- 10*mg*mgadp
>kadp <- 10^0.82*k*adp
>
>hpi <- 10^11.616*H*pi
>hhpi <- 10^6.7*h*hpi
>hhhpi <- 10^1.962*h*hhpi
>mgpi <- 10^3.4*mg*pi
>mghpi <- 10^1.946*mg*hpi
>mghhpi <- 10^1.19*mg*hhpi
>kpi <- 10^0.6*k*pi
>khpi <- 10^1.218*k*hpi
>khhpi <- 10^-0.2*k*hhpi
>
>hpcr <- 10^14.3*h*pcr
>hhpcr <- 10^4.5*h*hpcr
>hhhpcr <- 10^2.7*h*hhpcr
>pcr <- 100*h*hhhpcr
>mghpcr <- 10^1.6*mg*hpcr
>kpcr <- 10^0.74*k*pcr
>khpcr <- 10^0.31*k*hpcr
>khhpcr <- 10^-0.13*k*hhpcr
>
>hcr <- 10^14.3*h*cr
>hhcr <- 10^2.512*h*hcr
>
>hlactate <- 10^3.66*h*lactate
>mglactate <- 10^0.93*mg*lactate
>
>tatp <- atp + hatp + hhatp + hhhatp + mgatp + mghatp + mg2atp + katp
>
>tadp <- adp + hadp + hhadp + hhhadp + mghadp + mgadp + mg2adp + kadp
>
>tpi <- pi + hpi + hhpi + hhhpi + mgpi + mghpi + mghhpi + kpi + khpi + khhpi
>
>tpcr <- pcr + hpcr + hhpcr + hhhpcr + pcr + mghpcr + kpcr + khpcr + khhpcr
>
>tcr <- cr + hcr + hhcr
>
>tmg <- mg + mgatp + mghatp + mg2atp + mgadp + mghadp + mg2adp + mgpi + kghpi + 
>mghhpi +
>   mghpcr + mglactate
>
>tk <- k + katp + kadp + kpi + khpi + khhpi + kpcr + khpcr + khhpcr
>
>tlactate <- lactate + hlactate + mglactate
>
># conditions
>
>tatp <- 0.008
>tpcr <- 0.042
>tcr <- 0.004
>tadp <- 0.1
>tpi <- 0.003
>tlactate <- 0.005
>
># free K and Mg constrained to be fixed
>#
>mg <- 0.0006
>k <- 0.12
>
>Den 19-01-2023 kl. 12:11 skrev Valentin Petzel:
>>
>> Hello Troels,
>>
>>
>> As fair as I understand you attempt to numerically solve a system of 
>> non linear equations in multiple variables in R. R does not provide 
>> this functionality natively, but have you tried multiroot from the 
>> rootSolve package:
>>
>>
>> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcran
>> .r-project.org%2Fweb%2Fpackages%2FrootSolve%2FrootSolve.pdf=05%7C
>> 01%7Ctebert%40ufl.edu%7C7cb98cd926b34284cd5f08dafa28026c%7C0d4da0f84a3
>> 14d76ace60a62331e1b84%7C0%7C0%7C638097347110882622%7CUnknown%7CTWFpbGZ
>> sb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3
>> D%7C3000%7C%7C%7C=D9A3fwJ5x7GbEV4A01wncLUil7szTdSPul5vd0lsSBw%3D
>> =0
>>
>>
>> multiroot is called like
>>
>>
>> multiroot(f, start, ...)
>>
>>
>> where f is a function of one argument which is a vector of n values 
>> (representing the n variables) and returning a vector of d values 
>> (symbolising the d equations) and start is a vector of length n.
>>
>>
>> E.g. if we want so solve
>>
>>
>> x^2 + y^2 + z^2 = 1
>>
>> x^3-y^3 = 0
>>
>> x - z = 0
>>
>>
>> (which is of course equivalent to x = y = z, x^2 + y^2 + z^2 = 1, so x 
>> = y = z = ±sqrt(1/3) ~ 0.577)
>>
>>
>> we'd enter
>>
>>
>> f <- function(x) c(x[1]**2 + x[2]**2 + x[3]**2 - 1, x[1]**3 - x[2]**3, 
>> x[1] - x[3])
>>
>>
>> multiroot(f, c(0,0,0))
>>
>>
>> which yields
>>
>>
>> $root
>>
>> [1] 0.5773502 0.5773505 0.5773502
>>
>>
>> $f.root
>>
>> [1] 1.412261e-07 -2.197939e-07  0.00e+00
>>
>>
>> $iter
>>
>> [1] 31
>>
>>
>> $estim.precis
>>
>> [1] 1.2034e-07
>>
>>
>> Best regards,
>>
>> Valentin
>>
>>
>> Am Donnerstag, 19. Jänner 2023, 10:41:22 CET schrieb Troels Ring:
>>
>> > Hi friends - I hope this is not a misplaced question. From the
>>
>> > literature (Kushmerick AJP 1997;272:C1739-C1747) I have a series of
>>
>> > Mathematica 

Re: [R] R emulation of FindRoot in Mathematica

2023-01-19 Thread Troels Ring
Hi Tim  - the results from  this paper have had big impact on quite 
complicated problems of physiology so I thought I might like to 
understand how they came by, calculating them myself. Writing up the 
statements from which the inferences in the paper were generated using 
Mathematica were meant to inspire clever friends to suggest probably 
quite simple ways to handle the problem in R.


All best wishes
Troels

Den 19-01-2023 kl. 15:28 skrev Ebert,Timothy Aaron:

This is a poster child for why we like open source software. "I dump numbers into a 
black box and get numbers out but I cannot verify how the numbers out were calculated so 
they must be correct" approach to analysis does not really work for me.
Tim

-Original Message-
From: R-help  On Behalf Of Troels Ring
Sent: Thursday, January 19, 2023 9:18 AM
To: Valentin Petzel ; r-help mailing list 

Subject: Re: [R] R emulation of FindRoot in Mathematica

[External Email]

Thanks,   Valentin for the suggestion. I'm not sure I can go that way. I
include below the statements from the paper containing the knowledge on the 
basis of which I would like to know at specified [H] the concentration of each 
of the many metabolites given the constraints. I have tried to contact the 
author to get the full code but it seems difficult.

BW Troels


hatp <- 10^6.494*H*atp
hhatp <- 10^3.944*H*hatp
hhhatp <- 10^1.9*H*hhatp
atp  <- 10*H*hhhatp
mgatp <- 10^4.363*atp*mg
mghatp <- 10^2.299*hatp*mg
mg2atp <- 10^1-7*mg*mgatp
katp <- 10^0.959*atp*k

hadp <- 10^6.349*adp*H
hhadp <- 10^3.819*hadp*H
hhhadp <- 10*H*hhadp
mgadp <- 10^3.294*mg*adp
mghadp <- 10^1.61*mg*hadp
mg2adp <- 10*mg*mgadp
kadp <- 10^0.82*k*adp

hpi <- 10^11.616*H*pi
hhpi <- 10^6.7*h*hpi
hhhpi <- 10^1.962*h*hhpi
mgpi <- 10^3.4*mg*pi
mghpi <- 10^1.946*mg*hpi
mghhpi <- 10^1.19*mg*hhpi
kpi <- 10^0.6*k*pi
khpi <- 10^1.218*k*hpi
khhpi <- 10^-0.2*k*hhpi

hpcr <- 10^14.3*h*pcr
hhpcr <- 10^4.5*h*hpcr
hhhpcr <- 10^2.7*h*hhpcr
pcr <- 100*h*hhhpcr
mghpcr <- 10^1.6*mg*hpcr
kpcr <- 10^0.74*k*pcr
khpcr <- 10^0.31*k*hpcr
khhpcr <- 10^-0.13*k*hhpcr

hcr <- 10^14.3*h*cr
hhcr <- 10^2.512*h*hcr

hlactate <- 10^3.66*h*lactate
mglactate <- 10^0.93*mg*lactate

tatp <- atp + hatp + hhatp + hhhatp + mgatp + mghatp + mg2atp + katp

tadp <- adp + hadp + hhadp + hhhadp + mghadp + mgadp + mg2adp + kadp

tpi <- pi + hpi + hhpi + hhhpi + mgpi + mghpi + mghhpi + kpi + khpi + khhpi

tpcr <- pcr + hpcr + hhpcr + hhhpcr + pcr + mghpcr + kpcr + khpcr + khhpcr

tcr <- cr + hcr + hhcr

tmg <- mg + mgatp + mghatp + mg2atp + mgadp + mghadp + mg2adp + mgpi + kghpi + 
mghhpi +
mghpcr + mglactate

tk <- k + katp + kadp + kpi + khpi + khhpi + kpcr + khpcr + khhpcr

tlactate <- lactate + hlactate + mglactate

# conditions

tatp <- 0.008
tpcr <- 0.042
tcr <- 0.004
tadp <- 0.1
tpi <- 0.003
tlactate <- 0.005

# free K and Mg constrained to be fixed
#
mg <- 0.0006
k <- 0.12

Den 19-01-2023 kl. 12:11 skrev Valentin Petzel:

Hello Troels,


As fair as I understand you attempt to numerically solve a system of
non linear equations in multiple variables in R. R does not provide
this functionality natively, but have you tried multiroot from the
rootSolve package:


https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcran
.r-project.org%2Fweb%2Fpackages%2FrootSolve%2FrootSolve.pdf=05%7C
01%7Ctebert%40ufl.edu%7C7cb98cd926b34284cd5f08dafa28026c%7C0d4da0f84a3
14d76ace60a62331e1b84%7C0%7C0%7C638097347110882622%7CUnknown%7CTWFpbGZ
sb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3
D%7C3000%7C%7C%7C=D9A3fwJ5x7GbEV4A01wncLUil7szTdSPul5vd0lsSBw%3D
=0


multiroot is called like


multiroot(f, start, ...)


where f is a function of one argument which is a vector of n values
(representing the n variables) and returning a vector of d values
(symbolising the d equations) and start is a vector of length n.


E.g. if we want so solve


x^2 + y^2 + z^2 = 1

x^3-y^3 = 0

x - z = 0


(which is of course equivalent to x = y = z, x^2 + y^2 + z^2 = 1, so x
= y = z = ±sqrt(1/3) ~ 0.577)


we'd enter


f <- function(x) c(x[1]**2 + x[2]**2 + x[3]**2 - 1, x[1]**3 - x[2]**3,
x[1] - x[3])


multiroot(f, c(0,0,0))


which yields


$root

[1] 0.5773502 0.5773505 0.5773502


$f.root

[1] 1.412261e-07 -2.197939e-07  0.00e+00


$iter

[1] 31


$estim.precis

[1] 1.2034e-07


Best regards,

Valentin


Am Donnerstag, 19. Jänner 2023, 10:41:22 CET schrieb Troels Ring:


Hi friends - I hope this is not a misplaced question. From the
literature (Kushmerick AJP 1997;272:C1739-C1747) I have a series of
Mathematica equations which are solved together to yield over
different
pH values the concentrations of metabolites in skeletal muscle using
the
Mathematica function FindRoot((E1,E2...),(V2,V2..)] where E is a
list of
equations and V list of variables.  Most of the equations are
individual
binding reactions of the form 10^6.494*atp*h == hatp and next
10^9.944*hatp*h ==hhatp describing binding of singe protons or Mg or
K
to ATP or 

Re: [R] R emulation of FindRoot in Mathematica

2023-01-19 Thread Ebert,Timothy Aaron
This is a poster child for why we like open source software. "I dump numbers 
into a black box and get numbers out but I cannot verify how the numbers out 
were calculated so they must be correct" approach to analysis does not really 
work for me.
Tim

-Original Message-
From: R-help  On Behalf Of Troels Ring
Sent: Thursday, January 19, 2023 9:18 AM
To: Valentin Petzel ; r-help mailing list 

Subject: Re: [R] R emulation of FindRoot in Mathematica

[External Email]

Thanks,   Valentin for the suggestion. I'm not sure I can go that way. I
include below the statements from the paper containing the knowledge on the 
basis of which I would like to know at specified [H] the concentration of each 
of the many metabolites given the constraints. I have tried to contact the 
author to get the full code but it seems difficult.

BW Troels


hatp <- 10^6.494*H*atp
hhatp <- 10^3.944*H*hatp
hhhatp <- 10^1.9*H*hhatp
atp  <- 10*H*hhhatp
mgatp <- 10^4.363*atp*mg
mghatp <- 10^2.299*hatp*mg
mg2atp <- 10^1-7*mg*mgatp
katp <- 10^0.959*atp*k

hadp <- 10^6.349*adp*H
hhadp <- 10^3.819*hadp*H
hhhadp <- 10*H*hhadp
mgadp <- 10^3.294*mg*adp
mghadp <- 10^1.61*mg*hadp
mg2adp <- 10*mg*mgadp
kadp <- 10^0.82*k*adp

hpi <- 10^11.616*H*pi
hhpi <- 10^6.7*h*hpi
hhhpi <- 10^1.962*h*hhpi
mgpi <- 10^3.4*mg*pi
mghpi <- 10^1.946*mg*hpi
mghhpi <- 10^1.19*mg*hhpi
kpi <- 10^0.6*k*pi
khpi <- 10^1.218*k*hpi
khhpi <- 10^-0.2*k*hhpi

hpcr <- 10^14.3*h*pcr
hhpcr <- 10^4.5*h*hpcr
hhhpcr <- 10^2.7*h*hhpcr
pcr <- 100*h*hhhpcr
mghpcr <- 10^1.6*mg*hpcr
kpcr <- 10^0.74*k*pcr
khpcr <- 10^0.31*k*hpcr
khhpcr <- 10^-0.13*k*hhpcr

hcr <- 10^14.3*h*cr
hhcr <- 10^2.512*h*hcr

hlactate <- 10^3.66*h*lactate
mglactate <- 10^0.93*mg*lactate

tatp <- atp + hatp + hhatp + hhhatp + mgatp + mghatp + mg2atp + katp

tadp <- adp + hadp + hhadp + hhhadp + mghadp + mgadp + mg2adp + kadp

tpi <- pi + hpi + hhpi + hhhpi + mgpi + mghpi + mghhpi + kpi + khpi + khhpi

tpcr <- pcr + hpcr + hhpcr + hhhpcr + pcr + mghpcr + kpcr + khpcr + khhpcr

tcr <- cr + hcr + hhcr

tmg <- mg + mgatp + mghatp + mg2atp + mgadp + mghadp + mg2adp + mgpi + kghpi + 
mghhpi +
   mghpcr + mglactate

tk <- k + katp + kadp + kpi + khpi + khhpi + kpcr + khpcr + khhpcr

tlactate <- lactate + hlactate + mglactate

# conditions

tatp <- 0.008
tpcr <- 0.042
tcr <- 0.004
tadp <- 0.1
tpi <- 0.003
tlactate <- 0.005

# free K and Mg constrained to be fixed
#
mg <- 0.0006
k <- 0.12

Den 19-01-2023 kl. 12:11 skrev Valentin Petzel:
>
> Hello Troels,
>
>
> As fair as I understand you attempt to numerically solve a system of 
> non linear equations in multiple variables in R. R does not provide 
> this functionality natively, but have you tried multiroot from the 
> rootSolve package:
>
>
> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcran
> .r-project.org%2Fweb%2Fpackages%2FrootSolve%2FrootSolve.pdf=05%7C
> 01%7Ctebert%40ufl.edu%7C7cb98cd926b34284cd5f08dafa28026c%7C0d4da0f84a3
> 14d76ace60a62331e1b84%7C0%7C0%7C638097347110882622%7CUnknown%7CTWFpbGZ
> sb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3
> D%7C3000%7C%7C%7C=D9A3fwJ5x7GbEV4A01wncLUil7szTdSPul5vd0lsSBw%3D
> =0
>
>
> multiroot is called like
>
>
> multiroot(f, start, ...)
>
>
> where f is a function of one argument which is a vector of n values 
> (representing the n variables) and returning a vector of d values 
> (symbolising the d equations) and start is a vector of length n.
>
>
> E.g. if we want so solve
>
>
> x^2 + y^2 + z^2 = 1
>
> x^3-y^3 = 0
>
> x - z = 0
>
>
> (which is of course equivalent to x = y = z, x^2 + y^2 + z^2 = 1, so x 
> = y = z = ±sqrt(1/3) ~ 0.577)
>
>
> we'd enter
>
>
> f <- function(x) c(x[1]**2 + x[2]**2 + x[3]**2 - 1, x[1]**3 - x[2]**3, 
> x[1] - x[3])
>
>
> multiroot(f, c(0,0,0))
>
>
> which yields
>
>
> $root
>
> [1] 0.5773502 0.5773505 0.5773502
>
>
> $f.root
>
> [1] 1.412261e-07 -2.197939e-07  0.00e+00
>
>
> $iter
>
> [1] 31
>
>
> $estim.precis
>
> [1] 1.2034e-07
>
>
> Best regards,
>
> Valentin
>
>
> Am Donnerstag, 19. Jänner 2023, 10:41:22 CET schrieb Troels Ring:
>
> > Hi friends - I hope this is not a misplaced question. From the
>
> > literature (Kushmerick AJP 1997;272:C1739-C1747) I have a series of
>
> > Mathematica equations which are solved together to yield over 
> > different
>
> > pH values the concentrations of metabolites in skeletal muscle using 
> > the
>
> > Mathematica function FindRoot((E1,E2...),(V2,V2..)] where E is a 
> > list of
>
> > equations and V list of variables.  Most of the equations are 
> > individual
>
> > binding reactions of the form 10^6.494*atp*h == hatp and next
>
> > 10^9.944*hatp*h ==hhatp describing binding of singe protons or Mg or 
> > K
>
> > to ATP or creatin for example, but we also have constraints giving 
> > total
>
> > concentrations of say ATP i.e. ATP + ATPH, ATPH2..ATP.Mg
>
> >
>
> > I have, without success, tried to find ways to do this in R - I have 
> > 36
>
> > equations on 36 variables and 8 equations on 

Re: [R] R emulation of FindRoot in Mathematica

2023-01-19 Thread Troels Ring
Thanks,   Valentin for the suggestion. I'm not sure I can go that way. I 
include below the statements from the paper containing the knowledge on 
the basis of which I would like to know at specified [H] the 
concentration of each of the many metabolites given the constraints. I 
have tried to contact the author to get the full code but it seems 
difficult.

BW Troels


hatp <- 10^6.494*H*atp
hhatp <- 10^3.944*H*hatp
hhhatp <- 10^1.9*H*hhatp
atp  <- 10*H*hhhatp
mgatp <- 10^4.363*atp*mg
mghatp <- 10^2.299*hatp*mg
mg2atp <- 10^1-7*mg*mgatp
katp <- 10^0.959*atp*k

hadp <- 10^6.349*adp*H
hhadp <- 10^3.819*hadp*H
hhhadp <- 10*H*hhadp
mgadp <- 10^3.294*mg*adp
mghadp <- 10^1.61*mg*hadp
mg2adp <- 10*mg*mgadp
kadp <- 10^0.82*k*adp

hpi <- 10^11.616*H*pi
hhpi <- 10^6.7*h*hpi
hhhpi <- 10^1.962*h*hhpi
mgpi <- 10^3.4*mg*pi
mghpi <- 10^1.946*mg*hpi
mghhpi <- 10^1.19*mg*hhpi
kpi <- 10^0.6*k*pi
khpi <- 10^1.218*k*hpi
khhpi <- 10^-0.2*k*hhpi

hpcr <- 10^14.3*h*pcr
hhpcr <- 10^4.5*h*hpcr
hhhpcr <- 10^2.7*h*hhpcr
pcr <- 100*h*hhhpcr
mghpcr <- 10^1.6*mg*hpcr
kpcr <- 10^0.74*k*pcr
khpcr <- 10^0.31*k*hpcr
khhpcr <- 10^-0.13*k*hhpcr

hcr <- 10^14.3*h*cr
hhcr <- 10^2.512*h*hcr

hlactate <- 10^3.66*h*lactate
mglactate <- 10^0.93*mg*lactate

tatp <- atp + hatp + hhatp + hhhatp + mgatp + mghatp + mg2atp + katp

tadp <- adp + hadp + hhadp + hhhadp + mghadp + mgadp + mg2adp + kadp

tpi <- pi + hpi + hhpi + hhhpi + mgpi + mghpi + mghhpi + kpi + khpi + khhpi

tpcr <- pcr + hpcr + hhpcr + hhhpcr + pcr + mghpcr + kpcr + khpcr + 
khhpcr

tcr <- cr + hcr + hhcr

tmg <- mg + mgatp + mghatp + mg2atp + mgadp + mghadp + mg2adp + mgpi + 
kghpi + mghhpi +
   mghpcr + mglactate

tk <- k + katp + kadp + kpi + khpi + khhpi + kpcr + khpcr + khhpcr

tlactate <- lactate + hlactate + mglactate

# conditions

tatp <- 0.008
tpcr <- 0.042
tcr <- 0.004
tadp <- 0.1
tpi <- 0.003
tlactate <- 0.005

# free K and Mg constrained to be fixed
#
mg <- 0.0006
k <- 0.12

Den 19-01-2023 kl. 12:11 skrev Valentin Petzel:
>
> Hello Troels,
>
>
> As fair as I understand you attempt to numerically solve a system of 
> non linear equations in multiple variables in R. R does not provide 
> this functionality natively, but have you tried multiroot from the 
> rootSolve package:
>
>
> https://cran.r-project.org/web/packages/rootSolve/rootSolve.pdf
>
>
> multiroot is called like
>
>
> multiroot(f, start, ...)
>
>
> where f is a function of one argument which is a vector of n values 
> (representing the n variables) and returning a vector of d values 
> (symbolising the d equations) and start is a vector of length n.
>
>
> E.g. if we want so solve
>
>
> x^2 + y^2 + z^2 = 1
>
> x^3-y^3 = 0
>
> x - z = 0
>
>
> (which is of course equivalent to x = y = z, x^2 + y^2 + z^2 = 1, so x 
> = y = z = ±sqrt(1/3) ~ 0.577)
>
>
> we’d enter
>
>
> f <- function(x) c(x[1]**2 + x[2]**2 + x[3]**2 - 1, x[1]**3 - x[2]**3, 
> x[1] - x[3])
>
>
> multiroot(f, c(0,0,0))
>
>
> which yields
>
>
> $root
>
> [1] 0.5773502 0.5773505 0.5773502
>
>
> $f.root
>
> [1] 1.412261e-07 -2.197939e-07  0.00e+00
>
>
> $iter
>
> [1] 31
>
>
> $estim.precis
>
> [1] 1.2034e-07
>
>
> Best regards,
>
> Valentin
>
>
> Am Donnerstag, 19. Jänner 2023, 10:41:22 CET schrieb Troels Ring:
>
> > Hi friends - I hope this is not a misplaced question. From the
>
> > literature (Kushmerick AJP 1997;272:C1739-C1747) I have a series of
>
> > Mathematica equations which are solved together to yield over different
>
> > pH values the concentrations of metabolites in skeletal muscle using the
>
> > Mathematica function FindRoot((E1,E2...),(V2,V2..)] where E is a list of
>
> > equations and V list of variables.  Most of the equations are individual
>
> > binding reactions of the form 10^6.494*atp*h == hatp and next
>
> > 10^9.944*hatp*h ==hhatp describing binding of singe protons or Mg or K
>
> > to ATP or creatin for example, but we also have constraints giving total
>
> > concentrations of say ATP i.e. ATP + ATPH, ATPH2..ATP.Mg
>
> >
>
> > I have, without success, tried to find ways to do this in R - I have 36
>
> > equations on 36 variables and 8 equations on total concentrations. As
>
> > far as I can see from the definition of FindRoot in Wolfram, Newton
>
> > search or secant search is employed.
>
> >
>
> > I'm on Windows R 4.2.2
>
> >
>
> > Best wishes
>
> > Troels Ring, MD
>
> > Aalborg, Denmark
>
> >
>
> > __
>
> > 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.
>
>
>
[[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 

Re: [R-es] función dinámica con lapply en un data.table

2023-01-19 Thread patricio fuenmayor
Gracias Carlos
te cuento que el factor debe multiplicar a la columna
en lo que envías ... está multiplicando a cada fila consecutivamente
le metí un poco de cabeza y logré hacerlo con furrr::future_imap

dat1[,c(col_mdf):=furrr::future_imap(.SD,~as.integer(.x)/cfg3[hmlg_col_nm==.y,fct_vl]),.SDcols=col_mdf]

donde cfg3 es ta tabla de parámetros que arroja el factor cuando el nombre
de la variable coincide con el .y del barrido

gracias por tu apoyo !!!









El jue, 19 ene 2023 a la(s) 02:36, Carlos Ortega (c...@qualityexcellence.es)
escribió:

> Hola,
>
> Sí, puede ser así:
>
> #
> library(data.table)
>
> # Convertir iris en un data.table
> iris_dt <- as.data.table(iris)
> iris_dt
>
> # Crear vectores con nombres de columnas y factores
> cols_to_mult <- c("Sepal.Length", "Sepal.Width", "Petal.Length")
> factors <- c(2,3,4)
>
> iris_dt[, (cols_to_mult) := lapply(.SD, function(x) x*factors), .SDcols =
> cols_to_mult]
>
> #---
>
> Gracias,
> Carlos Ortega
> www.qualityexcellence.es
>
> El jue, 19 ene 2023 a las 4:20, patricio fuenmayor (<
> patricio.fuenma...@gmail.com>) escribió:
>
>> Hola a todos, espero que se encuentren bien.!!!
>>
>> Ando buscando la forma "elegante" de hacer esto.
>>
>> Tengo un data.table al que a ciertas columnas debo mullicarlas por un
>> factor, pero ese factor es distinto para cada columna y lo tengo en
>> un data.table a parte de parámetros
>>
>> tengo pensado esto pero no logro implementarlo:
>>
>> col_mdf <- c("A","B") # lista de columnas a multiplicar por un factor
>>
>> dt[,c(col_mdf):=lapply(.SD,\(x,y) x*y),.SDcols=col_mdf]
>>
>> lo que no logro es que "y" sea el factor que debe ser correspondiente a
>> "x"
>> en la tabla de parámetros
>>
>> Gracias por si se les ocurre una manera
>>
>> PD: ya lo hice con un bucle for, pero me gustaria hacerlo con la familia
>> apply y/o map
>>
>> [[alternative HTML version deleted]]
>>
>> ___
>> R-help-es mailing list
>> R-help-es@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>
>
> --
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] R emulation of FindRoot in Mathematica

2023-01-19 Thread Valentin Petzel
Hello Troels,

As fair as I understand you attempt to numerically solve a system of non linear 
equations 
in multiple variables in R. R does not provide this functionality natively, but 
have you tried 
multiroot from the rootSolve package:

https://cran.r-project.org/web/packages/rootSolve/rootSolve.pdf[1]

multiroot is called like

multiroot(f, start, ...)

where f is a function of one argument which is a vector of n values 
(representing the n 
variables) and returning a vector of d values (symbolising the d equations) and 
start is a 
vector of length n.

E.g. if we want so solve

x^2 + y^2 + z^2 = 1
x^3-y^3 = 0
x - z = 0

(which is of course equivalent to x = y = z, x^2 + y^2 + z^2 = 1, so x = y = z 
= ±sqrt(1/3) ~ 0.577)

we’d enter

f <- function(x) c(x[1]**2 + x[2]**2 + x[3]**2 - 1, x[1]**3 - x[2]**3, x[1] - 
x[3])

multiroot(f, c(0,0,0))

which yields

$root
[1] 0.5773502 0.5773505 0.5773502

$f.root
[1]  1.412261e-07 -2.197939e-07  0.00e+00

$iter
[1] 31

$estim.precis
[1] 1.2034e-07

Best regards,
Valentin

Am Donnerstag, 19. Jänner 2023, 10:41:22 CET schrieb Troels Ring:
> Hi friends - I hope this is not a misplaced question. From the
> literature (Kushmerick AJP 1997;272:C1739-C1747) I have a series of
> Mathematica equations which are solved together to yield over different
> pH values the concentrations of metabolites in skeletal muscle using the
> Mathematica function FindRoot((E1,E2...),(V2,V2..)] where E is a list of
> equations and V list of variables.  Most of the equations are individual
> binding reactions of the form 10^6.494*atp*h == hatp and next
> 10^9.944*hatp*h ==hhatp describing binding of singe protons or Mg or K
> to ATP or creatin for example, but we also have constraints giving total
> concentrations of say ATP i.e. ATP + ATPH, ATPH2..ATP.Mg
> 
> I have, without success, tried to find ways to do this in R - I have 36
> equations on 36 variables and 8 equations on total concentrations. As
> far as I can see from the definition of FindRoot in Wolfram, Newton
> search or secant search is employed.
> 
> I'm on Windows R 4.2.2
> 
> Best wishes
> Troels Ring, MD
> Aalborg, Denmark
> 
> __
> 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.




[1] https://cran.r-project.org/web/packages/rootSolve/rootSolve.pdf


signature.asc
Description: This is a digitally signed message part.
__
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] The rgl package update may affect your scripts

2023-01-19 Thread Duncan Murdoch

To all users of the rgl package:

CRAN has just accepted an update of rgl to version 1.0.1.

This release deprecates a number of functions which have been in the 
package for a very long time, and this may affect your scripts.  Here 
are the news items about it:


 * The long promised deprecations of the rgl.* functions have happened. 
Now deprecated: rgl.abclines, rgl.bbox, rgl.bg, rgl.clear, 
rgl.clipplanes, rgl.close, rgl.light, rgl.lines, rgl.linestrips, 
rgl.material, rgl.open, rgl.planes, rgl.points, rgl.quads, rgl.select3d, 
rgl.set, rgl.setAxisCallback, rgl.sprites, rgl.surface, rgl.texts, 
rgl.triangles, and rgl.viewpoint.


 * A vignette “Deprecating the rgl.* interface” has been added.

 * Also deprecated: elementId2Prefix, writeWebGL

I have notified all the CRAN and Bioconductor package maintainers who 
were using the old functions and have helped them to make updates, but I 
expect it will be a while before the updates are all published on CRAN. 
If you use the deprecated functions in your own scripts, or you use one 
of those packages before the updates are available, you will see 
warnings like this:


  Warning message:
  'rgl.points' is deprecated.
  Use 'points3d' instead.
  See help("Deprecated")

Those are just warnings:  the rgl.points function (and all the others) 
are still there with no changes except that they now issue these warnings.


In most cases, using the suggested replacement will just work with no 
other changes needed.  The exceptions to this that I know about are 
rgl.surface() and rgl.open(), where you might find the new defaults for 
colours and projections aren't what you want.  If that happens, feel 
free to contact me for advice on how to obtain the previous behaviour 
using the new functions.


For more details see the new vignette (online here: 
https://dmurdoch.github.io/rgl/articles/deprecation.html) for more 
details about the changes.


Duncan Murdoch

__
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.


Re: [R] MLE Estimation of Gamma Distribution Parameters for data with 'zeros'

2023-01-19 Thread peter dalgaard
Not necessarily homework, Bert. There's a generic issue with MLE and rounded 
data, in that gamma densities may be 0 at the boundary but small numbers are 
represented as 0, making the log-likelihood -Inf. 

The cleanest way out is to switch to a discretized distribution in the 
likelihood, so that instead of log(dgamma(0,...)) you use log(pgamma(.005,..) - 
pgamma(0,...)) == pgamma(.005,..., log=TRUE). (For data rounded to nearest .01, 
that is). Cruder techniques would be to just add, like, .0025 to all the zeros. 

-pd

> On 10 Jan 2023, at 18:42 , Bert Gunter  wrote:
> 
> Is this homework? This list has a no-homework policy.
> 
> 
> -- Bert
> 
> On Tue, Jan 10, 2023 at 8:13 AM Nyasha  wrote:
>> 
>> Please how can one go about this one? I don't know how to go about it.
>> 
>>[[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-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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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] R emulation of FindRoot in Mathematica

2023-01-19 Thread Troels Ring
Hi friends - I hope this is not a misplaced question. From the 
literature (Kushmerick AJP 1997;272:C1739-C1747) I have a series of 
Mathematica equations which are solved together to yield over different 
pH values the concentrations of metabolites in skeletal muscle using the 
Mathematica function FindRoot((E1,E2...),(V2,V2..)] where E is a list of 
equations and V list of variables.  Most of the equations are individual 
binding reactions of the form 10^6.494*atp*h == hatp and next 
10^9.944*hatp*h ==hhatp describing binding of singe protons or Mg or K 
to ATP or creatin for example, but we also have constraints giving total 
concentrations of say ATP i.e. ATP + ATPH, ATPH2..ATP.Mg


I have, without success, tried to find ways to do this in R - I have 36 
equations on 36 variables and 8 equations on total concentrations. As 
far as I can see from the definition of FindRoot in Wolfram, Newton 
search or secant search is employed.


I'm on Windows R 4.2.2

Best wishes
Troels Ring, MD
Aalborg, Denmark

__
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.


Re: [R-es] Suma de datos de una tabla

2023-01-19 Thread Proyecto R-UCA
Buenas, 

Creo que el siguiente código hace lo que pides, cambiando Chile y las columnas 
por los de tu caso.

library(carData)
data(Chile)
indice <- sort(unique(Chile$population))

f <- function(valor, data, indice) {
sum(data[indice == valor], na.rm = TRUE)
}

## Una lista con las sumas de income según population
lapply(indice, f, Chile$income, Chile$population)

ff <- function(data, indice) {
index <- sort(unique(indice))
lapply(index, f, data, indice)
}

## Una lista con tantos elementos como columnas
## Cada elemento es una lista con los valores de las sumas
data <- Chile[, c('population', 'income')]
apply(data, 2, ff, Chile$population)

Manuel, un saludo



El mié, 18-01-2023 a las 14:14 -0500, David Camilo Gomez Medina escribió:
> No sé si olvidé aclarar, pero quiero crear una lista para cada columna y así 
> almacenar esos valores.
> 
> On Wed, 18 Jan 2023 at 14:13, David Camilo Gomez Medina 
>  wrote:
> > Hola Carlos.
> > 
> > Por ejemplo la segunda columna (16040050), quiero sumar todos los datos de 
> > esa columna correspondientes al año 2000 (quiero
> > relacionarlos con la primera columna donde está la fecha) y ese valor 
> > almacenarlo en una lista y así sucesivamente con los demás años y
> > con las demás columnas.
> > 
> > Tengo pensado una lista así:
> > 
> > est_16040050 
> > 
> > [[2000]]
> > [1] 2.3
> > 
> > [[2001]]
> > [1] 1.7
> > 
> > [[2002]]
> > [1] 4.8
> > 
> > Quedo muy atento a sus sugerencias o guías.
> > 
> > Saludos.
> > 
> > On Wed, 18 Jan 2023 at 13:52, Carlos Ortega  
> > wrote:
> > > Hola, 
> > > 
> > > Por entenderlo mejor, quieres que para las filas, para cada año:
> > >    1. se sumen las columnas y por tanto tengas tantas sumas como columnas.
> > >    2. o sumar todas las columnas y obtener una única suma.
> > > Gracias,
> > > Carlos Ortega
> > > www.qualityexcellence.es
> > > 
> > > El mié, 18 ene 2023 a las 19:29, David Camilo Gomez Medina 
> > > () escribió:
> > > > Hola, espero que se encuentren muy bien.
> > > > 
> > > > Tengo una tabla de datos de precipitación y quiero sumar por columnas y 
> > > > así obtener la precipitación anual. Es decir, quiero sumar
> > > > solo los datos del año 2000 y guardarlos en una lista y así 
> > > > sucesivamente con los demás años, pero no encuentro todavía una función
> > > > o una manera eficiente de hacerlo. 
> > > > 
> > > > Agradecería mucho si alguien me puede guiar.
> > > > 
> > > > Saludos
> > > > 
> > > > image.png
> > > > 
> > > > Aviso legal: El contenido de este mensaje y los archivos adjuntos son 
> > > > confidenciales y de uso exclusivo de la Universidad Nacional
> > > > de Colombia. Se encuentran dirigidos sólo para el uso del destinatario 
> > > > al cual van enviados. La reproducción, lectura y/o copia se
> > > > encuentran prohibidas a cualquier persona diferente a este y puede ser 
> > > > ilegal. Si usted lo ha recibido por error, infórmenos y
> > > > elimínelo de su correo. Los Datos Personales serán tratados conforme a 
> > > > la Ley 1581 de 2012 y a nuestra Política de Datos Personales
> > > > que podrá consultar en la página web www.unal.edu.co. Las opiniones, 
> > > > informaciones, conclusiones y cualquier otro tipo de dato
> > > > contenido en este correo electrónico, no relacionados con la actividad 
> > > > de la Universidad Nacional de Colombia, se entenderá como
> > > > personales y de ninguna manera son avaladas por la Universidad.
> > > > ___
> > > > R-help-es mailing list
> > > > R-help-es@r-project.org
> > > > https://stat.ethz.ch/mailman/listinfo/r-help-es
> > > 
> > > 
> > > ___
> > > R-help-es mailing list
> > > R-help-es@r-project.org
> > > https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help-es__;!!D9dNQwwGXtA!Tgeig9lQK2J7Ho1714GCysi3CyV1Wuw9nLrzOWXrbyFyjgdlIlc5RIm24iXMtqtfVhg0EZrc2a06dVQLIOE$
> > >  

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es