Re: [R] coarsening levels problem

2012-11-17 Thread Murray Jorgensen

Thanks very much Arun!
Murray
On 18/11/12 11:07 AM, arun wrote:

HI,
There were some "spaces" inside the quotes that created the problem.


  reg <-
structure(c(6L, 6L, 1L, 7L, 1L, 1L, 1L, 5L, 2L, 1L, 6L, 3L, 1L,
1L, 7L, 1L, 4L, 1L, 1L, 1L, 1L, 1L, 7L, 6L, 6L, 1L, 1L, 1L, 1L,
6L, 2L, 7L), .Label = c(" auckland", " christchurch", " hb",
" manawatu", " taranaki", " waikato", " wellington"), class = "factor")
^^


I changed it to:
reg <-
structure(c(6L, 6L, 1L, 7L, 1L, 1L, 1L, 5L, 2L, 1L, 6L, 3L, 1L,
1L, 7L, 1L, 4L, 1L, 1L, 1L, 1L, 1L, 7L, 6L, 6L, 1L, 1L, 1L, 1L,
6L, 2L, 7L), .Label = c("auckland", "christchurch", "hb",
"manawatu", "taranaki", "waikato", "wellington"), class = 
"factor")levels(reg)<-rg2

  reg
# [1] other other akl   other akl   akl   akl   other other akl   other other
#[13] akl   akl   other akl   other akl   akl   akl   akl   akl   other other
#[25] other akl   akl   akl   akl   other other other
#Levels: akl other


A.K.

- Original Message -
From: Murray Jorgensen 
To: r-help 
Cc:
Sent: Saturday, November 17, 2012 4:28 PM
Subject: [R] coarsening levels problem

Greetings from New Zealand.

I hope that my difficulties are clear from the following output. Ideas 
gratefully received!

Murray Jorgensen

cc <- scan()
3000 3500 2500 2500 3000 3000 3000 3000 3000 2000
2000 2000 2000 4800 3000 4500 3000 2000 2000 4400
3000 3000 2500 3000 3000 2000 3000 2000 2000 2000 3000 2000

cc <- as.factor(cc)

cc

[1] 3000 3500 2500 2500 3000 3000 3000 3000 3000 2000
[11] 2000 2000 2000 4800 3000 4500 3000 2000 2000 4400
[21] 3000 3000 2500 3000 3000 2000 3000 2000 2000 2000
[31] 3000 2000
Levels: 2000 2500 3000 3500 4400 4500 4800

engroups <- list(L2 = 2000, L2.5 = 2500, L3 = 3000,

+large = c(3500,4400,4500,4800))

levels(cc) <- engroups
cc

[1] L3large L2.5  L2.5  L3L3L3L3L3
[10] L2L2L2L2large L3large L3L2
[19] L2large L3L3L2.5  L3L3L2L3
[28] L2L2L2L3L2
Levels: L2 L2.5 L3 large
reg <-
structure(c(6L, 6L, 1L, 7L, 1L, 1L, 1L, 5L, 2L, 1L, 6L, 3L, 1L,
1L, 7L, 1L, 4L, 1L, 1L, 1L, 1L, 1L, 7L, 6L, 6L, 1L, 1L, 1L, 1L,
6L, 2L, 7L), .Label = c(" auckland", " christchurch", " hb",
" manawatu", " taranaki", " waikato", " wellington"), class = "factor")

reg

[1]  waikato   waikato   auckland
[4]  wellingtonauckland  auckland
[7]  auckland  taranaki  christchurch
[10]  auckland  waikato   hb
[13]  auckland  auckland  wellington
[16]  auckland  manawatu  auckland
[19]  auckland  auckland  auckland
[22]  auckland  wellingtonwaikato
[25]  waikato   auckland  auckland
[28]  auckland  auckland  waikato
[31]  christchurch  wellington
7 Levels:  auckland  christchurch  hb ...  wellington

rg2 <- list(akl = c("auckland"), other = c("christchurch",

+"hb", "manawatu", "taranaki", "waikato", "wellington"))

levels(reg) <- rg2
reg

[1]  
[11]  
[21]  
[31]  
Levels: akl other


-- Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzmajorgen...@ihug.co.nz  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

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



--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nz  majm...@gmail.com Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] coarsening levels problem

2012-11-17 Thread Murray Jorgensen

Greetings from New Zealand.

I hope that my difficulties are clear from the following output. Ideas 
gratefully received!


Murray Jorgensen

cc <- scan()
 3000 3500 2500 2500 3000 3000 3000 3000 3000 2000
2000 2000 2000 4800 3000 4500 3000 2000 2000 4400
3000 3000 2500 3000 3000 2000 3000 2000 2000 2000 3000 2000

cc <- as.factor(cc)

cc

 [1] 3000 3500 2500 2500 3000 3000 3000 3000 3000 2000
[11] 2000 2000 2000 4800 3000 4500 3000 2000 2000 4400
[21] 3000 3000 2500 3000 3000 2000 3000 2000 2000 2000
[31] 3000 2000
Levels: 2000 2500 3000 3500 4400 4500 4800

engroups <- list(L2 = 2000, L2.5 = 2500, L3 = 3000,

+large = c(3500,4400,4500,4800))

levels(cc) <- engroups
cc

 [1] L3large L2.5  L2.5  L3L3L3L3L3
[10] L2L2L2L2large L3large L3L2
[19] L2large L3L3L2.5  L3L3L2L3
[28] L2L2L2L3L2
Levels: L2 L2.5 L3 large
reg <-
structure(c(6L, 6L, 1L, 7L, 1L, 1L, 1L, 5L, 2L, 1L, 6L, 3L, 1L,
1L, 7L, 1L, 4L, 1L, 1L, 1L, 1L, 1L, 7L, 6L, 6L, 1L, 1L, 1L, 1L,
6L, 2L, 7L), .Label = c(" auckland", " christchurch", " hb",
" manawatu", " taranaki", " waikato", " wellington"), class = "factor")

reg

 [1]  waikato   waikato   auckland
 [4]  wellingtonauckland  auckland
 [7]  auckland  taranaki  christchurch
[10]  auckland  waikato   hb
[13]  auckland  auckland  wellington
[16]  auckland  manawatu  auckland
[19]  auckland  auckland  auckland
[22]  auckland  wellingtonwaikato
[25]  waikato   auckland  auckland
[28]  auckland  auckland  waikato
[31]  christchurch  wellington
7 Levels:  auckland  christchurch  hb ...  wellington

rg2 <- list(akl = c("auckland"), other = c("christchurch",

+"hb", "manawatu", "taranaki", "waikato", "wellington"))

levels(reg) <- rg2
reg

 [1]  
[11]  
[21]  
[31]  
Levels: akl other


--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzmajorgen...@ihug.co.nz  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Converting Fortran or C++ etc to R

2011-01-07 Thread Murray Jorgensen
I will wind this thread up with some happy comments. I have indeed 
succeeded in constructing an R program to do the same thing as my 
Fortran program for an EM algorithm. I have not done timings yet but it 
seems to run acceptably fast for my purposes.


The key code to be replaced was the E and the M steps of the algorithm. 
I decided to try to replace all the loops with matrix operations such as 
%*%, t(), crossprod(), tcrossprod(). Other operations that I used were 
of the form

   A + v

where dim(A) = c(a, b) and length(v) = a. Here the vector v operates 
term by term down columns, recycling for each new column. [ *, - and / 
also work similarly.]


I was relived that matrices were as far as I needed to go, and I had 
visions of having to use tensor products of higher dimensioned arrays. 
Fortunately it did not come to that.


I didn't actually translate from F to R. The original is itself a 
translation of my underlying maths, and it was easier to translate the 
maths into R directly.


I preserved the form of my Fortran input and output files so that I will 
be able to run either version on the same files.


As I mentioned earlier the main point of doing all this is so that I may 
try out some variants of the program. I expect this will be much easier 
to do in R!


Thanks to all who replied.

Murray

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Converting Fortran or C++ etc to R

2011-01-05 Thread Murray Jorgensen
Thanks Barry and thanks to others who applied off-list. I can see that I 
should have given more details about my motives for wanting to replace a 
Fortran program by an R one.


At this stage I want to get something working in pure R because it is 
easier to fool around with and tweak with than Fortran and I have a few 
things that I want to try out that will involve perturbing the original 
code and I think I'd rather be doing them in R than in a 3GL.


Now that I have publicly asked the question I find that the answer to it 
occurs to me:


The program that I want to port to R is an ML estimation by the EM 
algorithm. The iterative steps are fairly simple except they need to be 
repeated a large number of times. What I have noticed is that I can 
replace (maybe) the within-step loops by matrix multiplications. This 
means that I will, by using %*%, be effectively handing a lot of the 
work to external Fortran (or similar) routines without calling .Fortran().


OK, I know that you can see though me and I accept that I am just 
rationalising my reluctance to get into package-writing. I will bite the 
bullet on that in due course but for the meantime I'm just going to fool 
around with straight R.


Barry came closest to answering my real question and I will formulate a 
follow-up question as follows:


Does anyone know of a helpful set of examples of the vectorization of code?

Cheers,  Murray


On 6/01/2011 12:32 a.m., Barry Rowlingson wrote:

On Wed, Jan 5, 2011 at 7:33 AM, lcn  wrote:


As for your actual requirement to do the "convertion", I guess there'd not
exist any quick ways. You have to be both familiar with R and the other
language to make the rewrite work.


  To make the rewrite work _well_ is the bigger problem! The easiest
way to big performance wins is going to be spotting vectorisation
possibilities in the Fortran code. Any time you see a DO K=1,N loop
then look to see if its just a single vector operation in R.

  Another way to big wins is to write test code, so you can check if
your R code gives the same results as the Fortran (C/C++) code at
every stage of the rewrite. Don't just write it all in one go and then
hope it works! Small steps

Barry


--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Converting Fortran or C++ etc to R

2011-01-04 Thread Murray Jorgensen
I'm going to try my hand at converting some Fortran programs to R. Does 
anyone know of any good articles giving hints at such tasks? I will post 
a selective summary of my gleanings.


Cheers,  Murray
--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Sweaving quotes

2010-07-29 Thread Murray Jorgensen

I tried
\usepackage[cp1252]{inputenc}

and it works well, giving cursive directional quotes in the final 
document. Thank you Brian.


I didn't find package ae on the Auckland CRAN mirror so I wonder if it 
is a LaTeX package. In any case I am happy now!


Cheers,  Murray

Prof Brian Ripley wrote:
The alternative is to tell LaTeX what encoding the file is in.  For 
those using UTF-8 locales this means adding the line


\usepackage[utf8]{inputenc}

Now Murray mentions 'Vista', and so is presumably using cp1252 (the 
Western-European-language Windows default).  That is spported by 
inputenc, so try


\usepackage[cp1252]{inputenc}

In either case, the LaTeX font used may or may not have directional 
quotes -- since this is an issue for the R manuals, see our 
documentation for ways around this (such as package ae).


On Wed, 28 Jul 2010, Marc Schwartz wrote:


On Jul 28, 2010, at 7:43 PM, Murray Jorgensen wrote:

The significance code line to summary() applied to an lm() fitted 
model object is


Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The corresponding line in the LaTeX source produced by Sweave is

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

which looks the same in my email (Thunderbird on a Vista machine), 
but when I look at the file in WinEdt the quotes appear rounded and 
cursive.


On LaTeXing and dvipsing the opening and closing quotes turn into 
S-acute and S-circumflex respectively.


Does anyone know how avoid this effect?

Cheers,  Murray



Murray,

Try this:


summary(lm.D9)


...

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

...


# Set to not use fancy quotes, but "TeX" style
# See ?options and ?sQuote
options(useFancyQuotes = "TeX")




summary(lm.D9)


...

Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1

...


HTH,

Marc Schwartz

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






--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzmajorgen...@ihug.co.nz  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Sweaving quotes

2010-07-29 Thread Murray Jorgensen

I am happy enough with

options(useFancyQuotes = FALSE)

(or = "TeX") but I will test Brian's suggestion tomorrow and report back.

Murray

Prof Brian Ripley wrote:
The alternative is to tell LaTeX what encoding the file is in.  For 
those using UTF-8 locales this means adding the line


\usepackage[utf8]{inputenc}

Now Murray mentions 'Vista', and so is presumably using cp1252 (the 
Western-European-language Windows default).  That is spported by 
inputenc, so try


\usepackage[cp1252]{inputenc}

In either case, the LaTeX font used may or may not have directional 
quotes -- since this is an issue for the R manuals, see our 
documentation for ways around this (such as package ae).


On Wed, 28 Jul 2010, Marc Schwartz wrote:


On Jul 28, 2010, at 7:43 PM, Murray Jorgensen wrote:

The significance code line to summary() applied to an lm() fitted 
model object is


Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The corresponding line in the LaTeX source produced by Sweave is

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

which looks the same in my email (Thunderbird on a Vista machine), 
but when I look at the file in WinEdt the quotes appear rounded and 
cursive.


On LaTeXing and dvipsing the opening and closing quotes turn into 
S-acute and S-circumflex respectively.


Does anyone know how avoid this effect?

Cheers,  Murray



Murray,

Try this:


summary(lm.D9)


...

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

...


# Set to not use fancy quotes, but "TeX" style
# See ?options and ?sQuote
options(useFancyQuotes = "TeX")




summary(lm.D9)


...

Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1

...


HTH,

Marc Schwartz

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






--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzmajorgen...@ihug.co.nz  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Sweaving quotes

2010-07-28 Thread Murray Jorgensen

Thanks, Marc, and also Jay Kearns.

After experimentation I think useFancyQuotes = FALSE my be best as TeX 
style can look a bit funny for R output.


Cheers,  Murray

Marc Schwartz wrote:

On Jul 28, 2010, at 7:43 PM, Murray Jorgensen wrote:


The significance code line to summary() applied to an lm() fitted model object 
is

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The corresponding line in the LaTeX source produced by Sweave is

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

which looks the same in my email (Thunderbird on a Vista machine), but when I 
look at the file in WinEdt the quotes appear rounded and cursive.

On LaTeXing and dvipsing the opening and closing quotes turn into S-acute and 
S-circumflex respectively.

Does anyone know how avoid this effect?

Cheers,  Murray



Murray,

Try this:


summary(lm.D9)


...

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 


...


# Set to not use fancy quotes, but "TeX" style
# See ?options and ?sQuote
options(useFancyQuotes = "TeX")




summary(lm.D9)


...

Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 


...


HTH,

Marc Schwartz




--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzmajorgen...@ihug.co.nz  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Sweaving quotes

2010-07-28 Thread Murray Jorgensen
The significance code line to summary() applied to an lm() fitted model 
object is


Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The corresponding line in the LaTeX source produced by Sweave is

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

which looks the same in my email (Thunderbird on a Vista machine), but 
when I look at the file in WinEdt the quotes appear rounded and cursive.


On LaTeXing and dvipsing the opening and closing quotes turn into 
S-acute and S-circumflex respectively.


Does anyone know how avoid this effect?

Cheers,  Murray
--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzmajorgen...@ihug.co.nz  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Sweave and scan()

2010-07-28 Thread Murray Jorgensen

Hi Duncan,

I at first thought that your suggestion was how the .tex file should be 
and that this would involve tediously editing the latex source each time 
I updated the .Rnw. But as you probably intended I find that I can slip 
the Schunks and Sinputs into the .Rnw and all still works.


Thank for that. BTW my previous "Thanks for all your help" was meant to 
be "Thanks to all for your help".


Cheers,  Murray

Duncan Murdoch wrote:

On 28/07/2010 6:33 PM, Murray Jorgensen wrote:
Omigod! The archival links shows that this was the same problem that 
caused me to give up on Sweave about 6 years ago. I guess I never 
properly assimilated Brian Ripley's comments at the time.


I finished up doing this:

\begin{verbatim}
 > height = scan()
1:  64 62 66 65
5:  62 69 72 72 70
10:
Read 9 items
 > part = scan(what = character(0))
1: "Soprano" "Soprano" "Soprano"
4: "Alto""Alto""Tenor"
7: "Tenor"   "Bass""Bass"
10:
Read 9 items
\end{verbatim}
<>=
height <- c(64, 62, 66, 65, 62, 69, 72, 72, 70)
part = c("Soprano","Soprano", "Soprano",
  "Alto","Alto","Tenor",
  "Tenor",   "Bass","Bass")
@

which does give the output I want (though in a different style) and 
leaves the R session in the state that I want.


If you the look to be the same as with other chunks, you should use the 
Sinput, Soutput and possibly Schunk environments.  (Schunk normally does 
nothing, but you might have customized it.)  That is, write your stuff as


\begin{Schunk}
\begin{Sinput}
 > height = scan()
1:  64 62 66 65
5:  62 69 72 72 70
10:
\end{Sinput}
\begin{Soutput}
Read 9 items
\end{Soutput}
\begin{Sinput}
 > part = scan(what = character(0))
1: "Soprano" "Soprano" "Soprano"
4: "Alto""Alto""Tenor"
7: "Tenor"   "Bass""Bass"
10:
\end{Sinput}
\begin{Soutput}
Read 9 items
\end{Soutput}
\end{Schunk}

(I suppose it's debatable whether lines to scan() should be typeset as 
input or output.)


Duncan Murdoch




Thanks for all your help.

Murray



David Winsemius wrote:

On Jul 27, 2010, at 7:01 AM, Murray Jorgensen wrote:

Both suggestions generate similar errors to those of the original 
code. I would also be worried if the results would not puzzle my 
students.
You are teaching them about R or about Sweave? You are setting up 
code that is designed to run at an open console session, but 
submitting it to a batch process.


http://finzi.psych.upenn.edu/R/Rhelp02/archive/31347.html

After reading that I am wondering if you could set up a 
textConnection first and then  scan from that?


 > con <- textConnection("64 62 66 65 62\n69 72 72 70")
 > scan(file=con)
Read 9 items
[1] 64 62 66 65 62 69 72 72 70









--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzmajorgen...@ihug.co.nz  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Sweave and scan()

2010-07-28 Thread Murray Jorgensen
Omigod! The archival links shows that this was the same problem that 
caused me to give up on Sweave about 6 years ago. I guess I never 
properly assimilated Brian Ripley's comments at the time.


I finished up doing this:

\begin{verbatim}
> height = scan()
1:  64 62 66 65
5:  62 69 72 72 70
10:
Read 9 items
> part = scan(what = character(0))
1: "Soprano" "Soprano" "Soprano"
4: "Alto""Alto""Tenor"
7: "Tenor"   "Bass""Bass"
10:
Read 9 items
\end{verbatim}
<>=
height <- c(64, 62, 66, 65, 62, 69, 72, 72, 70)
part = c("Soprano","Soprano", "Soprano",
 "Alto","Alto","Tenor",
 "Tenor",   "Bass","Bass")
@

which does give the output I want (though in a different style) and 
leaves the R session in the state that I want.


Thanks for all your help.

Murray



David Winsemius wrote:


On Jul 27, 2010, at 7:01 AM, Murray Jorgensen wrote:

Both suggestions generate similar errors to those of the original 
code. I would also be worried if the results would not puzzle my 
students.


You are teaching them about R or about Sweave? You are setting up code 
that is designed to run at an open console session, but submitting it to 
a batch process.


http://finzi.psych.upenn.edu/R/Rhelp02/archive/31347.html

After reading that I am wondering if you could set up a textConnection 
first and then  scan from that?


 > con <- textConnection("64 62 66 65 62\n69 72 72 70")
 > scan(file=con)
Read 9 items
[1] 64 62 66 65 62 69 72 72 70




--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzmajorgen...@ihug.co.nz  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Sweave and scan()

2010-07-27 Thread Murray Jorgensen
Both suggestions generate similar errors to those of the original code. 
I would also be worried if the results would not puzzle my students.


But thanks!  Murray

David Winsemius wrote:


On Jul 26, 2010, at 11:54 PM, Murray Jorgensen wrote:

I am introducing the scan() function to my class. Consider the 
following file (Scanexamp.Rnw )


\documentclass[12pt]{article}

\begin{document}
<<>>=
height = scan()



64 62 66 65 62
69 72 72 70


Have you considered adding an empty line or an ";" after the closing 
paren of scan? (At the console the semi-colon gambit has the desired 
effect while the empty line strategy fails.)




part = scan(what = character(0))
"Soprano" "Soprano" "Soprano"
"Alto""Alto""Tenor"
"Tenor"   "Bass""Bass"

sh = data.frame(height, part)
sh
@
\end{document}

Now what happens when I attempt to Sweave this is

> Sweave("scanexamp.Rnw")
Writing to file scanexamp.tex
Processing code chunks ...
1 : echo term verbatim

Error:  chunk 1
Error in parse(text = chunk) : unexpected numeric constant in:
"height = scan()
64 62"
>

Comments would be appreciated. (And thanks to Ross Darnell for a lot 
of help on another list.)


Cheers,  Murray Jorgensen

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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




--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzmajorgen...@ihug.co.nz  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Sweave and scan()

2010-07-26 Thread Murray Jorgensen
I am introducing the scan() function to my class. Consider the following 
file (Scanexamp.Rnw )


\documentclass[12pt]{article}

\begin{document}
<<>>=
height = scan()
64 62 66 65 62
69 72 72 70

part = scan(what = character(0))
 "Soprano" "Soprano" "Soprano"
 "Alto""Alto""Tenor"
 "Tenor"   "Bass""Bass"

sh = data.frame(height, part)
sh
@
\end{document}

Now what happens when I attempt to Sweave this is

> Sweave("scanexamp.Rnw")
Writing to file scanexamp.tex
Processing code chunks ...
 1 : echo term verbatim

Error:  chunk 1
Error in parse(text = chunk) : unexpected numeric constant in:
"height = scan()
64 62"
>

Comments would be appreciated. (And thanks to Ross Darnell for a lot of 
help on another list.)


Cheers,  Murray Jorgensen

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Html help

2010-06-14 Thread Murray Jorgensen
Thanks very much, Duncan. I understand this better now. It takes a bit 
of getting used to but the prospect of some day getting graphic elements 
to help should make it worthwhile. (And I guess it saves on disk space 
by only generating the help pages as needed.)


Cheers,  Murray

On 15/06/2010 4:13 a.m., Duncan Murdoch wrote:

Murray Jorgensen wrote:

I have just installed R 2.11.1 on my XP laptop.

I like html help

[...]

How do I go about getting a local set of html help files?



Since 2.10.0, HTML help is generated on demand. It doesn't go off your
local computer, it works locally. This saves a bit of space (the HTML is
generated from the same source as the text is generated from), but the
main point is that it allows help pages to contain dynamic content. For
example, Romain Francois posted some demo code a while ago to allow the
display of graphics generated by R within help pages. (Unfortunately it
depended on a particular browser feature not supported by Internet
Explorer, so I'm going to need to put together something less elegant,
but that's life.)

Duncan Murdoch


--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Html help

2010-06-14 Thread Murray Jorgensen

I have just installed R 2.11.1 on my XP laptop.

I like html help for browsing but text help for on-the-fly look-ups. I 
was a bit surprised when I was asked to choose between them during the 
installation. I chose text, thinking I could fix the html help later, 
which is what I am trying to do now.


Now when I ask for html help my browser goes to

'http://-ip-number-/doc/html/index.html'

instead of where I want on my computer:

C:\apps\R\R-2.11.1\doc\html\index.html

Now I can go where I want manually but then the package list on


C:\apps\R\R-2.11.1\doc\html\packages.html

does not include all the packages that I have installed and linked. I 
don't want to read my html help from the web because sometimes I am 
off-line or on a slow connection.


How do I go about getting a local set of html help files?

Cheers,   Murray Jorgensen

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nz  majorgen...@ihug.co.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] R or C++ on FreeNX servers

2009-11-25 Thread Murray Jorgensen

Hi all,

I have just found out that the machine learning group in our Faculty has 
a lot of spare capacity on their FreeNX servers. I do not know a lot 
about these beasts but I understand that they are a free version of 
something produced by a firm called "NoMachine".


They are designed for executing parallel algorithms and I thought that 
they might be of use in a project of mine comparing different 
model-fitting algorithms from the point of view of sensitivity to 
starting values.


Anyway before revealing my near-total ignorance to my computer science 
colleagues I thought I would ask if any of my fellow R users have any 
experience with these things and possibly advice to offer. The CS people 
 are probably using the servers in conjunction with Java or C++ and I 
could possibly use the latter of these. I wondered, though, if R could 
be used directly with such hardware and if so, how the parallelizing 
would be handled.



Regards,   Murray Jorgensen

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] R or C++ on FreeNX servers

2009-11-25 Thread Murray Jorgensen

Hi all,

I have just found out that the machine learning group in our Faculty has
a lot of spare capacity on their FreeNX servers. I do not know a lot
about these beasts but I understand that they are a free version of
something produced by a firm called "NoMachine".

They are designed for executing parallel algorithms and I thought that
they might be of use in a project of mine comparing different
model-fitting algorithms from the point of view of sensitivity to
starting values.

Anyway before revealing my near-total ignorance to my computer science
colleagues I thought I would ask if any of my fellow R users have any
experience with these things and possibly advice to offer. The CS people
 are probably using the servers in conjunction with Java or C++ and I
could possibly use the latter of these. I wondered, though, if R could
be used directly with such hardware and if so, how the parallelizing
would be handled.


Regards,   Murray Jorgensen

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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 with package reshape

2009-10-25 Thread Murray Jorgensen

I have got part of the way to what I want by playing with a small example:

> example2
   ano census total.pop class
1  222 96  113111
2  222  1  124512
3  239 96  392111
4  239  1  450312
5  260  1  421811
6  269  1  118512
7  275  1  355511
8  308 96   94812
9  349 96  251111
10 349  1  280812
> mexa2 = melt(example2, id = c("ano","census"))
> mexa2
   ano census  variable value
1  222 96 total.pop  1131
2  222  1 total.pop  1245
3  239 96 total.pop  3921
4  239  1 total.pop  4503
5  260  1 total.pop  4218
6  269  1 total.pop  1185
7  275  1 total.pop  3555
8  308 96 total.pop   948
9  349 96 total.pop  2511
10 349  1 total.pop  2808
11 222 96 class11
12 222  1 class12
13 239 96 class11
14 239  1 class12
15 260  1 class11
16 269  1 class12
17 275  1 class11
18 308 96 class12
19 349 96 class11
20 349  1 class12
> cast(mexa2, ... ~ census)
   ano  variable1   96
1  222 total.pop 1245 1131
2  222 class   12   11
3  239 total.pop 4503 3921
4  239 class   12   11
5  260 total.pop 4218   NA
6  260 class   11   NA
7  269 total.pop 1185   NA
8  269 class   12   NA
9  275 total.pop 3555   NA
10 275 class   11   NA
11 308 total.pop   NA  948
12 308 class   NA   12
13 349 total.pop 2808 2511
14 349 class   12   11
>

This is nearly what I want but I really want something like this:

   ano  total.pop1 total.pop96  class1  class96
   22212451131  12   11
   23945033921  12   11
   2604218  NA  11   NA
   2691185  NA  12   NA
   2753555  NA  11   NA
   308  NA 948  NA   12
   34928082511  12   11

Suggestions gratefully received!

Regards,  Murray Jorgensen

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzmajorgen...@ihug.co.nz  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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 with package reshape

2009-10-25 Thread Murray Jorgensen

I have got part of the way to what I want by playing with a small example:


example2

   ano census total.pop class
1  222 96  113111
2  222  1  124512
3  239 96  392111
4  239  1  450312
5  260  1  421811
6  269  1  118512
7  275  1  355511
8  308 96   94812
9  349 96  251111
10 349  1  280812

mexa2 = melt(example2, id = c("ano","census"))
mexa2

   ano census  variable value
1  222 96 total.pop  1131
2  222  1 total.pop  1245
3  239 96 total.pop  3921
4  239  1 total.pop  4503
5  260  1 total.pop  4218
6  269  1 total.pop  1185
7  275  1 total.pop  3555
8  308 96 total.pop   948
9  349 96 total.pop  2511
10 349  1 total.pop  2808
11 222 96 class11
12 222  1 class12
13 239 96 class11
14 239  1 class12
15 260  1 class11
16 269  1 class12
17 275  1 class11
18 308 96 class12
19 349 96 class11
20 349  1 class12

cast(mexa2, ... ~ census)

   ano  variable1   96
1  222 total.pop 1245 1131
2  222 class   12   11
3  239 total.pop 4503 3921
4  239 class   12   11
5  260 total.pop 4218   NA
6  260 class   11   NA
7  269 total.pop 1185   NA
8  269 class   12   NA
9  275 total.pop 3555   NA
10 275 class   11   NA
11 308 total.pop   NA  948
12 308 class   NA   12
13 349 total.pop 2808 2511
14 349 class   12   11




This is nearly what I want but I really want something like this:

   ano  total.pop1 total.pop96  class1  class96
   22212451131  12   11
   23945033921  12   11
   2604218  NA  11   NA
   2691185  NA  12   NA
   2753555  NA  11   NA
   308  NA 948  NA   12
   34928082511  12   11

Suggestions gratefully received!

Regards,  Murray Jorgensen

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzmajorgen...@ihug.co.nz  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] two-factor linear models with missing cells

2009-08-04 Thread Murray Jorgensen

Hi Peter,

there is no problem if the missing cell is not in the first row or 
column: the corresponding interaction parameter is omitted. In my case 
the data in the (1,4) cell is missing. What results is clear to me now: 
the (3,4) interaction parameter is dropped so that "(Intercept) + Biv" 
now refers to the mean of the (3,4) cell rather than the that of the 
(1,4) cell making the (3,4) cell a sort of 'honorary' member of the 
first row. This could have been done to the (2,4) cell but I guess the 
rule is to drop the cell with the highest sum of row and column number.


Murray Jorgensen

Peter Dalgaard wrote:

Murray Jorgensen wrote:

I am wondering how to interpret the parameter estimates that lm()
reports in this sort of situation:

y = round(rnorm(n=24,mean=5,sd=2),2)
A = gl(3,2,24,labels=c("one","two","three"))
B = gl(4,6,24,labels=c("i","ii","iii","iv"))
# Make both observations for A=1, B=4 missing
y[19] = NA
y[20] = NA
data.frame(y,A,B)
nonadd = lm(y ~ A * B)



summary(nonadd)


Call:
lm(formula = y ~ A * B)

Residuals:
Min 1Q Median 3Q Max
-3.555e+00 -7.675e-01 -6.939e-17 7.675e-01 3.555e+00

Coefficients: (1 not defined because of singularities)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.755 1.667 2.252 0.0457 *
Atwo 1.655 2.358 0.702 0.4974
Athree 3.330 2.358 1.412 0.1856
Bii 1.435 2.358 0.609 0.5552
Biii 2.055 2.358 0.871 0.4021
Biv -1.635 2.358 -0.693 0.5025
Atwo:Bii -1.145 3.335 -0.343 0.7378
Athree:Bii -4.535 3.335 -1.360 0.2011
Atwo:Biii -3.230 3.335 -0.969 0.3536
Athree:Biii -2.105 3.335 -0.631 0.5408
Atwo:Biv 1.655 3.335 0.496 0.6295
Athree:Biv NA NA NA NA
---
Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1   1

Residual standard error: 2.358 on 11 degrees of freedom
(2 observations deleted due to missingness)
Multiple R-squared: 0.2797, Adjusted R-squared: -0.3752
F-statistic: 0.4271 on 10 and 11 DF, p-value: 0.9044


fitted(nonadd)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 21
3.755 3.755 5.410 5.410 7.085 7.085 5.190 5.190 5.700 5.700 3.985 3.985
5.810 5.810 4.235 4.235 7.035 7.035 5.430
22 23 24
5.430 5.450 5.450

t(model.matrix(nonadd)%*%coef(nonadd))

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 21 22 23 24
[1,] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

I guess that the parameter estimates reported are linear combinations of
the cell means, but which linear combinations and how does lm() decide
what parameters to report?

Cheers, Murray



What's the problem? The parameters are defined as usual for the 
two-way layout:


The intercept is the fitted value in the top left corner
The A coefficients are the fitted values in the first column minus the 
intercept.

The B coefficients vice versa.
The interaction coefficients are the fitted values minus the sum of 
the the intercept and the corresponding A and B coefficients.


One interaction coefficient is set missing because you have no data, 
but except for that, the fitted values equal the cell means.




--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] two-factor linear models with missing cells

2009-08-02 Thread Murray Jorgensen

I am wondering how to interpret the parameter estimates that lm()
reports in this sort of situation:

y = round(rnorm(n=24,mean=5,sd=2),2)
A = gl(3,2,24,labels=c("one","two","three"))
B = gl(4,6,24,labels=c("i","ii","iii","iv"))
# Make both observations for A=1, B=4 missing
y[19] = NA
y[20] = NA
data.frame(y,A,B)
nonadd = lm(y ~ A * B)



summary(nonadd)


Call:
lm(formula = y ~ A * B)

Residuals:
Min 1Q Median 3Q Max
-3.555e+00 -7.675e-01 -6.939e-17 7.675e-01 3.555e+00

Coefficients: (1 not defined because of singularities)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.755 1.667 2.252 0.0457 *
Atwo 1.655 2.358 0.702 0.4974
Athree 3.330 2.358 1.412 0.1856
Bii 1.435 2.358 0.609 0.5552
Biii 2.055 2.358 0.871 0.4021
Biv -1.635 2.358 -0.693 0.5025
Atwo:Bii -1.145 3.335 -0.343 0.7378
Athree:Bii -4.535 3.335 -1.360 0.2011
Atwo:Biii -3.230 3.335 -0.969 0.3536
Athree:Biii -2.105 3.335 -0.631 0.5408
Atwo:Biv 1.655 3.335 0.496 0.6295
Athree:Biv NA NA NA NA
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.358 on 11 degrees of freedom
(2 observations deleted due to missingness)
Multiple R-squared: 0.2797, Adjusted R-squared: -0.3752
F-statistic: 0.4271 on 10 and 11 DF, p-value: 0.9044


fitted(nonadd)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 21
3.755 3.755 5.410 5.410 7.085 7.085 5.190 5.190 5.700 5.700 3.985 3.985
5.810 5.810 4.235 4.235 7.035 7.035 5.430
22 23 24
5.430 5.450 5.450

t(model.matrix(nonadd)%*%coef(nonadd))

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 21 22 23 24
[1,] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

I guess that the parameter estimates reported are linear combinations of
the cell means, but which linear combinations and how does lm() decide
what parameters to report?

Cheers, Murray

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] two-factor linear models with missing cells

2009-08-02 Thread Murray Jorgensen

I am wondering how to interpret the parameter estimates that lm()
reports in this sort of situation:

y = round(rnorm(n=24,mean=5,sd=2),2)
A = gl(3,2,24,labels=c("one","two","three"))
B = gl(4,6,24,labels=c("i","ii","iii","iv"))
# Make both observations for A=1, B=4 missing
y[19] = NA
y[20] = NA
data.frame(y,A,B)
nonadd = lm(y ~ A * B)



summary(nonadd)


Call:
lm(formula = y ~ A * B)

Residuals:
Min 1Q Median 3Q Max
-3.555e+00 -7.675e-01 -6.939e-17 7.675e-01 3.555e+00

Coefficients: (1 not defined because of singularities)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.755 1.667 2.252 0.0457 *
Atwo 1.655 2.358 0.702 0.4974
Athree 3.330 2.358 1.412 0.1856
Bii 1.435 2.358 0.609 0.5552
Biii 2.055 2.358 0.871 0.4021
Biv -1.635 2.358 -0.693 0.5025
Atwo:Bii -1.145 3.335 -0.343 0.7378
Athree:Bii -4.535 3.335 -1.360 0.2011
Atwo:Biii -3.230 3.335 -0.969 0.3536
Athree:Biii -2.105 3.335 -0.631 0.5408
Atwo:Biv 1.655 3.335 0.496 0.6295
Athree:Biv NA NA NA NA
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.358 on 11 degrees of freedom
(2 observations deleted due to missingness)
Multiple R-squared: 0.2797, Adjusted R-squared: -0.3752
F-statistic: 0.4271 on 10 and 11 DF, p-value: 0.9044


fitted(nonadd)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 21
3.755 3.755 5.410 5.410 7.085 7.085 5.190 5.190 5.700 5.700 3.985 3.985
5.810 5.810 4.235 4.235 7.035 7.035 5.430
22 23 24
5.430 5.450 5.450

t(model.matrix(nonadd)%*%coef(nonadd))

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 21 22 23 24
[1,] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

I guess that the parameter estimates reported are linear combinations of
the cell means, but which linear combinations and how does lm() decide
what parameters to report?

Cheers, Murray

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] Tick label orientation

2009-04-01 Thread Murray Jorgensen

I had hoped that

plot(c(0,24),c(0,-6),xlab="Time",ylab="Day",
 type="n", main="This Week",axes=FALSE)

axis(2,at=0:(-6), labels = 
c("Sun","Mon","Tues","Wed","Thurs","Fri","Sat"),hadj=TRUE)

axis(1,at=seq(0,24,4))

would give me horizontal tick labels.
It doesn't.  What would?

Murray
--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nzFax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441   Mobile 021 0200 8350

__
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] sampling from Laplace-Normal

2008-11-03 Thread Murray Jorgensen

Hi Armin,

Laplace-Normal random variables may be generated as the sum of a Normal 
rv and the difference of two exponential rvs. See


Reed, W.J. and Jorgensen, M.A. (2004) The Double Pareto-Lognormal 
distribution – A new parametric model for size distributions. 
Communications in Statistics B: Theory and Methods, 33(8), 1733-1753.


Perhaps you can get around your problem using this representation or 
alternatively reproduce the problem with one of the component rvs.


Cheers,

Murray Jorgensen


Hi,
I have to draw samples from an asymmetric-Laplace-Normal distribution:
f(u|y, x, beta, phi, sigma, tau) \propto exp( - sum( ( abs(lo) +
(2*tau-1)*lo )/(2*sigma) ) - 0.5/phi*u^2), where lo = (y - x*beta) and
y=(y_1, ..., y_n), x=(x_1, ..., x_n)
-- sorry for this huge formula --
A WinBUGS Gibbs sampler and the HI package arms sampler were used with the
same initial data for all parameters. I compared the mean from both the
Gibbs sample and the arms sample for several y and x. Surprisingly, both
means always differed by the same constant.
Shouldn't the sample means be equal? What could be the reason for the
constant difference? (burnin and sample size variation didn't change this)

Thanks in advance
Armin


--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED]Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 1395 862

__
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] step() and stepAIC()

2008-10-12 Thread Murray Jorgensen



Prof Brian Ripley wrote:

On Sun, 12 Oct 2008, Murray Jorgensen wrote:


The birth weight example from ?stepAIC in package MASS runs well as
indeed it should.

However when I change stepAIC() calls to step() calls I get warning
messages that I don't understand, although the output is similar.


Why would you do this?


I did this because I was originally following the code in V&R edition 2.
(I know, I know, I should have upgraded!)





Warning messages:
1: In model.response(m, "numeric") :
 using type="numeric" with a factor response will be ignored
(and three more the same.)


I presume you did

library(MASS)
example(birthwt)
birthwt.glm <- glm(low ~ ., family = binomial, data = bwt)
birthwt.step <- step(birthwt.glm, trace = FALSE)
birthwt.step$anova
birthwt.step2 <- step(birthwt.glm, ~ .^2 + I(scale(age)^2)
+ I(scale(lwt)^2), trace = FALSE)
birthwt.step2$anova

and are referrring to the second call?


Checked with 2.7.0 on Os X and 2.6.2 on Windows.


Those are not current versions.  But the difference is that stepAIC uses 
addterm and step uses add1, and this is a (harmless) infelicity in 
add1.glm.




Cheers,  Murray
--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED]Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 1395 862

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





--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED][EMAIL PROTECTED]  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 139 5862

__
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] step() and stepAIC()

2008-10-11 Thread Murray Jorgensen

The birth weight example from ?stepAIC in package MASS runs well as
indeed it should.

However when I change stepAIC() calls to step() calls I get warning
messages that I don't understand, although the output is similar.

Warning messages:
1: In model.response(m, "numeric") :
  using type="numeric" with a factor response will be ignored
(and three more the same.)

Checked with 2.7.0 on Os X and 2.6.2 on Windows.

Cheers,  Murray
--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED]Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 1395 862

__
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] lattice plotting character woes

2008-08-26 Thread Murray Jorgensen

[Rolf, this crosses with your reply. I will look at your email next.]

I pasted the wrong code last time. The following code is supposed to 
illustrate my problem with lattice plotting character changes.


patches <-

structure(list(URBAN_AREA = structure(c(2L, 19L, 23L, 2L, 19L,

23L, 2L, 19L, 23L, 2L, 19L, 23L), .Label = c("CENTRAL AUCKLAND ZONE",

"CHRISTCHURCH", "DUNEDIN", "HAMILTON ZONE", "HASTINGS ZONE",

"INVERCARGILL", "LOWER HUTT ZONE", "mean", "NAPIER ZONE", "NELSON",

"NEW PLYMOUTH", "NORTHERN AUCKLAND ZONE", "PALMERSTON NORTH",

"PORIRUA ZONE", "ROTORUA", "SD", "SE", "SOUTHERN AUCKLAND ZONE",

"TAURANGA", "WANGANUI", "WELLINGTON ZONE", "WESTERN AUCKLAND ZONE",

"WHANGAREI"), class = "factor"), NO_PATCHES = c(11L, 16L, 21L,

87L, 192L, 324L, 164L, 417L, 773L, 679L, 757L, 3083L), MEAN_AREA = 
c(9.623631225,


15.29089619, 149.2063532, 14.1676, 247.5262, 28.611, 11.5698,

221.0022, 37.3725, 11.918, 133.5804, 25.6759), AREA.ZONE = c(13683,

3666, 1558, 64830, 41103, 22581, 123819, 90107, 57627, 264735,

223963, 174456), Buffer.zone = c(0L, 0L, 0L, 5L, 5L, 5L, 10L,

10L, 10L, 20L, 20L, 20L)), .Names = c("URBAN_AREA", "NO_PATCHES",

"MEAN_AREA", "AREA.ZONE", "Buffer.zone"), class = "data.frame", 
row.names = c(2L,


15L, 19L, 22L, 36L, 40L, 42L, 56L, 60L, 62L, 76L, 80L))



library(lattice)

Region = factor(patches$URBAN_AREA)

lpatches = patches

for (i in 2:4) lpatches[,i] = log10(patches[,i])

# zone not transformed

lpatches.pca = princomp(lpatches[,-c(1,17)],cor=FALSE)

x = lpatches.pca$scores[,1]

y = lpatches.pca$scores[,2]

zz = as.character(patches$Buffer.zone/5)

table(zz)

plsy <- trellis.par.get("plot.symbol")
# only 0 or 1 used as plotting symbol
# I expected 0,1,2,4

plsy$pch = as.character(rep(1:6,2))
trellis.par.set("plot.symbol",plsy)
xyplot(y ~ x |Region)

# only 1,2,3,4 used as plotting symbol
# I expected 1:6


Mark Leeds has pointed out that whatever numbers appear as plotting 
characters on the screen, they are replaced by circles when you save a 
pdf via


pdf()
xyplot()
dev.off()


I have reproduced this on my Mac.

Cheers,  Murray

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED][EMAIL PROTECTED]  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 139 5862

__
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] lattice plotting character woes

2008-08-26 Thread Murray Jorgensen

Hi Rolf, Hi Mark, Hi List,

I have not digested Rolf's response yet. It may well answer my problems.

In the meantime I have some reproducible  code which actually shows my 
problem:



patches <-

structure(list(URBAN_AREA = structure(c(2L, 19L, 23L, 2L, 19L,

23L, 2L, 19L, 23L, 2L, 19L, 23L), .Label = c("CENTRAL AUCKLAND ZONE",

"CHRISTCHURCH", "DUNEDIN", "HAMILTON ZONE", "HASTINGS ZONE",

"INVERCARGILL", "LOWER HUTT ZONE", "mean", "NAPIER ZONE", "NELSON",

"NEW PLYMOUTH", "NORTHERN AUCKLAND ZONE", "PALMERSTON NORTH",

"PORIRUA ZONE", "ROTORUA", "SD", "SE", "SOUTHERN AUCKLAND ZONE",

"TAURANGA", "WANGANUI", "WELLINGTON ZONE", "WESTERN AUCKLAND ZONE",

"WHANGAREI"), class = "factor"), NO_PATCHES = c(11L, 16L, 21L,

87L, 192L, 324L, 164L, 417L, 773L, 679L, 757L, 3083L), MEAN_AREA = 
c(9.623631225,


15.29089619, 149.2063532, 14.1676, 247.5262, 28.611, 11.5698,

221.0022, 37.3725, 11.918, 133.5804, 25.6759), AREA.ZONE = c(13683,

3666, 1558, 64830, 41103, 22581, 123819, 90107, 57627, 264735,

223963, 174456), Buffer.zone = c(0L, 0L, 0L, 5L, 5L, 5L, 10L,

10L, 10L, 20L, 20L, 20L)), .Names = c("URBAN_AREA", "NO_PATCHES",

"MEAN_AREA", "AREA.ZONE", "Buffer.zone"), class = "data.frame", 
row.names = c(2L,


15L, 19L, 22L, 36L, 40L, 42L, 56L, 60L, 62L, 76L, 80L))



library(lattice)

Region = factor(patches$URBAN_AREA)

lpatches = patches

for (i in 2:4) lpatches[,i] = log10(patches[,i])

# zone not transformed

lpatches.pca = princomp(lpatches[,-c(1,17)],cor=FALSE)

x = lpatches.pca$scores[,1]

y = lpatches.pca$scores[,2]

zz = as.character(patches$Buffer.zone/5)

table(zz)

plsy <- trellis.par.get("plot.symbol")
# only 0 or 1 used as plotting symbol

plsy$pch = as.character(rep(1:6,2))
trellis.par.set("plot.symbol",plsy)
xyplot(y ~ x |Region)

# only 1,2,3,4 used as plotting symbol

I actually wish 0,1,2, or 4 to be used - to indicate the zone coded in zz.

Cheers,  Murray

PS The xyplots produced on R 2.7.0 for Mac OS X, the first one also on 
an older Windows version.



Rolf Turner wrote:



Murray:

I'm not at all sure that I understand what you're driving at --- but
does this do something like what you want?

require(lattice)
set.seed(260808)
n = 50
x = rnorm(n)
y = rnorm(n)
z = ceiling(runif(n,0,4))
g = runif(n,0,6)
G = factor(ceiling(g))
print(xyplot(y ~ x | G,pch=G,
panel=function(x,y,...,subscripts,pch) {
panel.xyplot(x,y,pch=pch[subscripts])
}
))


cheers,

Rolf

##
Attention: This e-mail message is privileged and confidential. If you 
are not the intended recipient please delete the message and notify 
the sender. Any views or opinions presented are solely those of the 
author.


This e-mail has been scanned and cleared by MailMarshal 
www.marshalsoftware.com

##


--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED][EMAIL PROTECTED]  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 139 5862

__
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] lattice plotting character woes

2008-08-25 Thread Murray Jorgensen

The following reproducable code shows the setting of my problem:

set.seed(260808)
n = 50
x = rnorm(n)
y = rnorm(n)
z = ceiling(runif(n,0,4))
g = runif(n,0,6)
G = factor(ceiling(g))
xyplot(y ~ x | G)
plsy <- trellis.par.get("plot.symbol")
plsy$pch = z
trellis.par.set("plot.symbol",plsy)
xyplot(y ~ x | G)

plsy$pch = as.character(z)
trellis.par.set("plot.symbol",plsy)
xyplot(y ~ x | G)

Unfortunately it does not reproduce the problem, which is that instead 
of the plotting characters being determined by the value of G, they are 
all the same, corresponding to the lowest level of G.


Here is my actual output:

> patches = read.csv(apf,header=TRUE)
> summary(patches)
X  URBAN_AREA   NO_PATCHES   MEAN_AREA
Mode:logical  CENTRAL AUCKLAND ZONE: 4  Min.   :   0.0   Min.   :   0.00
NA's:83   CHRISTCHURCH : 4  1st Qu.:  81.5   1st Qu.:  11.64
  DUNEDIN  : 4  Median : 200.0   Median :  23.19
  HAMILTON ZONE: 4  Mean   : 375.5   Mean   : 323.08
  HASTINGS ZONE: 4  3rd Qu.: 524.5   3rd Qu.: 149.54
  INVERCARGILL : 4  Max.   :3083.0   Max.   :6609.34
  (Other)  :59   NA's   :   3.00
MAX_AREAMIN_AREA STD_AREA   MEAN_EDGE
 Min.   :1.008e+01   Min.   :0.0029   Min.   :3.115   Min.   : 1075
 1st Qu.:1.716e+02   1st Qu.:0.1605   1st Qu.:   24.939   1st Qu.: 1867
 Median :2.336e+03   Median :0.2516   Median :  185.198   Median : 2669
 Mean   :6.211e+04   Mean   :0.5888   Mean   : 3888.733   Mean   : 6584
 3rd Qu.:3.670e+04   3rd Qu.:0.4713   3rd Qu.: 2148.932   3rd Qu.: 6149
 Max.   :1.449e+06   Max.   :8.8260   Max.   :64028.083   Max.   :94641
 NA's   :4.000e+00   NA's   :4.   NA's   :4.000   NA's   :4
MAX_EDGE   MIN_EDGE  STD_EDGE   MEAN_E_A
 Min.   :2340   Min.   :  34.35   Min.   :   290.2   Min.   :0.01491
 1st Qu.:   20369   1st Qu.: 162.04   1st Qu.:  2919.3   1st Qu.:0.03320
 Median :  124243   Median : 193.47   Median :  9182.8   Median :0.03910
 Mean   :  841731   Mean   : 286.33   Mean   : 53940.9   Mean   :0.03924
 3rd Qu.:  913745   3rd Qu.: 325.62   3rd Qu.: 56914.0   3rd Qu.:0.04527
 Max.   :13086956   Max.   :1770.00   Max.   :584281.0   Max.   :0.06010
 NA's   :   4   NA's   :   4.00   NA's   : 4.0   NA's   :4.0
MAX_E_A   MIN_E_ASTD_E_A   AREA.ZONE
 Min.   :0.01755   Min.   :0.000900   Min.   :0.002378   Min.   :  1114
 1st Qu.:0.08890   1st Qu.:0.001526   1st Qu.:0.016550   1st Qu.: 13996
 Median :0.10146   Median :0.002900   Median :0.018500   Median : 38015
 Mean   :0.14431   Mean   :0.005689   Mean   :0.019567   Mean   : 60883
 3rd Qu.:0.12040   3rd Qu.:0.008592   3rd Qu.:0.020784   3rd Qu.: 84787
 Max.   :1.20530   Max.   :0.024350   Max.   :0.059000   Max.   :264735
 NA's   :4.0   NA's   :4.00   NA's   :4.00   NA's   : 3
 No..patches.100.ha   X.1   Buffer.zone
 Min.   :0. Mode:logical   Min.   : 0.000
 1st Qu.:0.3534 NA's:831st Qu.: 5.000
 Median :0.5653Median :10.000
 Mean   :0.6952Mean   : 9.157
 3rd Qu.:0.90803rd Qu.:20.000
 Max.   :2.9374Max.   :20.000

> # clean
> patches = patches[,-c(1,18)]
> patches = patches[-c(20,81,82,83),]
> cnames = patches[,1]
> acn = abbreviate(cnames)
> zone = patches[,17]/5
> names(acn) = NULL
> Region = factor(acn)
> lpatches = patches
> for (i in 2:16) lpatches[,i] = log10(patches[,i])
> # zone not transformed
> lpatches.pca = princomp(lpatches[,-c(1,17)],cor=FALSE)
> x = lpatches.pca$scores[,1]
> y = lpatches.pca$scores[,2]
> zz = as.character(patches$Buffer.zone/5)
> plsy <- trellis.par.get("plot.symbol")
> plsy$pch = zz
> trellis.par.set("plot.symbol",plsy)
> xyplot(y ~ x |Region)
> table(zz)
zz
 0  1  2  4
19 20 20 20

I would dearly like to have my plotting symbols indicate the zone but I 
am frustrated.


Curiously I may put other (numeric or character) variable in place of zz 
and get variable plotting characters.


Murray
--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED]Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 1395 862

__
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] Extracting formula from an lm object

2008-08-24 Thread Murray Jorgensen
Thanks to Professors Ripley and Turlach for their help. Brian's solution 
was simple and elegant but Berwin's was also informative.


Murray Jorgensen

Prof Brian Ripley wrote:

On Sun, 24 Aug 2008, Berwin A Turlach wrote:


G'day Murray,

On Sun, 24 Aug 2008 18:34:39 +1200
Murray Jorgensen <[EMAIL PROTECTED]> wrote:


I want to extra the part of the formula not including the response
variable from an lm object. For example if the lm object ABx.lm was
created by the call

ABx.lm <- lm( y ~ A + B + x, ...)

Then ACx.lm is saved as part of a workspace.
I wish to extract   "~ A + B + x".  Later in my code I will fit
another linear model of the form z ~ A + B + x for some other
response variable z. I would be grateful for any suggestions of a
nice way to do this.


AFAIK, a formula is essentially a list of two or three components.  The
first component is "~".  The second is the LHS of the formula if there
are three components; otherwise the RHS of the formula.  The third
component, if it exists, is the RHS of the formula.

So storing "~ A + B + x" and manipulating this part for different
responses could turn out to be painful; you would have to insert the
new LHS as the second component of the list.  I would suggest that it
is easier to store the complete formula and just manipulate the LHS;
see:


An ulternative is to use update.formula on the formula extracted, or 
even just use update() on the lm fit.  For the information in this 
posting (there could be more going on, like where to find 'z'),


update(ABX.lm, z ~ .)

should be all that is needed.



R> library(MASS)
R> fm <- lm(time~dist+climb, hills)
R> formula(fm)
time ~ dist + climb
R> formula(fm)[[1]]
`~`
R> formula(fm)[[2]]
time
R> formula(fm)[[3]]
dist + climb
R> tt <- formula(fm)
R> tt[[2]] <- NULL
R> tt
~dist + climb

R> tt <- formula(fm)
R> class(tt[[2]])
[1] "name"
R> typeof(tt[[2]])
[1] "symbol"
R> tt[[2]] <- as.name("y")
R> tt
y ~ dist + climb

R> tt <- formula(fm)
R> tt[[2]] <- as.symbol("z")
R> tt
z ~ dist + climb

HTH.

Cheers,

Berwin

=== Full address =
Berwin A TurlachTel.: +65 6515 4416 (secr)
Dept of Statistics and Applied Probability+65 6515 6650 (self)
Faculty of Science  FAX : +65 6872 3919
National University of Singapore
6 Science Drive 2, Blk S16, Level 7  e-mail: [EMAIL PROTECTED]
Singapore 117546http://www.stat.nus.edu.sg/~statba

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






--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED]Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 1395 862

__
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] Extracting formula from an lm object

2008-08-24 Thread Murray Jorgensen

I want to extra the part of the formula not including the response
variable from an lm object. For example if the lm object ABx.lm was
created by the call

ABx.lm <- lm( y ~ A + B + x, ...)

Then ACx.lm is saved as part of a workspace.
I wish to extract   "~ A + B + x".  Later in my code I will fit another
linear model of the form z ~ A + B + x for some other response variable z.
I would be grateful for any suggestions of a nice way to do this.

Cheers,  Murray Jorgensen

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED][EMAIL PROTECTED]  Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 139 5862

__
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] Programming Concepts and Philosophy

2008-06-19 Thread Murray Jorgensen
I am wondering if people on the list could recommend books that they 
have found helpful about programming concepts and style? I often find 
that students write R programs by copying existing code but could really 
benefit from the understanding of more general programming ideas. An 
example would be to avoid writing functions which attempt to modify 
their parameters. Another principle would be not to write programs with 
numbers used as constants but to assign them to named objects as in


n <- 120 # number of observations
p <- 10  # number of variables

near the beginning of a program rather than using "10" and "120" 
throughout the script.


This sort of stuff is not specifically R but can be a problem for 
students with little programming background.


I am happy to summarise responses.

Murray Jorgensen

--
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED]Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 1395 862

__
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] Recommended Packages

2008-03-02 Thread Murray Jorgensen
Having just update to R 2.6.2 on my old Windows laptop I notice that the 
number of packages is growing exponentially and my usual approach of 
get-em-all may not be viable much longer. Has any thought been given to 
dividing "contributed" binaries into a recommended set, perhaps a couple 
of hundred, and the remained. That way one could install the recommended 
ones routinely and add in the others as required. Any comments?

Murray Jorgensen

-- 
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED]Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 1395 862

__
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] [OT] good reference for mixed models and EM algorithm

2008-02-11 Thread Murray Jorgensen

Erin,

as well as P & B can I recommend

McCullogh CE, Searle SR (2000), Generalized, Linear, and Mixed Models, Wiley

I also found

Data analysis using regression and multilevel/hierarchical models by
Andrew Gelman and Jennifer Hill.
  Cambridge ; New York : Cambridge University Press, 2007.

useful although it takes a Bayesian rather than EM approach.

Cheers,  Murray

-- 
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED]Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 1395 862

__
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] Reading R-help Digests with Mozilla Thunderbird

2007-11-01 Thread Murray Jorgensen
This is somewhat off-topic but I think that an answer may help other 
users of R-help.

Thunderbird trys to help in the display of messages by "greying out" 
quoted text. However when reading r-help in digest form it gets 
thoroughly confused and usually ends up greying out the fresh text in a 
message. [I'm using Windows XP].

Does anyone know how to turn off this Thunderbird feature? Also what 
would be the best way to raise this problem with the Thunderbird developers?

Cheers,  Murray Jorgensen

-- 
Dr Murray Jorgensen  http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: [EMAIL PROTECTED]Fax 7 838 4155
Phone  +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 1395 862

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