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

2023-11-07 Thread Ivan Krylov
On Mon, 6 Nov 2023 14:55:39 -0500
J C Nash  wrote:

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

Do you mean using this problem as a basis to illustrate ordering
constraints on parameters? Weird constraints do come up every now and
then in regression problems. I could definitely offer my help with at
least some of the text.

> If there's interest, I'll be happy to join in. And my own posting
> suggests how the ordering is enforced by bounding the "delta"
> parameters from below.

I have just tried nlsr::nlxb for a slightly larger dataset shared by
Troels off-list, and it worked great with the delta parameters as you
suggested, thank you!

It's interesting that nlxb and nlsLM give slightly different answers,
differing in 0.5 pK units for pK1 and (pK2-pK1) but not (pK3-pK2). Then
again, they both agree that the standard error for pK1 and (pK2-pK1) is
very large, so perhaps the problem is just very ill-conditioned.

-- 
Best regards,
Ivan

__
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] make a lattice dotplot with symbol size proportional to a variable in the plotted dataframe

2023-11-07 Thread Deepayan Sarkar
Handling NSE in these kinds of examples is a pain in lattice. I would
suggest using with() and dropping the data argument for simple examples,
e.g.,

dd |> mutate(new.proportion = las/total, new.bubble = total/100) |>
with(dotplot(agency ~ new.proportion, pch = 16, cex = new.bubble))

But if you care about multi-panel plots, you also need to be careful about
making sure that the 'cex' values get split properly. This is done
generally using the 'subscripts' argument provided to panel functions, so
something like this should be safer:

panel.bubble <- function(x, y, cex, ..., subscripts) {
panel.dotplot(x, y, cex = cex[subscripts], ...)
}

dd |> mutate(new.proportion = las/total, new.bubble = total/100) |>
with(dotplot(agency ~ new.proportion, pch = 16,
 cex = new.bubble, panel = panel.bubble))

Best,
-Deepayan

On Tue, 7 Nov 2023 at 11:03, Christopher Ryan via R-help <
r-help@r-project.org> wrote:

> Hello. My question is in the subject line. Using R 4.1.3 on Windows 10.
> Commented MWE below. Thanks.
>
> --Chris Ryan
>
>
>
> library(dplyr)
> library(lattice)
>
> ## fabricate a dataframe
> dd <- data.frame(agency = sample(LETTERS, size = 5),
> total = sample(100:200, size = 5),
> las = sample(20:40, size = 5))
> dd <- dd %>% mutate(proportion = las/total, bubble = total/100)
>
>
> ## attempt to make a dotplot with symbol size proportional
> ## to the variable named total
>
> dotplot(agency ~ proportion, pch = 16, cex = bubble, data = dd)
> ##  object 'bubble' not found
>
> dotplot(agency ~ proportion, pch = 16, cex = dd$bubble, data = dd)
> ## works
>
>
>
> ## also works in two commands
> external.bubble <- dd$bubble
> dotplot(agency ~ proportion, pch = 16, cex = external.bubble, data = dd)
>
>
>
> ## but how to chain it with pipes, dplyr-style,
> ## modifying the dataframe and then
> ## using the modified version in dotplot, all in one chain?
>
> dd %>% mutate(new.proportion = las/total, new.bubble = total/100) %>%
> dotplot(agency ~ new.proportion, pch = 16, cex = new.bubble, data = .)
> ## object 'new.bubble' not found
>
>
> dd %>% mutate(new.proportion = las/total, new.bubble = total/100) %>%
>  dotplot(agency ~ new.proportion, pch = 16, cex = .$new.bubble, data =
> .)
> ## the .$new.bubble syntax seems to work, but I've never
> ## used or seen that before, and it seems weird.
> ## Is there a "proper" syntax?
>
> [[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] make a lattice dotplot with symbol size proportional to a variable in the plotted dataframe

2023-11-07 Thread Christopher Ryan via R-help
Hello. My question is in the subject line. Using R 4.1.3 on Windows 10.
Commented MWE below. Thanks.

--Chris Ryan



library(dplyr)
library(lattice)

## fabricate a dataframe
dd <- data.frame(agency = sample(LETTERS, size = 5),
total = sample(100:200, size = 5),
las = sample(20:40, size = 5))
dd <- dd %>% mutate(proportion = las/total, bubble = total/100)


## attempt to make a dotplot with symbol size proportional
## to the variable named total

dotplot(agency ~ proportion, pch = 16, cex = bubble, data = dd)
##  object 'bubble' not found

dotplot(agency ~ proportion, pch = 16, cex = dd$bubble, data = dd)
## works



## also works in two commands
external.bubble <- dd$bubble
dotplot(agency ~ proportion, pch = 16, cex = external.bubble, data = dd)



## but how to chain it with pipes, dplyr-style,
## modifying the dataframe and then
## using the modified version in dotplot, all in one chain?

dd %>% mutate(new.proportion = las/total, new.bubble = total/100) %>%
dotplot(agency ~ new.proportion, pch = 16, cex = new.bubble, data = .)
## object 'new.bubble' not found


dd %>% mutate(new.proportion = las/total, new.bubble = total/100) %>%
 dotplot(agency ~ new.proportion, pch = 16, cex = .$new.bubble, data =
.)
## the .$new.bubble syntax seems to work, but I've never
## used or seen that before, and it seems weird.
## Is there a "proper" syntax?

[[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] Concordance and Kendall's tau in copula

2023-11-07 Thread Martin Maechler
> Steven Yen 
> on Tue, 7 Nov 2023 09:09:33 +0800 writes:

> 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 and what to use? Thank you.

> Steven Yen


I think you can estimate your model relatively easily using our
package {copula}  and the function  fitMvdc()

   https://search.r-project.org/CRAN/refmans/copula/html/fitMvdc.html

MVDC := Multivariate Variate Distribution {built from} Copula

To solve the question you asked --- but would not need to answer if
using fitMvdc(),
you can use  e.g.,

> iTau(claytonCopula(), tau = 1.4)
[1] -7

or look up the formulas for tau() or its inverse 'iTau':

  > copClayton@tau
  function (theta) 
  {
  theta/(theta + 2)
  }

  > copClayton@iTau
  function (tau) 
  {
  2 * tau/(1 - tau)
  }

  > 

Best regards,
Martin

{and yes, consider getting our 'useR! Springer series book, as
 it's the only "real" book, I've been a coauthor.. 
https://copula.r-forge.r-project.org/book/ }

--
Martin Maechler
ETH Zurich  and  R Core team

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