Re: [R] non-linear regression and root finding

2023-11-06 Thread Berwin A Turlach
G'day Troels, On Tue, 7 Nov 2023 07:14:02 +0100 Troels Ring wrote: > Be as it may, I wonder if not your method might work if only we KNOW > that pK1 is either positive OR negative, in which case we have pK1 = > -exp(theta1)? If pK1 can be either negative or positive (or 0 :-) ), and it is just

Re: [R] non-linear regression and root finding

2023-11-06 Thread Troels Ring
Thanks a lot, Berwin. Unfortunately, pK1 may well be negative and as I understand the literature it may be poorly defined as such, and also seems to be at a boundary, since when lower is set to say rep(-4,3) pK1 is returned as -4 while pK2 and pK3 are undisturbed. Perhaps the point is that pK1

Re: [R] non-linear regression and root finding

2023-11-06 Thread Berwin A Turlach
G'day Troels, On Mon, 6 Nov 2023 20:43:10 +0100 Troels Ring wrote: > Thanks a lot! This was amazing. I'm not sure I see how the conditiion > pK1 < pK2 < pK3 is enforced? One way of enforcing such constraints (well, in finite computer arithemtic only "<=" can be enforced) is to rewrite the para

[R] Concordance and Kendall's tau in copula

2023-11-06 Thread Steven Yen
Dear I estimate a sample selection model using the Clayton copula and Burr and Gaussian marginal. I need to derive ther Kendall'sw tau from the concordance coefficient by integration. I came across a way to do that in R long time ago but cannot find it again. Can somewone tell me what to read

Re: [R] understanding predict.lm

2023-11-06 Thread Spencer Graves
Doh! Thanks very much. sg On 11/6/23 5:17 PM, John Fox wrote: Dear Spencer, You need the t distribution with correct df, not the standard-normal distribution: > pt(-z.confInt/2, df=13)     1 2 3 4 5 6 7 8 9    10    11 0.025 0.025 0.025 0.025 0.025 0.025 0.

[R] understanding predict.lm

2023-11-06 Thread Spencer Graves
Hello, All: I am unable to manually replicate predict.lm, specifically comparing se.fit with (fit[,3]-fit[,2]): I think their ratio should be 2*qnorm((1-level)/2), and that's not what I'm getting. Consider the following slight modification of the first example in help('predict.lm'):

Re: [R] non-linear regression and root finding

2023-11-06 Thread J C Nash
I won't send to list, but just to the two of you, as I don't have anything to add at this time. However, I'm wondering if this approach is worth writing up, at least as a vignette or blog post. It does need a shorter example and some explanation of the "why" and some testing perhaps. If there's i

Re: [R] non-linear regression and root finding

2023-11-06 Thread Troels Ring
Thanks a lot! This was amazing. I'm not sure I see how the conditiion pK1 < pK2 < pK3 is enforced? - it comes from the derivation via generalized Henderson-Hasselbalch but perhaps it is not really necessary. Anyway, the use of Vectorize did the trick! Best wishes Troels Den 06-11-2023 kl. 19:

Re: [R] non-linear regression and root finding

2023-11-06 Thread J C Nash
Your script is missing something (in particular kw). I presume you are trying to estimate the pK values. You may have more success with package nlsr than nls(). nlsr::nlxb() tries to get the Jacobian of the model specified by a formula and do so by applying symbolic or automatic differentiation.

Re: [R] non-linear regression and root finding

2023-11-06 Thread Ivan Krylov
В Mon, 6 Nov 2023 17:53:49 +0100 Troels Ring пишет: > Hence I wonder if I could somehow have non linear regression to find > the 3 pK values. Below is HEPESFUNC which delivers charge in the > fluid for known pKs, HEPTOT and SID. Is it possible to have > root-finding in the formula with nls? Sure

Re: [R] strptime with +03:00 zone designator

2023-11-06 Thread Joshua Ulrich
On Mon, Nov 6, 2023 at 3:02 AM Martin Maechler wrote: > > > Richard O'Keefe > > on Mon, 6 Nov 2023 18:37:34 +1300 writes: > > > Thanks to all who replied. On Mon, 6 Nov 2023 at 18:37, > > Richard O'Keefe wrote: > > >> OK, so the consensus is (1) One cannot make strptime >

[R] non-linear regression and root finding

2023-11-06 Thread Troels Ring
Dear friends - I have a function for the charge in a fluid (water) buffered with HEPES and otherwise only containing Na and Cl so that [Na] - [Cl] = SID (strong ion difference) goes from -1 mM to 1 mM. With known SID and total HEPES concentration I can calculate accurately the pH if I know 3 pK

Re: [R] I need to create new variables based on two numeric variables and one dichotomize conditional category

2023-11-06 Thread Jorgen Harmse via R-help
Avi: Thank you for checking. I think the optimization is limited. If test is all TRUE or all FALSE then at most one vector is evaluated. Anything beyond that would be very complicated. (Inspect the two expressions and verify that both specify elementwise computations. Then use indexing to shrink

Re: [R] [EXTERNAL] Re: I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-06 Thread Jorgen Harmse via R-help
That�s ingenious, but I would hesitate to rely on a specific mapping between strings and integers. (I usually read data frames with stringsAsFactors=FALSE or coerce to character later: I don�t think it takes more memory.) Maybe create another column with the coefficients. What if gender is part

Re: [R] Cryptic error for mscmt function

2023-11-06 Thread Ivan Krylov
В Sun, 5 Nov 2023 13:35:39 + "Leu Thierry" пишет: > However, when trying to run it I get a very cryptic error message > saying "Error in lst[[nam]][intersect(tim, rownames(lst[[nam]])), > cols, drop = FALSE]: subscript out of bounds". Without a way to reproduce the error, I can offer a few

Re: [R] Cryptic error for mscmt function

2023-11-06 Thread Rui Barradas
Às 13:35 de 05/11/2023, Leu Thierry escreveu: Hi everyone, I am trying to conduct a synthetic control analysis using the MSCMT package. However, when trying to run it I get a very cryptic error message saying "Error in lst[[nam]][intersect(tim, rownames(lst[[nam]])), cols, drop = FALSE]: sub

[R] Cryptic error for mscmt function

2023-11-06 Thread Leu Thierry
Hi everyone, I am trying to conduct a synthetic control analysis using the MSCMT package. However, when trying to run it I get a very cryptic error message saying "Error in lst[[nam]][intersect(tim, rownames(lst[[nam]])), cols, drop = FALSE]: subscript out of bounds". Does anyone know what th

Re: [R] strptime with +03:00 zone designator

2023-11-06 Thread Martin Maechler
> Richard O'Keefe > on Mon, 6 Nov 2023 18:37:34 +1300 writes: > Thanks to all who replied. On Mon, 6 Nov 2023 at 18:37, > Richard O'Keefe wrote: >> OK, so the consensus is (1) One cannot make strptime >> accept ISO8601-compliant zone designators (2) The >> lubri