[R] windows completion in 2.5?

2007-04-29 Thread David Hugh-Jones
Can anyone tell me if the new R 2.5 has autocompletion for the default
windows shell? I know they integrated rcompletion but wasn't sure if
it was just Unix.

Cheers
David

__
R-help@stat.math.ethz.ch 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] level sets

2006-11-06 Thread David Hugh-Jones
Hi,

Can anyone suggest a good way to draw level curves of a function with
R? I am thinking of something analogous to curve. If there is a
package I should be looking at for this kind of mathematical stuff,
I'd like to know too...

cheers
d

__
R-help@stat.math.ethz.ch 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] inplace assignment: solution

2006-06-20 Thread David Hugh-Jones
I worked this out over the weekend. I appreciate that using temporary
variables would be simpler but I think this makes for quite readable
code:

# in RProfile.site
inplace - function (f, arg=1)
eval.parent(call(-,substitute(f)[[arg+1]], f),2)


# examples in code

inplace(foo[bar,baz] *2)
# or
inplace(paste(foo[bar,baz], 1:10))
# or
inplace(sub(blah, bleh, foo[bar,baz]), 3)


cheers
Dave


On 16/06/06, David Hugh-Jones [EMAIL PROTECTED] wrote:
 It's more a general point about having to write things out twice when
 you do assignments. I could also have written:

 data.frame[some.condition  another.condition, big.list.of.columns] -
 data.frame[some.condition  another.condition,  big.list.of.columns] * 2 + 55

 or anything else. Equally, there could be any method of subsetting, or
 any expression that can be an assignment target, on the left hand
 side:

 data.frame[[some.complex.expression.for.columnames]]
 -data.frame[[some.complex.expression.for.columnames]] * 333 + foo *
 56

 rownames(matrix)[45:53] - paste(rownames(matrix)[45:53], blah)


 David

 On 16/06/06, Adaikalavan Ramasamy [EMAIL PROTECTED] wrote:
  I do not fully understand your question but how about :
 
   inplace - function( df, cond1, cond2, cols, suffix ){
 
w  - which( cond1  cond2 )
df - df[ w, cols ]
paste(df, suffix)
return(df)
   }
 
 
  BTW, did you mean colnames(df) - paste(colnames(df), suffix) instead
  of paste(df, suffix) ?
 
  Regards, Adai
 
 
 
  On Fri, 2006-06-16 at 10:23 +0100, David Hugh-Jones wrote:
   I get tired of writing, e.g.
  
  
   data.frame[some.condition  another.condition, big.list.of.columns] -
   paste(data.frame[some.condition  another.condition,
   big.list.of.columns], foobar)
  
  
   I would a function like:
  
   inplace(paste(data.frame[some.condition  another.condition,
   big.list.of.columns], foobar))
  
   which would take the first argument of the inner function and assign
   the function's result to it.
  
   Has anyone done something like this? Are there simple alternative
   solutions that I'm missing?
  
   Cheers
   David
  
   __
   R-help@stat.math.ethz.ch mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide! 
   http://www.R-project.org/posting-guide.html
  
 
 


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


Re: [R] NLME: using the layout option with the plot command

2006-06-20 Thread David Hugh-Jones
hi greg

If you are using windows, set up a plot window and click the Record
option in the menu. Then run the command. Now you can scroll back
through previous pages by hitting Page Up.

Beware that if you save your workspace without clearing the history,
you may have a lot of bloat from the graphs.

David

On 20/06/06, Greg Distiller [EMAIL PROTECTED] wrote:
 Hi
 This is the 2nd time I am posting this question as I never got a reply the
 1st time round - apologies to anybody who might take offense at this but I
 dont know what else to do.

 I am struggling to split up the plots of the grouped objects in nlme in a
 usable way. The standard plot command generates plots for each group on a
 single page. When there are many groups however this does not look so good.
 I have discovered the layout option which allows one to split up these plots
 over a certain number of pages but the problem is it very quickly scrolls
 through all the pages only leaving the final page in the viewer.

 My question is how does one get to view all these pages? Or even better is
 there an option where the pages change only when prompted by the user?

 Thanks

 Greg

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


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


[R] inplace assignment

2006-06-16 Thread David Hugh-Jones
I get tired of writing, e.g.


data.frame[some.condition  another.condition, big.list.of.columns] -
paste(data.frame[some.condition  another.condition,
big.list.of.columns], foobar)


I would a function like:

inplace(paste(data.frame[some.condition  another.condition,
big.list.of.columns], foobar))

which would take the first argument of the inner function and assign
the function's result to it.

Has anyone done something like this? Are there simple alternative
solutions that I'm missing?

Cheers
David

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


Re: [R] inplace assignment

2006-06-16 Thread David Hugh-Jones
It's more a general point about having to write things out twice when
you do assignments. I could also have written:

data.frame[some.condition  another.condition, big.list.of.columns] -
data.frame[some.condition  another.condition,  big.list.of.columns] * 2 + 55

or anything else. Equally, there could be any method of subsetting, or
any expression that can be an assignment target, on the left hand
side:

data.frame[[some.complex.expression.for.columnames]]
-data.frame[[some.complex.expression.for.columnames]] * 333 + foo *
56

rownames(matrix)[45:53] - paste(rownames(matrix)[45:53], blah)


David

On 16/06/06, Adaikalavan Ramasamy [EMAIL PROTECTED] wrote:
 I do not fully understand your question but how about :

  inplace - function( df, cond1, cond2, cols, suffix ){

   w  - which( cond1  cond2 )
   df - df[ w, cols ]
   paste(df, suffix)
   return(df)
  }


 BTW, did you mean colnames(df) - paste(colnames(df), suffix) instead
 of paste(df, suffix) ?

 Regards, Adai



 On Fri, 2006-06-16 at 10:23 +0100, David Hugh-Jones wrote:
  I get tired of writing, e.g.
 
 
  data.frame[some.condition  another.condition, big.list.of.columns] -
  paste(data.frame[some.condition  another.condition,
  big.list.of.columns], foobar)
 
 
  I would a function like:
 
  inplace(paste(data.frame[some.condition  another.condition,
  big.list.of.columns], foobar))
 
  which would take the first argument of the inner function and assign
  the function's result to it.
 
  Has anyone done something like this? Are there simple alternative
  solutions that I'm missing?
 
  Cheers
  David
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide! 
  http://www.R-project.org/posting-guide.html
 



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


Re: [R] Name of a column

2006-06-16 Thread David Hugh-Jones
1. You don't need to say  truc==T. truc is already a logical vector.

2. colnames are just another vector, so do

colnames(truc)[truc]

Dave

On 15/06/06, David Hajage [EMAIL PROTECTED] wrote:
 Hello,

 My problem is quite simply, but I didn't find any solution...

 I have a vector :

  truc
longueur30 longueur40 longueur50 longueur60 longueur70 longueur80
 longueur90
 34  FALSE  FALSE  FALSE  FALSE   TRUE  FALSE
 FALSE

 I would like to have the name of the column where there is TRUE.

  colnames(truc)
 [1] longueur30 longueur40 longueur50 longueur60 longueur70
 [6] longueur80 longueur90

  truc[truc == T]
 [1] TRUE

  colnames(truc[truc == T])
 NULL

 How can I do it ?

 Thank you for your help.

 --
 David

 [[alternative HTML version deleted]]

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


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


Re: [R] help with combination problem

2006-06-08 Thread David Hugh-Jones
hi Srinivas

I'm not sure I understand: your example result has 10-9 for mu1 but 1
for mu2, which is not equal to 11-9. I will assume you just got the
numbers wrong. (Also J100 should be J1, no?)

I am also wondering why you want what you say. It doesn't seem very
sensible to mix the results from two data frames like this.

The simplest thing is probably to do the two data frames separately,
then intermix the rows. You can do this with for loops:


for (col1 in paste(T, 1:14, sep=)) {
  for (col2 in paste(N, 1:16, sep=)) result[[paste(col1, -,
col2, sep=)]] = df1[[col1]] - df1[[col2]]
}

Now repeat for data frame 2 with another data frame, e.g. result2
Then intermix the rows from result and result2. I'll leave you to
figure that bit out.

David



On 07/06/06, Srinivas Iyyer [EMAIL PROTECTED] wrote:
 hello:

 I have 3 data.frame objects.

 First df object:
 Of dim (149,31). Columns 2:31 are marked as T1..T14
 and N1..N16.

 Name T1T2N1   T3   N2  N3  N4  T4
 mu1  1010910   9   9   8   10
 mu2  1111911   9   9   9   11
 ...
 muN  1212911   9   9   8   12




 Second df object:
 of Dim (5,31). Columns 2:31 are maked as T1...T14
 and N1..N16.

 Name T1T2N1   T3   N2  N3  N4  T4
 J1   2 3 20   222  21  29   3
 J2   4 1 20   320  21  22   4
 J3   3 1 33   131  31  33   3
 ...
 JX   3 2 20   221  22  24   2

 The column samples are identical in both first and
 second data frames.

 Third df object:
 of Dim (200,2).

 V1 V2
 mu1:J1 -11
 mu1:J100   -10.4
 mu2:J31 11.3
 mu2:J2  10.4
 .   .
 muN:JX 34.5



 I want to create a combination of Ts and Ns. Where I
 want to subtract value of T-N in all combinations(225
 combinations). Such as
 T1-N1,T1-N2,T1-N3,T1-N4,T1-N5...T14-N16

 The rows should be the row pairs from 3rd dataframe.


 The final resultant matrix should look like the
 following:


  T1-N1  T1-N2  T1-N3  T1-N4  T1-N5...T14-N16
 mu1   1(10-9) 1(10-9)   12  11
 J100  -18(2-20) -20   -19  -27-20  -29

 mu2 1 32 2  11
 J2 -19   -21 -39-31-31 -28



 I am a beginner level in R.  I apologise for asking
 such a big question and subsequent help. I am unable
 to go forward as I have no idea as to how to do this.
 Could any one please help me.
 Thanks
 sri

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


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


[R] interpolating a lot of data at once

2006-05-31 Thread David Hugh-Jones
I have a big dataset containing a lot of values for 1970, 1980 and
1990. I want to interpolate values for the years in between, and also
if possible to extrapolate to 1968 and 1969. The method doesn't have
to be clever but I am looking for a function that will do all the data
at once. (Doing foreach, or apply, is just too slow!) Is there
something that will take

list(df$val.1970, df$val.1980, df$val.1990)

as inputs and output an interpolated matrix?

Cheers
David

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


Re: [R] Vector elements and ratios

2006-05-26 Thread David Hugh-Jones
 outer(c(20,40,20,60), c(5,4,2), /)
 [,1] [,2] [,3]
[1,]45   10
[2,]8   10   20
[3,]45   10
[4,]   12   15   30


cheers
D

On 26/05/06, Andrej Kastrin [EMAIL PROTECTED] wrote:
 Dear useRs,

 I have two different length vectors: one column (1...m) and one row
 vector (1...n):

 20
 40
 20
 60

 5 4 2

 Now I have to calculate ratios between column vector elements and each
 row vector elements:

 4 5 10
 8 10 20
 4 5 20
 15 12 30

 Thank's in advance for any suggestions,

 Andrej

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


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


Re: [R] GA-packages

2006-05-01 Thread David Hugh-Jones
Have you looked at package gafit on CRAN?

Cheers
David

On 01/05/06, j.joshua thomas [EMAIL PROTECTED] wrote:
 Hi,

 I'm looking for help on how to use *R for making use of Genetic
 Algorithm*to make optimal solution on the examination timetabling
 dataset? another
 point to analysis the dataset, in a manner similar to the method applied in
 InfoViz. Say, what is the optimal step, if:
 Step 1

   - What is the name of the package that i can install from CRAN for me
   to identify GA (Please consider)
   - I am using RGui 1.8.0

 Step 2

   - For the second doubt, i used the multiv, mva (EDA- packages)
   - I use RGui 1.8.0 because i couldn't find multiv, mva Or i'm not sure
   of getting it from RGui 2.3.0 (Please Consider)

 I have tried to read up on the 'R-search for Step-1 but i couldn't find the
 appropriate package.

 Can anyone point me in the right direction?

 Best regards,

 JJ

[[alternative HTML version deleted]]

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


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


[R] Writing a function to fit ALSOS models. problem with normalization?

2006-03-23 Thread David Hugh-Jones
Dear all,

Below is my attempt at a function to fit Alternate Least Squares
Optimal Scaling models, as described in Young (1981) Quantitative
Analysis of Qualitative Data and Jacoby (1999) Levels of Measurement
and Political Research: An Optimistic View.

I would welcome any comments on coding style, tips  tricks etc.

I also have a specific problem: the output tends to give very small
coefficients, and very large fitted values for specific factor levels.
Am I doing the normalization right?

Cheers
David


library(car) # for recode

alsos.fit = function (y, x, tol = 1e-7) {
# y is a vector or factor or ordered factor
# x is a data frame of vectors/factors/ordereds

# we treat the y's as the first column of the matrix
x = cbind(y, x)
x = x[complete.cases(x),]
ox = x
x.facs = sapply(x, is.factor)
x.ords = sapply(x, is.ordered)

# start with our numeric values whatever they are
x = sapply(x, as.numeric)

old.SSE = Inf
while(T) {
# least squares regression with an intercept
ols = lm.fit(cbind(rep(1,nrow(x)), x[,-1]) , x[,1])
b = ols$coefficients
SSE = drop(ols$residuals %*% ols$residuals)
if (old.SSE-SSEtol) {
factor.scores=list()
for (i in (1:ncol(x))[x.facs]) {
nm = colnames(x)[i]
factor.scores[[nm]] = tapply(x[,i], ox[,i],
function (foo) {return(foo[1])})
names(factor.scores[[nm]]) = levels(ox[,i])
}

return(list(
factor.scores=factor.scores,
scaled.y=x[,1], scaled.x=x[,-1],
coefficients=b, SSE=SSE,
))
}
old.SSE=SSE

mx = nx = x
mx[] = 0
nx[] = 0
for (i in (1:ncol(x))[x.facs]) {

# optimal scaling
if (i==1) nx[,i] = ols$fitted.values
else nx[,i] = (x[,1] - cbind(rep(1,nrow(x)), 
x[,c(-1,-i)]) %*% b[-i])/b[i]

# create within-category means
tmpfac = factor(ox[,i], labels=1:nlevels(ox[,i]))
catmeans = tapply(nx[,i], tmpfac, mean)

# ensure ordinal values are correctly ordered
if (x.ords[i]) {
tmp = kruskal.ordering(nx[,i], tmpfac)
tmpfac = tmp$tmpfac
catmeans = tmp$catmeans
}

# set values to within-category means
mx[,i] = catmeans[tmpfac]

# normalize according to Young (1981)
mx[,i] = mx[,i] * (nx[,i] %*% nx[,i]) / (mx[,i] %*% 
mx[,i])

}
x[,x.facs] = mx[,x.facs]
}
}

# as described in Kruskal (1964)
kruskal.ordering = function(numeric.data, tmpfac) {
j = 1
upact = T
while(T) {
catmeans = tapply(numeric.data, tmpfac, mean) # vector w as many
items as tmpfac cats
# have we finished?
if (jnlevels(tmpfac)) return 
(list(catmeans=catmeans,tmpfac=tmpfac))
if ((j==nlevels(tmpfac) || catmeans[j] = catmeans[j+1]) 
(j==1 || catmeans[j] = catmeans[j-1])) {
j=j+1
upact=T
next
}
if (upact) {
if (j  nlevels(tmpfac)  catmeans[j]  catmeans[j+1]) 
{
tmpfac = recode(tmpfac, paste(j, :, j+1,=', 
j+1, ', sep=))
levels(tmpfac) = 1:nlevels(tmpfac)
}
upact=F
}
else {
if (j  1  catmeans[j]  catmeans[j-1]) {
tmpfac = recode(tmpfac, paste(j-1, :, j, 
=', j, ', sep=))
levels(tmpfac) = 1:nlevels(tmpfac)
j=j-1
}
upact=T
}
}
}

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


Re: [R] heckit with a probit

2006-03-01 Thread David Hugh-Jones
Thank you both for your help. I've tried VGAM and it seems useful.

Cheers
David

On 27/02/06, Robert Duval [EMAIL PROTECTED] wrote:
 I don't know if I understand your problem very well but the first
 reference that comes to mind is

 James Heckman, Dummy Endogenous Variables in a Simultaneous Equation
 System, Econometrica, (July 1978).

 also you might find a good survey of the literature on

 Francis Vella Estimating models with sample selection bias: A
 survey, Journal of Human Resources, 1998, Vol 33 pp 127-169.

 I don't know how many of the methods here proposed are already
 implemented in R, but in principle many of them are Likelihood models
 that you could program.


 best
 robert


 On 2/27/06, David Hugh-Jones [EMAIL PROTECTED] wrote:
  Hi
 
  I have data for voting behaviour on two (related) binary votes. I want
  to examine the second vote, running separate regressions for groups
  who voted different ways on the first vote. As the votes are not
  independent, I guess that there is an issue with selection bias.
 
  So, I think I would like to fit a heckit style model but with a binary
  dependent variable - so, in effect, two successive probits. Is there a
  way to do it in R? (Alternatively: am I thinking about this the right
  way?)
 
  Cheers
  David
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide! 
  http://www.R-project.org/posting-guide.html
 

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


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


Re: [R] Help - lm, glm, aov results inconsistent with other stati stical package

2006-03-01 Thread David Hugh-Jones
Perhaps it's worth mentioning that you can view and edit the contrasts
for a particular factor by doing e.g.

contrasts(A)

contrasts(A) = contr.treatment(levels(A), base=2) # make the second
category the base

cheers
David


On 01/03/06, Christoph Buser [EMAIL PROTECTED] wrote:
 Dear Ben

 Berwin is correct in his answer about different
 parameterizations.

 After changing the contrasts in R from treatment to sum

 options(contrasts = c(contr.sum, contr.poly ))
 test.lm-lm(y~A*x)
 summary(test.lm)

 I got similar results to JMP. Be careful in doing a correct
 interpretation of your coefficients, especially when you have an
 interaction in your model.

 Regards,

 Christoph Buser

 --
 Christoph Buser [EMAIL PROTECTED]
 Seminar fuer Statistik, LEO C13
 ETH (Federal Inst. Technology)  8092 Zurich  SWITZERLAND
 phone: x-41-44-632-4673 fax: 632-1228
 http://stat.ethz.ch/~buser/
 --




 Ben Ridenhour writes:
   Okay, I took the data to SAS and it gives me the same answer that R does.  
 I don't why JMP is giving me an incorrect answer, but it seems to be.  
 (Either that or I have made the same mistake in SAS and R.) Any ideas what 
 JMP might be doing?
  
Ben
  
   ---
   Benjamin Ridenhour
   School of Biological Sciences
   Washigton State University
   P.O. Box 644236
   Pullman, WA 99164-4236
   Phone (509)335-7218
   
   Nothing in biology makes sense except in the light of evolution.
   -T. Dobzhansky
  
  
   - Original Message 
  
   To: Liaw, Andy [EMAIL PROTECTED]; r-help@stat.math.ethz.ch
   Sent: Tuesday, February 28, 2006 10:50:18 PM
   Subject: Re: [R] Help - lm, glm, aov results inconsistent with other stati 
 stical package
  
   Alright, I'll try to give some sample code.
  
# create A with 2 levels - 2 and 4
 A-c(rep(2,times=30),rep(4,times=42))
  
# make A a factor
 A-as.factor(A)
  
  #generate 72 random x points
 x-rnorm(72)
  
 #create different slopes  intercepts for A=2 and A=4
#add a random error term
 y-c(x[(1:30)]+1,2*x[(31:72)]-2)+rnorm(72,mean=0,sd=2)
  
#use model y~A*x for lm (or glm)
 test.lm-lm(y~A*x)
  
#check the output
 summary(test.lm)
  
This essentially creates something like my data set and uses the same 
 model.  In response to (1), I was just using 0/1 because these are codings 
 for the 2 levels, correct? (i.e., when A=2 the dummy variable=0, when A=4 the 
 dummy variable=1?).  In response to (2), yes, I do want different slopes for 
 the two categories (that is what I am interested in testing).
  
If I export the data created above to JMP and run what I believe to be 
 the same model, I get a different answer for my equations :(
  
  
   ---
   Benjamin Ridenhour
   School of Biological Sciences
   Washigton State University
   P.O. Box 644236
   Pullman, WA 99164-4236
   Phone (509)335-7218
   
   Nothing in biology makes sense except in the light of evolution.
   -T. Dobzhansky
  
  
   - Original Message 
   From: Liaw, Andy [EMAIL PROTECTED]
  
   Sent: Tuesday, February 28, 2006 5:14:57 PM
   Subject: RE: [R] Help - lm, glm, aov results inconsistent with other stati 
 stical package
  
   1. You have levels(A) as 2 and 4, yet you showed equations for A=0 and
   A=1?
  
   2. y = A + X + A*X means you're allowing the different groups of A to have
   different slopes.  Probably not what you intended.
  
   3. It's probably best to provide a small sample of the data (and R code) so
   we know how you got what you got.
  
   Andy
  
   From: Ben Ridenhour
   
Hello,
   
 I 'm sure there must a be a simple explanation for what I'm
doing wrong but I am stumped.  I am a novice R user and this
has shaken my confidence in what I'm doing! I am trying to
run a simple ANCOVA using the model y~A*x, where y and x are
continuous and A has two levels.  Everything seems fine until
I compare the output with what I get from another statistical
package (JMP).  JMP has the model y=A+x+A*x (this should be
the same as what I specified to R, correct?).  In comparison
I get the line equations
   
 y = 7072.09-1024.94 x (for A=0) and
 y = 7875.58-970.088 x (for A=1)
   
 from JMP.  And from R I get
   
 y = 6276.7-1259.8 x (for A=0) and
 y = 7867.5-1150.1 x (for A=1).
   
 Obviously, these aren't even close to the same answer.  I've
tried this using glm(), lm(), and aov() and as expected they
all give the same answer.  If I do
   
 levels(A)
 [1] 2 4
   
 which are the two levels of A.  Why can't I get the same
answer from JMP as in R?  This is very disturbing to me!
   
 Thanks,
 Ben
   
   
---
Benjamin Ridenhour
School of 

[R] heckit with a probit

2006-02-27 Thread David Hugh-Jones
Hi

I have data for voting behaviour on two (related) binary votes. I want
to examine the second vote, running separate regressions for groups
who voted different ways on the first vote. As the votes are not
independent, I guess that there is an issue with selection bias.

So, I think I would like to fit a heckit style model but with a binary
dependent variable - so, in effect, two successive probits. Is there a
way to do it in R? (Alternatively: am I thinking about this the right
way?)

Cheers
David

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


Re: [R] Re: nlme: Deficient rank in gls_loglik when creating corAR1()

2005-05-04 Thread David Hugh-Jones
I tried that but it didn't make any difference to the output.

David

On 04/05/05, Douglas Bates [EMAIL PROTECTED] wrote:
 David Hugh-Jones wrote:
  Is this a bug? Should I attach a test case?
 
 Try setting verbose=TRUE in the call to gls first and see if that gives
 you any insight into what is happening.
 
 
  D
 
  On 03/05/05, David Hugh-Jones [EMAIL PROTECTED] wrote:
 
 I have a bunch of data which is structured by year and US state, so I
 have created a nlme groupedData object for it:
 
 formula(gd2)
 DEPVAR ~ YEAR | ABREV
 
 Now I am trying to run a gls regression on it. I want the error
 correlation structure to be AR1 with a different rho for each state,
 so I do
 
 
 mdyn.1.1 = gls(model = DEPVAR ~ BLAH + BLAH, data=gd2, corr=corAR1(form= ~ 
 YEAR | ABREV),na.action=na.omit)
 
 YEAR and ABREV are always present; DEPVAR is absent for one state.
 
 I get the following error message:
 
 Error in logLik.glsStruct(glsSt, glsPars) :
 Deficient rank in gls_loglik
 
 Can anyone enlighten me? The error message goes away if I just do
 corAR1(form = ~1), but this is not meaningful for my data.
 
 Cheers
 David
 
 
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide! 
  http://www.R-project.org/posting-guide.html
 


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


Re: [R] Combining numeric vs numeric numeric vs factor graphs into one ps/pdf file

2005-05-03 Thread David Hugh-Jones
Hi David

You probably want to write your own panel function and pass it into
xyplot(). Something like

mypanel - function (x,y, groups, subscripts) {
  if (status[subscripts] == pass) {
panel.xyplot(H,CD)
  }
  else {
 panel.xyplot(site, CD)
  }
}

Check out the groups and subscripts arguments to xyplot.

cheers
Dave

On 03/05/05, Arenas, David R.  CIV NAVAIR DEPT [EMAIL PROTECTED] wrote:
 Dear R community,

 My previous email was incomplete because I used html format.  Here it is 
 again and sorry for any inconvenience:

 xyplot (lattice) has been great in displaying tons of data for my research.  
 I have used the following two xyplot commands (with example dataframe) to 
 create two separate postscript/pdf files with respect to the variable acft 
 and subset status:

 test.df - data.frame(acft=factor(c(A,B,C,D)),
   status=factor(c(fail,pass,fail,pass)),
   site=factor(c(E1,E1,E2,E2)),
   CD=as.numeric(c(1,1,3,3)),
   H=as.numeric(c(80,NA,60,NA)))

 xyplot(H ~ CD | acft,
   data=test.df,
   subset=status==fail,
   layout=c(1,1) )

 xyplot(site ~ CD | acft,
   data=test.df,
   subset=status==pass,
   layout=c(1,1) )

  I would like to combine all graphs into one file in alphabetical order of 
 variable acft.  The graphs would be one per page where in fact I use 
 layout=c(1,1) for the nice and easily seen strip labels for acft.  The 
 problem I am having is combining x-y plots that are numeric vs numeric  
 numeric vs factor.  I have search the R-help archives and R-project 
 references for an example to no avail.  I am thinking I may have to use 
 something (lattice or not) like ...

 if any(test.df$Status==fail)
 plot(H ~ CD)
 else
 plot(site ~ CD)

 with for in the beginning to loop through all data with respect to acft.  I 
 need a hint on how to further this along.  I am using R.2.1.0 via Windows XP.

 Thank you for any help,

 D. Arenas

 [[alternative HTML version deleted]]

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


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


[R] Re: nlme: Deficient rank in gls_loglik when creating corAR1()

2005-05-03 Thread David Hugh-Jones
Is this a bug? Should I attach a test case?

D

On 03/05/05, David Hugh-Jones [EMAIL PROTECTED] wrote:
 I have a bunch of data which is structured by year and US state, so I
 have created a nlme groupedData object for it:
 
 formula(gd2)
 DEPVAR ~ YEAR | ABREV
 
 Now I am trying to run a gls regression on it. I want the error
 correlation structure to be AR1 with a different rho for each state,
 so I do
 
  mdyn.1.1 = gls(model = DEPVAR ~ BLAH + BLAH, data=gd2, corr=corAR1(form= ~ 
  YEAR | ABREV),na.action=na.omit)
 
 YEAR and ABREV are always present; DEPVAR is absent for one state.
 
 I get the following error message:
 
 Error in logLik.glsStruct(glsSt, glsPars) :
 Deficient rank in gls_loglik
 
 Can anyone enlighten me? The error message goes away if I just do
 corAR1(form = ~1), but this is not meaningful for my data.
 
 Cheers
 David


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


Re: [R] correcting for autocorrelation in models with panel data?

2005-02-11 Thread David Hugh-Jones
Another question - is there a way to use autocorrelation with OLS,
rather than GLS?
I am really blindly following Beck and Katz (1995) here, and they
recommend OLS rather than Feasible Generalized Least Squares for
panel data where the number of individuals is larger than the number
of time units, which is my case.

Cheers
David

 On Thu, 10 Feb 2005 12:36:32 -0500, Doran, Harold [EMAIL PROTECTED] wrote:
  In the nlme package you can find the gls() function to account for
  autocorrelation over time using corAR1. Syntax might look something like
  this:
 
  fm1 - gls(response ~ IV, long, correlation=corAR1(form=~1|ID),
  method='ML')
 
  You can also use weights() for heteroscedasticity.
 
  -Harold
 
  -Original Message-
  From: [EMAIL PROTECTED]
  [mailto:[EMAIL PROTECTED] On Behalf Of David Hugh-Jones
  Sent: Thursday, February 10, 2005 12:15 PM
  To: r-help@stat.math.ethz.ch
  Subject: [R] correcting for autocorrelation in models with panel data?
 
  Hi
 
  I have some panel data for the 50 US states over about 25 years, and I
  would like to test a simple model via OLS, using this data. I know how
  to run OLS in R, and I think I can see how to  create Panel Corrected
  Standard Errors using
 
  http://jackman.stanford.edu/classes/350C/pcse.r
 
  What I can't figure out is how to correct for autocorrelation over time.
  I have found a lot of R stuff on time series models but they all seem
  focused on predicting a single variable from its previous values.
  Can anyone explain to me how to detect and get round autocorrelation?
  Is there a package for panel data that I have missed?
 
  I appreciate that this is probably just as much about my ignorance of
  econometrics as about R itself!
 
  Cheers
  David
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide!
  http://www.R-project.org/posting-guide.html
 
 


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


Re: [R] correcting for autocorrelation in models with panel data?

2005-02-11 Thread David Hugh-Jones
Specifically the Beck and Katz article points out that Feasible GLS,
which involves a special method for correcting standard errors for
panel data, doesn't work when time period is less than number of
individuals. They suggest using OLS, then correcting the standard
errors. But their method does not correct for autocorrelation over
time - only for heteroskedasticity and correlation between different
units at time t.

Cheers
David


On Fri, 11 Feb 2005 06:12:30 -0500, Doran, Harold [EMAIL PROTECTED] wrote:
 No, by definition the off-diagonal elements in the covariance matrix for an 
 OLS are 0. Thus, OLS is a special case of a GLS. You can see this if you 
 write out the formulae for an OLS solution and GLS solution.
 
 The typical solution for the standard errors in an OLS are (X'X)^{-1}*s^2. 
 This is the same as (X'V^{-1}X)^{-1} when V= s^2*I, I being the identity 
 matrix, which is also the gls solution.  But in the gls solution the off 
 diagonal elements of V are covariances, not 0. In the case of autocorrelation 
 (AR1) the off-diagonal elements decay exponentially over time.
 
 I'm not familiar with Beck and Katz or why they would recommend that OLS be 
 used when the number of time units is smaller than the number of individuals 
 in the data. But to me, this seems rather silly, isn't this often the case?
 
 HTH
 Harold
 
 -Original Message-
 From: David Hugh-Jones [mailto:[EMAIL PROTECTED]
 Sent: Fri 2/11/2005 5:23 AM
 To: Doran, Harold
 Cc: [EMAIL PROTECTED]
 Subject: Re: [R] correcting for autocorrelation in models with panel 
 data?
 
 Another question - is there a way to use autocorrelation with OLS,
 rather than GLS?
 I am really blindly following Beck and Katz (1995) here, and they
 recommend OLS rather than Feasible Generalized Least Squares for
 panel data where the number of individuals is larger than the number
 of time units, which is my case.
 
 Cheers
 David
 
  On Thu, 10 Feb 2005 12:36:32 -0500, Doran, Harold [EMAIL 
 PROTECTED] wrote:
   In the nlme package you can find the gls() function to account for
   autocorrelation over time using corAR1. Syntax might look 
 something like
   this:
  
   fm1 - gls(response ~ IV, long, correlation=corAR1(form=~1|ID),
   method='ML')
  
   You can also use weights() for heteroscedasticity.
  
   -Harold
  
   -Original Message-
   From: [EMAIL PROTECTED]
   [mailto:[EMAIL PROTECTED] On Behalf Of David Hugh-Jones
   Sent: Thursday, February 10, 2005 12:15 PM
   To: r-help@stat.math.ethz.ch
   Subject: [R] correcting for autocorrelation in models with panel 
 data?
  
   Hi
  
   I have some panel data for the 50 US states over about 25 years, 
 and I
   would like to test a simple model via OLS, using this data. I 
 know how
   to run OLS in R, and I think I can see how to  create Panel 
 Corrected
   Standard Errors using
  
   http://jackman.stanford.edu/classes/350C/pcse.r
  
   What I can't figure out is how to correct for autocorrelation 
 over time.
   I have found a lot of R stuff on time series models but they all 
 seem
   focused on predicting a single variable from its previous values.
   Can anyone explain to me how to detect and get round 
 autocorrelation?
   Is there a package for panel data that I have missed?
  
   I appreciate that this is probably just as much about my 
 ignorance of
   econometrics as about R itself!
  
   Cheers
   David
  
   __
   R-help@stat.math.ethz.ch mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide!
   http://www.R-project.org/posting-guide.html
  
  
 
 
 


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


[R] correcting for autocorrelation in models with panel data?

2005-02-10 Thread David Hugh-Jones
Hi 

I have some panel data for the 50 US states over about 25 years, and I
would like to test a simple model via OLS, using this data. I know how
to run OLS in R, and I think I can see how to  create Panel Corrected
Standard Errors using

http://jackman.stanford.edu/classes/350C/pcse.r

What I can't figure out is how to correct for autocorrelation over
time. I have found a lot of R stuff on time series models but they all
seem focused on predicting a single variable from its previous values.
Can anyone explain to me how to detect and get round autocorrelation?
Is there a package for panel data that I have missed?

I appreciate that this is probably just as much about my ignorance of
econometrics as about R itself!

Cheers
David

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


Re: [R] correcting for autocorrelation in models with panel data?

2005-02-10 Thread David Hugh-Jones
That's very helpful - I was on the point of giving up and going with
Stata! I will look into that in more detail. I assume that afterwards
it would be ok to apply the Beck and Katz procedure to get panel
corrected standard errors.

Cheers
David


On Thu, 10 Feb 2005 12:36:32 -0500, Doran, Harold [EMAIL PROTECTED] wrote:
 In the nlme package you can find the gls() function to account for
 autocorrelation over time using corAR1. Syntax might look something like
 this:
 
 fm1 - gls(response ~ IV, long, correlation=corAR1(form=~1|ID),
 method='ML')
 
 You can also use weights() for heteroscedasticity.
 
 -Harold
 
 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of David Hugh-Jones
 Sent: Thursday, February 10, 2005 12:15 PM
 To: r-help@stat.math.ethz.ch
 Subject: [R] correcting for autocorrelation in models with panel data?
 
 Hi
 
 I have some panel data for the 50 US states over about 25 years, and I
 would like to test a simple model via OLS, using this data. I know how
 to run OLS in R, and I think I can see how to  create Panel Corrected
 Standard Errors using
 
 http://jackman.stanford.edu/classes/350C/pcse.r
 
 What I can't figure out is how to correct for autocorrelation over time.
 I have found a lot of R stuff on time series models but they all seem
 focused on predicting a single variable from its previous values.
 Can anyone explain to me how to detect and get round autocorrelation?
 Is there a package for panel data that I have missed?
 
 I appreciate that this is probably just as much about my ignorance of
 econometrics as about R itself!
 
 Cheers
 David
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html
 


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


Re: [R] correcting for autocorrelation in models with panel data?

2005-02-10 Thread David Hugh-Jones
Assuming I have years in YEAR and state ids in ID, I guess the
correlation ought to be

corAR1(form = ~ YEAR | ID)

?

Thanks a lot,
David




On Thu, 10 Feb 2005 12:36:32 -0500, Doran, Harold [EMAIL PROTECTED] wrote:
 In the nlme package you can find the gls() function to account for
 autocorrelation over time using corAR1. Syntax might look something like
 this:
 
 fm1 - gls(response ~ IV, long, correlation=corAR1(form=~1|ID),
 method='ML')
 
 You can also use weights() for heteroscedasticity.
 
 -Harold
 
 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of David Hugh-Jones
 Sent: Thursday, February 10, 2005 12:15 PM
 To: r-help@stat.math.ethz.ch
 Subject: [R] correcting for autocorrelation in models with panel data?
 
 Hi
 
 I have some panel data for the 50 US states over about 25 years, and I
 would like to test a simple model via OLS, using this data. I know how
 to run OLS in R, and I think I can see how to  create Panel Corrected
 Standard Errors using
 
 http://jackman.stanford.edu/classes/350C/pcse.r
 
 What I can't figure out is how to correct for autocorrelation over time.
 I have found a lot of R stuff on time series models but they all seem
 focused on predicting a single variable from its previous values.
 Can anyone explain to me how to detect and get round autocorrelation?
 Is there a package for panel data that I have missed?
 
 I appreciate that this is probably just as much about my ignorance of
 econometrics as about R itself!
 
 Cheers
 David
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html
 


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


[R] expand.model.frame gives object not found

2004-09-30 Thread David Hugh-Jones
Hello,

I am a (relatively) experienced programmer, but new to R.

I have a problem using R 1.9.1. I have fit some data using glm(), from
within a function:

formula = as.formula(paste(depvarname, ~, rhs), env=globalenv())
return (glm(formula, family=binomial(link=logit)))

I have now come back to the formula and want to add some more
variables to it. So I do:

expand.model.frame(formulaname, ~ new_variable)

but I get the response

Error in eval(expr, envir, enclos) : Object foreignaid.dummy not found

where foreignaid.dummy is my dependent variable. However,
foreignaid.dummy is clearly visible in the global environment:

 ls(pat=foreignaid.dummy, envir=globalenv())
 [1] foreignaid.dummy
 ...

So why is my dependent variable lost?

I have read the earlier comments on the same topic, but they seem to
indicate that a previous bug was fixed. Am I missing the point about
scoping?

Any help much appreciated.

David Hugh-Jones
Essex University Govt Dept

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html