Re: [R] Method Guidance

2022-01-14 Thread Leonard Mada via R-help

Dear Jeff,


I am sending an updated version of the code.


The initial version assumed that the time points correspond to an 
integer sequence. The code would fail for arbitrary times.



The new code is robust. I still assume that the data is in column-format 
and that you want the time to the previous "A"-event, even if there are 
other non-A events in between.



The code is similar, but we cannot use seq(0, x-1) anymore. Instead, we 
will repeat the time point of the previous A-event. (Last-A Carried forward)



# jrdf = the data frame from my previous mail;
cumEvent = cumsum(jrdf$Event_A);
# we cannot use the actual values of the cumsum,
# but will use the number of (same) values to the previous event;
freqEvent = rle(cumEvent);
freqEvent = freqEvent$lengths;

# repeat the time-points
timesA = jrdf$Time[jrdf$Event_A == 1];
sameTime = rep(timesA, freqEvent);
timeToA = jrdf$Time - sameTime;

### Step 2:
# extract/view the times (as before);
timeToA[jrdf$Event_B >= 1];
# Every Time to A: e.g. for multiple extractions;
cbind(jrdf, timeToA);
# Time to A only for B: set non-B to 0;


# Note:
- the rle() function might be less known;
- it is "equivalent" to:
tbl = table(cumEvent);
# to be on the safe side (as the cumsum is increasing):
id = order(as.numeric(names(tbl)));
tbl = tbl[id];


Hope this helps,


Leonard


On 1/14/2022 3:30 AM, Leonard Mada wrote:

Dear Jeff,


My answer is a little bit late, but I hope it helps.


jrdf = read.table(text="Time   Event_A    Event_B   Lag_B
1  1 1    0
2  0 1    1
3  0 0    0
4  1 0    0
5  0 1    1
6  0 0    0
7  0 1    3
8  1 1    0
9  0 0    0
10 0 1    2",
header=TRUE, stringsAsFactors=FALSE)

Assuming that:
- Time, Event_A, Event_B are given;
- Lag_B needs to be computed;

Step 1:
- compute time to previous Event A;

tmp = jrdf[, c(1,2)];
# add an extra event so last rows are not lost:
tmp = rbind(tmp, c(nrow(tmp) + 1, 1));

timeBetweenA = diff(tmp$Time[tmp$Event_A > 0]);
timeToA = unlist(sapply(timeBetweenA, function(x) seq(0, x-1)))


### Step 2:
# - extract the times;
timeToA[jrdf$Event_B >= 1];
cbind(jrdf, timeToA);


Sincerely,


Leonard




__
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] Method Guidance

2022-01-13 Thread Bill Dunlap
Suppose your data were represented as parallel vectors "time" and "type",
meaning that at time[i] a type[i] event occurred.  You didn't say what you
wanted if there were a run of "A" or "B".  If you are looking for the time
span between the last of a run of one sort of event and the first of a run
of the other sort of event then the following can be used.

f <- function(time, type, fromType, toType) {
# return times of (fromTime) last of a run of 'fromType' and
# (toTime) first of subsequent run of 'toType for each such transition.
stopifnot(length(time)==length(type),
  !anyNA(type),
  !anyNA(time),
  !is.unsorted(time),
  length(fromType)==1,
  length(toType)==1)
i <- seq_len(length(time)-1)
iBeforeChange <- which((type[i] == fromType) & (type[i+1] == toType))
data.frame(fromTime=time[iBeforeChange], toTime=time[iBeforeChange+1L])
}

E.g.,

> d <- data.frame(time=c(101,102,102,105,107,111,115),
type=c("A","A","B","A","B","B","A"))
> d
  time type
1  101A
2  102A
3  102B
4  105A
5  107B
6  111B
7  115A
> f(time=d$time, type=d$type, fromType="A", toType="B")
  fromTime toTime
1  102102
2  105107
> with(.Last.value, toTime - fromTime)
[1] 0 2
> f(time=d$time, type=d$type, fromType="B", toType="A")
  fromTime toTime
1  102105
2  111115
> with(.Last.value, toTime - fromTime)
[1] 3 4

With the dplyr package you can avoid the index 'i' by using lag() inside of
mutate().  E.g.,

> d |> mutate(AtoB = (lag(type)=="A" & type=="B"))
  time type  AtoB
1  101A FALSE
2  102A FALSE
3  102B  TRUE
4  105A FALSE
5  107B  TRUE
6  111B FALSE
7  115A FALSE

-Bill


On Tue, Jan 11, 2022 at 4:56 PM Jeff Reichman 
wrote:

> R-Help Forum
>
>
>
> Looking for a little guidance. Have an issue were I'm trying to determine
> the time between when Event A happened(In days) to when a subsequent Event
> B
> happens. For Example at Time 1 Evat A happens and subsequently Event B
> happens at the same day (0) and the next day (1) then Event A happens again
> at time 4 and Event B happens the next day and 3 days later so on and so
> forth. I gather there is no function that will do that so I suspect I will
> need to grate so sour of do while loop?  Any suggestions?
>
>
>
>
>
> Time  Event_A   Event_B   Time_B
>
> 1  1  1
> 0
>
> 2  0  1
> 1
>
> 3  0  0
> 0
>
> 4  1  0
> 0
>
> 5  0  1
> 1
>
> 6  0  0
> 0
>
> 7  0  1
> 3
>
> 8  1  1
> 0
>
> 9  0  0
> 0
>
> 10   0  1
> 2
>
>
>
>
> Jeff Reichman
>
>
> [[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.


Re: [R] Method Guidance

2022-01-13 Thread Leonard Mada via R-help

Dear Jeff,


My answer is a little bit late, but I hope it helps.


jrdf = read.table(text="Time   Event_AEvent_B   Lag_B
1  1 10
2  0 11
3  0 00
4  1 00
5  0 11
6  0 00
7  0 13
8  1 10
9  0 00
10 0 12",
header=TRUE, stringsAsFactors=FALSE)

Assuming that:
- Time, Event_A, Event_B are given;
- Lag_B needs to be computed;

Step 1:
- compute time to previous Event A;

tmp = jrdf[, c(1,2)];
# add an extra event so last rows are not lost:
tmp = rbind(tmp, c(nrow(tmp) + 1, 1));

timeBetweenA = diff(tmp$Time[tmp$Event_A > 0]);
timeToA = unlist(sapply(timeBetweenA, function(x) seq(0, x-1)))


### Step 2:
# - extract the times;
timeToA[jrdf$Event_B >= 1];
cbind(jrdf, timeToA);


Sincerely,


Leonard

__
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] Method Guidance

2022-01-12 Thread Avi Gross via R-help
To be fair, Jim, when people stop and think carefully before sending a message 
to a forum like this, and then explain their situation and request carefully 
and in enough detail, often a solution comes to them and they can abort sending!
Yes, the question asked is a bit vague. Other than asking for more details, the 
answers would also tend to be vague, or completely mysterious.
Someone sent a pointer to a web page that may well supply ideas to use, but 
maybe not as the question remains unclear.
So here is my vague reply. You say you have data in what seems to be a 
data.frame that includes some events marked with a starting time and other 
related events with a starting/stopping time or something like that. 
You want in some way to line up two or more such related events so you can 
calculate something like time elapsed. I am not clear if these come in pairs or 
can be extended as in go from point A to B then C and so on. For some such 
things, a data.frame may not ultimately be the right data structure.
So first you need to specify how to match things up. Is there another common 
field like StudentID that can be used to find all records showing when they 
began doing A or B? If not, how do you recognize what B goes with what A? The 
difference matters in terms of how to approach the problem.
Once you show a small representative sample, maybe people can suggest 
approaches. I did not find your sample even slightly useful. Lots of 1 and 0 
and maybe some wrapping lines.
The overall approaches for doing what I hope you are doing, vary. You can of 
course go through the data row by row and look forward and do a calculation and 
print results. Or, you might want to reshape your data, perhaps merging subsets 
of the data with other subsets, to create new data where the start and stop 
segments are in the same row in multiple columns. The latter might be useful 
for all kinds of analyses including making graphs.
Your example seems to suggest you have a variable that is focused on days so 
you have not shown some kind of date field. But do events always happen in 
subsequent days, like in a game of postal chess, or can it happen within a day, 
perhaps multiple times, like taking your dog for a walk? Can two events 
interweave or is there a guarantee that each event completes before the next 
round starts? Is your data in a specific time order so B always follows A?
Many questions like the above matter in understanding your purpose and goal and 
then seeing what algorithm will take the data you start with and do something. 
If organized in certain ways and with no errors, it may be trivial. If not, in 
some cases it simply is not doable. And in some cases, such as buying and 
selling shares of stock, you have interesting things like rules of what happens 
if you buy back shares within a month or so as to whether you adjust the basis 
and of course the length of time can determine capital gains rates. More 
complexity is whether you have to do some kind of averaging or FIFO or can 
designate which shares. Now this may have nothing to do with your application, 
but is an example of why some problems may better be treated differently than 
others.

-Original Message-
From: Jim Lemon 
To: Jeff Newmiller 
Cc: r-help mailing list 
Sent: Wed, Jan 12, 2022 1:44 am
Subject: Re: [R] Method Guidance

Hi Jeff,
A completely obscure question deserves a completely obscure answer:

jrdf<-read.table(text="Time  Event_A    Event_B  Lag_B
1          1        1        0
2          0        1        1
3          0        0        0
4          1        0        0
5          0        1        1
6          0        0        0
7          0        1        3
8          1        1        0
9          0        0        0
10        0        1        2",
header=TRUE,stringsAsFactors=FALSE)
plot(jrdf$Time-0.2,jrdf$Event_A,type="p",
 xlim=c(1,12),ylim=c(0.9,1.1),
 xlab="Day",ylab="",main="The As and the Bs",
 pch=c(" ","A")[jrdf$Event_A+1],yaxt="n")
points(jrdf$Time+jrdf$Lag_B+0.2,jrdf$Event_B,pch=c(" ","B")[jrdf$Event_B+1])

Jim

On Wed, Jan 12, 2022 at 1:33 PM Jeff Newmiller  wrote:
>
> 1) Figure out how to post plain text please. What you saw is not what we see.
>
> 2) I see a "table" of input information but no specific expectation of what 
> would come out of this hypothetical function.
>
> 3) Maybe you will find something relevant in this blog post: 
> https://jdnewmil.github.io/blog/post/cumsum-and-diff-tricks/
>
> ps not sure what "grate so sour" was supposed to be.
>
> pps While loops are not necessarily evil.
>
> On January 11, 2022 4:56:20 PM PST, Jeff Reichman  
> wrote:
> >R-Help Forum
> >
> >
> >
> >Looking for a little guidance. Have an issue were I'm trying to determine
> >the time between when Event A happene

Re: [R] Method Guidance

2022-01-12 Thread Jeff Reichman
Rui

Well that certainly is a lot more straight forward than the direction I was 
trying and you have introduced me to a couple of new functions. Thank you

Jeff

-Original Message-
From: Rui Barradas  
Sent: Wednesday, January 12, 2022 5:08 AM
To: reichm...@sbcglobal.net; r-help@r-project.org
Subject: Re: [R] Method Guidance

Hello,

Here is a base R solution for what I understand of the question.
It involves ave and cumsum. cumsum of the values of Event_A breaks Event_B in 
segments and ave applies a function to each segment. To find where are the 
times B, coerce to logical and have which() take care of it. Data in dput 
format at the end.



ave(as.logical(df1$Event_B), cumsum(df1$Event_A),
 FUN = function(x) {
   y <- integer(length(x))
   y[x] <- which(x) - 1L
   y
 })
#[1] 0 1 0 0 1 0 3 0 0 2


More readable, with an auxiliary function.


aux_fun <- function(x) {
   y <- integer(length(x))
   y[x] <- which(x) - 1L
   y
}

ave(as.logical(df1$Event_B), cumsum(df1$Event_A), FUN = aux_fun) #[1] 0 1 0 0 1 
0 3 0 0 2



Now assign this result to a df1 column. Here I just test for equality.


new <- ave(as.logical(df1$Event_B), cumsum(df1$Event_A), FUN = aux_fun) 
identical(new, df1$Time_B) #[1] TRUE


# Data
df1 <-
structure(list(Time = 1:10, Event_A = c(1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 
0L), Event_B = c(1L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L), Time_B = c(0L, 1L, 
0L, 0L, 1L, 0L, 3L, 0L, 0L, 2L)), class = "data.frame", row.names = c(NA, -10L))



Hope this helps,

Rui Barradas

Às 00:56 de 12/01/22, Jeff Reichman escreveu:
> R-Help Forum
> 
>   
> 
> Looking for a little guidance. Have an issue were I'm trying to 
> determine the time between when Event A happened(In days) to when a 
> subsequent Event B happens. For Example at Time 1 Evat A happens and 
> subsequently Event B happens at the same day (0) and the next day (1) 
> then Event A happens again at time 4 and Event B happens the next day 
> and 3 days later so on and so forth. I gather there is no function 
> that will do that so I suspect I will need to grate so sour of do while loop? 
>  Any suggestions?
> 
>   
> 
>   
> 
> Time  Event_A   Event_B   Time_B
> 
> 1  1  1
> 0
> 
> 2  0  1
> 1
> 
> 3  0  0
> 0
> 
> 4  1  0
> 0
> 
> 5  0  1
> 1
> 
> 6  0  0
> 0
> 
> 7  0  1
> 3
> 
> 8  1  1
> 0
> 
> 9  0  0
> 0
> 
> 10   0  1  2
> 
> 
>   
> 
> Jeff Reichman
> 
> 
>   [[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.


Re: [R] Method Guidance

2022-01-12 Thread Rui Barradas

Hello,

Here is a base R solution for what I understand of the question.
It involves ave and cumsum. cumsum of the values of Event_A breaks 
Event_B in segments and ave applies a function to each segment. To find 
where are the times B, coerce to logical and have which() take care of 
it. Data in dput format at the end.




ave(as.logical(df1$Event_B), cumsum(df1$Event_A),
FUN = function(x) {
  y <- integer(length(x))
  y[x] <- which(x) - 1L
  y
})
#[1] 0 1 0 0 1 0 3 0 0 2


More readable, with an auxiliary function.


aux_fun <- function(x) {
  y <- integer(length(x))
  y[x] <- which(x) - 1L
  y
}

ave(as.logical(df1$Event_B), cumsum(df1$Event_A), FUN = aux_fun)
#[1] 0 1 0 0 1 0 3 0 0 2



Now assign this result to a df1 column. Here I just test for equality.


new <- ave(as.logical(df1$Event_B), cumsum(df1$Event_A), FUN = aux_fun)
identical(new, df1$Time_B)
#[1] TRUE


# Data
df1 <-
structure(list(Time = 1:10, Event_A = c(1L, 0L, 0L, 1L, 0L, 0L,
0L, 1L, 0L, 0L), Event_B = c(1L, 1L, 0L, 0L, 1L, 0L, 1L, 1L,
0L, 1L), Time_B = c(0L, 1L, 0L, 0L, 1L, 0L, 3L, 0L, 0L, 2L)),
class = "data.frame", row.names = c(NA, -10L))



Hope this helps,

Rui Barradas

Às 00:56 de 12/01/22, Jeff Reichman escreveu:

R-Help Forum

  


Looking for a little guidance. Have an issue were I'm trying to determine
the time between when Event A happened(In days) to when a subsequent Event B
happens. For Example at Time 1 Evat A happens and subsequently Event B
happens at the same day (0) and the next day (1) then Event A happens again
at time 4 and Event B happens the next day and 3 days later so on and so
forth. I gather there is no function that will do that so I suspect I will
need to grate so sour of do while loop?  Any suggestions?

  

  


Time  Event_A   Event_B   Time_B

1  1  1
0

2  0  1
1

3  0  0
0

4  1  0
0

5  0  1
1

6  0  0
0

7  0  1
3

8  1  1
0

9  0  0
0

10   0  1  2


  


Jeff Reichman


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


Re: [R] Method Guidance

2022-01-11 Thread Jim Lemon
Hi Jeff,
A completely obscure question deserves a completely obscure answer:

jrdf<-read.table(text="Time   Event_AEvent_B   Lag_B
1  1 10
2  0 11
3  0 00
4  1 00
5  0 11
6  0 00
7  0 13
8  1 10
9  0 00
10 0 12",
header=TRUE,stringsAsFactors=FALSE)
plot(jrdf$Time-0.2,jrdf$Event_A,type="p",
 xlim=c(1,12),ylim=c(0.9,1.1),
 xlab="Day",ylab="",main="The As and the Bs",
 pch=c(" ","A")[jrdf$Event_A+1],yaxt="n")
points(jrdf$Time+jrdf$Lag_B+0.2,jrdf$Event_B,pch=c(" ","B")[jrdf$Event_B+1])

Jim

On Wed, Jan 12, 2022 at 1:33 PM Jeff Newmiller  wrote:
>
> 1) Figure out how to post plain text please. What you saw is not what we see.
>
> 2) I see a "table" of input information but no specific expectation of what 
> would come out of this hypothetical function.
>
> 3) Maybe you will find something relevant in this blog post: 
> https://jdnewmil.github.io/blog/post/cumsum-and-diff-tricks/
>
> ps not sure what "grate so sour" was supposed to be.
>
> pps While loops are not necessarily evil.
>
> On January 11, 2022 4:56:20 PM PST, Jeff Reichman  
> wrote:
> >R-Help Forum
> >
> >
> >
> >Looking for a little guidance. Have an issue were I'm trying to determine
> >the time between when Event A happened(In days) to when a subsequent Event B
> >happens. For Example at Time 1 Evat A happens and subsequently Event B
> >happens at the same day (0) and the next day (1) then Event A happens again
> >at time 4 and Event B happens the next day and 3 days later so on and so
> >forth. I gather there is no function that will do that so I suspect I will
> >need to grate so sour of do while loop?  Any suggestions?
> >
> >
> >
> >
> >
> >Time  Event_A   Event_B   Time_B
> >
> >1  1  1
> >0
> >
> >2  0  1
> >1
> >
> >3  0  0
> >0
> >
> >4  1  0
> >0
> >
> >5  0  1
> >1
> >
> >6  0  0
> >0
> >
> >7  0  1
> >3
> >
> >8  1  1
> >0
> >
> >9  0  0
> >0
> >
> >10   0  1  2
> >
> >
> >
> >
> >Jeff Reichman
> >
> >
> >   [[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.
>
> --
> 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.

__
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] Method Guidance

2022-01-11 Thread Jeff Newmiller
1) Figure out how to post plain text please. What you saw is not what we see.

2) I see a "table" of input information but no specific expectation of what 
would come out of this hypothetical function.

3) Maybe you will find something relevant in this blog post: 
https://jdnewmil.github.io/blog/post/cumsum-and-diff-tricks/

ps not sure what "grate so sour" was supposed to be.

pps While loops are not necessarily evil.

On January 11, 2022 4:56:20 PM PST, Jeff Reichman  
wrote:
>R-Help Forum
>
> 
>
>Looking for a little guidance. Have an issue were I'm trying to determine
>the time between when Event A happened(In days) to when a subsequent Event B
>happens. For Example at Time 1 Evat A happens and subsequently Event B
>happens at the same day (0) and the next day (1) then Event A happens again
>at time 4 and Event B happens the next day and 3 days later so on and so
>forth. I gather there is no function that will do that so I suspect I will
>need to grate so sour of do while loop?  Any suggestions?
>
> 
>
> 
>
>Time  Event_A   Event_B   Time_B
>
>1  1  1
>0
>
>2  0  1
>1  
>
>3  0  0
>0
>
>4  1  0
>0
>
>5  0  1
>1
>
>6  0  0
>0
>
>7  0  1
>3
>
>8  1  1
>0
>
>9  0  0
>0
>
>10   0  1  2
>
>
> 
>
>Jeff Reichman
>
>
>   [[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.

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


[R] Method Guidance

2022-01-11 Thread Jeff Reichman
R-Help Forum

 

Looking for a little guidance. Have an issue were I'm trying to determine
the time between when Event A happened(In days) to when a subsequent Event B
happens. For Example at Time 1 Evat A happens and subsequently Event B
happens at the same day (0) and the next day (1) then Event A happens again
at time 4 and Event B happens the next day and 3 days later so on and so
forth. I gather there is no function that will do that so I suspect I will
need to grate so sour of do while loop?  Any suggestions?

 

 

Time  Event_A   Event_B   Time_B

1  1  1
0

2  0  1
1  

3  0  0
0

4  1  0
0

5  0  1
1

6  0  0
0

7  0  1
3

8  1  1
0

9  0  0
0

10   0  1  2


 

Jeff Reichman


[[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] Method dispatch sometimes failsfor lavaan objects

2019-12-05 Thread Ulrich KELLER
Hello,

in some R sessions, method dispatch for objects of the (S4) class “lavaan" 
fail. An example from such a “bad” session:

> library(lavaan)
> HS.model <- ' visual  =~ x1 + x2 + x3
+   textual =~ x4 + x5 + x6
+   speed   =~ x7 + x8 + x9 '
> fit <- cfa(HS.model, data = HolzingerSwineford1939)
> vcov(fit)
Error in UseMethod("vcov") : 
  no applicable method for 'vcov' applied to an object of class “lavaan"

But everything _seems_ to be fine:

> selectMethod("vcov", list("lavaan"))
[…]


Signatures:
object  
target  "lavaan"
defined “lavaan"

> pryr::method_from_call(vcov(fit))
[…]


Signatures:
object  
target  "lavaan"
defined “lavaan”

For other calls, R uses the default method instead of the one for lavaan, 
leading to other errors:

> coef(fit)
Error: $ operator not defined for this S4 class
> traceback()
2: coef.default(fit)
1: coef(fit)

Here too, selectMethod() seems to indicate that everything is fine.

As I mentioned, this happens in “some” R sessions, but I haven’t been able no 
narrow down what distinguishes “bad” from “good” sessions (where the problem 
does not occur). I’ve tried starting with a new session with just package 
lavaan loaded (where it works) and then one by one loading the same packages I 
have loaded in a bad session, but I can’t reproduce the error in the new 
session.

Some time ago, somebody posted this problem to the lavaan Google group, but 
nothing came of it 
(https://groups.google.com/forum/#!topic/lavaan/LoUemqNhXBM). My hope is that 
somebody here will have an idea for investigating this problem further.

Thanks a lot in advance,

Uli


Session info from a bad session with almost all objects removed from the 
workspace and restarted with only lavaan package loaded:

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: 
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

other attached packages:
[1] lavaan_0.6-5

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3   rstudioapi_0.10  knitr_1.25   magrittr_1.5 
tidyselect_0.2.5
 [6] mnormt_1.5-5 pbivnorm_0.6.0   R6_2.4.0 rlang_0.4.1  
stringr_1.4.0   
[11] dplyr_0.8.3  globals_0.12.4   tools_3.6.1  parallel_3.6.1   
xfun_0.10   
[16] htmltools_0.4.0  assertthat_0.2.1 digest_0.6.22tibble_2.1.3 
crayon_1.3.4
[21] pryr_0.1.4   purrr_0.3.3  codetools_0.2-16 glue_1.3.1   
stringi_1.4.3   
[26] compiler_3.6.1   pillar_1.4.2 stats4_3.6.1 future_1.15.0
listenv_0.7.0   
[31] pkgconfig_2.0.3 


Session info from a good session with lots of packages loaded while trying to 
reproduce the problem:

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: 
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

other attached packages:
 [1] future_1.15.0 rlang_0.4.1   magrittr_1.5  
TAM_3.3-10   
 [5] CDM_7.4-19mvtnorm_1.0-11semPlot_1.1.2 
MplusAutomation_0.7-3
 [9] forcats_0.4.0 stringr_1.4.0 dplyr_0.8.3   
purrr_0.3.3  
[13] readr_1.3.1   tidyr_1.0.0   tibble_2.1.3  
ggplot2_3.2.1
[17] tidyverse_1.2.1   psych_1.8.12  semTools_0.5-2
lavaan_0.6-5 

loaded via a namespace (and not attached):
  [1] minqa_1.2.4 colorspace_1.4-1rjson_0.2.20
htmlTable_1.13.2   
  [5] corpcor_1.6.9   base64enc_0.1-3 rstudioapi_0.10 listenv_0.7.0 
 
  [9] lubridate_1.7.4 xml2_1.2.2  codetools_0.2-16splines_3.6.1 
 
 [13] mnormt_1.5-5knitr_1.25  glasso_1.11 
texreg_1.36.23 
 [17] zeallot_0.1.0   Formula_1.2-3   jsonlite_1.6nloptr_1.2.1  
 
 [21] broom_0.5.2 cluster_2.1.0   png_0.1-7   regsem_1.3.9  
 
 [25] compiler_3.6.1  httr_1.4.1  backports_1.1.5 
assertthat_0.2.1   
 [29] Matrix_1.2-17   lazyeval_0.2.2  cli_1.1.0   acepack_1.4.1 
 
 [33] htmltools_0.4.0 tools_3.6.1 OpenMx_2.14.11  
igraph_1.2.4.1 
 [37] coda_0.19-3 gtable_0.3.0glue_1.3.1  
reshape

[R] method of moments estimation

2015-02-16 Thread hms Dreams
Hi,
I'm trying to use method of moments estimation to estimate 3 unkown paramters 
delta,k and alpha.
so I had system of 3 non linear equations:
 
1)  [delta^(1/alpha) *gamma (k-(1/alpha)) ]/gamma(k) = xbar
2)  [delta^(2/alpha) *gamma (k-(2/alpha)) ]/gamma(k) = 1/n *sum (x^2)
3)   [delta^(3/alpha) *gamma (k-(3/alpha)) ]/gamma(k) = 1/n *sum (x^3)
where gamma is a gamma function and  n is the sample size 

 How can I solve these system , Is there a package on R can give me MOM ??
 
Thank you ,
Sara 

 
  
[[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] method default for hclust function

2013-12-13 Thread David Carlson
I think the OP was asking about the agglomeration method in
hclust(), not the distance measure in dist(). And the default in
dist() is not absolute distance which is not an option, but
Euclidean distance:

> dist(cbind(v, v))
 12345
2 1.414214
3 2.828427 1.414214   
4 4.242641 2.828427 1.414214  
5 5.656854 4.242641 2.828427 1.414214 
6 7.071068 5.656854 4.242641 2.828427 1.414214

For a single vector (column) such as v <- 1:6, Euclidean,
Manhattan, Maximum, and Minkowski will all give the same result.

-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of eliza botto
Sent: Thursday, December 12, 2013 5:15 PM
To: capricy gao; r-help@r-project.org
Subject: Re: [R] method default for hclust function

Absolute distance is the default distance in hclust.
v<-c(1,2,3,4,5,6)
dist(v)
2 1
3 2 1  
4 3 2 1
5 4 3 2 1  
6 5 4 3 2 1

Eliza

> Date: Thu, 12 Dec 2013 15:09:19 -0800
> From: capri...@yahoo.com
> To: r-help@r-project.org
> Subject: [R] method default for hclust function
> 
> I could not figure out what was the default when I ran
hclust() without specifying the method.
> 
> For example:
> 
> I just have a code like:
> 
> hclust(dist(data))
> 
> Any input would be appreciated:)
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org 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.
  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] method default for hclust function

2013-12-12 Thread Peter Langfelder
On Thu, Dec 12, 2013 at 3:09 PM, capricy gao  wrote:
> I could not figure out what was the default when I ran hclust() without 
> specifying the method.

According to help("hclust"), the default method is complete linkage.

HTH,

Peter

__
R-help@r-project.org 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.


Re: [R] method default for hclust function

2013-12-12 Thread eliza botto
Absolute distance is the default distance in hclust. v<-c(1,2,3,4,5,6)
dist(v)
2 1
3 2 1  
4 3 2 1
5 4 3 2 1  
6 5 4 3 2 1

Eliza

> Date: Thu, 12 Dec 2013 15:09:19 -0800
> From: capri...@yahoo.com
> To: r-help@r-project.org
> Subject: [R] method default for hclust function
> 
> I could not figure out what was the default when I ran hclust() without 
> specifying the method.
> 
> For example:
> 
> I just have a code like:
> 
> hclust(dist(data))
> 
> Any input would be appreciated:)
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org 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.
  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] method default for hclust function

2013-12-12 Thread capricy gao
I could not figure out what was the default when I ran hclust() without 
specifying the method.

For example:

I just have a code like:

hclust(dist(data))

Any input would be appreciated:)
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Method dispatch in S4

2013-08-09 Thread Bert Gunter
Please read the proto vignette before asking further questions about
it. It is an alternative to/version of OOP different from S3 and S4.

-- Bert

On Fri, Aug 9, 2013 at 8:13 AM, Simon Zehnder  wrote:
> Hi Martin,
>
> is proto in S3?
>
> I will take a look first at the simple package EBImage.
>
> Thank you very much for the suggestions!
>
> Best
>
> Simon
>
>
> On Aug 9, 2013, at 5:01 PM, Martin Morgan  wrote:
>
>> On 08/09/2013 07:45 AM, Bert Gunter wrote:
>>> Simon:
>>>
>>> Have a look at the "proto" package for which there is a vignette. You
>>> may find it suitable for your needs and less intimidating.
>>
>> Won't help much with S4, though! Some answers here
>>
>> http://stackoverflow.com/questions/5437238/which-packages-make-good-use-of-s4-objects
>>
>> including from Bioconductor simple class in EBImage, the advanced IRanges 
>> package and the 'toy' StudentGWAS.
>>
>> Martin
>>
>>>
>>> Cheers,
>>> Bert
>>>
>>> On Fri, Aug 9, 2013 at 7:40 AM, Simon Zehnder  wrote:
 Hi Martin,

 thank you very much for this profound answer! Your added design advice is 
 very helpful, too!

 For the 'simple example': Sometimes I am still a little overwhelmed from a 
 certain setting in the code and my ideas how I want to handle a process. 
 But I learn from session to session. In future I will also span the lines 
 more than 80 columns. I am used to the indent in my vim editor.

 I have one further issue: I do know, that you are one of the leading 
 developers of the bioconductor package which uses (as far as I have read) 
 extensively OOP in R. Is there a package you could suggest to me to learn 
 from by reading and understanding the code? Where can I find the source 
 code?

 Best

 Simon


 On Aug 8, 2013, at 10:00 PM, Martin Morgan  wrote:

> On 08/04/2013 02:13 AM, Simon Zehnder wrote:
>> So, I found a solution: First in the "initialize" method of class C 
>> coerce
>> the C object into a B object. Then call the next method in the list with 
>> the
>> B class object. Now, in the "initialize" method of class B the object is 
>> a B
>> object and the respective "generateSpec" method is called. Then, in the
>> "initialize" method of C the returned object from "callNextMethod" has 
>> to be
>> written to the C class object in .Object. See the code below.
>>
>> setMethod("initialize", "C", function(.Object, value) {.Object@c <- 
>> value;
>> object <- as(.Object, "B"); object <- callNextMethod(object, value);
>> as(.Object, "B") <- object; .Object <- generateSpec(.Object);
>> return(.Object)})
>>
>> This setting works. I do not know though, if this setting is the "usual" 
>> way
>> such things are done in R OOP. Maybe the whole class design is
>> disadvantageous. If anyone detects a mistaken design, I am very thankful 
>> to
>> learn.
>
> Hi Simon -- your 'simple' example is pretty complicated, and I didn't 
> really follow it in detail! The code is not formatted for easy reading 
> (e.g., lines spanning no more than 80 columns) and some of it (e.g., 
> generateSpec) might not be necessary to describe the problem you're 
> having.
>
> A good strategy is to ensure that 'new' called with no arguments works 
> (there are other solutions, but following this rule has helped me to keep 
> my classes and methods simple). This is not the case for
>
>  new("A")
>  new("C")
>
> The reason for this strategy has to do with the way inheritance is 
> implemented, in particular the coercion from derived to super class. 
> Usually it is better to provide default values for arguments to 
> initialize, and to specify arguments after a '...'. This means that your 
> initialize methods will respects the contract set out in ?initialize, in 
> particular the handling of unnamed arguments:
>
> ...: data to include in the new object.  Named arguments
>  correspond to slots in the class definition. Unnamed
>  arguments must be objects from classes that this class
>  extends.
>
> I might have written initialize,A-method as
>
>  setMethod("initialize", "A", function(.Object, ..., value=numeric()){
>  .Object <- callNextMethod(.Object, ..., a=value)
>  generateSpec(.Object)
>  })
>
> Likely in a subsequent iteration I would have ended up with (using the 
> convention that function names preceded by '.' are not exported)
>
>  .A <- setClass("A", representation(a = "numeric", specA = "numeric"))
>
>  .generateSpecA <- function(a) {
>  1 / a
>   }
>
>  A <- function(a=numeric(), ...) {
>  specA <- .generateSpecA(a)
>  .A(..., a=a, specA=specA)
>  }
>
>  setMethod(generateSpec, "A", function(object) {
>  .generateSpecA(o

Re: [R] Method dispatch in S4

2013-08-09 Thread Simon Zehnder
Hi Martin,

is proto in S3? 

I will take a look first at the simple package EBImage. 

Thank you very much for the suggestions!

Best

Simon


On Aug 9, 2013, at 5:01 PM, Martin Morgan  wrote:

> On 08/09/2013 07:45 AM, Bert Gunter wrote:
>> Simon:
>> 
>> Have a look at the "proto" package for which there is a vignette. You
>> may find it suitable for your needs and less intimidating.
> 
> Won't help much with S4, though! Some answers here
> 
> http://stackoverflow.com/questions/5437238/which-packages-make-good-use-of-s4-objects
> 
> including from Bioconductor simple class in EBImage, the advanced IRanges 
> package and the 'toy' StudentGWAS.
> 
> Martin
> 
>> 
>> Cheers,
>> Bert
>> 
>> On Fri, Aug 9, 2013 at 7:40 AM, Simon Zehnder  wrote:
>>> Hi Martin,
>>> 
>>> thank you very much for this profound answer! Your added design advice is 
>>> very helpful, too!
>>> 
>>> For the 'simple example': Sometimes I am still a little overwhelmed from a 
>>> certain setting in the code and my ideas how I want to handle a process. 
>>> But I learn from session to session. In future I will also span the lines 
>>> more than 80 columns. I am used to the indent in my vim editor.
>>> 
>>> I have one further issue: I do know, that you are one of the leading 
>>> developers of the bioconductor package which uses (as far as I have read) 
>>> extensively OOP in R. Is there a package you could suggest to me to learn 
>>> from by reading and understanding the code? Where can I find the source 
>>> code?
>>> 
>>> Best
>>> 
>>> Simon
>>> 
>>> 
>>> On Aug 8, 2013, at 10:00 PM, Martin Morgan  wrote:
>>> 
 On 08/04/2013 02:13 AM, Simon Zehnder wrote:
> So, I found a solution: First in the "initialize" method of class C coerce
> the C object into a B object. Then call the next method in the list with 
> the
> B class object. Now, in the "initialize" method of class B the object is 
> a B
> object and the respective "generateSpec" method is called. Then, in the
> "initialize" method of C the returned object from "callNextMethod" has to 
> be
> written to the C class object in .Object. See the code below.
> 
> setMethod("initialize", "C", function(.Object, value) {.Object@c <- value;
> object <- as(.Object, "B"); object <- callNextMethod(object, value);
> as(.Object, "B") <- object; .Object <- generateSpec(.Object);
> return(.Object)})
> 
> This setting works. I do not know though, if this setting is the "usual" 
> way
> such things are done in R OOP. Maybe the whole class design is
> disadvantageous. If anyone detects a mistaken design, I am very thankful 
> to
> learn.
 
 Hi Simon -- your 'simple' example is pretty complicated, and I didn't 
 really follow it in detail! The code is not formatted for easy reading 
 (e.g., lines spanning no more than 80 columns) and some of it (e.g., 
 generateSpec) might not be necessary to describe the problem you're having.
 
 A good strategy is to ensure that 'new' called with no arguments works 
 (there are other solutions, but following this rule has helped me to keep 
 my classes and methods simple). This is not the case for
 
  new("A")
  new("C")
 
 The reason for this strategy has to do with the way inheritance is 
 implemented, in particular the coercion from derived to super class. 
 Usually it is better to provide default values for arguments to 
 initialize, and to specify arguments after a '...'. This means that your 
 initialize methods will respects the contract set out in ?initialize, in 
 particular the handling of unnamed arguments:
 
 ...: data to include in the new object.  Named arguments
  correspond to slots in the class definition. Unnamed
  arguments must be objects from classes that this class
  extends.
 
 I might have written initialize,A-method as
 
  setMethod("initialize", "A", function(.Object, ..., value=numeric()){
  .Object <- callNextMethod(.Object, ..., a=value)
  generateSpec(.Object)
  })
 
 Likely in a subsequent iteration I would have ended up with (using the 
 convention that function names preceded by '.' are not exported)
 
  .A <- setClass("A", representation(a = "numeric", specA = "numeric"))
 
  .generateSpecA <- function(a) {
  1 / a
   }
 
  A <- function(a=numeric(), ...) {
  specA <- .generateSpecA(a)
  .A(..., a=a, specA=specA)
  }
 
  setMethod(generateSpec, "A", function(object) {
  .generateSpecA(object@a)
  })
 
 ensuring that A() returns a valid object and avoiding the definition of an 
 initialize method entirely.
 
 Martin
 
> 
> Best
> 
> Simon
> 
> 
> On Aug 3, 2013, at 9:43 PM, Simon Zehnder 
> wrote:
> 
>> setMethod("initialize", "C", function(.

Re: [R] Method dispatch in S4

2013-08-09 Thread Martin Morgan

On 08/09/2013 07:45 AM, Bert Gunter wrote:

Simon:

Have a look at the "proto" package for which there is a vignette. You
may find it suitable for your needs and less intimidating.


Won't help much with S4, though! Some answers here

http://stackoverflow.com/questions/5437238/which-packages-make-good-use-of-s4-objects

including from Bioconductor simple class in EBImage, the advanced IRanges 
package and the 'toy' StudentGWAS.


Martin



Cheers,
Bert

On Fri, Aug 9, 2013 at 7:40 AM, Simon Zehnder  wrote:

Hi Martin,

thank you very much for this profound answer! Your added design advice is very 
helpful, too!

For the 'simple example': Sometimes I am still a little overwhelmed from a 
certain setting in the code and my ideas how I want to handle a process. But I 
learn from session to session. In future I will also span the lines more than 
80 columns. I am used to the indent in my vim editor.

I have one further issue: I do know, that you are one of the leading developers 
of the bioconductor package which uses (as far as I have read) extensively OOP 
in R. Is there a package you could suggest to me to learn from by reading and 
understanding the code? Where can I find the source code?

Best

Simon


On Aug 8, 2013, at 10:00 PM, Martin Morgan  wrote:


On 08/04/2013 02:13 AM, Simon Zehnder wrote:

So, I found a solution: First in the "initialize" method of class C coerce
the C object into a B object. Then call the next method in the list with the
B class object. Now, in the "initialize" method of class B the object is a B
object and the respective "generateSpec" method is called. Then, in the
"initialize" method of C the returned object from "callNextMethod" has to be
written to the C class object in .Object. See the code below.

setMethod("initialize", "C", function(.Object, value) {.Object@c <- value;
object <- as(.Object, "B"); object <- callNextMethod(object, value);
as(.Object, "B") <- object; .Object <- generateSpec(.Object);
return(.Object)})

This setting works. I do not know though, if this setting is the "usual" way
such things are done in R OOP. Maybe the whole class design is
disadvantageous. If anyone detects a mistaken design, I am very thankful to
learn.


Hi Simon -- your 'simple' example is pretty complicated, and I didn't really 
follow it in detail! The code is not formatted for easy reading (e.g., lines 
spanning no more than 80 columns) and some of it (e.g., generateSpec) might not 
be necessary to describe the problem you're having.

A good strategy is to ensure that 'new' called with no arguments works (there 
are other solutions, but following this rule has helped me to keep my classes 
and methods simple). This is not the case for

  new("A")
  new("C")

The reason for this strategy has to do with the way inheritance is implemented, 
in particular the coercion from derived to super class. Usually it is better to 
provide default values for arguments to initialize, and to specify arguments 
after a '...'. This means that your initialize methods will respects the 
contract set out in ?initialize, in particular the handling of unnamed 
arguments:

 ...: data to include in the new object.  Named arguments
  correspond to slots in the class definition. Unnamed
  arguments must be objects from classes that this class
  extends.

I might have written initialize,A-method as

  setMethod("initialize", "A", function(.Object, ..., value=numeric()){
  .Object <- callNextMethod(.Object, ..., a=value)
  generateSpec(.Object)
  })

Likely in a subsequent iteration I would have ended up with (using the 
convention that function names preceded by '.' are not exported)

  .A <- setClass("A", representation(a = "numeric", specA = "numeric"))

  .generateSpecA <- function(a) {
  1 / a
   }

  A <- function(a=numeric(), ...) {
  specA <- .generateSpecA(a)
  .A(..., a=a, specA=specA)
  }

  setMethod(generateSpec, "A", function(object) {
  .generateSpecA(object@a)
  })

ensuring that A() returns a valid object and avoiding the definition of an 
initialize method entirely.

Martin



Best

Simon


On Aug 3, 2013, at 9:43 PM, Simon Zehnder 
wrote:


setMethod("initialize", "C", function(.Object, value) {.Object@c <- value;
.Object <- callNextMethod(.Object, value); .Object <-
generateSpec(.Object); return(.Object)})


__ R-help@r-project.org 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.




--
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-

Re: [R] Method dispatch in S4

2013-08-09 Thread Simon Zehnder
Hi Bert,

thank you very much for your suggestion! I will take a look at it soon!

Best

Simon

On Aug 9, 2013, at 4:45 PM, Bert Gunter  wrote:

> Simon:
> 
> Have a look at the "proto" package for which there is a vignette. You
> may find it suitable for your needs and less intimidating.
> 
> Cheers,
> Bert
> 
> On Fri, Aug 9, 2013 at 7:40 AM, Simon Zehnder  wrote:
>> Hi Martin,
>> 
>> thank you very much for this profound answer! Your added design advice is 
>> very helpful, too!
>> 
>> For the 'simple example': Sometimes I am still a little overwhelmed from a 
>> certain setting in the code and my ideas how I want to handle a process. But 
>> I learn from session to session. In future I will also span the lines more 
>> than 80 columns. I am used to the indent in my vim editor.
>> 
>> I have one further issue: I do know, that you are one of the leading 
>> developers of the bioconductor package which uses (as far as I have read) 
>> extensively OOP in R. Is there a package you could suggest to me to learn 
>> from by reading and understanding the code? Where can I find the source code?
>> 
>> Best
>> 
>> Simon
>> 
>> 
>> On Aug 8, 2013, at 10:00 PM, Martin Morgan  wrote:
>> 
>>> On 08/04/2013 02:13 AM, Simon Zehnder wrote:
 So, I found a solution: First in the "initialize" method of class C coerce
 the C object into a B object. Then call the next method in the list with 
 the
 B class object. Now, in the "initialize" method of class B the object is a 
 B
 object and the respective "generateSpec" method is called. Then, in the
 "initialize" method of C the returned object from "callNextMethod" has to 
 be
 written to the C class object in .Object. See the code below.
 
 setMethod("initialize", "C", function(.Object, value) {.Object@c <- value;
 object <- as(.Object, "B"); object <- callNextMethod(object, value);
 as(.Object, "B") <- object; .Object <- generateSpec(.Object);
 return(.Object)})
 
 This setting works. I do not know though, if this setting is the "usual" 
 way
 such things are done in R OOP. Maybe the whole class design is
 disadvantageous. If anyone detects a mistaken design, I am very thankful to
 learn.
>>> 
>>> Hi Simon -- your 'simple' example is pretty complicated, and I didn't 
>>> really follow it in detail! The code is not formatted for easy reading 
>>> (e.g., lines spanning no more than 80 columns) and some of it (e.g., 
>>> generateSpec) might not be necessary to describe the problem you're having.
>>> 
>>> A good strategy is to ensure that 'new' called with no arguments works 
>>> (there are other solutions, but following this rule has helped me to keep 
>>> my classes and methods simple). This is not the case for
>>> 
>>> new("A")
>>> new("C")
>>> 
>>> The reason for this strategy has to do with the way inheritance is 
>>> implemented, in particular the coercion from derived to super class. 
>>> Usually it is better to provide default values for arguments to initialize, 
>>> and to specify arguments after a '...'. This means that your initialize 
>>> methods will respects the contract set out in ?initialize, in particular 
>>> the handling of unnamed arguments:
>>> 
>>>...: data to include in the new object.  Named arguments
>>> correspond to slots in the class definition. Unnamed
>>> arguments must be objects from classes that this class
>>> extends.
>>> 
>>> I might have written initialize,A-method as
>>> 
>>> setMethod("initialize", "A", function(.Object, ..., value=numeric()){
>>> .Object <- callNextMethod(.Object, ..., a=value)
>>> generateSpec(.Object)
>>> })
>>> 
>>> Likely in a subsequent iteration I would have ended up with (using the 
>>> convention that function names preceded by '.' are not exported)
>>> 
>>> .A <- setClass("A", representation(a = "numeric", specA = "numeric"))
>>> 
>>> .generateSpecA <- function(a) {
>>> 1 / a
>>>  }
>>> 
>>> A <- function(a=numeric(), ...) {
>>> specA <- .generateSpecA(a)
>>> .A(..., a=a, specA=specA)
>>> }
>>> 
>>> setMethod(generateSpec, "A", function(object) {
>>> .generateSpecA(object@a)
>>> })
>>> 
>>> ensuring that A() returns a valid object and avoiding the definition of an 
>>> initialize method entirely.
>>> 
>>> Martin
>>> 
 
 Best
 
 Simon
 
 
 On Aug 3, 2013, at 9:43 PM, Simon Zehnder 
 wrote:
 
> setMethod("initialize", "C", function(.Object, value) {.Object@c <- value;
> .Object <- callNextMethod(.Object, value); .Object <-
> generateSpec(.Object); return(.Object)})
 
 __ R-help@r-project.org 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.
 
>>> 
>>> 
>>> --
>>> Computational Biology / Fred Hutchinson Cancer Resea

Re: [R] Method dispatch in S4

2013-08-09 Thread Bert Gunter
Simon:

Have a look at the "proto" package for which there is a vignette. You
may find it suitable for your needs and less intimidating.

Cheers,
Bert

On Fri, Aug 9, 2013 at 7:40 AM, Simon Zehnder  wrote:
> Hi Martin,
>
> thank you very much for this profound answer! Your added design advice is 
> very helpful, too!
>
> For the 'simple example': Sometimes I am still a little overwhelmed from a 
> certain setting in the code and my ideas how I want to handle a process. But 
> I learn from session to session. In future I will also span the lines more 
> than 80 columns. I am used to the indent in my vim editor.
>
> I have one further issue: I do know, that you are one of the leading 
> developers of the bioconductor package which uses (as far as I have read) 
> extensively OOP in R. Is there a package you could suggest to me to learn 
> from by reading and understanding the code? Where can I find the source code?
>
> Best
>
> Simon
>
>
> On Aug 8, 2013, at 10:00 PM, Martin Morgan  wrote:
>
>> On 08/04/2013 02:13 AM, Simon Zehnder wrote:
>>> So, I found a solution: First in the "initialize" method of class C coerce
>>> the C object into a B object. Then call the next method in the list with the
>>> B class object. Now, in the "initialize" method of class B the object is a B
>>> object and the respective "generateSpec" method is called. Then, in the
>>> "initialize" method of C the returned object from "callNextMethod" has to be
>>> written to the C class object in .Object. See the code below.
>>>
>>> setMethod("initialize", "C", function(.Object, value) {.Object@c <- value;
>>> object <- as(.Object, "B"); object <- callNextMethod(object, value);
>>> as(.Object, "B") <- object; .Object <- generateSpec(.Object);
>>> return(.Object)})
>>>
>>> This setting works. I do not know though, if this setting is the "usual" way
>>> such things are done in R OOP. Maybe the whole class design is
>>> disadvantageous. If anyone detects a mistaken design, I am very thankful to
>>> learn.
>>
>> Hi Simon -- your 'simple' example is pretty complicated, and I didn't really 
>> follow it in detail! The code is not formatted for easy reading (e.g., lines 
>> spanning no more than 80 columns) and some of it (e.g., generateSpec) might 
>> not be necessary to describe the problem you're having.
>>
>> A good strategy is to ensure that 'new' called with no arguments works 
>> (there are other solutions, but following this rule has helped me to keep my 
>> classes and methods simple). This is not the case for
>>
>>  new("A")
>>  new("C")
>>
>> The reason for this strategy has to do with the way inheritance is 
>> implemented, in particular the coercion from derived to super class. Usually 
>> it is better to provide default values for arguments to initialize, and to 
>> specify arguments after a '...'. This means that your initialize methods 
>> will respects the contract set out in ?initialize, in particular the 
>> handling of unnamed arguments:
>>
>> ...: data to include in the new object.  Named arguments
>>  correspond to slots in the class definition. Unnamed
>>  arguments must be objects from classes that this class
>>  extends.
>>
>> I might have written initialize,A-method as
>>
>>  setMethod("initialize", "A", function(.Object, ..., value=numeric()){
>>  .Object <- callNextMethod(.Object, ..., a=value)
>>  generateSpec(.Object)
>>  })
>>
>> Likely in a subsequent iteration I would have ended up with (using the 
>> convention that function names preceded by '.' are not exported)
>>
>>  .A <- setClass("A", representation(a = "numeric", specA = "numeric"))
>>
>>  .generateSpecA <- function(a) {
>>  1 / a
>>   }
>>
>>  A <- function(a=numeric(), ...) {
>>  specA <- .generateSpecA(a)
>>  .A(..., a=a, specA=specA)
>>  }
>>
>>  setMethod(generateSpec, "A", function(object) {
>>  .generateSpecA(object@a)
>>  })
>>
>> ensuring that A() returns a valid object and avoiding the definition of an 
>> initialize method entirely.
>>
>> Martin
>>
>>>
>>> Best
>>>
>>> Simon
>>>
>>>
>>> On Aug 3, 2013, at 9:43 PM, Simon Zehnder 
>>> wrote:
>>>
 setMethod("initialize", "C", function(.Object, value) {.Object@c <- value;
 .Object <- callNextMethod(.Object, value); .Object <-
 generateSpec(.Object); return(.Object)})
>>>
>>> __ R-help@r-project.org 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.
>>>
>>
>>
>> --
>> Computational Biology / Fred Hutchinson Cancer Research Center
>> 1100 Fairview Ave. N.
>> PO Box 19024 Seattle, WA 98109
>>
>> Location: Arnold Building M1 B861
>> Phone: (206) 667-2793
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-proje

Re: [R] Method dispatch in S4

2013-08-09 Thread Simon Zehnder
Hi Martin,

thank you very much for this profound answer! Your added design advice is very 
helpful, too! 

For the 'simple example': Sometimes I am still a little overwhelmed from a 
certain setting in the code and my ideas how I want to handle a process. But I 
learn from session to session. In future I will also span the lines more than 
80 columns. I am used to the indent in my vim editor. 

I have one further issue: I do know, that you are one of the leading developers 
of the bioconductor package which uses (as far as I have read) extensively OOP 
in R. Is there a package you could suggest to me to learn from by reading and 
understanding the code? Where can I find the source code? 

Best

Simon


On Aug 8, 2013, at 10:00 PM, Martin Morgan  wrote:

> On 08/04/2013 02:13 AM, Simon Zehnder wrote:
>> So, I found a solution: First in the "initialize" method of class C coerce
>> the C object into a B object. Then call the next method in the list with the
>> B class object. Now, in the "initialize" method of class B the object is a B
>> object and the respective "generateSpec" method is called. Then, in the
>> "initialize" method of C the returned object from "callNextMethod" has to be
>> written to the C class object in .Object. See the code below.
>> 
>> setMethod("initialize", "C", function(.Object, value) {.Object@c <- value;
>> object <- as(.Object, "B"); object <- callNextMethod(object, value);
>> as(.Object, "B") <- object; .Object <- generateSpec(.Object);
>> return(.Object)})
>> 
>> This setting works. I do not know though, if this setting is the "usual" way
>> such things are done in R OOP. Maybe the whole class design is
>> disadvantageous. If anyone detects a mistaken design, I am very thankful to
>> learn.
> 
> Hi Simon -- your 'simple' example is pretty complicated, and I didn't really 
> follow it in detail! The code is not formatted for easy reading (e.g., lines 
> spanning no more than 80 columns) and some of it (e.g., generateSpec) might 
> not be necessary to describe the problem you're having.
> 
> A good strategy is to ensure that 'new' called with no arguments works (there 
> are other solutions, but following this rule has helped me to keep my classes 
> and methods simple). This is not the case for
> 
>  new("A")
>  new("C")
> 
> The reason for this strategy has to do with the way inheritance is 
> implemented, in particular the coercion from derived to super class. Usually 
> it is better to provide default values for arguments to initialize, and to 
> specify arguments after a '...'. This means that your initialize methods will 
> respects the contract set out in ?initialize, in particular the handling of 
> unnamed arguments:
> 
> ...: data to include in the new object.  Named arguments
>  correspond to slots in the class definition. Unnamed
>  arguments must be objects from classes that this class
>  extends.
> 
> I might have written initialize,A-method as
> 
>  setMethod("initialize", "A", function(.Object, ..., value=numeric()){
>  .Object <- callNextMethod(.Object, ..., a=value)
>  generateSpec(.Object)
>  })
> 
> Likely in a subsequent iteration I would have ended up with (using the 
> convention that function names preceded by '.' are not exported)
> 
>  .A <- setClass("A", representation(a = "numeric", specA = "numeric"))
> 
>  .generateSpecA <- function(a) {
>  1 / a
>   }
> 
>  A <- function(a=numeric(), ...) {
>  specA <- .generateSpecA(a)
>  .A(..., a=a, specA=specA)
>  }
> 
>  setMethod(generateSpec, "A", function(object) {
>  .generateSpecA(object@a)
>  })
> 
> ensuring that A() returns a valid object and avoiding the definition of an 
> initialize method entirely.
> 
> Martin
> 
>> 
>> Best
>> 
>> Simon
>> 
>> 
>> On Aug 3, 2013, at 9:43 PM, Simon Zehnder 
>> wrote:
>> 
>>> setMethod("initialize", "C", function(.Object, value) {.Object@c <- value;
>>> .Object <- callNextMethod(.Object, value); .Object <-
>>> generateSpec(.Object); return(.Object)})
>> 
>> __ R-help@r-project.org 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.
>> 
> 
> 
> -- 
> Computational Biology / Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N.
> PO Box 19024 Seattle, WA 98109
> 
> Location: Arnold Building M1 B861
> Phone: (206) 667-2793

__
R-help@r-project.org 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.


Re: [R] Method dispatch in S4

2013-08-08 Thread Martin Morgan

On 08/04/2013 02:13 AM, Simon Zehnder wrote:

So, I found a solution: First in the "initialize" method of class C coerce
the C object into a B object. Then call the next method in the list with the
B class object. Now, in the "initialize" method of class B the object is a B
object and the respective "generateSpec" method is called. Then, in the
"initialize" method of C the returned object from "callNextMethod" has to be
written to the C class object in .Object. See the code below.

setMethod("initialize", "C", function(.Object, value) {.Object@c <- value;
object <- as(.Object, "B"); object <- callNextMethod(object, value);
as(.Object, "B") <- object; .Object <- generateSpec(.Object);
return(.Object)})

This setting works. I do not know though, if this setting is the "usual" way
such things are done in R OOP. Maybe the whole class design is
disadvantageous. If anyone detects a mistaken design, I am very thankful to
learn.


Hi Simon -- your 'simple' example is pretty complicated, and I didn't really 
follow it in detail! The code is not formatted for easy reading (e.g., lines 
spanning no more than 80 columns) and some of it (e.g., generateSpec) might not 
be necessary to describe the problem you're having.


A good strategy is to ensure that 'new' called with no arguments works (there 
are other solutions, but following this rule has helped me to keep my classes 
and methods simple). This is not the case for


  new("A")
  new("C")

The reason for this strategy has to do with the way inheritance is implemented, 
in particular the coercion from derived to super class. Usually it is better to 
provide default values for arguments to initialize, and to specify arguments 
after a '...'. This means that your initialize methods will respects the 
contract set out in ?initialize, in particular the handling of unnamed arguments:


 ...: data to include in the new object.  Named arguments
  correspond to slots in the class definition. Unnamed
  arguments must be objects from classes that this class
  extends.

I might have written initialize,A-method as

  setMethod("initialize", "A", function(.Object, ..., value=numeric()){
  .Object <- callNextMethod(.Object, ..., a=value)
  generateSpec(.Object)
  })

Likely in a subsequent iteration I would have ended up with (using the 
convention that function names preceded by '.' are not exported)


  .A <- setClass("A", representation(a = "numeric", specA = "numeric"))

  .generateSpecA <- function(a) {
  1 / a
   }

  A <- function(a=numeric(), ...) {
  specA <- .generateSpecA(a)
  .A(..., a=a, specA=specA)
  }

  setMethod(generateSpec, "A", function(object) {
  .generateSpecA(object@a)
  })

ensuring that A() returns a valid object and avoiding the definition of an 
initialize method entirely.


Martin



Best

Simon


On Aug 3, 2013, at 9:43 PM, Simon Zehnder 
wrote:


setMethod("initialize", "C", function(.Object, value) {.Object@c <- value;
.Object <- callNextMethod(.Object, value); .Object <-
generateSpec(.Object); return(.Object)})


__ R-help@r-project.org 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.




--
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

__
R-help@r-project.org 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.


Re: [R] Method dispatch in S4

2013-08-04 Thread Simon Zehnder
So, I found a solution: First in the "initialize" method of class C coerce the 
C object into a B object. Then call the next method in the list with the B 
class object. Now, in the "initialize" method of class B the object is a B 
object and the respective "generateSpec" method is called. Then, in the 
"initialize" method of C the returned object from "callNextMethod" has to be 
written to the C class object in .Object. See the code below.

setMethod("initialize", "C", function(.Object, value) {.Object@c <- value; 
object <- as(.Object, "B"); object <- callNextMethod(object, value); 
as(.Object, "B") <- object; .Object <- generateSpec(.Object); return(.Object)})

This setting works. I do not know though, if this setting is the "usual" way 
such things are done in R OOP. Maybe the whole class design is disadvantageous. 
If anyone detects a mistaken design, I am very thankful to learn.

Best

Simon

 
On Aug 3, 2013, at 9:43 PM, Simon Zehnder  wrote:

> setMethod("initialize", "C", function(.Object, value) {.Object@c <- value; 
> .Object <- callNextMethod(.Object, value); .Object <- generateSpec(.Object); 
> return(.Object)})

__
R-help@r-project.org 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.


[R] Method dispatch in S4

2013-08-03 Thread Simon Zehnder
Dear R-Users and R-Devels,

I am struggling with the method dispatch for S4 objects. First I will give a 
simple example to make clear what the general setting in my project is. 

Three classes will be build in the example: A is just a simple class. B 
contains A in a slot and C inherits from B. In addition all classes have a slot 
called "specA", "specB", specC" that should be computed during initialization 
by calling the method "generateSpec" defined for each class A,B,C:

## Define class A##
setClass("A", representation(a = "numeric", specA = "numeric"))
setMethod("initialize", "A", function(.Object, value){.Object@a <- value; 
.Object <- generateSpec(.Object); return(.Object)})
setGeneric("generateSpec", function(object) standardGeneric("generateSpec"))
setMethod("generateSpec", "A", function(object) {object@specA <- 1/object@a; 
return(object)})

## Define class B containing A in a slot ##
setClass("B", representation(b = "numeric", specB = "numeric", A = "A"))
setMethod("initialize", "B", function(.Object, value = 0){.Object@b <- value; 
.Object@A <- new("A", value = value); .Object <- generateSpec(.Object); 
return(.Object)})
setMethod("generateSpec", "B", function(object) {aSpec <- object@A@specA; 
object@specB <- 1/aSpec; return(object)})
## all fine:
new("B", value = 2)

## Define class C inheriting from class B ##
setClass("C", representation(c = "numeric", specC = "numeric"), contains=c("B"))
setMethod("initialize", "C", function(.Object, value) {.Object@c <- value; 
.Object <- callNextMethod(.Object, value); .Object <- generateSpec(.Object); 
return(.Object)})
setMethod("generateSpec", "C", function(object) {bSpec <- object@specB; 
object@specC <- 1/bSpec; return(object)})
## numeric(0) for specB and specC
new("C", value = 2)

Note, that the "generateSpec" method of B depends on the "specA" slot of A, the 
"generateSpec" method of class C depends on the "specB" slot of class B. Note 
also, that in the "initialize" method of B one has to give the "value" argument 
a default value. When calling the last line of code, "specB" and "specC" are 
numeric(0). As the slot "b" of the new "C" class is equal to 2, the 
"initialize" method of class B is called but the ".Object" in the "initialize" 
method of class B is an object of class C. And of course in this case method 
dispatching chooses the "generateSpec" method of class C - "generateSpec" for 
class B gets never called. In general this is exactly what we want, when 
inheriting classes: dispatching makes OOP programming not only simpler, but 
actually possible. 

My question: How can I make this setting work? How can I generate an 
"initialize" method for class B that calls ALWAYS the "generateSpec" method of 
class B (using "as" lets me end up in the "initialize" method of class C with 
an object of class B as it is only possible to convert a derived object to its 
base class but not the other way around)? 

Best

Simon

__
R-help@r-project.org 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.


Re: [R] method show

2012-11-19 Thread Martin Morgan

On 11/19/2012 04:21 PM, Andrea Spano wrote:

Hello the list,

As a simple example:



rm(list = ls())> setClass("tre", representation(x="numeric"))> setMethod("show", "tre", def = function(object) cat(object@x))[1] "show"> 
setMethod("summary", "tre", def = function(object) cat("This is a tre of value ", object@x, "\n"))Creating a generic function for ‘summary’ from package ‘base’ 
in the global environment[1] "summary"> ls()[1] "summary"



R copies generic summary into the current environment.

I understand it as: If you want R to create a specific "summary"
method for objects of class "tre" R needs the generic method in the
same environment (R_GloabalEnv).

In fact, summary is listed by ls in in my local env.


Why R does not do the same with generic method "show"?


I know that generic method "show" is from package "methods" while
summary is package "base". Does it matter somehow?


There are several object systems in R. Your use of setMethod indicates that you 
are creating an S4 method, to be associated with an S4 generic. 'show' is a 
generic in the S4 object system, and setMethod(show, <...>) associates your 
method with this generic. 'summary' is a generic in the S3 object system. 
setMethod(summary, <...>) realizes that there is not yet an S4 generic summary, 
so creates an S4 generic (with the S3 generic as the default method) and then 
adds your method to the newly created S4 generic. The S3 generic is not copied 
to the global environment.


Martin




Can anyone point me to the right reference?


Thanks in advance for your help ...


Andrea

[[alternative HTML version deleted]]



__
R-help@r-project.org 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.




--
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

__
R-help@r-project.org 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.


[R] method show

2012-11-19 Thread Andrea Spano
Hello the list,

As a simple example:


> rm(list = ls())> setClass("tre", representation(x="numeric"))> 
> setMethod("show", "tre", def = function(object) cat(object@x))[1] "show"> 
> setMethod("summary", "tre", def = function(object) cat("This is a tre of 
> value ", object@x, "\n"))Creating a generic function for ‘summary’ from 
> package ‘base’ in the global environment[1] "summary"> ls()[1] "summary"


R copies generic summary into the current environment.

I understand it as: If you want R to create a specific "summary"
method for objects of class "tre" R needs the generic method in the
same environment (R_GloabalEnv).

In fact, summary is listed by ls in in my local env.


Why R does not do the same with generic method "show"?


I know that generic method "show" is from package "methods" while
summary is package "base". Does it matter somehow?


Can anyone point me to the right reference?


Thanks in advance for your help ...


Andrea

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] method or package to make special boxplot

2012-09-09 Thread Jim Lemon

On 09/09/2012 12:14 AM, Zhang Qintao wrote:

Hi, All,

I am trying to use R to make the following type of boxplot while I couldn't
find a way to do it.

My dataset looks like X1 Y1 X2 Y2 SPLIT. The split highlights my
experiment details and both x and y are continuous numerical values.  I
need to plot y vs. x with split as legend and boxplot has to be used for
all splits. May I ask how to get it? Currently available boxplot only
applies on the case that X axis is character.


Hi Qintao,
Do you want a sort of 2D boxplot? The example below gives a rough idea 
as to what it would look like, with boxplots for your Xs and Ys centered 
at their medians and an abcissa with the labels for your splits. Needs a 
bit of work to turn this into a function, so let me know if it does what 
you want.


Jim

x1<-rnorm(10)
y1<-rnorm(10)
y2<-rnorm(10)
x2<-rnorm(10)
x1sum<-boxplot(x1)
y1sum<-boxplot(y1)
offset=4
x2sum<-boxplot(x2,at=median(y2)+offset,add=TRUE)
y2sum<-boxplot(y2+offset)
bxp(x1sum,at=median(y1),xlim=c(y1sum$stats[1],y2sum$stats[5]),
 ylim=c(min(c(x1sum$stats[1],x2sum$stats[1])),
 max(c(x1sum$stats[5],x2sum$stats[5]))),axes=FALSE)
bxp(y1sum,at=median(x1),add=TRUE,horizontal=TRUE,axes=FALSE)
bxp(x2sum,at=median(y2+offset),add=TRUE,axes=FALSE)
bxp(y2sum,at=median(x2),horizontal=TRUE,add=TRUE,axes=FALSE)
box()
axis(2)
axis(1,at=c(median(y1),median(y2)+offset),labels=c("Split1","Split2"))

__
R-help@r-project.org 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.


Re: [R] method or package to make special boxplot

2012-09-08 Thread Greg Snow
The symbols function allows you to place boxplot symbols at specified
x,y coordinates.  Would that do what you want?

On Sat, Sep 8, 2012 at 8:14 AM, Zhang Qintao  wrote:
> Hi, All,
>
> I am trying to use R to make the following type of boxplot while I couldn't
> find a way to do it.
>
> My dataset looks like X1 Y1 X2 Y2 SPLIT. The split highlights my
> experiment details and both x and y are continuous numerical values.  I
> need to plot y vs. x with split as legend and boxplot has to be used for
> all splits. May I ask how to get it? Currently available boxplot only
> applies on the case that X axis is character.
>
> Thanks
>
> Qintao
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org 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.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

__
R-help@r-project.org 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.


Re: [R] method or package to make special boxplot

2012-09-08 Thread David Winsemius

On Sep 8, 2012, at 7:14 AM, Zhang Qintao wrote:

> Hi, All,
> 
> I am trying to use R to make the following type of boxplot while I couldn't
> find a way to do it.
> 
> My dataset looks like X1 Y1 X2 Y2 SPLIT. The split highlights my
> experiment details and both x and y are continuous numerical values.  I
> need to plot y vs. x with split as legend and boxplot has to be used for
> all splits. May I ask how to get it? Currently available boxplot only
> applies on the case that X axis is character.

Boxplots do _not_ have continuous "X" axes. You will need to explain in greater 
detail what goal you are seeking. Perhaps something like a bagplot?

http://gallery.r-enthusiasts.com/RGraphGallery.php?graph=112

--
David Winsemius, MD
Alameda, CA, USA

__
R-help@r-project.org 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.


Re: [R] method or package to make special boxplot

2012-09-08 Thread John Kane
Please supply some sample data and preferably the code that you have used so 
far.  

To supply data the best way is probably to use the dput() function.  If your 
data is 'mydata' simply do : dput(mydata) and paste the results into your email


John Kane
Kingston ON Canada


> -Original Message-
> From: qintao.zh...@gmail.com
> Sent: Sat, 8 Sep 2012 22:14:26 +0800
> To: r-help@r-project.org
> Subject: [R] method or package to make special boxplot
> 
> Hi, All,
> 
> I am trying to use R to make the following type of boxplot while I
> couldn't
> find a way to do it.
> 
> My dataset looks like X1 Y1 X2 Y2 SPLIT. The split highlights my
> experiment details and both x and y are continuous numerical values.  I
> need to plot y vs. x with split as legend and boxplot has to be used for
> all splits. May I ask how to get it? Currently available boxplot only
> applies on the case that X axis is character.
> 
> Thanks
> 
> Qintao
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org 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.


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your 
desktop!

__
R-help@r-project.org 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.


[R] method or package to make special boxplot

2012-09-08 Thread Zhang Qintao
Hi, All,

I am trying to use R to make the following type of boxplot while I couldn't
find a way to do it.

My dataset looks like X1 Y1 X2 Y2 SPLIT. The split highlights my
experiment details and both x and y are continuous numerical values.  I
need to plot y vs. x with split as legend and boxplot has to be used for
all splits. May I ask how to get it? Currently available boxplot only
applies on the case that X axis is character.

Thanks

Qintao

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Method=df for coxph in survival package

2012-04-17 Thread David Parker
I've been following the example in the R help page:
http://stat.ethz.ch/R-manual/R-devel/library/survival/html/frailty.html


library(survival);
coxph(Surv(time, status) ~ age + frailty(inst, df=4), lung)


Here, in this particular example they fixed the degrees of freedom for the
random institution effects to be 4. 
But, how did they decide?

This clearly can't be the number of institutions as there are 19
institutions.
> length(unique(lung$inst))
[1] 19

But, how to decide what degrees of freedom to specify for your random
institution effect? What was the reason they chose df=4? 

Can anyone please direct me (Reference or explanations) how to decide what
df to use for the frailty terms?

Thank you very much.

Dave

--
View this message in context: 
http://r.789695.n4.nabble.com/Method-df-for-coxph-in-survival-package-tp4566006p4566006.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Method dispatch for function call operator?

2011-01-13 Thread Taras Zakharko

Thank you both for very helpful answers. I have indeed missed the help pages
about "(" and now the situation is more clear.

> You can use this syntax by defining a function `x<-` <- function(...) {} 
> and it could be an S3 method, but it is a completely separate object from
> x.  

Unfortunately, it won't work as assignment function form treats the first
argument specially. My intention was to create syntactic sugar like

x$metadata(condition) <- newvalue

instead of 

x$setMetadata(condition, value=newvalue)

I know that

metadata(x, condition) <- newvalue 

would work, but I would like to avoid that particular syntax for a number of
reasons.

Well, you can't have everything, I guess. I'll just stick to the []
operator.

Thanks again for the clarification!

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Method-dispatch-for-function-call-operator-tp3215381p3215590.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Method dispatch for function call operator?

2011-01-13 Thread Prof Brian Ripley
The details here are much more appropriate for R-devel, but please 
check the help pages for "(" and "[", and note


- "[" is generic and "(" is not.
- the primitive `(` is used to implement constructions such as
(x <- pi) and not x(...).

The special handling of operators such as "[" is part of the parser, 
and you are guessing incorrectly how function calls are parsed.


(Note to Duncan Murdoch whose reply came in whilst I was writig this: 
"(" is essentially a no-op, but it does turn visibility on, something 
often used with assignments.)


On Thu, 13 Jan 2011, Taras Zakharko wrote:



Dear R gurus,

I am trying to create a nicer API interface for some R modules I have
written. Here, I heavily rely on S3 method dispatch mechanics and
makeActiveBinding()  function

I have discovered that I apparently can't dispatch on function call
operator (). While .Primitive("(") exists, which leads me to believe that
things like x(...) are internally translated to .Primitive("(")(x, ...), I
can't seem to do something like:

x <- integer()
class(x) <- "testclass"
"(.testclass" <- function(o, x, y) print(paste(x, y))
x(1, 2)

Similar code does work for other operators like "[".

A workaround I have discovered is to make x a function from the beginning
and then extend the functionality by via S3 methods. Unfortunately, it does
not allow me to do something I'd really like to - use syntax like this:

x(...) <- y

For this, I'd need to dispatch on something like

"(<-.testclass" <- function(x, arglist, value)

Currently, I am using the index operator for this (i.e. x[...] <- y) - it
works nicely, but I'd prefer the () syntax, if possible.

Does anyone know a way to do this?

--
View this message in context: 
http://r.789695.n4.nabble.com/Method-dispatch-for-function-call-operator-tp3215381p3215381.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org 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.


Re: [R] Method dispatch for function call operator?

2011-01-13 Thread Duncan Murdoch

On 11-01-13 3:09 AM, Taras Zakharko wrote:


Dear R gurus,

  I am trying to create a nicer API interface for some R modules I have
written. Here, I heavily rely on S3 method dispatch mechanics and
makeActiveBinding()  function

  I have discovered that I apparently can't dispatch on function call
operator (). While .Primitive("(") exists, which leads me to believe that
things like x(...) are internally translated to .Primitive("(")(x, ...), I
can't seem to do something like:


The "(" function is not a function call operator.  It's essentially a 
no-op.  I believe its only purpose is to help in deparsing, so that 
things like (x + y) would deparse in the same way as entered.





x<- integer()
class(x)<- "testclass"
"(.testclass"<- function(o, x, y) print(paste(x, y))
x(1, 2)

Similar code does work for other operators like "[".

A workaround I have discovered is to make x a function from the beginning
and then extend the functionality by via S3 methods. Unfortunately, it does
not allow me to do something I'd really like to - use syntax like this:

x(...)<- y


You can use this syntax by defining a function `x<-` <- function(...) {}
and it could be an S3 method, but it is a completely separate object from x.

Duncan Murdoch



For this, I'd need to dispatch on something like

"(<-.testclass"<- function(x, arglist, value)

Currently, I am using the index operator for this (i.e. x[...]<- y) - it
works nicely, but I'd prefer the () syntax, if possible.

  Does anyone know a way to do this?



__
R-help@r-project.org 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.


[R] Method dispatch for function call operator?

2011-01-13 Thread Taras Zakharko

Dear R gurus,

 I am trying to create a nicer API interface for some R modules I have
written. Here, I heavily rely on S3 method dispatch mechanics and
makeActiveBinding()  function

 I have discovered that I apparently can't dispatch on function call
operator (). While .Primitive("(") exists, which leads me to believe that
things like x(...) are internally translated to .Primitive("(")(x, ...), I
can't seem to do something like:

x <- integer()
class(x) <- "testclass"
"(.testclass" <- function(o, x, y) print(paste(x, y))
x(1, 2)

Similar code does work for other operators like "[".

A workaround I have discovered is to make x a function from the beginning
and then extend the functionality by via S3 methods. Unfortunately, it does
not allow me to do something I'd really like to - use syntax like this:

x(...) <- y

For this, I'd need to dispatch on something like

"(<-.testclass" <- function(x, arglist, value) 

Currently, I am using the index operator for this (i.e. x[...] <- y) - it
works nicely, but I'd prefer the () syntax, if possible. 

 Does anyone know a way to do this?

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Method-dispatch-for-function-call-operator-tp3215381p3215381.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] method dispatching vs inheritance/polymorphism (re-post)

2010-04-25 Thread Duncan Murdoch

On 25/04/2010 9:07 AM, Albert-Jan Roskam wrote:

Hi,

I'm having trouble seeing the added value over functions defined by setGeneric 
vis-a-vis
methods defined by inheritance and polymorphism. setGeneric offers a 'clean' call 
to a generic function, ie. no need to call new(), so less typing to do for the 
user. But such explicit calls can also be avoided by functions like f <- 
function(x, y) new(Class = SomeClass, x=x, y=y). Then again, R relies heavily on 
method dispatching, so it must have clear advantages.

*confused* Can anybody enlighten me? Thanks in advance!


I agree you are confused.  setGeneric sets up a function to use to 
dispatch methods on an object; e.g. the stats4 package defines the 
generic AIC, so that AIC(obj) will calculate the AIC for any object that 
provides an AIC method.  new() is not involved, because the object was 
already created somewhere else.


What you seem to be asking about is something like a constructor 
function.  E.g. if I have a class "SomeClass", instead of 
new("SomeClass", x=x, y=y) I might prefer to type SomeClass(x=x, y=y).  
That's possible (you have to do it yourself, like your f() above), but 
is really unrelated to setGeneric.


Duncan Murdoch

__
R-help@r-project.org 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.


[R] method dispatching vs inheritance/polymorphism (re-post)

2010-04-25 Thread Albert-Jan Roskam
Hi,

I'm having trouble seeing the added value over functions defined by setGeneric 
vis-a-vis
methods defined by inheritance and polymorphism. setGeneric offers a 'clean' 
call to a generic function, ie. no need to call new(), so less typing to do for 
the user. But such explicit calls can also be avoided by functions like f <- 
function(x, y) new(Class = SomeClass, x=x, y=y). Then again, R relies heavily 
on method dispatching, so it must have clear advantages.

*confused* Can anybody enlighten me? Thanks in advance!

Cheers!!
Albert-Jan

~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have 
the Romans ever done for us?
~~


  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] method dispatching vs inheritance/polymorphism

2010-04-24 Thread Albert-Jan Roskam
Hi,

I'm having trouble seeing the added value over functions defined by setGeneric 
vis-a-vis
methods defined by inheritance and polymorphism. setGeneric offers a 'clean' 
call to a generic function, ie. no need to call new(), so less typing to do for 
the user. But such explicit calls can also be avoided by functions like f <- 
function(x, y) new(Class = SomeClass, x=x, y=y). Then again, R relies heavily 
on method dispatching, so it must have clear advantages. 

*confused* Can anybody enlighten me? Thanks in advance!

Cheers!!

Albert-Jan



~~

All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have 
the Romans ever done for us?

~~


  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Method dispatch

2010-03-01 Thread Martin Morgan
; [28] "qpaid"   "RAA" "residCov"   
> [31] "residuals"   "rstandard"   "vcov"   
> 
> 
> 
> I know this is a namespace issue, but I do not know how to fix this. The 
> following is a part of the namespace file, but you can see that I did export 
> the "summary" method in "exportMethods". What did I miss here?  Thanks a lot 
> for your help.
> 
> 
> 
> export(MackChainLadder, MunichChainLadder, BootChainLadder, MultiChainLadder)
> export(Join2Fits, JoinFitMse, Mse, residCov)
> 
> importFrom(stats, quantile, predict, coef, vcov,
>   residuals, fitted, fitted.values, rstandard)
> importFrom(methods,  show, coerce)
> importFrom(graphics, plot)
> 
> #Classes
> exportClasses(triangles, MultiChainLadder, MultiChainLadderFit,
>   MCLFit, GMCLFit, MultiChainLadderMse)
>
> #Methods
> S3method(plot, MackChainLadder)
> S3method(plot, MunichChainLadder)
> 
> S3method(summary, MunichChainLadder)
> S3method(summary, BootChainLadder)
> 
> exportMethods(predict, Mse, summary, show, coerce,
>   "[", "$", "[[", names, coef, vcov, residCov,
>   residuals, rstandard, fitted, fitted.values, plot)
> 
> 
>  
> 
> 
> Wayne (Yanwei) Zhang
> Statistical Research 
>> CNA
> 
> -Original Message-
> From: Martin Morgan [mailto:mtmor...@fhcrc.org] 
> Sent: Monday, March 01, 2010 5:10 PM
> To: Zhang,Yanwei
> Cc: r-help@r-project.org
> Subject: Re: [R] Method dispatch
> 
> On 03/01/2010 01:31 PM, Zhang,Yanwei wrote:
>> Dear all,
>>
>> In a package, I defined a method for "summary" using
> setMethod(summary, signature="abc") for my class "abc", but when the
> package is loaded, the function "summary(x)" where x is of class "abc"
> seems to have called the default summary function for "ANY" class.
> Shouldn't it call the method I have defined? How could I get around with
> that? Thanks.
> 
> Hi Wayne -- It's hard to tell from what you've written, but this and
> your earlier question on 'S4 issues' sounds like a NAMESPACE problem.
> Are you using a name space? If so, provide additional detail. Also,
> verify that you are only loading your package and not another, e.g., one
> with a 'summary' generic that is being found before yours.
> 
> Probably your best bet is to simplify as much as possible -- I have a
> single file in 'pkgA/R', with
> 
>   setClass("A", "numeric")
>   setMethod("summary", "A", function(object, ...) "A")
> 
> 
>> library(pkgA)
>> summary(new("A"))
> [1] "A"
>> sessionInfo()
> R version 2.10.1 Patched (2010-02-23 r51168)
> x86_64-unknown-linux-gnu
> 
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
> 
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
> 
> other attached packages:
> [1] pkgA_1.0
> 
> Martin
> 
> 
>>
>>
>> Wayne (Yanwei) Zhang
>> Statistical Research
>> CNA
>>
>>
>>
>>
>>
>> NOTICE:  This e-mail message, including any attachments and appended 
>> messages, is for the sole use of the intended recipients and may contain 
>> confidential and legally privileged information.
>> If you are not the intended recipient, any review, dissemination, 
>> distribution, copying, storage or other use of all or any portion of this 
>> message is strictly prohibited.
>> If you received this message in error, please immediately notify the sender 
>> by reply e-mail and delete this message in its entirety.
>>
>>  [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org 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.
> 
> 


-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

__
R-help@r-project.org 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.


Re: [R] Method dispatch

2010-03-01 Thread Zhang,Yanwei
Dear Martin,

Thanks a lot for your reply. I do have a namespace and it does seem to be a 
namespace problem. But this time, it's getting even stranger:

My package name is ChainLadder:

> library(ChainLadder)

> sessionInfo()
R version 2.10.1 (2009-12-14) 
i386-pc-mingw32 

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C  
[5] LC_TIME=English_United States.1252

attached base packages:
[1] splines   stats graphics  grDevices utils datasets  methods  
[8] base 

other attached packages:
[1] ChainLadder_0.1.3-3 systemfit_1.1-4 lmtest_0.9-26  
[4] zoo_1.6-2   car_1.2-16  Matrix_0.999375-33 
[7] lattice_0.17-26 Hmisc_3.7-0 survival_2.35-7

loaded via a namespace (and not attached):
[1] cluster_1.12.1 grid_2.10.1tools_2.10.1  


Then I called the main function to create an object "uni2" of class 
"MultiChainLadder".

> uni2 <- MultiChainLadder(list(GenIns),
+  fit.method="OLS",
+  extrap=TRUE,
+  model="MCL")
> 
> class(uni2)
[1] "MultiChainLadder"
attr(,"package")
[1] "ChainLadder"

The summary function defined for this class "MultiChainLadder" works as desired:

> showMethods(summary)
Function: summary (package base)
object="ANY"
object="MultiChainLadder"
object="sparseMatrix"

> summary(uni2)
$`Summary Statistics for the Input Triangle`
Latest Dev.To.Date UltimateIBNRS.ECV
2  5339085  0.98258397  543371994633.81   75535.04 0.7981823
3  4909315  0.91271120  5378826   469511.29  121698.56 0.2592026
4  4588268  0.86605315  5297906   709637.82  133548.85 0.1881930
5  3873311  0.79727292  4858200   984888.64  261406.45 0.2654173


However, problems come when I call the "show" function defined for this class, 
which is essentially the same as the "summary" function, since the default 
"summary" for class "ANY" is called, not my new method:

> getMethod(show,signature="MultiChainLadder")
Method Definition:

function (object) 
{
summary(object)
}


Signatures:
object
target  "MultiChainLadder"
defined "MultiChainLadder"
> show(uni2)
  LengthClass Mode 
   1 MultiChainLadder   S4 


I can't figure out why the call of "summary" within "show" failed. And what is 
even stranger is that although the showMethods(summary) indicates a method is 
defined for "MultiChainLadder", I could not find the "summary" function in the 
namespace "ChainLadder":

> ChainLadder::summary
Error: 'summary' is not an exported object from 'namespace:ChainLadder'
> objects(2)
 [1] "ABC" "as.triangle" "auto"   
 [4] "BootChainLadder" "chainladder" "coef"   
 [7] "cum2incr""fitted"  "fitted.values"  
[10] "GenIns"  "GenInsLong"  "getLatestCumulative"
[13] "incr2cum""Join2Fits"   "JoinFitMse" 
[16] "liab""M3IR5"   "MackChainLadder"
[19] "MCLincurred" "MCLpaid" "Mortgage"   
[22] "Mse" "MultiChainLadder""MunichChainLadder"  
[25] "plot""predict" "qincurred"  
[28] "qpaid"   "RAA" "residCov"   
[31] "residuals"   "rstandard"   "vcov"   



I know this is a namespace issue, but I do not know how to fix this. The 
following is a part of the namespace file, but you can see that I did export 
the "summary" method in "exportMethods". What did I miss here?  Thanks a lot 
for your help.



export(MackChainLadder, MunichChainLadder, BootChainLadder, MultiChainLadder)
export(Join2Fits, JoinFitMse, Mse, residCov)

importFrom(stats, quantile, predict, coef, vcov,
  residuals, fitted, fitted.values, rstandard)
importFrom(methods,  show, coerce)
importFrom(graphics, plot)

#Classes
exportClasses(triangles, MultiChainLadder, MultiChainLadderFit,
  MCLFit, GMCLFit, MultiChainLadderMse)
   
#Methods
S3method(plot, MackChainLadder)
S3method(plot, MunichChainLadder)

S3method(summary, MunichChainLadder)
S3method(summary, BootChainLadder)

exportMethods(predict, Mse, summary, show, coer

Re: [R] Method dispatch

2010-03-01 Thread Martin Morgan
On 03/01/2010 01:31 PM, Zhang,Yanwei wrote:
> Dear all,
> 
> In a package, I defined a method for "summary" using
setMethod(summary, signature="abc") for my class "abc", but when the
package is loaded, the function "summary(x)" where x is of class "abc"
seems to have called the default summary function for "ANY" class.
Shouldn't it call the method I have defined? How could I get around with
that? Thanks.

Hi Wayne -- It's hard to tell from what you've written, but this and
your earlier question on 'S4 issues' sounds like a NAMESPACE problem.
Are you using a name space? If so, provide additional detail. Also,
verify that you are only loading your package and not another, e.g., one
with a 'summary' generic that is being found before yours.

Probably your best bet is to simplify as much as possible -- I have a
single file in 'pkgA/R', with

  setClass("A", "numeric")
  setMethod("summary", "A", function(object, ...) "A")


> library(pkgA)
> summary(new("A"))
[1] "A"
> sessionInfo()
R version 2.10.1 Patched (2010-02-23 r51168)
x86_64-unknown-linux-gnu

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] pkgA_1.0

Martin


> 
> 
> Wayne (Yanwei) Zhang
> Statistical Research
> CNA
> 
> 
> 
> 
> 
> NOTICE:  This e-mail message, including any attachments and appended 
> messages, is for the sole use of the intended recipients and may contain 
> confidential and legally privileged information.
> If you are not the intended recipient, any review, dissemination, 
> distribution, copying, storage or other use of all or any portion of this 
> message is strictly prohibited.
> If you received this message in error, please immediately notify the sender 
> by reply e-mail and delete this message in its entirety.
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org 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.


-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

__
R-help@r-project.org 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.


[R] Method dispatch

2010-03-01 Thread Zhang,Yanwei
Dear all,

In a package, I defined a method for "summary" using setMethod(summary, 
signature="abc") for my class "abc", but when the package is loaded, the 
function "summary(x)" where x is of class "abc" seems to have called the 
default summary function for "ANY" class. Shouldn't it call the method I have 
defined? How could I get around with that?  Thanks.



Wayne (Yanwei) Zhang
Statistical Research
CNA





NOTICE:  This e-mail message, including any attachments and appended messages, 
is for the sole use of the intended recipients and may contain confidential and 
legally privileged information.
If you are not the intended recipient, any review, dissemination, distribution, 
copying, storage or other use of all or any portion of this message is strictly 
prohibited.
If you received this message in error, please immediately notify the sender by 
reply e-mail and delete this message in its entirety.

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Method for reduction of independent variables

2010-01-13 Thread Daniel Malter
Hi, please read the posting guide. You are not likely to get an extensive
answer to your question from this list. Your question is a "please
solve/explain my statistical problem for me" question. There are two things
problematic with that. First, "statistical", and second "please solve for
me."

First, the R-help list is mostly concerned with problems in implementing
analyses in R, not with the (choice of the) statistical approach per se
(there are few exceptions). Second, "please solve for me" questions are
generally frowned upon, unless you evidence a specific point at which you
are stuck and have to make a choice. That is, the list members want to see
that you have done your "homework" to the extent one can expect you to. To
ask the list to provide an introduction to data reduction methods without
having any background knowledge is, frankly, a waste of your and the list
members' time. There are books on the topic, which you can buy or lend, and
certainly many online sources to give you a basic background. Or you can
start here: http://en.wikipedia.org/wiki/Dimension_reduction. If you want
your statistical questions answered and problems solved without reading
yourself into the matter, your question is more suitable for a local
statistician at your institution or a paid service rather than this list.

Best,
Daniel 

-
cuncta stricte discussurus
-
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of rubystallion
Sent: Wednesday, January 13, 2010 11:57 AM
To: r-help@r-project.org
Subject: [R] Method for reduction of independent variables


Hello

I am currently investing software code metrics for a variety of software
projects of a company to determine the worst parts of software products
according to specified quality characteristics. 
As the gathering of metrics correlates with effort, I would like to find a
subset of the metrics preserving significant predictive power for the
"problem value" while using the least amount of code metrics. 

I have the results of 25 metrics for 6 software projects for a combined 9355
"individuals", i.e. software parts with metrics.
However, as many metrics only measure metric values above a predefined
limit, 58% of the responses for independent variables are 0.

Which method can I use to determine a reduced set of independent variables
with significant predictive power?
As I do not have a statistics background, I would also appreciate a simple
explanation of the chosen method and sensible choices for parameters, so
that I will be able to infer the reduced set of software metrics to keep.

Thank you in advance!

Johannes
-- 
View this message in context:
http://n4.nabble.com/Method-for-reduction-of-independent-variables-tp1013171
p1013171.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.

__
R-help@r-project.org 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.


[R] Method for reduction of independent variables

2010-01-13 Thread rubystallion

Hello

I am currently investing software code metrics for a variety of software
projects of a company to determine the worst parts of software products
according to specified quality characteristics. 
As the gathering of metrics correlates with effort, I would like to find a
subset of the metrics preserving significant predictive power for the
"problem value" while using the least amount of code metrics. 

I have the results of 25 metrics for 6 software projects for a combined 9355
"individuals", i.e. software parts with metrics.
However, as many metrics only measure metric values above a predefined
limit, 58% of the responses for independent variables are 0.

Which method can I use to determine a reduced set of independent variables
with significant predictive power?
As I do not have a statistics background, I would also appreciate a simple
explanation of the chosen method and sensible choices for parameters, so
that I will be able to infer the reduced set of software metrics to keep.

Thank you in advance!

Johannes
-- 
View this message in context: 
http://n4.nabble.com/Method-for-reduction-of-independent-variables-tp1013171p1013171.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-25 Thread yonosoyelmejor

You are right,but I´ll explain,my code creates a time series,after some
transformations I need to make a prediction,which predicts 10values using
the above,then written in a file,I put the code to see if it looks better:

# TODO: Add comment
# 
# Author: Ignacio2
###



library(TSA)
library(tseries)

Invernadero<-read.table(file.choose(),header=T,sep=",")

attach(Invernadero)
names(Invernadero)
Invernadero<-ts(Invernadero<-Temp..Ext)
plot(Hora,Invernadero,main="Temperatura Ext.
Invernadero",xlab="Tiempo",ylab="Temperatura Ext.")

x = log(Invernadero)  #Estabilizar la varianza

varianza<-function(x) { ((length(x)-1)/length(x))*var(x) }#para saber la
varianza
varianza(x)
varianza(Invernadero)
x1<-diff(x,lag=60)
adf.test(x1)
x2<-diff(x1,lag=1)
adf.test(x2)
mean(x2)
# La función “ar” permite seleccionar automáticamente “el
#mejor modelo #autorregresivo:

ar(x2)
orden <- ar(x2)$order #con esto obtenemos el orden seleccionado no toda la
informacion

#AIC(arima(x2,order=c(8,0,0)),arima(x2,order=c(31,0,0)))

# Predicción:
x2.pred.ar31<-predict(arima(x2,order=c(orden,0,0)),n.ahead=10)$pred
# Errores de predicción:
x2.err.ar31<-predict(arima(x2,order=c(orden,0,0)),n.ahead=10)$se
plot(x2.err.ar31)

#deshacer cambios

x.completada<-c(x2,x2.pred.ar31)
xinv1<-diffinv(x.completada,lag=1,xi=x1[1])
xinv2<-diffinv(xinv1,lag=60,xi=x[1:60])
x.reconstruida<-ts(xinv2,frequency=60)
# Comprobación de que la reconstrucción fue correcta:
yy<-x-x.reconstruida[1:length(x)] # esto para Hora8
## yy debe ser una serie de 0’s
plot(yy)


# Las predicciones para los minutos siguientes de la serie
#original son:
#prediccion = exp(x.reconstruida[481:491]) #en nuestro caso pondriamos los
minutos a saber.
prediccion = exp(x.reconstruida[length(x)+1:length(x)+9]) 
###This is what I do not work, we still need to be reusable by if I change
the number of elements

write.table(prediccion,"C:\\Temp\\prePrueba.txt",quote=F,row.names=F,append=T,col.names=F)


Sarah Goslee wrote:
> 
> If the last position of your vector is 1440, what do you expect to get
> from 1440 + 1???
> And you certainly need some parentheses in there if you expect to get a
> range of
> values from your vector.
> 
> Perhaps you need some subtraction?
> 
> And no, we still can't tell exactly what you want. If this doesn't
> answer your question,
> make a reproducible example with a short vector, your code that
> doesn't work, and
> the _result you expect to get_ so we can help you.
> 
> Sarah
> 
> On Tue, Nov 24, 2009 at 1:44 PM, yonosoyelmejor
>  wrote:
>>
>> I use length(myVector),but when i want to use for example
>> exp(x.reconstruida[length(myVector)+1:length(myVector)+9]), I need that
>> function returns the number of last element,would then:
>>
>> if the last position of my vector is 1440
>>
>> exp(x.reconstruida[1440+1:1440+9]
>>
>> This is what I need, I hope having explained,
>>
>> A gretting,
>> Ignacio.
>>
> 
> 
> -- 
> Sarah Goslee
> http://www.functionaldiversity.org
> 
> __
> R-help@r-project.org 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.
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Method-tp26493442p26509891.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-25 Thread yonosoyelmejor

Your suspicions were correct, I just try and works perfectly. Thank you very
much for your help, :-

Greetings,
Ignacio.

William Dunlap wrote:
> 
> Message-
>> From: r-help-boun...@r-project.org 
>> [mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius
>> Sent: Tuesday, November 24, 2009 12:22 PM
>> To: yonosoyelmejor
>> Cc: r-help@r-project.org
>> Subject: Re: [R] Method
>> 
>> 
>> On Nov 24, 2009, at 1:44 PM, yonosoyelmejor wrote:
>> 
>> >
>> > I use length(myVector),but when i want to use for example
>> > exp(x.reconstruida[length(myVector)+1:length(myVector)+9]), I need  
> 
> This may have nothing to do with your original problem,
> but I suspect that expression should be
>exp(x.reconstruida[(length(myVector)+1):(length(myVector)+9)])
> or, equivalently,
>exp(x.reconstruida[length(myVector)+(1:9)])
> (where the parentheses around 1:9 are not required but often
> helpful for understanding).
> 
> Compare
>> 5+1:5+10
>[1] 16 17 18 19 20
>> (5+1):(5+10)
> [1]  6  7  8  9 10 11 12 13 14 15
> 
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com 
> 
>> > that
>> > function returns the number of last element,would then:
>> >
>> > if the last position of my vector is 1440
>> >
>> > exp(x.reconstruida[1440+1:1440+9]
> 
> Again, (1440+1):(1440+9) or 1440+(1:9).
> 
>> 
>> So that should give you (assuming that you close the expression) a  
>> vector of values, "e" raised to a vector from elements 1441 to 1449,  
>> if such elements have already been defined and are numeric.
>> >
>> > This is what I need, I hope having explained,
>> 
>> I do not think you have explained well enough. What is  
>> "x.reconstruida"? Does it have a longer length than myVector?
>> 
>> Things would be much clearer if you made a small example (not 1440  
>> elements long, maybe 10?).
>> 
>> -- 
>> David
>> >
>> > A gretting,
>> > Ignacio.
>> >
>> > Johannes Graumann-2 wrote:
>> >>
>> >> myVector <- c(seq(10),23,35)
>> >> length(myVector)
>> >> myVector[length(myVector)]
>> >>
>> >> it's unclear to me which of the two you want ...
>> >>
>> >> HTH, Joh
>> >>
>> >> yonosoyelmejor wrote:
>> >>
>> >>>
>> >>> Hello, i would like to ask you another question. Is exist  
>> >>> anymethod to
>> >>> vectors that tells me the last element?That is to say,I have a  
>> >>> vector, I
>> >>> want to return the position of last element. I hope having  
>> >>> explained.
>> >>>
>> >>> A greeting,
>> >>> Ignacio.
>> >>
>> >> __
>> >> R-help@r-project.org 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.
>> >>
>> >>
>> >
>> > -- 
>> > View this message in context: 
>> http://old.nabble.com/Method-tp26493442p26499919.html
>> > Sent from the R help mailing list archive at Nabble.com.
>> >
>> > __
>> > R-help@r-project.org 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, MD
>> Heritage Laboratories
>> West Hartford, CT
>> 
>> __
>> R-help@r-project.org 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.
>> 
> 
> __
> R-help@r-project.org 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.
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Method-tp26493442p26510040.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-24 Thread David Winsemius


On Nov 24, 2009, at 3:21 PM, David Winsemius wrote:



On Nov 24, 2009, at 1:44 PM, yonosoyelmejor wrote:



I use length(myVector),but when i want to use for example
exp(x.reconstruida[length(myVector)+1:length(myVector)+9]), I need  
that

function returns the number of last element,would then:

if the last position of my vector is 1440

exp(x.reconstruida[1440+1:1440+9]




== 1450:(1449+1440)


So that should give you (assuming that you close the expression) a  
vector of values, "e" raised to a vector from elements 1441 to 1449,  
if such elements have already been defined and are numeric.


Just for the archives and the other newbies like me:  Bill Dunlap's  
advice makes it clear that (not of the first time) I had forgotten  
that ":" has higher precedence than "+".  My other advice today (which  
was aided by having a workable example) where I did advise that x:(x 
+5) was the correct formulation, would also apply here.


?Syntax

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-24 Thread William Dunlap
Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius
> Sent: Tuesday, November 24, 2009 12:22 PM
> To: yonosoyelmejor
> Cc: r-help@r-project.org
> Subject: Re: [R] Method
> 
> 
> On Nov 24, 2009, at 1:44 PM, yonosoyelmejor wrote:
> 
> >
> > I use length(myVector),but when i want to use for example
> > exp(x.reconstruida[length(myVector)+1:length(myVector)+9]), I need  

This may have nothing to do with your original problem,
but I suspect that expression should be
   exp(x.reconstruida[(length(myVector)+1):(length(myVector)+9)])
or, equivalently,
   exp(x.reconstruida[length(myVector)+(1:9)])
(where the parentheses around 1:9 are not required but often
helpful for understanding).

Compare
   > 5+1:5+10
   [1] 16 17 18 19 20
   > (5+1):(5+10)
[1]  6  7  8  9 10 11 12 13 14 15

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> > that
> > function returns the number of last element,would then:
> >
> > if the last position of my vector is 1440
> >
> > exp(x.reconstruida[1440+1:1440+9]

Again, (1440+1):(1440+9) or 1440+(1:9).

> 
> So that should give you (assuming that you close the expression) a  
> vector of values, "e" raised to a vector from elements 1441 to 1449,  
> if such elements have already been defined and are numeric.
> >
> > This is what I need, I hope having explained,
> 
> I do not think you have explained well enough. What is  
> "x.reconstruida"? Does it have a longer length than myVector?
> 
> Things would be much clearer if you made a small example (not 1440  
> elements long, maybe 10?).
> 
> -- 
> David
> >
> > A gretting,
> > Ignacio.
> >
> > Johannes Graumann-2 wrote:
> >>
> >> myVector <- c(seq(10),23,35)
> >> length(myVector)
> >> myVector[length(myVector)]
> >>
> >> it's unclear to me which of the two you want ...
> >>
> >> HTH, Joh
> >>
> >> yonosoyelmejor wrote:
> >>
> >>>
> >>> Hello, i would like to ask you another question. Is exist  
> >>> anymethod to
> >>> vectors that tells me the last element?That is to say,I have a  
> >>> vector, I
> >>> want to return the position of last element. I hope having  
> >>> explained.
> >>>
> >>> A greeting,
> >>> Ignacio.
> >>
> >> __
> >> R-help@r-project.org 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.
> >>
> >>
> >
> > -- 
> > View this message in context: 
> http://old.nabble.com/Method-tp26493442p26499919.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > __
> > R-help@r-project.org 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, MD
> Heritage Laboratories
> West Hartford, CT
> 
> __
> R-help@r-project.org 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.
> 

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-24 Thread David Winsemius


On Nov 24, 2009, at 1:44 PM, yonosoyelmejor wrote:



I use length(myVector),but when i want to use for example
exp(x.reconstruida[length(myVector)+1:length(myVector)+9]), I need  
that

function returns the number of last element,would then:

if the last position of my vector is 1440

exp(x.reconstruida[1440+1:1440+9]


So that should give you (assuming that you close the expression) a  
vector of values, "e" raised to a vector from elements 1441 to 1449,  
if such elements have already been defined and are numeric.


This is what I need, I hope having explained,


I do not think you have explained well enough. What is  
"x.reconstruida"? Does it have a longer length than myVector?


Things would be much clearer if you made a small example (not 1440  
elements long, maybe 10?).


--
David


A gretting,
Ignacio.

Johannes Graumann-2 wrote:


myVector <- c(seq(10),23,35)
length(myVector)
myVector[length(myVector)]

it's unclear to me which of the two you want ...

HTH, Joh

yonosoyelmejor wrote:



Hello, i would like to ask you another question. Is exist  
anymethod to
vectors that tells me the last element?That is to say,I have a  
vector, I
want to return the position of last element. I hope having  
explained.


A greeting,
Ignacio.


__
R-help@r-project.org 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.




--
View this message in context: 
http://old.nabble.com/Method-tp26493442p26499919.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-24 Thread Sarah Goslee
If the last position of your vector is 1440, what do you expect to get
from 1440 + 1???
And you certainly need some parentheses in there if you expect to get a range of
values from your vector.

Perhaps you need some subtraction?

And no, we still can't tell exactly what you want. If this doesn't
answer your question,
make a reproducible example with a short vector, your code that
doesn't work, and
the _result you expect to get_ so we can help you.

Sarah

On Tue, Nov 24, 2009 at 1:44 PM, yonosoyelmejor
 wrote:
>
> I use length(myVector),but when i want to use for example
> exp(x.reconstruida[length(myVector)+1:length(myVector)+9]), I need that
> function returns the number of last element,would then:
>
> if the last position of my vector is 1440
>
> exp(x.reconstruida[1440+1:1440+9]
>
> This is what I need, I hope having explained,
>
> A gretting,
> Ignacio.
>


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-24 Thread yonosoyelmejor

I use length(myVector),but when i want to use for example
exp(x.reconstruida[length(myVector)+1:length(myVector)+9]), I need that
function returns the number of last element,would then:

if the last position of my vector is 1440

exp(x.reconstruida[1440+1:1440+9]

This is what I need, I hope having explained,

A gretting,
Ignacio.

Johannes Graumann-2 wrote:
> 
> myVector <- c(seq(10),23,35)
> length(myVector)
> myVector[length(myVector)]
> 
> it's unclear to me which of the two you want ...
> 
> HTH, Joh
> 
> yonosoyelmejor wrote:
> 
>> 
>> Hello, i would like to ask you another question. Is exist anymethod to
>> vectors that tells me the last element?That is to say,I have a vector, I
>> want to return the position of last element. I hope having explained.
>> 
>> A greeting,
>> Ignacio.
> 
> __
> R-help@r-project.org 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.
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Method-tp26493442p26499919.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-24 Thread Johannes Graumann
myVector <- c(seq(10),23,35)
length(myVector)
myVector[length(myVector)]

it's unclear to me which of the two you want ...

HTH, Joh

yonosoyelmejor wrote:

> 
> Hello, i would like to ask you another question. Is exist anymethod to
> vectors that tells me the last element?That is to say,I have a vector, I
> want to return the position of last element. I hope having explained.
> 
> A greeting,
> Ignacio.

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-24 Thread Karl Ove Hufthammer
On Tue, 24 Nov 2009 10:14:18 -0500 Sarah Goslee  
wrote:
> x <- runif(45)   # make a test vector
> length(x) # position of the last element
> x[length(x)] # value of the last element

For the last one, this should be even better: tail(x, 1)

But, actually benchmarking this, it turns out that the 'length' solution 
is about 10 times faster than the 'tail' solution. :-(

-- 
Karl Ove Hufthammer

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-24 Thread David Winsemius


On Nov 24, 2009, at 10:20 AM, Keo Ormsby wrote:


yonosoyelmejor escribió:
Hello, i would like to ask you another question. Is exist anymethod  
to
vectors that tells me the last element?That is to say,I have a  
vector, I

want to return the position of last element. I hope having explained.

A greeting,
Ignacio.


vect1 <- c(1,2,3)
vect1[length(vect1)]


As well as:

tail(vect1, 1)






--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-24 Thread Sarah Goslee
It isn't entirely clear what you want. Maybe one of these?

x <- runif(45)   # make a test vector
length(x) # position of the last element
x[length(x)] # value of the last element

Sarah

On Tue, Nov 24, 2009 at 5:18 AM, yonosoyelmejor
 wrote:
>
> Hello, i would like to ask you another question. Is exist anymethod to
> vectors that tells me the last element?That is to say,I have a vector, I
> want to return the position of last element. I hope having explained.
>
> A greeting,
> Ignacio.
> --


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org 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.


Re: [R] Method

2009-11-24 Thread Keo Ormsby

yonosoyelmejor escribió:

Hello, i would like to ask you another question. Is exist anymethod to
vectors that tells me the last element?That is to say,I have a vector, I
want to return the position of last element. I hope having explained.

A greeting,
Ignacio.
  

vect1 <- c(1,2,3)
vect1[length(vect1)]

Hope this helps.

Saludos,
Keo.

__
R-help@r-project.org 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.


[R] Method

2009-11-24 Thread yonosoyelmejor

Hello, i would like to ask you another question. Is exist anymethod to
vectors that tells me the last element?That is to say,I have a vector, I
want to return the position of last element. I hope having explained.

A greeting,
Ignacio.
-- 
View this message in context: 
http://old.nabble.com/Method-tp26493442p26493442.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


[R] Method dispatch for function

2009-11-18 Thread Stavros Macrakis
How can I determine what S3 method will be called for a particular
first-argument class?

I was imagining something like functionDispatch('str','numeric') =>
utils:::str.default , but I can't find anything like this.

For that matter, I was wondering if anyone had written a version of
`methods` which gave their fully qualified names if they were not visible,
e.g.

methods('str') =>
utils:::str.data.frameutils:::str.default
stats:::str.dendrogramstats:::str.logLikutils:::str.POSIXt

or

methods('str') =>
 $utils
   "str.data.frame" "str.default""str.POSIXt"
 $stats
   "str.dendrogram" "str.logLik"

Thank you,

 -s

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] method for calculating grey level occurrence matrices (GLCM) with R

2009-05-05 Thread Hans-Joachim Klemmt

hello,

does anybody know a method for calculating grey-level co-occurrence 
matrices (GLCM) for RGB-pictures with R?
(unfortunately i haven't found a solution for this problem neither via 
(scholar)google nor via r-project helplist)


thank you very much!

best regards

Hans-Joachim Klemmt

--
--

Dr. Hans-Joachim Klemmt

Forstoberrat
Organisationsprogrammierer IHK


Bayerische Landesanstalt für Wald und Forstwirtschaft

zugewiesen an

Lehrstuhl für Waldwachstumskunde
Technische Universität München
Am Hochanger 13

85354 Freising

Tel.: 08161/ 7147-14
Fax : 08161/ 7147-21

eMail: h-j.kle...@lrz.tum.de

Skype: hajo_klemmt

__
R-help@r-project.org 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.


Re: [R] method ML

2009-04-14 Thread Luc Villandre

Hi Joe,

You're using the lme() function? If so, then adding

/method = "ML" /

to the argument list should do the trick.

Cheers,

Luc

joewest wrote:

Hi

I am doing lme models and they are coming out using the REML method, can
anyone please tell me how i use the ML method and exactly what i put in to R
to do this?

Just wanted to say thanks for everyone who helped with my last question.  


Thanks

Joe



__
R-help@r-project.org 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.


[R] method ML

2009-04-14 Thread joewest

Hi

I am doing lme models and they are coming out using the REML method, can
anyone please tell me how i use the ML method and exactly what i put in to R
to do this?

Just wanted to say thanks for everyone who helped with my last question.  

Thanks

Joe
-- 
View this message in context: 
http://www.nabble.com/method-ML-tp23040635p23040635.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


[R] Still confused about R method of data exchanging between caller and called function

2009-04-01 Thread mauede
First of all I'd like to thank all those who answered me back teaching me 
different ways to get the calledfunction modify global data rather than its 
own. I fixed that.

Now I have a similar pproblem. Whenever the caller passes a matrix to the 
called function I thought  the called function would make a copy of the passed 
array in its own memory frame, modify its own copy, but be able to pass back 
the results to the caller as follows ... but I am mistaken (I find all "NA" on 
the second call ... how caome ?


"ford" <- function(X,N,Nfour,Kfour,LevMin,LevMax) {
  

   Y <- X
   Nord <- Kord
   if(Nord == 2){
cat("\n call HAAR \n")
  Y <- Haar(Y,Nfour,1)
   }else{
cat("\n call pwtset \n")
  pwtset(Nord)
cat("\n call wt1 \n")
  Y <- wt1(Y,Nfour,1)
cat("\n function 'ford' Y = ",Y,"\n")
   }

#
"wt1" <- function (a,n,isign){

cat("\n BEGIN 'wt1' \n")
cat("\n 'wt1': n = ",n,"\n")
cat("\n 'wt1': a = ",a,"\n")

  if (n < 4){
cat("\n function 'wt1':  WRONG INPUT SIGNAL LENGTH \n")
return()
  }
  if(isign >= 0){
 nn <- n
 while(nn >= 4){
cat("\n call pwt \n")
a <- pwt(a,nn,isign)
nn <- nn/2
 }
...

cat("\n END 'wt1' \n")
  a   #RETURN WAVELET COEFFICIENTS
}#  end function "wt1" 




tutti i telefonini TIM!


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] method to return rgb values from pixels of an image

2008-11-07 Thread Duncan Murdoch

On 11/7/2008 3:24 AM, Hans-Joachim Klemmt wrote:

hello,

i am looking for a method to return rgb-values of predifined pixels of 
jpg images.


can anybody help me?



See the rimage package, with function read.jpeg.  It will read the whole 
file into a large array, with separate red, green, blue entries.


Duncan Murdoch

__
R-help@r-project.org 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.


Re: [R] is there any way to run R method as a background process from R interface

2008-11-07 Thread Philippe Grosjean

Hello,

Two approaches depending when you want to trigger this background 
calculation:


1) It is enough to trigger the background computation after each 
top-level instruction entered at the command line: use ?addTaskCallback


2) You want to trigger the background calculation at a given time, or 
redo it every xxx ms. This is a little bit more complicate. I have 
success using the tcltk package and the 'after' Tcl function.


Best,

Philippe Grosjean

..<°}))><
 ) ) ) ) )
( ( ( ( (Prof. Philippe Grosjean
 ) ) ) ) )
( ( ( ( (Numerical Ecology of Aquatic Systems
 ) ) ) ) )   Mons-Hainaut University, Belgium
( ( ( ( (
..

Kurapati, Ravichandra (Ravichandra) wrote:

Hi ,

 


can some body tell to me "how to run a R method /function as a
background process from R interface"

 


Thanks

K.Ravichandra

 

 



[[alternative HTML version deleted]]

__
R-help@r-project.org 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.



__
R-help@r-project.org 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.


[R] method to return rgb values from pixels of an image

2008-11-07 Thread Hans-Joachim Klemmt

hello,

i am looking for a method to return rgb-values of predifined pixels of 
jpg images.


can anybody help me?

thank you very much

best regards

hans-joachim klemmt

--
--

Dr. Hans-Joachim Klemmt

Forstoberrat
Organisationsprogrammierer IHK


Bayerische Landesanstalt für Wald und Forstwirtschaft

zugewiesen an

Lehrstuhl für Waldwachstumskunde
Technische Universität München
Am Hochanger 13

85354 Freising

Tel.: 08161/ 7147-14
Fax : 08161/ 7147-21

eMail: [EMAIL PROTECTED]

Skype: hajo_klemmt

__
R-help@r-project.org 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.


[R] is there any way to run R method as a background process from R interface

2008-11-07 Thread Kurapati, Ravichandra (Ravichandra)
Hi ,

 

can some body tell to me "how to run a R method /function as a
background process from R interface"

 

Thanks

K.Ravichandra

 

 


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Method for checking automatically which distribtions fits a data

2008-07-07 Thread Frank E Harrell Jr

David Reinke wrote:

The function ks.test(x,y, ...) performs a Kolmogorov-Smirnov test on a set
of sample values x against a distribution y. Both x and y must be
cumulative distributions; y can be either a vector of cumulative values or
a predefined distribution such as pnorm().

David Reinke


If you find which distribution best fits the empirical distribution, the 
resulting estimates will have variances (once model uncertainty is taken 
into account through bootstrapping) that are equal to those from the 
empirical CDF so nothing is gained.   You can use the empirical CDF as 
the "final answer" unless prior knowledge on the distributional shape is 
available.


Frank Harrell



Senior Transportation Engineer/Economist
Dowling Associates, Inc.
180 Grand Avenue, Suite 250
Oakland, California 94612-3774
510.839.1742 x104 (voice)
510.839.0871 (fax)
www.dowlinginc.com

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of hadley wickham
Sent: Monday, July 07, 2008 8:10 AM
To: Ben Bolker
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Method for checking automatically which distribtions fits
a data


Suppose I have a vector of data.
Is there a method in R to help us automatically
suggest which distributions fits to that data
(e.g. normal, gamma, multinomial etc) ?

- Gundala Viswanath
Jakarta - Indonesia


See

https://stat.ethz.ch/pipermail/r-help/2008-June/166259.html

 for example, normal vs gamma might be a sensible question
(for which you can use fitdistr() as suggested above), but
"multinomial" implies a very specific kind of response --
discrete data with a specified number of possible outcomes.


Yes - the question as it is poorly stated.   If you have a small
(finite) choice of possible distributions you can use some kind of
likelihood based statistic to determine which fits the data best.  But
what is the population of distributions in this case?   All
distributions that you see in stats101?  All distributions that have
names?   All continuous distributions?

Hadley





--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University

__
R-help@r-project.org 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.


Re: [R] Method for checking automatically which distribtions fits a data

2008-07-07 Thread David Reinke
The function ks.test(x,y, ...) performs a Kolmogorov-Smirnov test on a set
of sample values x against a distribution y. Both x and y must be
cumulative distributions; y can be either a vector of cumulative values or
a predefined distribution such as pnorm().

David Reinke

Senior Transportation Engineer/Economist
Dowling Associates, Inc.
180 Grand Avenue, Suite 250
Oakland, California 94612-3774
510.839.1742 x104 (voice)
510.839.0871 (fax)
www.dowlinginc.com

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of hadley wickham
Sent: Monday, July 07, 2008 8:10 AM
To: Ben Bolker
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Method for checking automatically which distribtions fits
a data

>> Suppose I have a vector of data.
>> Is there a method in R to help us automatically
>> suggest which distributions fits to that data
>> (e.g. normal, gamma, multinomial etc) ?
>>
>> - Gundala Viswanath
>> Jakarta - Indonesia
>>
>
> See
>
> https://stat.ethz.ch/pipermail/r-help/2008-June/166259.html
>
>  for example, normal vs gamma might be a sensible question
> (for which you can use fitdistr() as suggested above), but
> "multinomial" implies a very specific kind of response --
> discrete data with a specified number of possible outcomes.

Yes - the question as it is poorly stated.   If you have a small
(finite) choice of possible distributions you can use some kind of
likelihood based statistic to determine which fits the data best.  But
what is the population of distributions in this case?   All
distributions that you see in stats101?  All distributions that have
names?   All continuous distributions?

Hadley


-- 
http://had.co.nz/

__
R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] Method for checking automatically which distribtions fits a data

2008-07-07 Thread hadley wickham
>> Suppose I have a vector of data.
>> Is there a method in R to help us automatically
>> suggest which distributions fits to that data
>> (e.g. normal, gamma, multinomial etc) ?
>>
>> - Gundala Viswanath
>> Jakarta - Indonesia
>>
>
> See
>
> https://stat.ethz.ch/pipermail/r-help/2008-June/166259.html
>
>  for example, normal vs gamma might be a sensible question
> (for which you can use fitdistr() as suggested above), but
> "multinomial" implies a very specific kind of response --
> discrete data with a specified number of possible outcomes.

Yes - the question as it is poorly stated.   If you have a small
(finite) choice of possible distributions you can use some kind of
likelihood based statistic to determine which fits the data best.  But
what is the population of distributions in this case?   All
distributions that you see in stats101?  All distributions that have
names?   All continuous distributions?

Hadley


-- 
http://had.co.nz/

__
R-help@r-project.org 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.


Re: [R] Method for checking automatically which distribtion s fits a data

2008-07-07 Thread Ben Bolker
Stephen Tucker  yahoo.com> writes:

> 
> I don't know that there is a single function, but you can perhaps apply a
sequence of available functions - 
> 
> For instance, you can use fitdistr() in library(MASS) to estimate optimal
parameters for a candidate set
> of distributions; then look at each fit and also compare the deviance among
the fits (possibly penalizing
> distributions which require more parameters - for instance, using the Akaike
Information
> Criterion(?)). 
> 
> - Original Message 
> From: Gundala Viswanath  gmail.com>
> To: r-help  stat.math.ethz.ch
> Sent: Sunday, July 6, 2008 4:50:20 PM
> Subject: [R] Method for checking automatically which distribtions fits a data
> 
> Hi,
> 
> Suppose I have a vector of data.
> Is there a method in R to help us automatically
> suggest which distributions fits to that data
> (e.g. normal, gamma, multinomial etc) ?
> 
> - Gundala Viswanath
> Jakarta - Indonesia
> 

See

https://stat.ethz.ch/pipermail/r-help/2008-June/166259.html

  for example, normal vs gamma might be a sensible question
(for which you can use fitdistr() as suggested above), but
"multinomial" implies a very specific kind of response --
discrete data with a specified number of possible outcomes.

  Ben Bolker

__
R-help@r-project.org 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.


Re: [R] Method for checking automatically which distribtions fits a data

2008-07-07 Thread Stephen Tucker
I don't know that there is a single function, but you can perhaps apply a 
sequence of available functions - 

For instance, you can use fitdistr() in library(MASS) to estimate optimal 
parameters for a candidate set of distributions; then look at each fit and also 
compare the deviance among the fits (possibly penalizing distributions which 
require more parameters - for instance, using the Akaike Information 
Criterion(?)). 


- Original Message 
From: Gundala Viswanath <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Sent: Sunday, July 6, 2008 4:50:20 PM
Subject: [R] Method for checking automatically which distribtions fits a data

Hi,

Suppose I have a vector of data.
Is there a method in R to help us automatically
suggest which distributions fits to that data
(e.g. normal, gamma, multinomial etc) ?

- Gundala Viswanath
Jakarta - Indonesia

__
R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] Method for checking automatically which distribtions fits a data

2008-07-06 Thread ctu

Hi,
In my experience, I just plot the data set then figure it out.
Maybe you could try this?
I really wonder that there is such a R function exists.

If yes, please let me know.
Thanks
Chunhao Tu

Quoting Gundala Viswanath <[EMAIL PROTECTED]>:


Hi,

Suppose I have a vector of data.
Is there a method in R to help us automatically
suggest which distributions fits to that data
(e.g. normal, gamma, multinomial etc) ?

- Gundala Viswanath
Jakarta - Indonesia

__
R-help@r-project.org 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.



__
R-help@r-project.org 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.


[R] Method for checking automatically which distribtions fits a data

2008-07-06 Thread Gundala Viswanath
Hi,

Suppose I have a vector of data.
Is there a method in R to help us automatically
suggest which distributions fits to that data
(e.g. normal, gamma, multinomial etc) ?

- Gundala Viswanath
Jakarta - Indonesia

__
R-help@r-project.org 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.