# How to do a global fit?

34 views

### Jan

May 24, 2017, 2:15:44 PM5/24/17
to Stan users mailing list
Hey stan Team,
what would be the smartest way do do global regression  in stan? The model block seems to something else than intended. It defently doesn't boost the precision of my fit.

Thanx for any comment.

Jan

`data {    int<lower=1> N_data;                                 // number of data points    int<lower=0, upper = 1000> y_t1[N_data];             // array of observations     int<lower=0, upper = 1000> y_t2[N_data];		// Array of observations    real<lower=0, upper =  10> time[N_data];		//predictor    int N_channel;}transformed data{                                   // ... declarations ... statements ...}parameters {                                        // The parameters we want to inference by via Stan    simplex[2] mu;    positive_ordered[2] theta;}`
`transformed parameters {                            	// ... declarations ... statements ...     real<lower = 0, upper = 1> probabilty[N_data];       // fitted values    for(i in 1:N_data){        probabilty[i] = 1 - mu[1] * exp(-theta[1] * time[i])- mu[2]* exp(-theta[2]*time[i]);    }}`

`model {      ...... `
`    y_t1 ~ binomial(N_channel, probabilty);    y_t2 ~ binomial(N_channel, probabilty);}`

### Bob Carpenter

May 24, 2017, 2:33:00 PM5/24/17
What's a "global regression"?

Your model can't be right because there's nothing insuring
your "probability" value falls in (0, 1).

There are lots of regression examples in the manual chapter
on regression and more in the case studies (web site under
docs) and example-models (ditto).

- Bob

P.S. This list is shutting down and moving to:

http://discourse.mc-stan.org
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

### Jan Münch

May 24, 2017, 4:13:47 PM5/24/17
Hi Bob,
hmm maybe I don't use the right terms. By global I mean that I use not just one time series of data but several which I want to use for inferencing the posterior of the model. > model {
>
>     ......
>     y_t1 ~ binomial(N_channel, probability);
>     y_t2 ~ binomial(N_channel, probability);
>
> }

seems not to do this job. So I guess I am using the sampling statement wrong. By writing two times the likelihood. The probability variable just worked fine for a single trace of data and stayed in the half open interval (0,1] as the stan output told me. And I expect that to be as long as "mu" is element of a simplex, "time_i" "theta_i" all bigger the zero. Hm I guess I am getting you wrong...

Anyways have a good afternoon

Jan

> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/gEkegRSrUWA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.

### Bob Carpenter

May 25, 2017, 5:02:00 PM5/25/17

> On May 24, 2017, at 4:13 PM, Jan Münch <jan.lenna...@gmail.com> wrote:
>
> Hi Bob,
> hmm maybe I don't use the right terms. By global I mean that I use not just one time series of data but several which I want to use for inferencing the posterior of the model. > model {
> >
> > ......
> > y_t1 ~ binomial(N_channel, probability);
> > y_t2 ~ binomial(N_channel, probability);
> >
> > }
>
> seems not to do this job.

That's fine. It says that both observations y_t1 and y_t2 have the same
number of trials and same success probability.

> So I guess I am using the sampling statement wrong. By writing two times the likelihood. The probability variable just worked fine for a single trace of data

I don't know what "single trace" means either.

> and stayed in the half open interval (0,1] as the stan output told me. And I expect that to be as long as "mu" is element of a simplex, "time_i" "theta_i" all bigger the zero. Hm I guess I am getting you wrong...

> probabilty[i] = 1 - mu[1] * exp(-theta[1] * time[i])- mu[2]* exp(-theta[2]*time[i]);

If time[i] = 0, then probability[i] = 0, too. This will require your outcomes
to have zero successes (and even then I'm not sure we handle the probability=0
case as it's degenerate).

- Bob
> > To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> > To post to this group, send email to stan-...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/gEkegRSrUWA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.