|
|
Dear list,
How do you delete repeated samples? In MCMC, when your candidate value has
been reject, so you remain on the same point, so you keep that value.
Say I have this toy example,
> c(1,6,6,6,3,5,4,4,2,3,5)
The 6 and 4 are repeated, I only want the index of the non-repeated values.
I thought of using which() and unique(), but that does not give you the
index of the unique values.
Thanks in advance.
Mike
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|
On 13-01-17 4:50 PM, C W wrote:
> Dear list,
> How do you delete repeated samples? In MCMC, when your candidate value has
> been reject, so you remain on the same point, so you keep that value.
>
> Say I have this toy example,
>
>> c(1,6,6,6,3,5,4,4,2,3,5)
>
> The 6 and 4 are repeated, I only want the index of the non-repeated values.
>
> I thought of using which() and unique(), but that does not give you the
> index of the unique values.
You could use x[!duplicated(x)] or rle(x)$values, depending on your
definition of "repeated". I hope you're aware that you can't use either
for things like quantiles and moments of the limiting distribution.
> x <- c(1,6,6,6,3,5,4,4,2,3,5)
> x[!duplicated(x)]
[1] 1 6 3 5 4 2
> rle(x)$values
[1] 1 6 3 5 4 2 3 5
Duncan Murdoch
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|
Exactly what I am looking for.
Thanks a lot!
Mike
On Thu, Jan 17, 2013 at 4:59 PM, Duncan Murdoch < [hidden email]>wrote:
> On 13-01-17 4:50 PM, C W wrote:
>
>> Dear list,
>> How do you delete repeated samples? In MCMC, when your candidate value
>> has
>> been reject, so you remain on the same point, so you keep that value.
>>
>> Say I have this toy example,
>>
>> c(1,6,6,6,3,5,4,4,2,3,5)
>>>
>>
>> The 6 and 4 are repeated, I only want the index of the non-repeated
>> values.
>>
>> I thought of using which() and unique(), but that does not give you the
>> index of the unique values.
>>
>
> You could use x[!duplicated(x)] or rle(x)$values, depending on your
> definition of "repeated". I hope you're aware that you can't use either
> for things like quantiles and moments of the limiting distribution.
>
> > x <- c(1,6,6,6,3,5,4,4,2,3,5)
> > x[!duplicated(x)]
> [1] 1 6 3 5 4 2
> > rle(x)$values
> [1] 1 6 3 5 4 2 3 5
>
> Duncan Murdoch
>
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|
On Jan 17, 2013, at 1:50 PM, C W wrote:
> Dear list,
> How do you delete repeated samples? In MCMC, when your candidate value has
> been reject, so you remain on the same point, so you keep that value.
>
> Say I have this toy example,
>
>> c(1,6,6,6,3,5,4,4,2,3,5)
> c(1,6,6,6,3,5,4,4,2,3,5)[!duplicated(c(1,6,6,6,3,5,4,4,2,3,5))]
[1] 1 6 3 5 4 2
> x <- c(1,6,6,6,3,5,4,4,2,3,5)
> x[!duplicated(x)]
[1] 1 6 3 5 4 2
> !duplicated(x)
[1] TRUE TRUE FALSE FALSE TRUE TRUE TRUE FALSE TRUE FALSE FALSE
> which(!duplicated(x))
[1] 1 2 5 6 7 9
>
> The 6 and 4 are repeated, I only want the index of the non-repeated values.
>
> I thought of using which() and unique(), but that does not give you the
> index of the unique values.
>
> Thanks in advance.
>
> Mike
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> 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.
David Winsemius
Alameda, CA, USA
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|
What answer is wanted for
c(1,1,1,2,3,1) ?
Note that Duncan's two suggestions below give different answers for this.
-- Bert
On Thu, Jan 17, 2013 at 1:59 PM, Duncan Murdoch
< [hidden email]> wrote:
> On 13-01-17 4:50 PM, C W wrote:
>>
>> Dear list,
>> How do you delete repeated samples? In MCMC, when your candidate value
>> has
>> been reject, so you remain on the same point, so you keep that value.
>>
>> Say I have this toy example,
>>
>>> c(1,6,6,6,3,5,4,4,2,3,5)
>>
>>
>> The 6 and 4 are repeated, I only want the index of the non-repeated
>> values.
>>
>> I thought of using which() and unique(), but that does not give you the
>> index of the unique values.
>
>
> You could use x[!duplicated(x)] or rle(x)$values, depending on your
> definition of "repeated". I hope you're aware that you can't use either for
> things like quantiles and moments of the limiting distribution.
>
>> x <- c(1,6,6,6,3,5,4,4,2,3,5)
>> x[!duplicated(x)]
> [1] 1 6 3 5 4 2
>> rle(x)$values
> [1] 1 6 3 5 4 2 3 5
>
> Duncan Murdoch
>
> ______________________________________________
> [hidden email] mailing list
> 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.
--
Bert Gunter
Genentech Nonclinical Biostatistics
Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|
I was looking for the first answer.
In MCMC, at time t, when the candidate sample is rejected,
> candidate_sample[t] <- current_sample
say, at time t+1, the sample is rejected AGAIN, we have
> candidate_sample[t+1] <- current_sample
so, at time t, and t+1, we have the same value. When I calculate the monte
carlo mean, I don't want repeated value.
Mike
On Thu, Jan 17, 2013 at 5:20 PM, Bert Gunter < [hidden email]> wrote:
> What answer is wanted for
>
> c(1,1,1,2,3,1) ?
>
> Note that Duncan's two suggestions below give different answers for this.
>
> -- Bert
>
> On Thu, Jan 17, 2013 at 1:59 PM, Duncan Murdoch
> < [hidden email]> wrote:
> > On 13-01-17 4:50 PM, C W wrote:
> >>
> >> Dear list,
> >> How do you delete repeated samples? In MCMC, when your candidate value
> >> has
> >> been reject, so you remain on the same point, so you keep that value.
> >>
> >> Say I have this toy example,
> >>
> >>> c(1,6,6,6,3,5,4,4,2,3,5)
> >>
> >>
> >> The 6 and 4 are repeated, I only want the index of the non-repeated
> >> values.
> >>
> >> I thought of using which() and unique(), but that does not give you the
> >> index of the unique values.
> >
> >
> > You could use x[!duplicated(x)] or rle(x)$values, depending on your
> > definition of "repeated". I hope you're aware that you can't use either
> for
> > things like quantiles and moments of the limiting distribution.
> >
> >> x <- c(1,6,6,6,3,5,4,4,2,3,5)
> >> x[!duplicated(x)]
> > [1] 1 6 3 5 4 2
> >> rle(x)$values
> > [1] 1 6 3 5 4 2 3 5
> >
> > Duncan Murdoch
> >
> > ______________________________________________
> > [hidden email] mailing list
> > 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.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
>
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|
On 13-01-17 5:33 PM, C W wrote:
> I was looking for the first answer.
>
> In MCMC, at time t, when the candidate sample is rejected,
>
> > candidate_sample[t] <- current_sample
>
> say, at time t+1, the sample is rejected AGAIN, we have
>
> > candidate_sample[t+1] <- current_sample
>
> so, at time t, and t+1, we have the same value. When I calculate the
> monte carlo mean, I don't want repeated value.
Then you will get the wrong answer, unless you want something very strange.
Duncan Murdoch
>
> Mike
>
> On Thu, Jan 17, 2013 at 5:20 PM, Bert Gunter < [hidden email]
> <mailto: [hidden email]>> wrote:
>
> What answer is wanted for
>
> c(1,1,1,2,3,1) ?
>
> Note that Duncan's two suggestions below give different answers for
> this.
>
> -- Bert
>
> On Thu, Jan 17, 2013 at 1:59 PM, Duncan Murdoch
> < [hidden email] <mailto: [hidden email]>> wrote:
> > On 13-01-17 4:50 PM, C W wrote:
> >>
> >> Dear list,
> >> How do you delete repeated samples? In MCMC, when your
> candidate value
> >> has
> >> been reject, so you remain on the same point, so you keep that
> value.
> >>
> >> Say I have this toy example,
> >>
> >>> c(1,6,6,6,3,5,4,4,2,3,5)
> >>
> >>
> >> The 6 and 4 are repeated, I only want the index of the non-repeated
> >> values.
> >>
> >> I thought of using which() and unique(), but that does not give
> you the
> >> index of the unique values.
> >
> >
> > You could use x[!duplicated(x)] or rle(x)$values, depending on your
> > definition of "repeated". I hope you're aware that you can't use
> either for
> > things like quantiles and moments of the limiting distribution.
> >
> >> x <- c(1,6,6,6,3,5,4,4,2,3,5)
> >> x[!duplicated(x)]
> > [1] 1 6 3 5 4 2
> >> rle(x)$values
> > [1] 1 6 3 5 4 2 3 5
> >
> > Duncan Murdoch
> >
> > ______________________________________________
> > [hidden email] <mailto: [hidden email]> mailing list
> > 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.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm>
>
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|