[R] export only if data is available

2013-02-08 Thread Mat
Hello together,

i have a problem with an export.
I want to export a data.frame, only if there ist data in it.
My data.frame (CO.PHB) ist empty but with this code, the .txt-file gets
exported every time, with no content.

{
pfad-paste(paste(paste(C:/Test/,Reminder,sep=),
Orders,sep=/),txt,sep=.)
write.xls( Orders,pfad,colNames = TRUE,sheet = 1,from = 1,rowNames = FALSE )
if(dim(CO.PHB)[1]0){
write.table( CO.PHB,pfad,row.names=FALSE,sep= | )
}}

how should my code look like, if i want only an Export, when there is data
in the data.frame?

Thanks Mat



--
View this message in context: 
http://r.789695.n4.nabble.com/export-only-if-data-is-available-tp4657922.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Peak detector help!?

2013-02-08 Thread PIKAL Petr
Hi

I am not sure if it suits your needs but I use this function for identifying 
peaks in different spectral data.

peaks - function (series, span = 3, ties.method = first) 
{
if ((span - as.integer(span))%%2 != 1) 
stop('span' must be odd)
z - embed(series, span)
s - span%/%2
v - max.col(z, ties.method = ties.method) == 1 + s
pad - rep(FALSE, s)
result - c(pad, v, pad)
result
  }

Works for both your examples.

Regards
Petr

test - c(9,8,7,5,4,1,1,2,1,1,3,4,5,6,7,5,4,3,2,1,1,3,4,5,6,7,8)
plot(seq(length(test)),test)
peaks(test)
 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[13] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[25] FALSE FALSE FALSE
pp-peaks(test)
abline(v=seq(length(test))[pp], col=2)

test - c(rep(1,10),20,rep(1,10))
plot(seq(length(test)),test)
pp-peaks(test)
abline(v=seq(length(test))[pp], col=2)


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Johannes Graumann
 Sent: Thursday, February 07, 2013 1:42 PM
 To: r-h...@stat.math.ethz.ch
 Subject: Re: [R] Peak detector help!?
 
 Johannes Graumann wrote:
 
  Grrr ... new trial with code here: http://pastebin.com/RjHNNG9J Maybe
  the amount of inline-code prevented posting?
 
  Hello,
 
  I am writing a simple peak detector and it works quite well ...
  however there's one special case below, that I can't get my head
  wrapped around ... the problem is in the Deal with not fully
  qualified peaks at the sequence extremes section, but I cannot seem
  to come up with a condition that would be met in the special case
  below and base a fix on it ... mind completely poisoned with trial
 solutions that didn't work ...
 
  A fresh hint anyone?
 
  Sincerely, Joh
 
 Sleep brought some insight.
 
 The code here http://pastebin.com/UXzbzqp8 works for now - I have
 already quite a number of test cases that gave me problems and now
 don't ...
 probably more corner cases somewhere, but they will be dealt with as
 they show up.
 
 Cheers, Joh
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Nested loop and output help

2013-02-08 Thread PIKAL Petr
Hi
You must use indexing based on loops

sim(ss[i],cc[j],oo1[k],oo2[l])

an of course assign result to some object.

result[...] - sim(ss[i],cc[j],oo1[k],oo2[l])

where ... means some suitable index either chosen from loop index or 
constructed during loop execution.
Maybe it is time to go through R intro document (chapter 2 and chapter 9).

You probably could find answer yourself quicker then waiting for me to answer 
it.

Regards
Petr


From: staysafe23 [mailto:staysaf...@gmail.com]
Sent: Thursday, February 07, 2013 9:09 PM
To: PIKAL Petr
Subject: RE: [R] Nested loop and output help


Hi Petr,

I have refined my question and would like to ask it another way if I may. Here 
are the conditions I would like to vary in my inquiry.

ss - seq(5,9,by=1) 5 6 7 8 9

cc - seq(-0.5,0.5, by=0.25) -0.50 -0.25 0.00 0.25 0.50

oo1 - seq(-10,10, by=5) -10 -5 0 5 10

oo2 - seq(0,20, by=5) 0 5 10 15 20

Here is the loop I would like to run.

for(i in ss) {

for (j in cc) {

for (k in oo1) {

for (l in oo2) {

sim(ss,cc,oo1,oo2)





}

}

}

}

There are the results that would like to get.

sim(5,-0.5,-10,0)

sim(5,-0.5,-10,5)

sim(5,-0.5,-10,10)

sim(5,-0.5,-10,15)

sim(5,-0.5,-10,20)

. . .

. . .

. . .

sim(9,0.5,10,0)

sim(9,0.5,10,5)

sim(9,0.5,10,10)

sim(9,0.5,10,15)

sim(9,0.5,10,20)

Here is my function but I am not getting the loop to run over all the possible 
permutations of the conditions nor and I getting an output for each condition.

sim - function(ss,cc,oo1,oo2) {

lll - vector(mode = list, length = 16)

names(lll) - c(og_table, McNemar, McNemar_corr,

sd_table, Chisq, Chisq_corr,

og_data, mean_X, cut_T1, mean_X2,

mean_Y,cut_T2, mean_Y2,

dev_data, sum_D, sum_D2)

z1 - rnorm(ss,mean=400, sd=70)

z2 - rnorm(ss,mean=450, sd=90)

r - cc

X - z1

Y = r*z1+(1-r)*z2

lll[[og_data]] - cbind(X,Y)

dev1 - oo1

lll[[cut_T1]] - mean(X) + dev1

dev2 - oo2

lll[[cut_T2]] - mean(X) + dev1 + dev2

X2 - X-lll[[cut_T1]]

Y2 - Y-lll[[cut_T2]]

c3 - cor(X2,Y2)

D - Y2-X2

lll[[sum_D]] - sum(D)

D2 -D*D

lll[[sum_D2]] - sum(D2)

lll[[dev_data]] -cbind(X2,Y2)

a11 - ifelse( X  lll[[cut_T1]]  Y  lll[[cut_T2]], 1, 0)

a12 - ifelse( X  lll[[cut_T1]]  Y = lll[[cut_T2]], 1, 0)

a21 - ifelse( X = lll[[cut_T1]]  Y  lll[[cut_T2]], 1, 0)

a22 - ifelse( X = lll[[cut_T1]]  Y = lll[[cut_T2]], 1, 0)

lll[[og_table]] -matrix(c(sum(a11),sum(a21), sum(a12),sum(a22)), nrow = 2)

lll[[McNemar]] -mcnemar.test(lll[[og_table]], correct=FALSE)

lll[[McNemar_corr]] -mcnemar.test(lll[[og_table]], correct=TRUE)

lll[[sd_table]] -matrix(c(sum(a11),sum(a22), sum(a12),sum(a21)), nrow = 2)

lll[[Chisq]] -chisq.test(lll[[sd_table]], correct = FALSE)

lll[[Chisq_corr]] -chisq.test(lll[[sd_table]], correct = TRUE)

lll[[mean_X]] - mean(X)

lll[[mean_Y]] - mean(Y)

lll[[mean_X2]] - mean(X2)

lll[[mean_Y2]] - mean(Y2)

lll[[T]] - sum(D)/((length(D)*sum(D2)-sum(D)*sum(D))/(length(D)-1))**(0.5)

lll[[dep_t]] - t.test(Y2, X2, alternative='two.sided', conf.level=0.95, 
paired=TRUE)

print(lll)

capture.output(print(lll), file = 
C:/Chi_Square_fix/temp_[ss]_[cc]_[oo1]_[002].txt, append = TRUE)

}
On Feb 6, 2013 3:26 PM, staysafe23 
staysaf...@gmail.commailto:staysaf...@gmail.com wrote:

Hi Petr,

Thank you again for your help. I am making a mistake since I have assigned an 
entire vector oo1 to dev1. What I errantly thought I was doing was starting 
with the value of 5 in ss, then picking the value of -0.50 in cc, then picking 
the value of -10 in oo1, then picking the value of 0 in oo2, and running the 
code that is within the inner most brackets and putting the output into an 
output file.

Then I thought the loop would move on to the next case, 5 in ss, then picking 
the value of -0.50 in cc, then picking the value of -10 in oo1, then picking 
the value of 5 in oo2. So I thought I would end up with my code being run a 
number of times that would equal the 
length(ss)*length(cc)*length(oo1)*length(oo2) .

I can't seem to get the code to run through each of these conditions. Do you 
have any idea that may help me do so?

Thank you Petr,

Thomas
On Feb 6, 2013 2:25 AM, PIKAL Petr 
petr.pi...@precheza.czmailto:petr.pi...@precheza.cz wrote:
Hi

This is an error I get with your loop code due to this line

capture.output(print(lll), file = C:/Chi_Square_fix/temp.txt, append = TRUE)
Error in file(file, if (append) a else w) :
  cannot open the connection
In addition: Warning messages:
1: In chisq.test(lll[[mat4]], correct = FALSE) :
  Chi-squared approximation may be incorrect
2: In chisq.test(lll[[mat4]], correct = TRUE) :
  Chi-squared approximation may be incorrect
3: In file(file, if (append) a else w) :
  cannot open file 'C:/Chi_Square_fix/temp.txt': No such file or directory


Without this line I get no error and everything is probably printed. I do not 
know function capture.output but I presume that you need initialise the file 
temp.txt before you can output to it.

Anyway those cycles are rather weird. E.g. in each cycle you assign whole 
vector oo1 to 

Re: [R] Peak detector help!?

2013-02-08 Thread Pascal Oettli

Hello,

There is also that previous discussion:

http://r.789695.n4.nabble.com/peak-detection-td3086410.html

Pascal


Le 07/02/2013 03:22, Johannes Graumann a écrit :

Grrr ... new trial with code here: http://pastebin.com/RjHNNG9J
Maybe the amount of inline-code prevented posting?

Hello,

I am writing a simple peak detector and it works quite well ... however
there's one special case below, that I can't get my head wrapped around ...
the problem is in the Deal with not fully qualified peaks at the sequence
extremes section, but I cannot seem to come up with a condition that would
be met in the special case below and base a fix on it ... mind completely
poisoned with trial solutions that didn't work ...

A fresh hint anyone?

Sincerely, Joh

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] convert 12 time stamp to 24 hour

2013-02-08 Thread e-letter
Readers,

For a 12 hour time stamp:

 testtime-(2013-01-01 01:00:01 PM)
 testtime
[1] 2013-01-01 01:00:01 PM
 testtime24hour-strftime(testtime,'%H:%M:%S')
 testtime24hour
[1] 01:00:01

how to convert to 24 hour format so that the object 'testtime24hour' is:

'13:00:01'

Thanks.

--
r2151

__
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] plot ᵒ C in graph axis label

2013-02-08 Thread Pascal Oettli

Hello,

I don't know whether it matches what you are looking for. Here are some 
example using different spacing:


 par(las=1, mfrow=c(2,2))
 plot(1,1,ylab=expression(paste('rate (',degree~C^-1,')')), 
main='Spacing with ~')
 plot(1,1,ylab=expression(paste('rate (',degree,phantom(0),C^-1,')')), 
main='Spacing with phantom(0)')
 plot(1,1,ylab=expression(paste('rate (',degree,phantom(),C^-1,')')), 
main='Spacing with phantom()')
 plot(1,1,ylab=expression(paste('rate (',degree*C^-1,')')), 
main='Spacing with *')


Hope this helps,
Pascal

Le 08/02/2013 18:36, e-letter a écrit :

Readers,

For a part of the 'plot' command:

...ylab=expression(paste('rate (',degree~C^-1,')'))...

Is it possible to introduce 'thinspace' (e.g. '\thinspace' in LaTeX)
between the degree (°) sign and the centigrade (C) symbol?

--
r2151

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] convert 12 time stamp to 24 hour

2013-02-08 Thread Pascal Oettli

Hello,

Try this:

 testtime-(2013-01-01 01:00:01 PM)
 strptime(testtime, %Y-%m-%d %I:%M:%S %p)
[1] 2013-01-01 13:00:01

HTH,
Pascal


Le 08/02/2013 18:44, e-letter a écrit :

Readers,

For a 12 hour time stamp:


testtime-(2013-01-01 01:00:01 PM)
testtime

[1] 2013-01-01 01:00:01 PM

testtime24hour-strftime(testtime,'%H:%M:%S')
testtime24hour

[1] 01:00:01

how to convert to 24 hour format so that the object 'testtime24hour' is:

'13:00:01'

Thanks.

--
r2151

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] add data symbol to axis label

2013-02-08 Thread e-letter
Readers,

Is it possible to add a data symbol (e.g. pch='21') to an axis label?
The objective is to plot a graph with two (2) y-axes and the plotting
character for data set 1 is added to the label of y1 axis (left); plot
character for data set 2 is added to label of y2 (right) axis.

Thanks.

--
r2151

__
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-pkgs] release 2.4 of distr-family of packages on CRAN

2013-02-08 Thread Peter Ruckdeschel
New versions 2.4 of our distr-family of packages are submitted to
CRAN and will soon be available on all mirrors

(i.e.; startupmsg, SweaveListingUtils, distr, distrEx, distrDoc,
distrEllipse, distrMod, distrSim, distrTEst, distrTeach)

In addition, there is a new package distrRmetrics with distr support
for (some) distributions provided in the Rmetrics family of packages.

For more details see the corresponding NEWS files in the pkgs, e.g.
news(package = distr) or NEWS(distr) [the latter using fct NEWS
from pkg startupmsg].

We are looking forward to getting your RFEs, bug reports
or simple feedback,

Best, Peter and coauthors (CC).

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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] How to debug the C programs associated with R-packages?

2013-02-08 Thread Pulkit Mehrotra
hello,

I was having some problems in debugging C codes assocaited with R-packages.
I don't have much experience with debugging tools used in C language. Is
there any methods similar to R-debugging tools such as browser  ,debug etc
which can be used to debug such C files.

I was using the foreign package and found a bug in reading dta files
containing empty strings  in the data. I was able to find where the error
originated in the R file but was unable to do so for the C files.

Any help would be deeply appreciated.

Thank you for your time and consideration.

with regards,
Pulkit Mehrotra

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] convert 12 time stamp to 24 hour

2013-02-08 Thread PIKAL Petr
Hi

Does not work in some locale environment

 strptime(testtime, %Y-%m-%d %I:%M:%S %p) 
[1] NA

 Sys.getlocale(LC_TIME)
[1] Czech_Czech Republic.1250

 Sys.setlocale(LC_TIME, C)
[1] C

 strptime(testtime, %Y-%m-%d %I:%M:%S %p) 
[1] 2013-01-01 13:00:01

Regards
Petr

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Pascal Oettli
 Sent: Friday, February 08, 2013 11:08 AM
 To: e-letter
 Cc: r-help@r-project.org
 Subject: Re: [R] convert 12 time stamp to 24 hour
 
 Hello,
 
 Try this:
 
   testtime-(2013-01-01 01:00:01 PM)
   strptime(testtime, %Y-%m-%d %I:%M:%S %p) [1] 2013-01-01 13:00:01
 
 HTH,
 Pascal
 
 
 Le 08/02/2013 18:44, e-letter a écrit :
  Readers,
 
  For a 12 hour time stamp:
 
  testtime-(2013-01-01 01:00:01 PM)
  testtime
  [1] 2013-01-01 01:00:01 PM
  testtime24hour-strftime(testtime,'%H:%M:%S')
  testtime24hour
  [1] 01:00:01
 
  how to convert to 24 hour format so that the object 'testtime24hour'
 is:
 
  '13:00:01'
 
  Thanks.
 
  --
  r2151
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-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] Border width on symbols plotted with the lattice package

2013-02-08 Thread Karl Ove Hufthammer

Dear list members,

I can't figure out how get 'xyplot' or 'dotplot' in the 'lattice' 
package to respect the 'lwd' value for specifying the border with for 
*symbols* (for lines it works fine). Example:


-
# Base graphics works fine (gives a 'fat’ circle)
plot(5, cex=10, pch=21, lwd=10)

# But 'xyplot' or 'dotplot' doesn't
library(lattice)
xyplot(4:5~4:5, groups=4:5, par.settings = simpleTheme(cex=10, pch=21, 
lwd=5),

auto.key=TRUE)
-

For 'xyplot' or 'dotplot' the border stays thin no matter what I set 
'lwd' to. However, the symbols shown in the *legend* has the 'lwd' 
correctly applied.


How can I fix this? Or is it simply a bug in the 'lattice' package?


Karl Ove Hufthammer



Output of 'sessionInfo()':

R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Norwegian-Nynorsk_Norway.1252
[2] LC_CTYPE=Norwegian-Nynorsk_Norway.1252
[3] LC_MONETARY=Norwegian-Nynorsk_Norway.1252
[4] LC_NUMERIC=C
[5] LC_TIME=Norwegian-Nynorsk_Norway.1252

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

other attached packages:
[1] lattice_0.20-13

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

__
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] Calculating the cumulative incidence function

2013-02-08 Thread Terry Therneau

 You can do this directly with the survfit function (survival verstion 2.37 or 
greater)
If status is a factor variable with levels of censored, relapse and death
fit - survfit(Surv(time, status) ~ sex, data=mydata)
plot(fit, xlab=...

The primary advantage of this over the cuminc package is that all of the usual options for 
survival plots carry forward.

   Terry Therneau


On 02/05/2013 05:00 AM, r-help-requ...@r-project.org wrote:

Hello,
I have a problem regarding calculation of Cumulative Incidence Function.
The event of interest is failure of bone-marrow transplantation, which may
occur due to relapse or death in remission. The data set that I have
consists of- lifetime variable, two indicator variables-one for relapse and
one for death in remission, and the other variables are donor type (having
3 categories), disease type(having 3 categories), disease stage(having 3
categories) and karnofsky score (having 2 categories).

I want to create an R function for cumulative incidence function for the
event (failure of bone-marrow transplantation) due to relapse (cause-1) and
also for the event (failure of bone-marrow transplantation) due to death in
remission (cause-2). Can anyone help me please?
Tas.


__
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] export only if data is available

2013-02-08 Thread Ben Tupper
Hi,

On Feb 8, 2013, at 2:49 AM, Mat wrote:

 Hello together,
 
 i have a problem with an export.
 I want to export a data.frame, only if there ist data in it.
 My data.frame (CO.PHB) ist empty but with this code, the .txt-file gets
 exported every time, with no content.
 
 {
 pfad-paste(paste(paste(C:/Test/,Reminder,sep=),
 Orders,sep=/),txt,sep=.)
 write.xls( Orders,pfad,colNames = TRUE,sheet = 1,from = 1,rowNames = FALSE )
 if(dim(CO.PHB)[1]0){
 write.table( CO.PHB,pfad,row.names=FALSE,sep= | )
 }}
 
 how should my code look like, if i want only an Export, when there is data
 in the data.frame?
 

Try using nrow() to test the data frame first.

if (nrow(CO.PHB) != 0) {
   # write the file
} else {
   cat(The data frame is empty\n)
}

Cheers,
Ben



 Thanks Mat
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/export-only-if-data-is-available-tp4657922.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] effect() error: non-conformable arguments

2013-02-08 Thread John Fox
Dear Elisha,

It's impossible to tell from the information that you provide what the
source of the problem is. The gold standard for a problem report is
commented, minimal, self-contained, reproducible code (quoting from the
text at the bottom of all r-help postings) that would allow me to track down
the error, but you don't even show the model that you've fit. I suspect that
there's something about the model that's incompatible with the effect()
function but what that might be is impossible to know from your message.

Please provide some more details and ideally a reproducible example.

Best,
 John

---
John Fox
Senator McMaster Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Elisha Sigmon
 Sent: Thursday, February 07, 2013 2:57 PM
 To: r-help@r-project.org
 Subject: [R] effect() error: non-conformable arguments
 
 I am trying to calculate adjusted means according to a glm model with a
 Poisson distribution using effect() in the 'effects' package. I've done
 this many times before with great success, but this time I'm getting an
 error. My model contains two factors and two covariates/blocks and I
 would
 like the adjusted mean and confidence intervals for each factor
 separately.
 The model runs without errors as does Anova() and HSD.test() on the
 model,
 but when I try to run effect(factor, model) I get the following error:
 Error in mod.matrix %*% V : non-conformable arguments
 
 I understand that this error indicates that matrices are being created
 with
 dimensions that can't be used in the calculations, or something to that
 effect. But I don't understand enough about how the effect() function is
 calculated to figure out where the problem is in my data. I checked my
 data
 file for any NAs, missing values, etc. and can't find any problems. If
 anyone has any suggestions for diagnostics or how to find the source of
 this error I would greatly appreciate the help.
 
 Thanks!
 
 --
 Elisha Sigmon
 Ph.D. Candidate
 The George Washington University
 Department Of Biological Sciences
 2023 G St. NW Suite 340
 Washington, DC, USA 20052
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] low pass filter analysis in R

2013-02-08 Thread Bretschneider SIG-R
Dear Janesh,


Re:

 Dear Franklin Bretschneider,
 
 Thank you so much for your reply and explanation about the filter using the 
 stats and signal package. 
 
 I decided to opt the filter method in signal package. I have a simple 
 question about the cut off frequency here. 
 
 I have 30 minute collected tidal data and I want to use the 48 hour low pass 
 filter to my data to remove the fluctuations and then get only the residuals. 
 What should be the cutoff frequency in my case ? I have tried to figure out 
 cut off frequency with the following rationale : . 
 
 The parameters for butter filter are n, Wn and type. In the help, Wis 
 defined as critical frequencies of the filter. W must be a scalar for 
 low-pass and high-pass filters, and W must be a two-element vector c(low, 
 high) specifying the lower and upper bands. For digital filters, W must be 
 between 0 and 1 where 1 is the Nyquist frequency.
 
 A value of 1 corresponds to half the sampling frequency. In my case the 
 sampling frequency is 2 hr^-1. Hence a value of 0.01 corresponds to a 
 frequency cutoff of .01*1 = .01 hr^-1 or 100 hrs time. Using unitary method, 
 if 100 hours cut off frequency is 0.01 then 48 hours cut off frequency is 
 0.01/100*48 = 0.0048 hr^-1 . Is that correct ?
 
 Thank you so much
 
 Janesh
 


With digital filters (called z-plane in the signal package), the cut-off 
frequency must indeed be given as a fraction of the Nyquist freqency.

With your tidal data, taken at 2 samples per hour, the nyquist is 1 per hour. 
So, a cutoff interval of 48 h means a cutoff frequncy of 1/48 f(nyq) , or 
0.020833. This must be fed into the butterworth function.

Note btw that at the cut-off frequency, the amplitude is still rather high 
(about 0.707), so the tidal signal (period about 12.5 h) will not be attenuated 
much.
I hope this helps. It's always best to check with a simple example, such as an 
f= 1/48 sine, which after your filter should be reduced to an amplitude of 
0.707). Then check with a simulated tidal signal (say, a sine of about 12:25 h 
period). 
With such simple tests, I often find my own programming errors.
Best wishes,


Franklin
--


Franklin Bretschneider
--
Dept Biology
Kruyt Building W711
Padualaan 8
3584 CH Utrecht
The Netherlands






[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] write.table and append

2013-02-08 Thread Brian Smith
Hi,

I am trying to append tables on file with this sample code:

for(i in 1:2){
mat - data.frame(sample(1:30,9),3,3)
colnames(mat) - letters[1:3]
ifelse(i ==
1,write.table(mat,paste('test.txt',sep=''),row.names=F),

write.table(mat,paste('test.txt',sep=''),row.names=F,col.names=F,append=TRUE))
}

However, this gives an error:

Error in ifelse(i == 1, write.table(mat, paste(test.txt, sep = ),  :
  replacement has length zero

- Should I be passing in some other parameters or using a different
function to append tables to file?

thanks!

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] write.table and append

2013-02-08 Thread Louis Aslett
I believe your problem stems from using ifelse() actually ... it
requires the statements which it runs to return a value with the same
shape as the test, which write.table() isn't doing.

Just change it to a regular if with an else and you'll be fine:

for(i in 1:2){
  mat - data.frame(sample(1:30,9),3,3)
  colnames(mat) - letters[1:3]
  if(i == 1){
write.table(mat,paste('test.txt',sep=''),row.names=F)
  } else {

write.table(mat,paste('test.txt',sep=''),row.names=F,col.names=F,append=TRUE)
  }
}

Hope that helps,

Louis


On Fri, Feb 8, 2013 at 2:40 PM, Brian Smith bsmith030...@gmail.com wrote:

 Hi,

 I am trying to append tables on file with this sample code:

 for(i in 1:2){
 mat - data.frame(sample(1:30,9),3,3)
 colnames(mat) - letters[1:3]
 ifelse(i ==
 1,write.table(mat,paste('test.txt',sep=''),row.names=F),

 write.table(mat,paste('test.txt',sep=''),row.names=F,col.names=F,append=TRUE))
 }

 However, this gives an error:

 Error in ifelse(i == 1, write.table(mat, paste(test.txt, sep = ),  :
   replacement has length zero

 - Should I be passing in some other parameters or using a different
 function to append tables to file?

 thanks!

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] write.table and append

2013-02-08 Thread Brian Smith
Thanks Louis! That seems to work!

On Fri, Feb 8, 2013 at 10:06 AM, Louis Aslett lasl...@louisaslett.comwrote:

 I believe your problem stems from using ifelse() actually ... it
 requires the statements which it runs to return a value with the same
 shape as the test, which write.table() isn't doing.

 Just change it to a regular if with an else and you'll be fine:

 for(i in 1:2){
   mat - data.frame(sample(1:30,9),3,3)
   colnames(mat) - letters[1:3]
   if(i == 1){
 write.table(mat,paste('test.txt',sep=''),row.names=F)
   } else {

 write.table(mat,paste('test.txt',sep=''),row.names=F,col.names=F,append=TRUE)
   }
 }

 Hope that helps,

 Louis


 On Fri, Feb 8, 2013 at 2:40 PM, Brian Smith bsmith030...@gmail.com
 wrote:
 
  Hi,
 
  I am trying to append tables on file with this sample code:
 
  for(i in 1:2){
  mat - data.frame(sample(1:30,9),3,3)
  colnames(mat) - letters[1:3]
  ifelse(i ==
  1,write.table(mat,paste('test.txt',sep=''),row.names=F),
 
 
 write.table(mat,paste('test.txt',sep=''),row.names=F,col.names=F,append=TRUE))
  }
 
  However, this gives an error:
 
  Error in ifelse(i == 1, write.table(mat, paste(test.txt, sep = ),  :
replacement has length zero
 
  - Should I be passing in some other parameters or using a different
  function to append tables to file?
 
  thanks!
 
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] write.table and append

2013-02-08 Thread Ben Tupper
Hi,

On Feb 8, 2013, at 9:40 AM, Brian Smith wrote:

 Hi,
 
 I am trying to append tables on file with this sample code:
 
for(i in 1:2){
mat - data.frame(sample(1:30,9),3,3)
colnames(mat) - letters[1:3]
ifelse(i ==
 1,write.table(mat,paste('test.txt',sep=''),row.names=F),
 
 write.table(mat,paste('test.txt',sep=''),row.names=F,col.names=F,append=TRUE))
}
 
 However, this gives an error:
 
 Error in ifelse(i == 1, write.table(mat, paste(test.txt, sep = ),  :
  replacement has length zero
 
 - Should I be passing in some other parameters or using a different
 function to append tables to file?


You might try assign each parameter based upon the value of i instead of trying 
to manage two different calls to write.table through an ifelse function.  
ifelse doesn't seem to like the value returned by write.table (NULL).  Here's a 
simply example...

 ok - ifelse( TRUE, NULL, NULL)
Error in ifelse(TRUE, NULL, NULL) : replacement has length zero
 ok - ifelse( FALSE, NULL, NULL)
Error in ifelse(FALSE, NULL, NULL) : replacement has length zero

I think that is what the warning in ?ifelse is alluding to.  You would only 
know that write.table returns NULL if you have bitten by it before.  I have 
bite marks.

for(i in 1:2){
   mat - data.frame(sample(1:30,9),3,3)
   colnames(mat) - letters[1:3]
   write.table(mat, file = test.txt, 
  row.names = FALSE,
  col.names = (i == 1),
  append = (i != 1) )   
}


Cheers,
Ben

 
 thanks!
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Bringing tk_choose.files to front

2013-02-08 Thread mmiikkii
I want to make a script in R (I use RStudio if it matters) in which the user
chooses the initial data file interactively using tk_choose.files

the code goes like this:

fname1-tk_choose.files(default = , caption = Choose file,multi = FALSE,
filters = NULL, index = 1)

however, it pops out new window behind the RStudio window.

How can I make it pop out as top level window (in front of everything)?

Thank you for helping.



--
View this message in context: 
http://r.789695.n4.nabble.com/Bringing-tk-choose-files-to-front-tp4657938.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color query in mosaic in package vcd

2013-02-08 Thread David Meyer

Thanks, fixed upstream.

David

On 2013-02-08 07:20, Achim Zeileis wrote:

On Fri, 8 Feb 2013, Richard M. Heiberger wrote:


require(vcd)
mosaic(matrix(1:6, 2, 3), gp=gpar(fill=c(red,gray,blue)),
main=three
colors in each row)
mosaic(matrix(1:3, 1, 3), gp=gpar(fill=c(red,gray,blue)),
main=only
one color in each row)
I anticipated three colors in the second plot.  My guess is that there
is a matrix subscript without drop=FALSE somewhere on the inside of
one of the functions.


No, it's more subtle.

If the dimension of the data (1, 3) is not the same as that of the fill
(NULL), they are recycled along the last dimension (see Section 3 of
vignette(strucplot, package = vcd)). Thus supplying a suitable fill
matrix works:

mosaic(matrix(1:3, 1, 3),
   gp = gpar(fill=matrix(c(red,gray,blue), 1, 3)))

David: The reason why Rich's original code does not work properly is
that the recycling is not triggered properly. In line 160 of strucplot.R
we check if(length(par)  size) which is not the case here and hence the
dimension is not added. I think we could do

if (length(par)  size | is.null(dim(par)))
   aperm(array(par, dim = rev(d))) else par

That fixes the problem.

Best,
Z


This is with
Package: vcd
Version: 1.2-13
Date: 2012-02-19

on
version.string R Under development (unstable) (2013-02-02 r61822)
platform   i386-w64-mingw32
arch   i386
os mingw32
system i386, mingw32

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.







--
Priv.-Doz. Dr. David Meyer
Department of Information Systems and Operations

WU
Wirtschaftsuniversität Wien
Vienna University of Economics and Business
Augasse 2-6, 1090 Vienna, Austria
Tel: +43-1-313-36-4393
Fax: +43-1-313-36-90-4393
HP:  http://ec.wu.ac.at/~meyer

__
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] convert 12 time stamp to 24 hour

2013-02-08 Thread arun
Hi,
library(lubridate)
 ymd_hms(testtime)
 1 parsed with %Y-%m-%d %I:%M:%S %p
#[1] 2013-01-01 13:00:01 UTC
A.K.




- Original Message -
From: e-letter inp...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Friday, February 8, 2013 4:44 AM
Subject: [R] convert 12 time stamp to 24 hour

Readers,

For a 12 hour time stamp:

 testtime-(2013-01-01 01:00:01 PM)
 testtime
[1] 2013-01-01 01:00:01 PM
 testtime24hour-strftime(testtime,'%H:%M:%S')
 testtime24hour
[1] 01:00:01

how to convert to 24 hour format so that the object 'testtime24hour' is:

'13:00:01'

Thanks.

--
r2151

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] write.table and append

2013-02-08 Thread Brian Smith
Ah, I didn't know this! Thanks Ben.

On Fri, Feb 8, 2013 at 10:18 AM, Ben Tupper btup...@bigelow.org wrote:

 Hi,

 On Feb 8, 2013, at 9:40 AM, Brian Smith wrote:

  Hi,
 
  I am trying to append tables on file with this sample code:
 
 for(i in 1:2){
 mat - data.frame(sample(1:30,9),3,3)
 colnames(mat) - letters[1:3]
 ifelse(i ==
  1,write.table(mat,paste('test.txt',sep=''),row.names=F),
 
 
 write.table(mat,paste('test.txt',sep=''),row.names=F,col.names=F,append=TRUE))
 }
 
  However, this gives an error:
 
  Error in ifelse(i == 1, write.table(mat, paste(test.txt, sep = ),  :
   replacement has length zero
 
  - Should I be passing in some other parameters or using a different
  function to append tables to file?


 You might try assign each parameter based upon the value of i instead of
 trying to manage two different calls to write.table through an ifelse
 function.  ifelse doesn't seem to like the value returned by write.table
 (NULL).  Here's a simply example...

  ok - ifelse( TRUE, NULL, NULL)
 Error in ifelse(TRUE, NULL, NULL) : replacement has length zero
  ok - ifelse( FALSE, NULL, NULL)
 Error in ifelse(FALSE, NULL, NULL) : replacement has length zero

 I think that is what the warning in ?ifelse is alluding to.  You would
 only know that write.table returns NULL if you have bitten by it before.  I
 have bite marks.

 for(i in 1:2){
mat - data.frame(sample(1:30,9),3,3)
colnames(mat) - letters[1:3]
write.table(mat, file = test.txt,
   row.names = FALSE,
   col.names = (i == 1),
   append = (i != 1) )
 }


 Cheers,
 Ben

 
  thanks!
 
[[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.

 Ben Tupper
 Bigelow Laboratory for Ocean Sciences
 60 Bigelow Drive, P.O. Box 380
 East Boothbay, Maine 04544
 http://www.bigelow.org










[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Saving model and other objects from caret

2013-02-08 Thread R. Michael Weylandt
On Thu, Feb 7, 2013 at 9:58 PM, James Jong ribonucle...@gmail.com wrote:
 What are the *RDS counterparts? What is the difference?


apropos(RDS)
? readRDS
? saveRDS

They allow serialization of an individual object and restoring it --
the advantage is that you can restore to a different name instead of
clobbering any pre-existing object with the name under which it was
originally serialized.

MW

__
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 double looping

2013-02-08 Thread christel lacaze

hi there,

I have a dataframe in the shape vA1, vA2,..., vA11, vB1, vB2,..., VB11,..., 
VP1, VP2,, VP11 (so 16 times a sequence of 11 variables)
I am trying to build a double loop so that i can apply the function (i-1)*v(i) 
to the first 10 variables, then the same for the next 10 variables, etc... 16 
times.

I have tried the following with no luck:

iscores-list()
for (j in seq(1,166,11)) 
  {
  for (i in j:(j+10))
{iscores[[i-j+1]]=(i-j)*data[[i-j+1]]
}
  }

any suggestion...?

many thanks,

Christel
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] confidence / prediction ellipse

2013-02-08 Thread David Winsemius

On Feb 7, 2013, at 8:20 AM, Giuseppe Amatulli wrote:

 Hi Rolf,
 sorry for this late answer and thanks for your kind explanation and
 relative R code. I really appreciate.
 In reality the concept that I'm trying to address is a bit more complex.
 I'm fitting a model y vs 6 predictors with MARS / RandomForest /
 Multiple Linear Regression Models having 140 observations.
 I have the prediction of each model and would like to delineate the
 prediction ellipses for 3 models, for the 95% probability, and
 plotting them together with the observation vs prediction.
 I think that the prediction-ellipses code that you provide to me is
 valid also for predictions derived by not-linear model (such as MARS
 and RF).
 Is it correct? or should i use an alternative solution ?

Well, if a method provides a probability estimate or even if it only provides a 
rankable order,  could always use color change to highlight the the most 
predicted 95%. I say most predicted rather than most probable, since it's 
not clear that these are probability or credibility estimates.

 
 Moreover, I was expecting that the  abline (lm(b,a)) would be
 correspond to the main axis of the prediction ellipse, but is not this
 the case.
 why?

Presumably you meant lm(b~a)? You might have also expected ( ... also 
incorrectly) that the line for lm(a~b) would be along the major axis. Perhaps 
reading some material on orthogonal regression (AKA total least squares 
regression, AKA Deming regression) would be of interest. The major axis should 
split the difference between those two estimates.

-- 
David
 
 Thanks in advance
 Giuseppe
 
 On 28 January 2013 19:04, Rolf Turner rolf.tur...@xtra.co.nz wrote:
 
 I believe that the value of radius that you are using is incorrect. If you
 have a data
 matrix X whose columns  are jointly distributed N(mu,Sigma) then a
 confidence
 ellipse for mu is determined by
 
n * (x - Xbar)' S^{-1}(x - Xbar) ~ T^2
 
 where Xbar is the mean vector for X and S is the sample covariance matrix,
 and where T^2 means Hotelling's T-squared distribution, which is equal to
 
(n-1)*2/(n-2) * F_{2,n-2}
 
 the latter representing the F distribution on 2 and n-2 degrees of freedom.
 
 Thus (I think) your radius should be
 
radius - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2)))
 
 where npts - length(a).  Note that it is qf(0.95,2,npts-2) and *NOT*
 qf(0.95,2,npts-1).
 
 To get the corresponding *prediction* ellipse simply multiply the foregoing
 radius by sqrt(npts+1).  By prediction ellipse I mean an ellipse such that
 the probability that a new independent observation from the same population
 will fall in that ellipse is the given probability (e.g. 0.95). Note that
 this does
 not mean that 95% of the data will fall in the calculated ellipse (basically
 because
 of the *dependence* between S and the individual observations).
 
 These confidence and prediction ellipses are (I'm pretty sure) valid under
 the assumption that the data are (two dimensional, independent) Gaussian,
 and that you use the sample covariance and sample mean as shape and
 centre.  I don't know what impact your robustification procedure of using
 cov.trob() will/would have on the properties of these ellipses.
 
 A script which does the ellipses for your toy data, using the sample
 covariance
 and sample mean (rather than output from cov.trob()) is as follows:
 
 #
 # Script scr.amatulli
 #
 
 require(car)
 a - c(12,12,4,5,63,63,23)
 b - c(13,15,7,10,73,83,43)
 npts   - length(a)
 shape  - var(cbind(a, b))
 center - c(mean(a),mean(b))
 rconf  - sqrt(2 * (npts-1) * qf(0.95, 2, npts-2)/(npts*(npts-2)))
 rpred  - sqrt(npts+1)*rconf
 
 conf.elip - ellipse(center, shape, rconf,draw = FALSE)
 pred.elip - ellipse(center, shape, rpred,draw = FALSE)
 plot(pred.elip, type='l')
 points(a,b)
 lines(conf.elip,col=red)
 
cheers,
 
Rolf Turner
 
 
 On 01/27/2013 10:12 AM, Giuseppe Amatulli wrote:
 
 Hi,
 I'm using the R library(car) to draw confidence/prediction ellipses in a
 scatterplot.
 From what i understood  the ellipse() function return an ellipse based
 parameters:  shape, center,  radius .
 If i read  dataEllipse() function i can see how these parameters are
 calculated for a confidence ellipse.
 
 ibrary(car)
 
 a=c(12,12,4,5,63,63,23)
 b=c(13,15,7,10,73,83,43)
 
 v - cov.trob(cbind(a, b))
 shape - v$cov
 center - v$center
 
 radius - sqrt(2 * qf(0.95, 2, length(a) - 1))   # radius - sqrt(dfn *
 qf(level, dfn, dfd))
 
 conf.elip = ellipse(center, shape, radius,draw = F)
 plot(conf.elip, type='l')
 points(a,b)
 
 My question is how I can calculate shape, center and radius  to obtain a
 prediction ellipses rather than a confidence ellipse?
 Thanks in Advance
 Giuseppe
 
 
 
 
 
 --
 Giuseppe Amatulli
 Web: www.spatial-ecology.net
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 

[R] aggregation-type question

2013-02-08 Thread carslaw
I seem to have a Friday afternoon block and can't see the easiest way of
doing this.

Given a data frame like:

dat - data.frame(x = runif(100), y = runif(100), group = rep(letters[1:10],
each = 10))
 head(dat)
x y group
1 0.876751503 0.6518345 a
2 0.627067150 0.8801790 a
3 0.632465192 0.1768305 a
4 0.060359554 0.8835652 a
5 0.675868776 0.7721177 a
6 0.008465241 0.5046486 a

I want to work out cor(x, y) by group, so in this case ending up with 10
correlation coefficients by group.

I'm not seeing a straightforward solution and I'd appreciate your help.

Thanks

David



--
View this message in context: 
http://r.789695.n4.nabble.com/aggregation-type-question-tp4657966.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] add data symbol to axis label

2013-02-08 Thread David Winsemius

On Feb 8, 2013, at 3:53 AM, e-letter wrote:

 Readers,
 
 Is it possible to add a data symbol (e.g. pch='21') to an axis label?
 The objective is to plot a graph with two (2) y-axes and the plotting
 character for data set 1 is added to the label of y1 axis (left); plot
 character for data set 2 is added to label of y2 (right) axis.
 
There are par settings in base graphics that allow plotting outside the user 
plot area. My memory is saying this might be xpd but you ought to review the 
help file for par().

 
-- 

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to debug the C programs associated with R-packages?

2013-02-08 Thread David Winsemius

On Feb 8, 2013, at 5:13 AM, Pulkit Mehrotra wrote:

 hello,
 
 I was having some problems in debugging C codes assocaited with R-packages.
 I don't have much experience with debugging tools used in C language. Is
 there any methods similar to R-debugging tools such as browser  ,debug etc
 which can be used to debug such C files.
 
 I was using the foreign package and found a bug in reading dta files
 containing empty strings  in the data. I was able to find where the error
 originated in the R file but was unable to do so for the C files.

You could report the bug on r-devel, but they are going to expect a description 
and code that demonstrates that there is a bug. The preferred practice is to 
ask on R-devel rather than submitting a bug report immediately. That's also the 
proper mailing list  for asking questions about C-level programming concerns.

-- 

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with double looping

2013-02-08 Thread Rui Barradas

Hello,

Maybe seq(1, 16*11, 11)? (16*11 is 176, not 166)


Hope this helps,

Rui Barradas

Em 08-02-2013 16:03, christel lacaze escreveu:


hi there,

I have a dataframe in the shape vA1, vA2,..., vA11, vB1, vB2,..., VB11,..., 
VP1, VP2,, VP11 (so 16 times a sequence of 11 variables)
I am trying to build a double loop so that i can apply the function (i-1)*v(i) 
to the first 10 variables, then the same for the next 10 variables, etc... 16 
times.

I have tried the following with no luck:

iscores-list()
for (j in seq(1,166,11))
   {
   for (i in j:(j+10))
 {iscores[[i-j+1]]=(i-j)*data[[i-j+1]]
 }
   }

any suggestion...?

many thanks,

Christel

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Border width on symbols plotted with the lattice package

2013-02-08 Thread ilai
Like this ?
xyplot(4:5~4:5, groups=4:5, lex = 5 ,
par.settings = simpleTheme(cex=10, pch=21, lwd=5),
auto.key=TRUE)



On Fri, Feb 8, 2013 at 6:46 AM, Karl Ove Hufthammer k...@huftis.org wrote:

 Dear list members,

 I can't figure out how get 'xyplot' or 'dotplot' in the 'lattice' package
 to respect the 'lwd' value for specifying the border with for *symbols*
 (for lines it works fine). Example:

 -
 # Base graphics works fine (gives a 'fat’ circle)
 plot(5, cex=10, pch=21, lwd=10)

 # But 'xyplot' or 'dotplot' doesn't
 library(lattice)
 xyplot(4:5~4:5, groups=4:5, par.settings = simpleTheme(cex=10, pch=21,
 lwd=5),
 auto.key=TRUE)
 -

 For 'xyplot' or 'dotplot' the border stays thin no matter what I set 'lwd'
 to. However, the symbols shown in the *legend* has the 'lwd' correctly
 applied.

 How can I fix this? Or is it simply a bug in the 'lattice' package?


 Karl Ove Hufthammer



 Output of 'sessionInfo()':

 R version 2.15.2 (2012-10-26)
 Platform: x86_64-w64-mingw32/x64 (64-bit)

 locale:
 [1] LC_COLLATE=Norwegian-Nynorsk_**Norway.1252
 [2] LC_CTYPE=Norwegian-Nynorsk_**Norway.1252
 [3] LC_MONETARY=Norwegian-Nynorsk_**Norway.1252
 [4] LC_NUMERIC=C
 [5] LC_TIME=Norwegian-Nynorsk_**Norway.1252

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

 other attached packages:
 [1] lattice_0.20-13

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

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Border width on symbols plotted with the lattice package

2013-02-08 Thread David Winsemius

On Feb 8, 2013, at 5:46 AM, Karl Ove Hufthammer wrote:

 Dear list members,
 
 I can't figure out how get 'xyplot' or 'dotplot' in the 'lattice' package to 
 respect the 'lwd' value for specifying the border with for *symbols* (for 
 lines it works fine). Example:
 
 -
 # Base graphics works fine (gives a 'fat’ circle)
 plot(5, cex=10, pch=21, lwd=10)
 
 # But 'xyplot' or 'dotplot' doesn't
 library(lattice)
 xyplot(4:5~4:5, groups=4:5, par.settings = simpleTheme(cex=10, pch=21, lwd=5),
auto.key=TRUE)
 -
 
 For 'xyplot' or 'dotplot' the border stays thin no matter what I set 'lwd' 
 to. However, the symbols shown in the *legend* has the 'lwd' correctly 
 applied.
 
 How can I fix this? Or is it simply a bug in the 'lattice' package?

The grid.points function can accept a lwd argument:

xyplot(4:5~4:5, groups=4:5, panel=function(x,y,groups,...){ 
   panel.xyplot(x,y,...,col='white')
grid.points(x,y, gp=gpar(cex=10, lwd=7) ) },
auto.key=TRUE)

This probably means there is a less hackish way of setting the lwd.points, but 
I don't find it in my sequesntial following through the lattice help pages.

-- 
David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with double looping

2013-02-08 Thread christel lacaze

that doesn't seem to be the issue i'm afraid... both j sequences produce the 
same numbers:

 j-seq(1,166,11)
 j
 [1]   1  12  23  34  45  56  67  78  89 100 111 122 133 144 155 166
 j-seq(1,176,11)
 j
 [1]   1  12  23  34  45  56  67  78  89 100 111 122 133 144 155 166

 Date: Fri, 8 Feb 2013 16:37:52 +
 From: ruipbarra...@sapo.pt
 To: christellac...@hotmail.co.uk
 CC: r-help@r-project.org
 Subject: Re: [R] help with double looping
 
 Hello,
 
 Maybe seq(1, 16*11, 11)? (16*11 is 176, not 166)
 
 
 Hope this helps,
 
 Rui Barradas
 
 Em 08-02-2013 16:03, christel lacaze escreveu:
 
  hi there,
 
  I have a dataframe in the shape vA1, vA2,..., vA11, vB1, vB2,..., 
  VB11,..., VP1, VP2,, VP11 (so 16 times a sequence of 11 variables)
  I am trying to build a double loop so that i can apply the function 
  (i-1)*v(i) to the first 10 variables, then the same for the next 10 
  variables, etc... 16 times.
 
  I have tried the following with no luck:
 
  iscores-list()
  for (j in seq(1,166,11))
 {
 for (i in j:(j+10))
   {iscores[[i-j+1]]=(i-j)*data[[i-j+1]]
   }
 }
 
  any suggestion...?
 
  many thanks,
 
  Christel
  
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Border width on symbols plotted with the lattice package

2013-02-08 Thread David Winsemius

On Feb 8, 2013, at 8:55 AM, ilai wrote:

 Like this ?
 xyplot(4:5~4:5, groups=4:5, lex = 5 ,
 par.settings = simpleTheme(cex=10, pch=21, lwd=5),
 auto.key=TRUE)
 

And if I had used a more general search strategy I might have found it, too, 
rather than hacking my way to a less adequate solution; less adequate in the 
sense of no supporting a proper coloring of points.

http://markmail.org/search/?q=list%3Aorg.r-project.r-help+xyplot+points++lwd

On the other hand this solution has possibly undesireable effects on the key 
symbols.

-- 
 
 
 On Fri, Feb 8, 2013 at 6:46 AM, Karl Ove Hufthammer k...@huftis.org wrote:
 
 Dear list members,
 
 I can't figure out how get 'xyplot' or 'dotplot' in the 'lattice' package
 to respect the 'lwd' value for specifying the border with for *symbols*
 (for lines it works fine). Example:
 
 -
 # Base graphics works fine (gives a 'fat‚ circle)
 plot(5, cex=10, pch=21, lwd=10)
 
 # But 'xyplot' or 'dotplot' doesn't
 library(lattice)
 xyplot(4:5~4:5, groups=4:5, par.settings = simpleTheme(cex=10, pch=21,
 lwd=5),
auto.key=TRUE)
 -
 
 For 'xyplot' or 'dotplot' the border stays thin no matter what I set 'lwd'
 to. However, the symbols shown in the *legend* has the 'lwd' correctly
 applied.
 
 How can I fix this? Or is it simply a bug in the 'lattice' package?
 
 
 Karl Ove Hufthammer
 
 
 
 Output of 'sessionInfo()':
 
 R version 2.15.2 (2012-10-26)
 Platform: x86_64-w64-mingw32/x64 (64-bit)
 
 locale:
 [1] LC_COLLATE=Norwegian-Nynorsk_**Norway.1252
 [2] LC_CTYPE=Norwegian-Nynorsk_**Norway.1252
 [3] LC_MONETARY=Norwegian-Nynorsk_**Norway.1252
 [4] LC_NUMERIC=C
 [5] LC_TIME=Norwegian-Nynorsk_**Norway.1252
 
 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base
 
 other attached packages:
 [1] lattice_0.20-13
 
 loaded via a namespace (and not attached):
 [1] grid_2.15.2  tools_2.15.2
 
 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Border width on symbols plotted with the lattice package

2013-02-08 Thread ilai
On Fri, Feb 8, 2013 at 10:14 AM, David Winsemius dwinsem...@comcast.netwrote:


 On Feb 8, 2013, at 8:55 AM, ilai wrote:

  Like this ?
  xyplot(4:5~4:5, groups=4:5, lex = 5 ,
  par.settings = simpleTheme(cex=10, pch=21, lwd=5),
  auto.key=TRUE)
 

 And if I had used a more general search strategy I might have found it,
 too, rather than hacking my way to a less adequate solution; less adequate
 in the sense of no supporting a proper coloring of points.


 http://markmail.org/search/?q=list%3Aorg.r-project.r-help+xyplot+points++lwd

 On the other hand this solution has possibly undesireable effects on the
 key symbols.


Not sure I follow you, but lex (among others) is described in ?grid::gpar
which indeed may not be pointed to by lattice docs - took the hint from an
old posting myself.



 --
 
 
  On Fri, Feb 8, 2013 at 6:46 AM, Karl Ove Hufthammer k...@huftis.org
 wrote:
 
  Dear list members,
 
  I can't figure out how get 'xyplot' or 'dotplot' in the 'lattice'
 package
  to respect the 'lwd' value for specifying the border with for *symbols*
  (for lines it works fine). Example:
 
  -
  # Base graphics works fine (gives a 'fat‚ circle)
  plot(5, cex=10, pch=21, lwd=10)
 
  # But 'xyplot' or 'dotplot' doesn't
  library(lattice)
  xyplot(4:5~4:5, groups=4:5, par.settings = simpleTheme(cex=10, pch=21,
  lwd=5),
 auto.key=TRUE)
  -
 
  For 'xyplot' or 'dotplot' the border stays thin no matter what I set
 'lwd'
  to. However, the symbols shown in the *legend* has the 'lwd' correctly
  applied.
 
  How can I fix this? Or is it simply a bug in the 'lattice' package?
 
 
  Karl Ove Hufthammer
 
 
 
  Output of 'sessionInfo()':
 
  R version 2.15.2 (2012-10-26)
  Platform: x86_64-w64-mingw32/x64 (64-bit)
 
  locale:
  [1] LC_COLLATE=Norwegian-Nynorsk_**Norway.1252
  [2] LC_CTYPE=Norwegian-Nynorsk_**Norway.1252
  [3] LC_MONETARY=Norwegian-Nynorsk_**Norway.1252
  [4] LC_NUMERIC=C
  [5] LC_TIME=Norwegian-Nynorsk_**Norway.1252
 
  attached base packages:
  [1] stats graphics  grDevices utils datasets  methods   base
 
  other attached packages:
  [1] lattice_0.20-13
 
  loaded via a namespace (and not attached):
  [1] grid_2.15.2  tools_2.15.2
 
  __**
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/**listinfo/r-help
 https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/**
  posting-guide.html http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
[[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.

 David Winsemius
 Alameda, CA, USA



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] setting off-diagonals to zero

2013-02-08 Thread Morway, Eric
useRs,

Using a code suggestion from the previous post in this thread (quoted
next), I was able to work through a smaller example problem and get some
results I was aiming for.

That might not construct the bands in the blocks correctly: This might
be better:

MAT [ kronecker( matrix(1, 4,4), abs( col(Mat)-row(Mat) )  5,
FUN= ) ] - 0

With this working example in hand, I tried applying the R code to the larger
problem but ran into 'allocate' error.  The small working example (next) is
followed by the larger problem that kicks back an error message.  I'm
hopeful someone may know of a work-around for avoiding the allocate error?

##Small example
Mat - matrix( 1:(4*4), 4, 4)
test - rbind(Mat, Mat)
test2- cbind(test,test)
#test2 is a 8x8 matrix with 4 4x4 sub-matrices

#The following preserves the diagonal bands I want to keep (has TRUE where
desired)
edm-!kronecker( matrix(1, 4,4), abs( col(Mat)-row(Mat) )  1, FUN= )

#However, the size was doubled in the above, so here I keep only that portion
that is the same size as test2
edm-edm[1:8,1:8]

#The following retains the values I'm interested in.
test3-ifelse(edm,test2,0)

##Repeat the process on the larger problem which contains 16 365 x 365
submatrices
Mat - matrix( 1:(365*365), 365, 365)
test - rbind(Mat, Mat, Mat, Mat)
test2- cbind(test,test,test,test)

edm-!kronecker( matrix(1, 365,365), abs( col(Mat)-row(Mat) )  1, FUN= )
#Error: cannot allocate vector of size 4.2 Gb
edm-edm[1:1460,1:1460]

Is there a way around this?

Thanks, Eric

On Wed, Jan 23, 2013 at 11:32 PM, David Winsemius dwinsem...@comcast.netwrote:


 On Jan 23, 2013, at 5:31 PM, David Winsemius wrote:


 On Jan 23, 2013, at 7:13 AM, emorway wrote:

  The following 1460 x 1460 matrix can be throught of as 16 distinct 365 x
 365
 matrices.  I'm trying to set off-diaganol terms in the 16 sub-matrices
 with
 indices more than +/- 5 (days) from each other to zero using some for
 loops.
 This works well for some, but not all, of the for loops.  The R code Im
 using follows.  For some reason the third loop below zero's-out
 everything
 in the sub-quadrant it is targeting, which is readily observable when
 viewing the matrix (View(MAT)).

 library(Matrix)
 MAT-matrix(rnorm(1460*1460,**mean=0,sd=1),nrow = 1460, ncol = 1460)


 The way to do that in a single 365 x 365 matrix is:

 Mat - matrix( 1:(365*365), 365, 365)
 Mat[ abs( col(Mat)-row(Mat) )  5 ] - 0
 Mat

 The way to propagate that pattern is to use rep(), so here is a one-liner
 for the task:

 MAT[ rep( abs( col(Mat)-row(Mat) )  5, 16) ] - 0


 That might not construct the bands in the blocks correctly: This might be
 better:

 MAT [ kronecker( matrix(1, 4,4), abs( col(Mat)-row(Mat) )  5, FUN= ) ]
 - 0

 --
 David.



 Didn't test on you gigantuan matrix;  used smaller example:

 Mat - matrix( 1:(16*16), 16, 16)
 test - rbind(Mat, Mat)
 test[rep( abs( col(Mat)-row(Mat) )  2 , 2)] - 0
 test

 --
 David.


  #works great
 for (i in 1:365) {
 SEQ - (i - 5):(i + 5)
 SEQ - SEQ[SEQ  0  SEQ  366]
 MAT[(1:365)[-SEQ], i] - 0
 }

 #works great
 for (i in 1:365) {
 SEQ - (i - 5):(i + 5)
 SEQ - SEQ[SEQ  0  SEQ  366]
 MAT[(1:365)[-SEQ], i + 365] - 0
 }

 #zero's out everything, including main-diagonal and near-main-diagonal
 terms???
 for (i in 731:1095) {
 SEQ - (i - 5):(i + 5)
 SEQ - SEQ[SEQ  730  SEQ  1096]
 MAT[(731:1095)[-SEQ], i + 365] - 0
 }

 View(MAT)

 I'm not sure why the third FOR loop above is not leaving the
 main-diagonal
 and near-main-diagonal terms alone?



 --
 View this message in context: http://r.789695.n4.nabble.com/**
 setting-off-diagonals-to-zero-**tp4656407.htmlhttp://r.789695.n4.nabble.com/setting-off-diagonals-to-zero-tp4656407.html
 Sent from the R help mailing list archive at Nabble.com.

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 David Winsemius
 Alameda, CA, USA

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 David Winsemius, MD
 Alameda, CA, USA



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to debug the C programs associated with R-packages?

2013-02-08 Thread Martin Morgan

On 02/08/2013 05:13 AM, Pulkit Mehrotra wrote:

hello,

I was having some problems in debugging C codes assocaited with R-packages.
I don't have much experience with debugging tools used in C language. Is
there any methods similar to R-debugging tools such as browser  ,debug etc
which can be used to debug such C files.

I was using the foreign package and found a bug in reading dta files
containing empty strings  in the data. I was able to find where the error
originated in the R file but was unable to do so for the C files.

Any help would be deeply appreciated.

Thank you for your time and consideration.


For debugging package code at the C level, one usually starts (on non-Windows) 
by installing the package without any compiler optimizations, e.g., by following


  RShowDoc(R-admin)

section 6.3.3. setting for instance

  CFLAGS=-g -O0

in .R/Makevars.

Then when the bug is isolated and easily produced in a script buggy.R start R 
with a C-level debugger such as gdb (this is an old-school command-line style 
debugger, not to everyone's taste)


  R -d gdb -f buggy.R

You'll end up at the gdb prompt

  gdb

and a typical operation is to (r)un or (c)ontinue execution

  gdb r

to run buggy.R. You'll end up back in C when there is a segfault, or you press 
cntrl-C, or when you've inserted a breakpoint at some C-level function that you 
suspect is buggy, e.g.,


   ^C
  gdb b some_buggy_fun
  gdb c

When you do end up back in the debugger, you can print C variables or the C 
representation of R variables


  gdb p c_var
  gdb call Rf_PrintValue(some_R_variable)

go (u)p and (d)own the call stack, etc. See

  gdb help

and of course our mutual friend Google.

But this is not for the faint of heart and requires some C-level familiarity. It 
might also be possible to spot the bug with


  R -d valgrind -f buggy.R

which runs quite slowly and will also require C familiarity to interpret output. 
Again it is helpful to run the buggy code with a package that has been installed 
without compiler optimizations. See section 4.3 of RShowDoc(R-exts)


Good luck!

Martin



with regards,
Pulkit Mehrotra

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




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

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] aggregation-type question

2013-02-08 Thread John Kane
I seem to be suffering from the same problem (the Friday one, not the cor one) 

Have a look at 
http://stats.stackexchange.com/questions/4040/r-compute-correlation-by-group 
for something that looks like it will work

John Kane
Kingston ON Canada


 -Original Message-
 From: david.cars...@kcl.ac.uk
 Sent: Fri, 8 Feb 2013 08:33:45 -0800 (PST)
 To: r-help@r-project.org
 Subject: [R] aggregation-type question
 
 I seem to have a Friday afternoon block and can't see the easiest way of
 doing this.
 
 Given a data frame like:
 
 dat - data.frame(x = runif(100), y = runif(100), group =
 rep(letters[1:10],
 each = 10))
 head(dat)
 x y group
 1 0.876751503 0.6518345 a
 2 0.627067150 0.8801790 a
 3 0.632465192 0.1768305 a
 4 0.060359554 0.8835652 a
 5 0.675868776 0.7721177 a
 6 0.008465241 0.5046486 a
 
 I want to work out cor(x, y) by group, so in this case ending up with 10
 correlation coefficients by group.
 
 I'm not seeing a straightforward solution and I'd appreciate your help.
 
 Thanks
 
 David
 
 
 
 --
 View this message in context:
 http://r.789695.n4.nabble.com/aggregation-type-question-tp4657966.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] simple pdf font embedding example for Bera

2013-02-08 Thread ivo welch
I wanted to put a short example into the r-help archives how to embed
the Bera (texlive) font.

options(texlive= /usr/local/texlive/2012/)
options(texfonts= paste0(getOption(texlive), /texmf-dist/fonts/))
library(grDevices)
pdfFonts(Bera = Type1Font(Bera, paste0(getOption(texfonts),
afm/public/bera/, c(fvsr8a,fvsb8a,fvsro8a,fvsbo8a),
.afm)))
options(pfbdir = c(paste0(getOption(texfonts), type1/public/bera/)))

and now

pdf(file=test.pdf, family=Bera)
plot(1:10, 1:10)
dev.off()
embedFonts( file= test.pdf, fontpaths = getOption(pfbdir) )

it would be more elegant if pdf() could take fontpaths that the
subsequent embedFonts needs and the dev.off would execute embedFonts
automatically on dev.off; and/or if pdfFonts could take an optional
.pfbdir that embedFonts would search.  but this is pretty painless
already as is, esp to how it was 5 years ago.  thanks to all the folks
that put in the hard work to make this possible.

[PS: The above may be incorrect in terms of encoding, dingbats
(symbols), or other issues.  I just checked that the basics worked.]

regards,

/iaw

Ivo Welch (ivo.we...@gmail.com)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Can not melt data.frame

2013-02-08 Thread John Kane
I realize it's -12C and we're having the next best thing to a blizzard but why  
can I not melt this data frame.

I am missing something terribly obvious but I just don't understand what the 
error message is saying.

John Kane
Kingston ON Canada

Code and aata below
 ##
  library(reshape2)
  melt(mydata, id.vars = c(date))
 ##

##DATA
mydata  -  structure(list(date = structure(list(sec = c(0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L), hour = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), mday = c(20L, 23L, 24L, 25L, 
26L, 27L, 30L, 31L, 1L, 2L, 3L, 6L, 7L, 8L, 9L, 10L, 13L, 14L, 
15L, 16L), mon = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), year = c(112L, 112L, 112L, 
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 
112L, 112L, 112L, 112L, 112L, 112L), wday = c(5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L
), yday = c(19L, 22L, 23L, 24L, 25L, 26L, 29L, 30L, 31L, 32L, 
33L, 36L, 37L, 38L, 39L, 40L, 43L, 44L, 45L, 46L), isdst = c(0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L)), .Names = c(sec, min, hour, mday, mon, 
year, wday, yday, isdst), class = c(POSIXlt, POSIXt
)), open = c(36.445, 35.087, 34.859, 35.89, 36.544, 37.08, 36.336, 
36.842, 36.961, 36.505, 36.911, 36.435, 37.139, 36.961, 36.921, 
36.098, 36.326, 35.781, 35.404, 34.908), high = c(36.693, 35.206, 
36.386, 36.197, 37.06, 37.427, 36.495, 37.635, 37.06, 36.604, 
36.911, 37.09, 37.189, 37.189, 36.921, 36.197, 36.376, 35.9, 
35.86, 35.503), low = c(35.305, 34.313, 34.531, 35.007, 35.702, 
36.663, 35.702, 35.989, 36.306, 35.821, 36.257, 36.098, 36.118, 
36.316, 36.207, 35.523, 35.483, 35.027, 34.839, 34.541), close = c(35.9, 
35.146, 36.059, 36.108, 35.86, 36.792, 36.366, 36.475, 36.336, 
36.237, 36.525, 37.09, 36.693, 36.713, 36.465, 35.761, 35.84, 
35.404, 34.938, 35.345), x10d.sma = c(34.912, 34.958, 35.055, 
35.063, 35.14, 35.375, 35.646, 35.936, 36.099, 36.128, 36.19, 
36.385, 36.448, 36.509, 36.569, 36.466, 36.414, 36.306, 36.167, 
36.077), x50d.sma = c(34.438, 34.373, 34.373, 34.357, 34.311, 
34.284, 34.242, 34.2, 34.194, 34.207, 34.248, 34.323, 34.419, 
34.525, 34.605, 34.655, 34.642, 34.628, 34.601, 34.574), x200d.sma = c(41.622, 
41.559, 41.502, 41.445, 41.393, 41.354, 41.311, 41.266, 41.217, 
41.166, 41.107, 41.048, 40.983, 40.917, 40.848, 40.778, 40.709, 
40.638, 40.571, 40.512)), .Names = c(date, open, high, 
low, close, x10d.sma, x50d.sma, x200d.sma), row.names = c(NA, 
-20L), class = data.frame)
###

sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_CA.UTF-8   LC_NUMERIC=C   LC_TIME=en_CA.UTF-8  
 
 [4] LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8
LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=C LC_NAME=C  LC_ADDRESS=C 
 
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C  
 

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

other attached packages:
 [1] lubridate_1.2.0directlabels_2.9   RColorBrewer_1.0-5 gridExtra_0.9.1   
 [5] stringr_0.6.2  scales_0.2.3   plyr_1.8   reshape2_1.2.2
 [9] ggplot2_0.9.3  quantmod_0.4-0 TTR_0.21-1 xts_0.9-3 
[13] zoo_1.7-9  Defaults_1.1-1

loaded via a namespace (and not attached):
 [1] colorspace_1.2-1 dichromat_2.0-0  digest_0.6.2 gtable_0.1.2 
labeling_0.1
 [6] lattice_0.20-13  MASS_7.3-23  munsell_0.4  proto_0.3-10 
tools_2.15.2


TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if5
Capture screenshots, upload images, edit and send them to your friends
through IMs, post on Twitter®, Facebook®, MySpace™, LinkedIn® – FAST!

__
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] how to extract test for collinearity and constantcy used in lda

2013-02-08 Thread David Romano
Just posting to answer my own question, at least for the variables
constant error:  I hadn't noticed that lda has an argument called 'tol'
that governs when variables are interpreted as constant within groups; it's
right there in the help entry for lda, so I apologize for having missed
it.As to the variables collinear warning,  it's still not clear to me
what level of correlation will trigger it.

My apologies,
David

On Wed, Feb 6, 2013 at 12:21 PM, David Romano drom...@stanford.edu wrote:

 Hi everyone,

 I'm trying to vectorize an application of lda to each 2D slice of a 3D
 array, but am running into trouble:  It seems there are quite a few 2D
 slices that trigger either the variables are collinear warning, or worse,
 trigger a variable appears to be constant within groups error and fails
 (i.e., ceases computation rather than skips bad slice).

 There are cases where neither warning is literally true, so I expect the
 warning and error must be triggered in a neighborhood of collinearity and
 within-group-constancy, and I would like to be able to remove the offending
 slice in advance.   Does anyone know where I can find the explicit tests
 that are used for these?

 Thanks in advance for any light you can help shed on this question.

 Best,
 David

 P.S.  The 3D array has roughly 40K 2D slices, so inspection is not an
 option!


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] The use of R Commander for beginning students and newbies

2013-02-08 Thread John Fox
Dear Tom,

As you can imagine, I watched your video with interest and found it quite
impressive. I do have a couple of comments and a question.

The comments: You change a numeric ID variable into a factor with several
thousand levels. I think that it would be more natural and efficient to
assign the ID variable as the row names of the data set, which you can do
via Data - Active data set - Set case names. I also noticed that you run
the Rcmdr from the RGUI MDI (multiple-document interface). This works better
than it used to, but I think that it's still preferable to use the SDI
(single-document interface).

The question: You alluded repeatedly to the necessity to close the R
graphics-device window after each plot in order not to have the plots pile
up on each other (a paraphrase, but I think close to what you said). I'm
not sure what you mean. In most cases, a new plot should just replace the
previous one in the graphics-device window, unless you've turned plot
recording on, in which case you should be able to page between plots. I've
never had any trouble in either case, and am interested to learn what the
problem is.

Best,
 John

---
John Fox
Senator McMaster Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Dr. Thomas W. MacFarland
 Sent: Thursday, February 07, 2013 3:25 PM
 To: r-help@r-project.org
 Subject: [R] The use of R Commander for beginning students and newbies
 
 Everyone:
 
 
 
 In the last few months I've noticed an increasing number of questions to
 this list from students who are new to the use of R and who have limited
 (in
 any) local support on R and specifically support for R syntax.
 
 
 
 My text
 (http://www.springer.com/statistics/social+sciences+%26+law/book/978-1-
 4614-
 2133-7) from last year was specific to the use of R syntax but given
 recent
 feedback I see that perhaps those of us who teach beginning students
 need to
 give a bit more attention to R Commander and/or other GUIs, to help
 students
 build on their confidence so that we can start them out with some
 immediately successful outcomes.  Then, with experience we can move them
 over to the use of R syntax, which is certainly far more robust.
 
 
 
 For beginning students, newbies, and any others who may be interested,
 I've
 opened for guest access an Elluminate-Blackboard video on the use of R
 Commander.  The URL follows and a password is not required:
 
 
 
 https://mako.nova.edu/webapps/bb-collaborate-
 bb_bb60/guest.recording.launch.
 event?uid=476978d4-00c4-488e-98a3-495201e17f5f
 
 
 
 The full video is about 1 hour and 20 minutes.  You can make the active
 screen (right side of the screen) larger by moving it around, minimizing
 the
 status column (left side of the screen).
 
 
 
 Best wishes.
 
 
 
 Tom MacFarland
 
 
 
 --
 
 Thomas W. MacFarland, Ed.D.
 
 Senior Research Associate; Institutional Effectiveness and Associate
 Professor
 
 Nova Southeastern University
 
 Voice 954-262-5395 tom...@nova.edu
 
 
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] First R package, advice

2013-02-08 Thread Terry Therneau



On 02/07/2013 05:00 AM, r-help-requ...@r-project.org wrote:

I'd argue that there's an important distinction between documenting a
function (how to use it) vs. documenting an algorithm (how it works).
I think noweb can work well for describing how something works, but
it's not so good for describing how to use it
I'm a big fan of noweb for the source code, take a look a the coxme package for extensive 
use of this.  That contains the most complex mathematics of any code I have written, and 
it is a big help to have real equations and discussion mixed in with the code.  The sparse 
matrix algorithms aren't very transparent either so it is a plus on that front too.  A big 
help to me whenever I look back at something.
  That given, I agree with the above that documentation of the algorithm and 
documentation of useage are disjoint tasks.  The pdf file from my noweb source is of 
critical importance to someone changing the code, and of essentially no use to anyone 
else.  Use vignettes for the latter.


 Terry Therneau

__
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] question about reproducibility/consistency of principal component and lda directions in R

2013-02-08 Thread David Romano
Hi everyone,

I'm not exactly sure how to ask this question most clearly, but I hope that
giving the context in which it occurs for me will help:   I'm trying to
compare the brain images of two patient populations; each image is composed
of voxels (the 3D analogue of pixels), and I have two images per patient,
one reflecting grey matter concentration at each voxel, and the other
reflecting white matter concentration at each voxel.

I determined the groups by means of an analysis that involved information
from both types of images, and what I set out to do was to get a rough idea
of where in the brain the two groups showed the most striking differences.

My first attempt was to replace -- on a voxel by voxel basis -- the
bivariate grey/white data by a combined univariate measure, namely the
first principal component score.   From these principal component scores I
calculated Cohen's d to obtain a rough estimate of the effect size at each
voxel, and the resulting brain images show very nice separation into
meaningful brain regions, some corresponding to negative effect sizes and
some to positive ones.

What puzzles me about how nice the separation into brain regions is, is
that the meaning of positive and negative is determined by the choice of
the first principal component direction at each voxel, but this choice is
-- in principle (no pun intended -- sorry!) -- arbitrary.  (Meaning whether
an eigenvector or its negative is chosen as the direction is in principle
arbitrary.)

So here are my questions:   Does the algorithm used in R produce the same
principal component directions if applied to the same data repeatedly?
And if so, should the directions chosen by the algorithm change
continuously with the data?  For example, if one data set were obtained by
applying a small amount of noise to another, should the resulting
directions be close to each other (as opposed to close negative of each
other)?  (Assuming the data is far from being singular in some vague
sense I'm not sure how to make precise.)

My second attempt was to do the same, but with the first lda scores, so I
have the same questions about lda directions, too.

Any light you could shed on these questions would be very welcome!

Thanks in advance,
David Romano

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Can not melt data.frame

2013-02-08 Thread Rui Barradas

Hello,

The id.vars must be integer (variable position) or string (variable 
name) (from the help page ?melt.data.frame)

This seems to work.

myd - mydata
myd$date - as.character(myd$date)
melt(myd, id.vars = c(date))


Hope this helps,

Rui Barradas


Em 08-02-2013 18:31, John Kane escreveu:

I realize it's -12C and we're having the next best thing to a blizzard but why  
can I not melt this data frame.

I am missing something terribly obvious but I just don't understand what the 
error message is saying.

John Kane
Kingston ON Canada

Code and aata below
  ##
   library(reshape2)
   melt(mydata, id.vars = c(date))
  ##

##DATA
mydata  -  structure(list(date = structure(list(sec = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L), hour = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), mday = c(20L, 23L, 24L, 25L,
26L, 27L, 30L, 31L, 1L, 2L, 3L, 6L, 7L, 8L, 9L, 10L, 13L, 14L,
15L, 16L), mon = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), year = c(112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L), wday = c(5L, 1L, 2L, 3L,
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L
), yday = c(19L, 22L, 23L, 24L, 25L, 26L, 29L, 30L, 31L, 32L,
33L, 36L, 37L, 38L, 39L, 40L, 43L, 44L, 45L, 46L), isdst = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L)), .Names = c(sec, min, hour, mday, mon,
year, wday, yday, isdst), class = c(POSIXlt, POSIXt
)), open = c(36.445, 35.087, 34.859, 35.89, 36.544, 37.08, 36.336,
36.842, 36.961, 36.505, 36.911, 36.435, 37.139, 36.961, 36.921,
36.098, 36.326, 35.781, 35.404, 34.908), high = c(36.693, 35.206,
36.386, 36.197, 37.06, 37.427, 36.495, 37.635, 37.06, 36.604,
36.911, 37.09, 37.189, 37.189, 36.921, 36.197, 36.376, 35.9,
35.86, 35.503), low = c(35.305, 34.313, 34.531, 35.007, 35.702,
36.663, 35.702, 35.989, 36.306, 35.821, 36.257, 36.098, 36.118,
36.316, 36.207, 35.523, 35.483, 35.027, 34.839, 34.541), close = c(35.9,
35.146, 36.059, 36.108, 35.86, 36.792, 36.366, 36.475, 36.336,
36.237, 36.525, 37.09, 36.693, 36.713, 36.465, 35.761, 35.84,
35.404, 34.938, 35.345), x10d.sma = c(34.912, 34.958, 35.055,
35.063, 35.14, 35.375, 35.646, 35.936, 36.099, 36.128, 36.19,
36.385, 36.448, 36.509, 36.569, 36.466, 36.414, 36.306, 36.167,
36.077), x50d.sma = c(34.438, 34.373, 34.373, 34.357, 34.311,
34.284, 34.242, 34.2, 34.194, 34.207, 34.248, 34.323, 34.419,
34.525, 34.605, 34.655, 34.642, 34.628, 34.601, 34.574), x200d.sma = c(41.622,
41.559, 41.502, 41.445, 41.393, 41.354, 41.311, 41.266, 41.217,
41.166, 41.107, 41.048, 40.983, 40.917, 40.848, 40.778, 40.709,
40.638, 40.571, 40.512)), .Names = c(date, open, high,
low, close, x10d.sma, x50d.sma, x200d.sma), row.names = c(NA,
-20L), class = data.frame)
###

sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: i686-pc-linux-gnu (32-bit)

locale:
  [1] LC_CTYPE=en_CA.UTF-8   LC_NUMERIC=C   LC_TIME=en_CA.UTF-8
  [4] LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8
LC_MESSAGES=en_CA.UTF-8
  [7] LC_PAPER=C LC_NAME=C  LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
  [1] lubridate_1.2.0directlabels_2.9   RColorBrewer_1.0-5 gridExtra_0.9.1
  [5] stringr_0.6.2  scales_0.2.3   plyr_1.8   reshape2_1.2.2
  [9] ggplot2_0.9.3  quantmod_0.4-0 TTR_0.21-1 xts_0.9-3
[13] zoo_1.7-9  Defaults_1.1-1

loaded via a namespace (and not attached):
  [1] colorspace_1.2-1 dichromat_2.0-0  digest_0.6.2 gtable_0.1.2 
labeling_0.1
  [6] lattice_0.20-13  MASS_7.3-23  munsell_0.4  proto_0.3-10 
tools_2.15.2


TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if5
Capture screenshots, upload images, edit and send them to your friends
through IMs, post on Twitter®, Facebook®, MySpace™, LinkedIn® – FAST!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Add text A, B, C and D on multiple ordered plot

2013-02-08 Thread Fabrice Tourre
Dear list,

Is there a elegant way to name multiple ordered plot as A, B, C and D?
Just put A, B, C and D on the top left corner of each plot.

Usually I do it in Illustrator, but I think in R should there is a way.

Could you please provide a example?

Thank you very much in advance.

__
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] Can not melt data.frame

2013-02-08 Thread Jeff Newmiller
Use POSIXct instead of POSIXlt in data frames in general, and particularly for 
this task.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

John Kane jrkrid...@inbox.com wrote:

I realize it's -12C and we're having the next best thing to a blizzard
but why  can I not melt this data frame.

I am missing something terribly obvious but I just don't understand
what the error message is saying.

John Kane
Kingston ON Canada

Code and aata below
 ##
  library(reshape2)
  melt(mydata, id.vars = c(date))
 ##

##DATA
mydata  -  structure(list(date = structure(list(sec = c(0, 0, 0, 0, 0,
0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L), hour = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), mday = c(20L, 23L, 24L, 25L, 
26L, 27L, 30L, 31L, 1L, 2L, 3L, 6L, 7L, 8L, 9L, 10L, 13L, 14L, 
15L, 16L), mon = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), year = c(112L, 112L, 112L, 
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 
112L, 112L, 112L, 112L, 112L, 112L), wday = c(5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L
), yday = c(19L, 22L, 23L, 24L, 25L, 26L, 29L, 30L, 31L, 32L, 
33L, 36L, 37L, 38L, 39L, 40L, 43L, 44L, 45L, 46L), isdst = c(0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L)), .Names = c(sec, min, hour, mday, mon, 
year, wday, yday, isdst), class = c(POSIXlt, POSIXt
)), open = c(36.445, 35.087, 34.859, 35.89, 36.544, 37.08, 36.336, 
36.842, 36.961, 36.505, 36.911, 36.435, 37.139, 36.961, 36.921, 
36.098, 36.326, 35.781, 35.404, 34.908), high = c(36.693, 35.206, 
36.386, 36.197, 37.06, 37.427, 36.495, 37.635, 37.06, 36.604, 
36.911, 37.09, 37.189, 37.189, 36.921, 36.197, 36.376, 35.9, 
35.86, 35.503), low = c(35.305, 34.313, 34.531, 35.007, 35.702, 
36.663, 35.702, 35.989, 36.306, 35.821, 36.257, 36.098, 36.118, 
36.316, 36.207, 35.523, 35.483, 35.027, 34.839, 34.541), close =
c(35.9, 
35.146, 36.059, 36.108, 35.86, 36.792, 36.366, 36.475, 36.336, 
36.237, 36.525, 37.09, 36.693, 36.713, 36.465, 35.761, 35.84, 
35.404, 34.938, 35.345), x10d.sma = c(34.912, 34.958, 35.055, 
35.063, 35.14, 35.375, 35.646, 35.936, 36.099, 36.128, 36.19, 
36.385, 36.448, 36.509, 36.569, 36.466, 36.414, 36.306, 36.167, 
36.077), x50d.sma = c(34.438, 34.373, 34.373, 34.357, 34.311, 
34.284, 34.242, 34.2, 34.194, 34.207, 34.248, 34.323, 34.419, 
34.525, 34.605, 34.655, 34.642, 34.628, 34.601, 34.574), x200d.sma =
c(41.622, 
41.559, 41.502, 41.445, 41.393, 41.354, 41.311, 41.266, 41.217, 
41.166, 41.107, 41.048, 40.983, 40.917, 40.848, 40.778, 40.709, 
40.638, 40.571, 40.512)), .Names = c(date, open, high, 
low, close, x10d.sma, x50d.sma, x200d.sma), row.names = c(NA,

-20L), class = data.frame)
###

sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: i686-pc-linux-gnu (32-bit)

locale:
[1] LC_CTYPE=en_CA.UTF-8   LC_NUMERIC=C  
LC_TIME=en_CA.UTF-8   
[4] LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8   
LC_MESSAGES=en_CA.UTF-8   
[7] LC_PAPER=C LC_NAME=C  LC_ADDRESS=C 

[10] LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8
LC_IDENTIFICATION=C   

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

other attached packages:
[1] lubridate_1.2.0directlabels_2.9   RColorBrewer_1.0-5
gridExtra_0.9.1   
[5] stringr_0.6.2  scales_0.2.3   plyr_1.8  
reshape2_1.2.2
[9] ggplot2_0.9.3  quantmod_0.4-0 TTR_0.21-1 xts_0.9-3 
   
[13] zoo_1.7-9  Defaults_1.1-1

loaded via a namespace (and not attached):
[1] colorspace_1.2-1 dichromat_2.0-0  digest_0.6.2 gtable_0.1.2
labeling_0.1
[6] lattice_0.20-13  MASS_7.3-23  munsell_0.4  proto_0.3-10
tools_2.15.2


TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if5
Capture screenshots, upload images, edit and send them to your friends
through IMs, post on Twitter®, Facebook®, MySpace™, LinkedIn® – FAST!

__
R-help@r-project.org mailing list

Re: [R] Add text A, B, C and D on multiple ordered plot

2013-02-08 Thread John Kane
Yes there probably is if you would show us what you are doing.
Minimal working code helps.

https://github.com/hadley/devtools/wiki/Reproducibility

John Kane
Kingston ON Canada


 -Original Message-
 From: fabrice.c...@gmail.com
 Sent: Fri, 8 Feb 2013 14:28:17 -0500
 To: r-help@r-project.org
 Subject: [R] Add text A, B, C and D on multiple ordered plot
 
 Dear list,
 
 Is there a elegant way to name multiple ordered plot as A, B, C and D?
 Just put A, B, C and D on the top left corner of each plot.
 
 Usually I do it in Illustrator, but I think in R should there is a way.
 
 Could you please provide a example?
 
 Thank you very much in advance.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!

__
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] Add text A, B, C and D on multiple ordered plot

2013-02-08 Thread Fabrice Tourre
Thank your reminder.
Here is the example code:

a- rnorm(1000,0,1)
b-rnorm(1000,0,2)
c-rnorm(1000,0,3)
d-rnorm(1000,0,4)
par(mfrow=c(2,2))
hist(a)
hist(b)
hist(c)
hist(d)

I want to add A, B, C and D on each top left.

On Fri, Feb 8, 2013 at 2:35 PM, John Kane jrkrid...@inbox.com wrote:
 Yes there probably is if you would show us what you are doing.
 Minimal working code helps.

 https://github.com/hadley/devtools/wiki/Reproducibility

 John Kane
 Kingston ON Canada


 -Original Message-
 From: fabrice.c...@gmail.com
 Sent: Fri, 8 Feb 2013 14:28:17 -0500
 To: r-help@r-project.org
 Subject: [R] Add text A, B, C and D on multiple ordered plot

 Dear list,

 Is there a elegant way to name multiple ordered plot as A, B, C and D?
 Just put A, B, C and D on the top left corner of each plot.

 Usually I do it in Illustrator, but I think in R should there is a way.

 Could you please provide a example?

 Thank you very much in advance.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

 
 FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
 family!
 Visit http://www.inbox.com/photosharing to find out more!

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Add text A, B, C and D on multiple ordered plot

2013-02-08 Thread John Kane
Here is a rough example of what you want. You will need to adjust the actual 
placement by hand by redefining the x  y values.

set.seed(100)
  a - rnorm(1000,0,1)
  b -rnorm(1000,0,2)
  c -rnorm(1000,0,3)
  d -rnorm(1000,0,4)
   opr  -  par(mfrow=c(2,2))
  hist(a)
  text(-3, 150, labels =a)
  hist(b)
  text(-4, 150, labels =b)
  hist(c)
  text(-4, 150, labels =c)
  hist(d)
  text(-4, 150, labels =d)
  
  par  -  opr


John Kane
Kingston ON Canada


 -Original Message-
 From: fabrice.c...@gmail.com
 Sent: Fri, 8 Feb 2013 14:42:10 -0500
 To: jrkrid...@inbox.com
 Subject: Re: [R] Add text A, B, C and D on multiple ordered plot
 
 Thank your reminder.
 Here is the example code:
 
 a- rnorm(1000,0,1)
 b-rnorm(1000,0,2)
 c-rnorm(1000,0,3)
 d-rnorm(1000,0,4)
 par(mfrow=c(2,2))
 hist(a)
 hist(b)
 hist(c)
 hist(d)
 
 I want to add A, B, C and D on each top left.
 
 On Fri, Feb 8, 2013 at 2:35 PM, John Kane jrkrid...@inbox.com wrote:
 Yes there probably is if you would show us what you are doing.
 Minimal working code helps.
 
 https://github.com/hadley/devtools/wiki/Reproducibility
 
 John Kane
 Kingston ON Canada
 
 
 -Original Message-
 From: fabrice.c...@gmail.com
 Sent: Fri, 8 Feb 2013 14:28:17 -0500
 To: r-help@r-project.org
 Subject: [R] Add text A, B, C and D on multiple ordered plot
 
 Dear list,
 
 Is there a elegant way to name multiple ordered plot as A, B, C and D?
 Just put A, B, C and D on the top left corner of each plot.
 
 Usually I do it in Illustrator, but I think in R should there is a way.
 
 Could you please provide a example?
 
 Thank you very much in advance.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 FREE ONLINE PHOTOSHARING - Share your photos online with your friends
 and family!
 Visit http://www.inbox.com/photosharing to find out more!
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Add text A, B, C and D on multiple ordered plot

2013-02-08 Thread Rolf Turner


Try:

a- rnorm(1000,0,1)
b- rnorm(1000,0,2)
c- rnorm(1000,0,3)
d- rnorm(1000,0,4)
par(mfrow=c(2,2))
hist(a,main=)
title(main=A,adj=0)
hist(b,main=)
title(main=B,adj=0)
hist(c,main=)
title(main=C,adj=0)
hist(d,main=)
title(main=D,adj=0)

cheers,

Rolf Turner

On 02/09/2013 08:42 AM, Fabrice Tourre wrote:

Thank your reminder.
Here is the example code:

a- rnorm(1000,0,1)
b-rnorm(1000,0,2)
c-rnorm(1000,0,3)
d-rnorm(1000,0,4)
par(mfrow=c(2,2))
hist(a)
hist(b)
hist(c)
hist(d)
I want to add A, B, C and D on each top left.

On Fri, Feb 8, 2013 at 2:35 PM, John Kane jrkrid...@inbox.com wrote:

Yes there probably is if you would show us what you are doing.
Minimal working code helps.

https://github.com/hadley/devtools/wiki/Reproducibility

John Kane
Kingston ON Canada



-Original Message-
From: fabrice.c...@gmail.com
Sent: Fri, 8 Feb 2013 14:28:17 -0500
To: r-help@r-project.org
Subject: [R] Add text A, B, C and D on multiple ordered plot

Dear list,

Is there a elegant way to name multiple ordered plot as A, B, C and D?
Just put A, B, C and D on the top left corner of each plot.

Usually I do it in Illustrator, but I think in R should there is a way.

Could you please provide a example?

Thank you very much in advance.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with double looping

2013-02-08 Thread Rui Barradas

Hello,

You're right, sorry for the misleading tip. How about seq(1, 177, 11)? 
Please note that without a data example, it's not very easy to say. 
Can't you post a small dataset using ?dput


dput(head(data, 20))  # paste the output of this.


Rui Barradas

Em 08-02-2013 17:10, christel lacaze escreveu:


that doesn't seem to be the issue i'm afraid... both j sequences produce the 
same numbers:


j-seq(1,166,11)
j

  [1]   1  12  23  34  45  56  67  78  89 100 111 122 133 144 155 166

j-seq(1,176,11)
j

  [1]   1  12  23  34  45  56  67  78  89 100 111 122 133 144 155 166


Date: Fri, 8 Feb 2013 16:37:52 +
From: ruipbarra...@sapo.pt
To: christellac...@hotmail.co.uk
CC: r-help@r-project.org
Subject: Re: [R] help with double looping

Hello,

Maybe seq(1, 16*11, 11)? (16*11 is 176, not 166)


Hope this helps,

Rui Barradas

Em 08-02-2013 16:03, christel lacaze escreveu:


hi there,

I have a dataframe in the shape vA1, vA2,..., vA11, vB1, vB2,..., VB11,..., 
VP1, VP2,, VP11 (so 16 times a sequence of 11 variables)
I am trying to build a double loop so that i can apply the function (i-1)*v(i) 
to the first 10 variables, then the same for the next 10 variables, etc... 16 
times.

I have tried the following with no luck:

iscores-list()
for (j in seq(1,166,11))
{
for (i in j:(j+10))
  {iscores[[i-j+1]]=(i-j)*data[[i-j+1]]
  }
}

any suggestion...?

many thanks,

Christel

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.






__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] aggregation-type question

2013-02-08 Thread Rui Barradas

Hello,

With the following, the first instruction will give you correlations 
matrices, the second coefficients.


dat - read.table(text = 
 x y group
1 0.876751503 0.6518345 a
2 0.627067150 0.8801790 a
3 0.632465192 0.1768305 a
4 0.060359554 0.8835652 a
5 0.675868776 0.7721177 a
6 0.008465241 0.5046486 a
, header = TRUE)
str(dat)

lapply(split(dat[, c(x, y)], dat$group), cor)
lapply(split(dat[, c(x, y)], dat$group), function(d) cor(d$x, d$y))


Hope this helps,

Rui Barradas

Em 08-02-2013 16:33, carslaw escreveu:

I seem to have a Friday afternoon block and can't see the easiest way of
doing this.

Given a data frame like:

dat - data.frame(x = runif(100), y = runif(100), group = rep(letters[1:10],
each = 10))

head(dat)

 x y group
1 0.876751503 0.6518345 a
2 0.627067150 0.8801790 a
3 0.632465192 0.1768305 a
4 0.060359554 0.8835652 a
5 0.675868776 0.7721177 a
6 0.008465241 0.5046486 a

I want to work out cor(x, y) by group, so in this case ending up with 10
correlation coefficients by group.

I'm not seeing a straightforward solution and I'd appreciate your help.

Thanks

David



--
View this message in context: 
http://r.789695.n4.nabble.com/aggregation-type-question-tp4657966.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Count of Histogram Bins using Shingles with lattice

2013-02-08 Thread Burns, Jonathan (NONUS)
I know that I can get a count of histogram bins in base R with plot=FALSE. 
However, I'd like to do the same thing with lattice.  The problem is that I've 
set up shingles, and I'd like to get the count within each bin within each 
shingle.  plot=FALSE doesn't seem to do it.



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Add text A, B, C and D on multiple ordered plot

2013-02-08 Thread Fabrice Tourre
John Kane,

Thanks. It makes some of sense. But it seems not exactly what I want.
I just remember it need using mtext and adjust margin. I saw such of
example long time ago, but I have forgotten it.

On Fri, Feb 8, 2013 at 3:32 PM, John Kane jrkrid...@inbox.com wrote:
 Here is a rough example of what you want. You will need to adjust the actual 
 placement by hand by redefining the x  y values.

 set.seed(100)
   a - rnorm(1000,0,1)
   b -rnorm(1000,0,2)
   c -rnorm(1000,0,3)
   d -rnorm(1000,0,4)
opr  -  par(mfrow=c(2,2))
   hist(a)
   text(-3, 150, labels =a)
   hist(b)
   text(-4, 150, labels =b)
   hist(c)
   text(-4, 150, labels =c)
   hist(d)
   text(-4, 150, labels =d)

   par  -  opr


 John Kane
 Kingston ON Canada


 -Original Message-
 From: fabrice.c...@gmail.com
 Sent: Fri, 8 Feb 2013 14:42:10 -0500
 To: jrkrid...@inbox.com
 Subject: Re: [R] Add text A, B, C and D on multiple ordered plot

 Thank your reminder.
 Here is the example code:

 a- rnorm(1000,0,1)
 b-rnorm(1000,0,2)
 c-rnorm(1000,0,3)
 d-rnorm(1000,0,4)
 par(mfrow=c(2,2))
 hist(a)
 hist(b)
 hist(c)
 hist(d)

 I want to add A, B, C and D on each top left.

 On Fri, Feb 8, 2013 at 2:35 PM, John Kane jrkrid...@inbox.com wrote:
 Yes there probably is if you would show us what you are doing.
 Minimal working code helps.

 https://github.com/hadley/devtools/wiki/Reproducibility

 John Kane
 Kingston ON Canada


 -Original Message-
 From: fabrice.c...@gmail.com
 Sent: Fri, 8 Feb 2013 14:28:17 -0500
 To: r-help@r-project.org
 Subject: [R] Add text A, B, C and D on multiple ordered plot

 Dear list,

 Is there a elegant way to name multiple ordered plot as A, B, C and D?
 Just put A, B, C and D on the top left corner of each plot.

 Usually I do it in Illustrator, but I think in R should there is a way.

 Could you please provide a example?

 Thank you very much in advance.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

 
 FREE ONLINE PHOTOSHARING - Share your photos online with your friends
 and family!
 Visit http://www.inbox.com/photosharing to find out more!

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

 
 FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
 Check it out at http://www.inbox.com/earth



__
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] Merging and Updating Data Frames with Unequal Size

2013-02-08 Thread Lorenzo Isella

Dear All,
I am trying to merge 2 dataframes of with different sizes.
Let's say that one dataframe R contains some raw data and another data  
frame F contains the information to fix R.

For instance

F - data.frame(cbind(x=-seq(10),
  y=1:10,
  z=3:12,
  w=8:17,
  p=18
  ))



R - data.frame(cbind(x=rep(-seq(3),5), y=18:32,z=100:86,w=4,k=9))

I would like to do the following: for every value of R$x (i.e. 1,2,3 in  
this case), I will look up the same value in
F$x and use the info on that row of F to update the values of R$y, R$z,R$w  
(i.e. the raws which have the same names in both data frames), whereas I  
will simply append (as a new column) the values of F$p to the new  
dataframe.


The resulting data frame should look like this

 x y z  w k  p
-1 1 3  8 9 18
-2 2 4  9 9 18
-3 3 5 10 9 18
-1 1 3  8 9 18
-2 2 4  9 9 18
-3 3 5 10 9 18
-1 1 3  8 9 18
-2 2 4  9 9 18
-3 3 5 10 9 18
-1 1 3  8 9 18
-2 2 4  9 9 18
-3 3 5 10 9 18
-1 1 3  8 9 18
-2 2 4  9 9 18
-3 3 5 10 9 18

(it took longer to explain it than to do it!).

I can do this with a double loop, but I think that playing with the merge  
command should do the trick, although so far I have been unsuccessful.

Any suggestion is welcome.

Lorenzo

__
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] The use of R Commander for beginning students and newbies

2013-02-08 Thread Ista Zahn
Hi Tom,

I also teach R to newbies (materials at
http://projects.iq.harvard.edu/rtc/filter_by/r-0), and I've found
RStudio (http://rstudio.com/ide) a huge help, and much less
intimidating than the Windows GUI. File and object browsers,
integrated help window, syntax highlighting and code completion are
some of the features that students like. Not trying to discourage your
use of Rcommander, just thought I'd share my positive experience
teaching with Rstudio in case you have not checked it out yet.

Best,
Ista

On Thu, Feb 7, 2013 at 3:25 PM, Dr. Thomas W. MacFarland
tom...@nova.edu wrote:
 Everyone:



 In the last few months I've noticed an increasing number of questions to
 this list from students who are new to the use of R and who have limited (in
 any) local support on R and specifically support for R syntax.



 My text
 (http://www.springer.com/statistics/social+sciences+%26+law/book/978-1-4614-
 2133-7) from last year was specific to the use of R syntax but given recent
 feedback I see that perhaps those of us who teach beginning students need to
 give a bit more attention to R Commander and/or other GUIs, to help students
 build on their confidence so that we can start them out with some
 immediately successful outcomes.  Then, with experience we can move them
 over to the use of R syntax, which is certainly far more robust.



 For beginning students, newbies, and any others who may be interested, I've
 opened for guest access an Elluminate-Blackboard video on the use of R
 Commander.  The URL follows and a password is not required:



 https://mako.nova.edu/webapps/bb-collaborate-bb_bb60/guest.recording.launch.
 event?uid=476978d4-00c4-488e-98a3-495201e17f5f



 The full video is about 1 hour and 20 minutes.  You can make the active
 screen (right side of the screen) larger by moving it around, minimizing the
 status column (left side of the screen).



 Best wishes.



 Tom MacFarland



 --

 Thomas W. MacFarland, Ed.D.

 Senior Research Associate; Institutional Effectiveness and Associate
 Professor

 Nova Southeastern University

 Voice 954-262-5395 tom...@nova.edu




 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem reading dates from Excel

2013-02-08 Thread David Winsemius

On Feb 8, 2013, at 10:55 AM, Edwin Isensee wrote:

 I'm using the read.xls function from gdata package to read one Excel file,
 like the example below:
 
 library(gdata)
 my_file - '/Users/Desktop/Project.xlsx'
 valores - read.xls(my_file)
 
 The problem is: one of the columns at the Excel file holds date information
 like 1-Jan-13, 5-Jan-13, 25-Jan-13.

Actually it holds them as number of days and only displayes themin htat format.


 At Excel these information are treated
 as dates. When I read the file into a dataframe the corresponding data
 frame column holds numeric information like 41275, 41279, 41299. How can I
 convert these numeric information into the original date information?

The easiest way would be to create a format in Excel. -mm-dd should work 
well. Otherwise you should read the documentation about date encoding. You can 
take those values and add them to something like:  as.Date(1900-01-01). I say 
something like because Excel date calculations have always had a strange bug 
that MS  refuses to acknowledge or fix that may make the date one or two days 
more or  less.

  as.Date(1900-01-01) +c( 41275, 41279, 41299)
 [1] 2013-01-03 2013-01-07 2013-01-27

 Thanks,
 Edwin
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Merging and Updating Data Frames with Unequal Size

2013-02-08 Thread arun
Hi,
Try:
 R[,2:4]-F[,2:4][match(R$x,F$x),]
 R$p- unique(F$p)
    
R
    x y z  w k  p
1  -1 1 3  8 9 18
2  -2 2 4  9 9 18
3  -3 3 5 10 9 18
4  -1 1 3  8 9 18
5  -2 2 4  9 9 18
6  -3 3 5 10 9 18
7  -1 1 3  8 9 18
8  -2 2 4  9 9 18
9  -3 3 5 10 9 18
10 -1 1 3  8 9 18
11 -2 2 4  9 9 18
12 -3 3 5 10 9 18
13 -1 1 3  8 9 18
14 -2 2 4  9 9 18
15 -3 3 5 10 9 18
A.K.




- Original Message -
From: Lorenzo Isella lorenzo.ise...@gmail.com
To: r-h...@stat.math.ethz.ch r-h...@stat.math.ethz.ch
Cc: 
Sent: Friday, February 8, 2013 3:57 PM
Subject: [R] Merging and Updating Data Frames with Unequal Size

Dear All,
I am trying to merge 2 dataframes of with different sizes.
Let's say that one dataframe R contains some raw data and another data frame F 
contains the information to fix R.
For instance

F - data.frame(cbind(x=-seq(10),
                      y=1:10,
                      z=3:12,
                      w=8:17,
                      p=18
                      ))



R - data.frame(cbind(x=rep(-seq(3),5), y=18:32,z=100:86,w=4,k=9))

I would like to do the following: for every value of R$x (i.e. 1,2,3 in this 
case), I will look up the same value in
F$x and use the info on that row of F to update the values of R$y, R$z,R$w 
(i.e. the raws which have the same names in both data frames), whereas I will 
simply append (as a new column) the values of F$p to the new dataframe.

The resulting data frame should look like this

x y z  w k  p
-1 1 3  8 9 18
-2 2 4  9 9 18
-3 3 5 10 9 18
-1 1 3  8 9 18
-2 2 4  9 9 18
-3 3 5 10 9 18
-1 1 3  8 9 18
-2 2 4  9 9 18
-3 3 5 10 9 18
-1 1 3  8 9 18
-2 2 4  9 9 18
-3 3 5 10 9 18
-1 1 3  8 9 18
-2 2 4  9 9 18
-3 3 5 10 9 18

(it took longer to explain it than to do it!).

I can do this with a double loop, but I think that playing with the merge 
command should do the trick, although so far I have been unsuccessful.
Any suggestion is welcome.

Lorenzo

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem reading dates from Excel

2013-02-08 Thread Ben Bolker
David Winsemius dwinsemius at comcast.net writes:

 On Feb 8, 2013, at 10:55 AM, Edwin Isensee wrote:
 
  I'm using the read.xls function from gdata package to read one Excel file,
  like the example below:
  
  library(gdata)
  my_file - '/Users/Desktop/Project.xlsx'
  valores - read.xls(my_file)
  
  The problem is: one of the columns at the Excel file holds date information
  like 1-Jan-13, 5-Jan-13, 25-Jan-13.
 
 Actually it holds them as number of days and only displays them in
  that format.
 
  At Excel these information are treated
  as dates. When I read the file into a dataframe the corresponding data
  frame column holds numeric information like 41275, 41279, 41299. How can I
  convert these numeric information into the original date information?

 The easiest way would be to create a format in Excel. -mm-dd
 should work well. Otherwise you should read the documentation about
 date encoding. You can take those values and add them to something
 like: as.Date(1900-01-01). I say something like because Excel
 date calculations have always had a strange bug that MS refuses to
 acknowledge or fix that may make the date one or two days more or
 less.

   as.Date(1900-01-01) +c( 41275, 41279, 41299)
  [1] 2013-01-03 2013-01-07 2013-01-27
 

 The HFWutils package, now archived, had a function that
did this.  I extracted just that function: below I also
post some information about where (I think) the
Excel date bug referred to above comes from -- an
interesting historical story.
  If you are using dates before Feb 1900, watch out (and
read below)!

## from http://cran.r-project.org/src/contrib/Archive/
## HFWutils/HFWutils_0.9.2008.05.17.tar.gz

excelDate2Date - function(excelDate) {
Date - excelDate + as.Date(1900-01-01) - 2
## FIXME: add if 1900-Feb-28 switch?
return(Date)
}

## http://www.cpearson.com/excel/datetime.htm
## Dates

## The integer portion of the number, d, represents the number of
## days since 1900-Jan-0.  For example, the date 19-Jan-2000 is stored
## as 36,544, since 36,544 days have passed since 1900-Jan-0.  The
## number 1 represents 1900-Jan-1.  It should be noted that the number
## 0 does not represent 1899-Dec-31.  It does not. If you use the
## MONTH function with the date 0, it will return January, not
## December.  Moreover, the YEAR function will return 1900, not 1899.

## Actually, this number is one greater than the actual number of
## days.  This is because Excel behaves as if the date 1900-Feb-29
## existed.  It did not.  The year 1900 was not a leap year (the year
## 2000 is a leap year).  In Excel, the day after 1900-Feb-28 is
## 1900-Feb-29.  In reality, the day after 1900-Feb-28 was 1900-Mar-1.
## This is not a bug.  Indeed, it is by design.  Excel works this
## way because it was truly a bug in Lotus 123.  When Excel was
## introduced, 123 has nearly the entire market for spreadsheet
## software.  Microsoft decided to continue Lotus' bug, in order to
## fully compatible.  Users who switched from 123 to Excel would not
## have to make any changes to their data.  As long as all your dates
## later than 1900-Mar-1, this should be of no concern.

__
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] Contrasts for a data

2013-02-08 Thread jing tang
Hi,
I am using a data called Rail in the nlme package. The data contains two
variables: Rail and Travel.
Rail
Grouped Data: travel ~ 1 | Rail
   Rail travel
1 1 55
2 1 53
3 1 54
4 2 26
5 2 37
6 2 32
7 3 78
8 3 91
9 3 85
104 92
114100
124 96
135 49
145 51
155 50
166 80
176 85
186 83
Rail$Rail
[1] 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6
Levels: 2  5  1  6  3  4

Then I used the contrasts function as:
contrasts(Rail$Rail)
And it returns with some strange continuous values:
 .L .Q .C ^4  ^5
[1,] -0.5976143  0.5455447 -0.3726780  0.1889822 -0.06299408
[2,] -0.3585686 -0.1091089  0.5217492 -0.5669467  0.31497039
[3,] -0.1195229 -0.4364358  0.2981424  0.3779645 -0.62994079
[4,]  0.1195229 -0.4364358 -0.2981424  0.3779645  0.62994079
[5,]  0.3585686 -0.1091089 -0.5217492 -0.5669467 -0.31497039
[6,]  0.5976143  0.5455447  0.3726780  0.1889822  0.06299408

I am expecting to see 0s and 1s in the contrast, but it may be due to the
order of the factor levels for Rail variable?

Best,
Jing

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Contrasts for a data

2013-02-08 Thread Bert Gunter
Rail is an ordered factor. ?ordered for details.
Default contrasts for an ordered factor are orthogonal polynomials.

See:   https://stat.ethz.ch/pipermail/r-help/2007-January/123268.html

and

http://www.ats.ucla.edu/stat/r/library/contrast_coding.htm#ORTHOGONAL

-- Bert

On Fri, Feb 8, 2013 at 1:36 PM, jing tang gimmyt...@gmail.com wrote:
 Hi,
 I am using a data called Rail in the nlme package. The data contains two
 variables: Rail and Travel.
Rail
 Grouped Data: travel ~ 1 | Rail
Rail travel
 1 1 55
 2 1 53
 3 1 54
 4 2 26
 5 2 37
 6 2 32
 7 3 78
 8 3 91
 9 3 85
 104 92
 114100
 124 96
 135 49
 145 51
 155 50
 166 80
 176 85
 186 83
Rail$Rail
[1] 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6
Levels: 2  5  1  6  3  4

 Then I used the contrasts function as:
contrasts(Rail$Rail)
 And it returns with some strange continuous values:
  .L .Q .C ^4  ^5
 [1,] -0.5976143  0.5455447 -0.3726780  0.1889822 -0.06299408
 [2,] -0.3585686 -0.1091089  0.5217492 -0.5669467  0.31497039
 [3,] -0.1195229 -0.4364358  0.2981424  0.3779645 -0.62994079
 [4,]  0.1195229 -0.4364358 -0.2981424  0.3779645  0.62994079
 [5,]  0.3585686 -0.1091089 -0.5217492 -0.5669467 -0.31497039
 [6,]  0.5976143  0.5455447  0.3726780  0.1889822  0.06299408

 I am expecting to see 0s and 1s in the contrast, but it may be due to the
 order of the factor levels for Rail variable?

 Best,
 Jing

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
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] Add text A, B, C and D on multiple ordered plot

2013-02-08 Thread Bretschneider SIG-R
Dear Fabrice Tourre,


Re:



 John Kane,
 
 Thanks. It makes some of sense. But it seems not exactly what I want.
 I just remember it need using mtext and adjust margin. I saw such of
 example long time ago, but I have forgotten it.

(etc...)




Maybe this is what you're after?

Fiddled a bit with the margins:


a- rnorm(1000,0,1)
b-rnorm(1000,0,2)
c-rnorm(1000,0,3)
d-rnorm(1000,0,4)
quartz(w=6,h=8)
par(mfrow=c(2,2))
#par(mai=c(1,0,1,1))
par(mar=c(3,2,4,1))
#par(plt=c(1.1,1.1,1.1,1.1))
tlin=2
hist(a)
mtext(A,3, line=tlin, adj=0, cex=2)
hist(b)
mtext(B,3, line=tlin, adj=1, cex=2)
hist(c)
mtext(C,3, line=tlin, adj=0, cex=2)
hist(d)
mtext(D,3, line=tlin, adj=1, cex=2)


Hope this helps,
Best regards,


Franklin Bretschneider


--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] character strings with embedded commands: perl /gee ?

2013-02-08 Thread ivo welch
dear R experts---I am trying to replicate a perl feature. I want to be
able to embed R commands inside a character string, and have the
string be printed with the command executed.  my perl equivalent is

  my $a=10;
  my $teststring = the expression, $a+1, is ::$a+1::, but add one
more for ::$a+2::\n;
  $teststring =~ s/::(.*?)::/$1/gee;
  print $teststring;

of course, R does not use '$' for variable names.  my ultimate goal is
to write something like

  cat(d is a ::class(d):: with names ::names(d)::)

of course, I know I can write this as cat(d is a, class(d), with
names, names(d)), but I also want to be define %or% so that I can
write

  (is.data.frame(d)) %or% d is a ::class(d):: with names ::names(d):: ;

operators don't take variable arguments afaik.  :-(.

advice appreciated.

regards,

/iaw

Ivo Welch (ivo.we...@gmail.com)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem reading dates from Excel

2013-02-08 Thread Orvalho Augusto
I do not promise much. But try to use XLConnect package. It requires rJava
package which requires java on your system.

Good luck
Orvalho

On Fri, Feb 8, 2013 at 8:55 PM, Edwin Isensee edwin.isen...@gmail.comwrote:

 I'm using the read.xls function from gdata package to read one Excel file,
 like the example below:

 library(gdata)
 my_file - '/Users/Desktop/Project.xlsx'
 valores - read.xls(my_file)

 The problem is: one of the columns at the Excel file holds date information
 like 1-Jan-13, 5-Jan-13, 25-Jan-13. At Excel these information are treated
 as dates. When I read the file into a dataframe the corresponding data
 frame column holds numeric information like 41275, 41279, 41299. How can I
 convert these numeric information into the original date information?

 Thanks,
 Edwin

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] vegdist Error en double(N * (N - 1)/2) : tama?o del vector especificado es muy grande

2013-02-08 Thread Carolina Bello
-- Forwarded message --
From: r-help-ow...@r-project.org
Date: 2013/2/8
Subject: vegdist Error en double(N * (N - 1)/2) : tama?o del vector
especificado es muy grande
To: caro.bell...@gmail.com


Message rejected by filter rule match



-- Mensaje reenviado --
From: caro bello caro.bell...@gmail.com
To: r-help@r-project.org
Cc:
Date: Fri, 8 Feb 2013 15:18:40 -0800 (PST)
Subject: vegdist Error en double(N * (N - 1)/2) : tamaño del vector
especificado es muy grande
Hi
I have some problems with the vegdist function. I want to calculate a
distance matrix with jaccard. I have binary data.

The problem is that i have a matrix of 138037 rows (sites) and 89 columns
(species). my script is:

rm(list=ls(all=T))

gc() ##para borrar todo lo que quede oculto en memoria

memory.limit(size = 10) # it gives 1 Tera from HDD in case ram
memory is over

DF=as.data.frame(MODELOS)

DF=na.omit(DF)

DISTAN=vegdist(DF[,2:ncol(DF)],jaccard)

Almost immediately IT produces the error: Error en double(N * (N - 1)/2) :
tamaño del vector especificado es muy grande

I think this a memory error, but i don´t know why if i have a pc with 32GB
of ram and 1 Tera of HDD.

I also try to do a dist matrix whit the function dist from package proxy, i
did:

  library(proxy)

vector=dist(DF, method = Jaccard)

it starts to run but when it gets to 10 GB of ram, a window announces that R
committed an error and it will close, so it closes and start a new section.

I really don't know what is going on and less how to solve this, can anybody
help me?

thanks

Carolina Bello IAVH-COLOMBIA




--
View this message in context:
http://r.789695.n4.nabble.com/vegdist-Error-en-double-N-N-1-2-tama-o-del-vector-especificado-es-muy-grande-tp4658010.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] qcc package

2013-02-08 Thread Steven LeBlanc
Greets,

My data looks like:

 p3.18
  s xbar subgroup
1  0.84 12.21
2  1.64 11.22
3  2.07 10.63
4  2.49 12.24
5  0.84 11.25
...

Using the command

 qcc(p3.18$xbar,type=xbar,sizes=5,center=mean(p3.18$xbar),std.dev=mean(p3.18$s)/0.94,title=X-bar
  Chart for Paper Sheet Length Data)

I get the x-bar chart I expect.

However, using the command

 qcc(p3.18$s,type=S,sizes=5,center=mean(p3.18$s),std.dev=mean(p3.18$s)/0.94,title=S
  Chart for Paper Sheet Length Data)

I get the following error:

Error in plot.window(...) : need finite 'ylim' values

It seems reasonable that if the first command produces correct results, so 
should the second. What am I doing wrong?

Thanks  Best Regards,
Steven





[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Troubleshooting underidentification issues in structural equation modelling (SEM)

2013-02-08 Thread Ruijie
Hi all, hope someone can help me out with this.
Background Introduction

I have a data set consisting of data collected from a questionnaire that I
wish to validate. I have chosen to use confirmatory factor analysis to
analyse this data set.
Instrument

The instrument consists of 11 subscales. There is a total of 68 items in
the 11 subscales. Each item is scored on an integer scale between 1 to 4.
Confirmatory factor analysis (CFA) setup

I use the sem package to conduct the CFA. My code is as below:

cov.mat - as.matrix(read.table(http://dl.dropbox.com/u/1445171/cov.mat.csv;,
sep = ,, header = TRUE))
rownames(cov.mat) - colnames(cov.mat)

model - cfa(file = http://dl.dropbox.com/u/1445171/cfa.model.txt;,
reference.indicators = FALSE)
cfa.output - sem(model, cov.mat, N = 900, maxiter = 8, optimizer
= optimizerOptim)
Warning message:In eval(expr, envir, enclos) : Negative parameter
variances.Model may be underidentified.

Straight off you might notice a few anomalies, let me explain.

   - Why is the optimizer chosen to be optimizerOptim?

ANS: I originally stuck with the default optimizerSem but no matter how
many iterations I run, either I run out of memory first (8GB RAM setup) or
it would report no convergence Things seemed a little better when I
switched to optimizerOptim where by it would conclude successfully but
throws up the error that the model is underidentified. Upon closer
inspection, I realise that the output shows convergence as TRUE but
iterations is NA so I am not sure what is exactly happening.

   - The maxiter is too high.

ANS: If I set it to a lower value, it refuses to converge, although as
mentioned above, I doubt real convergence actually occurred.
Problem

So by now I guess that the model is really underidentified so I looked for
resources to resolve this problem and found:

   - http://davidakenny.net/cm/identify_formal.htm
   - http://faculty.ucr.edu/~hanneman/soc203b/lectures/identify.html

I followed the 2nd link quite closely and applied the t-rule:

   - I have 68 observed variables, providing me with 68 variances and 2278
   covariances between variables = *2346 data points*.
   - I also have 68 regression coefficients, 68 error variances of
   variables, 11 factor variances and 55 factor covariances to estimate making
   it a total of 191 parameters.
   - Since I will be fixing the variances of the 11 latent factors to 1 for
   scaling, I would remove them from the parameters to estimate making it a
   total of *180 parameters to estimate*.
  - My degrees of freedom is therefore 2346 - 180 = 2166, making it an
  over identified model by the t-rule.

Questions

   1. Is the low variance of some of my items a possible cause for the
   underidentification? I was advised previously to remove items with zero
   variance which led me to think about items which are very close to zero.
   Should they be removed too?
   2. After reading much, I think but am not sure that it might be a case
   of empirical underidentification. Is there a systematic way of diagnosing
   what kind of underidentification it is? And what are my options to proceed
   with my analysis?

I have more questions but let's take it at these 2 for now. Thanks for any
help!

Regards,
Ruijie (RJ)


He who has a why can endure any how.

~ Friedrich Nietzsche

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] add data symbol to axis label

2013-02-08 Thread Jim Lemon

On 02/08/2013 10:53 PM, e-letter wrote:

Readers,

Is it possible to add a data symbol (e.g. pch='21') to an axis label?
The objective is to plot a graph with two (2) y-axes and the plotting
character for data set 1 is added to the label of y1 axis (left); plot
character for data set 2 is added to label of y2 (right) axis.


Hi e-letter,
You can use escape codes in a string to insert symbols in an axis label 
like this:


plot(...,xlab=Male\u2642)

if you are in a Unicode locale. You will have to find out which escape 
codes work in your locale, if the symbols you wish to use exist in that 
locale and what their escape codes are.


Jim

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