[R] new line between '}' and 'else' in function body

2009-04-03 Thread Yihui Xie
Hi list members,

?else tells us

 In particular, you should not have a newline between '}' and
 'else' to avoid a syntax error in entering a 'if ... else'
 construct at the keyboard or via 'source'.

but there's no syntax error when you break the line between } and
else in a function, e.g.

f = function(x) {
if (x) {
1
} # a new line here!
else {
2
}
}

 f(TRUE)
[1] 1
 f(FALSE)
[1] 2

Seems strange...

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China

__
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] extract tables as data.frames from HTML source

2009-04-03 Thread Yihui Xie
Hi,

I wonder whether there is any convenient function (or package) to
extract tables from a HTML page? e.g. from
http://www.google.com/finance/historical?q=SHE:002251

I know we can readLines('URL'), gsub('td...', '...', source), ...
and at last get the numbers; I'm writing to ask whether someone has
already contributed a more general function (with the package XML or
other packages). Thanks!

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China

__
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] new line between '}' and 'else' in function body

2009-04-03 Thread Romain Francois

Hi,

That's because the parser knows how to deal with that stuff. However, 
when you type the same if/else at the command line, it will be parsed 
line by line, and the evaluator will not wait for the else to evaluate 
the if. Try to copy and paste your if/else to the command line.


Romain


Yihui Xie wrote:

Hi list members,

?else tells us

 In particular, you should not have a newline between '}' and
 'else' to avoid a syntax error in entering a 'if ... else'
 construct at the keyboard or via 'source'.

but there's no syntax error when you break the line between } and
else in a function, e.g.

f = function(x) {
if (x) {
1
} # a new line here!
else {
2
}
}

  

f(TRUE)


[1] 1
  

f(FALSE)


[1] 2

Seems strange...

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China
  



--
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr

__
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] Survey Package with Binary Data (no Standard Errors reported)

2009-04-03 Thread Paul Jones

Hi,

I'm trying to get standard errors for some of the variables in my data 
frame. One of the questions on my survey is whether faculty coordinate 
across curriculum to include Arts Education as subject matter. All the 
responses are coded in zeros and ones obviously. For some of the other 
variables I have a 2 for those that responded with Don't Know.


I'm getting NA for mean and standard deviations from svymean. Am I doing 
something wrong of can the survey package not handle this type of data?


Here's my code.

 survey - svydesign(id=~1, data=General, strata=~Grade.Level)
Warning message:
In svydesign.default(id = ~1, data = General, strata = ~Grade.Level) :
 No weights or probabilities supplied, assuming equal probability

 summary(survey)
Stratified Independent Sampling design (with replacement)
svydesign(id = ~1, data = General, strata = ~Grade.Level)
Probabilities:
  Min. 1st Qu.  MedianMean 3rd Qu.Max.
 1   1   1   1   1   1
Stratum Sizes:
  Elementary High Middle
obs   312  236156
design.PSU312  236156
actual.PSU312  236156
Data variables:
[1] Grade.Level  Curriculum 
[3] Field.Trips  Residencies
[5] PTA.Support  Community.Open.Performances
[7] Visual.Arts.Attendance   Literary.Arts.Attendance   
[9] Arts.Organization.Membership Arts.Essential
 
 svymean(~Curriculum, survey)

  mean SE
Curriculum   NA NA

???

PJ

__
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] Intraday financial returns

2009-04-03 Thread Huth Nicolas
Hello,
 
I would like to create a function that computes intraday returns of a financial 
asset
on a calendar time basis, without making any loop. For instance, I want to get 
price returns every 60 seconds.
The main problem is that the times series of prices is irregularly spaced in 
time.
I have looked in the zoo or its classes but have not found any answer to my 
problem. Thanks in advance.
 
Nicolas Huth


  
[[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 missing values/timestamps

2009-04-03 Thread j.k

Thanks a lot!
The way with zoo worked perfect.

Here is the code I've used finally:

data.input01 -read.csv(./1_15min.txt, header = TRUE, sep = ;,
quote=\, dec=,, fill = TRUE, comment.char=)
data.input02 -read.csv(./2_15min.txt, header = TRUE, sep = ;,
quote=\, dec=,, fill = TRUE, comment.char=)
data.input03 -read.csv(./3_15min.txt, header = TRUE, sep = ;,
quote=\, dec=,, fill = TRUE, comment.char=)
data.troughput01 - rbind(data.input01,data.input02,data.input03)
data.test - seq(as.POSIXct(2006-01-01 00:00:00),as.POSIXct(2006-12-31
23:45:00),900)
data.troughput02 - as.zoo(data.troughput01$V2)
index(data.troughput02) - as.POSIXct(data.troughput01$V1)
data.output01 - merge(data.troughput04,zoo(,data.test))
data.output02 - na.approx(data.output01,na.rm = FALSE)


Gabor Grothendieck wrote:
 
 Try this where we read in a zoo series and then merge it with
 a zero width regularly spaced series to create the result.
 
 Lines - V1,V2
 2008-10-14 08:45:00,94411.08
 2008-10-14 08:50:00,90745.45
 2008-10-14 08:55:00,82963.35
 2008-10-14 09:00:00,75684.38
 2008-10-14 09:05:00,78931.82
 2008-10-14 09:20:00,74580.11
 2008-10-14 09:25:00,69666.48
 2008-10-14 09:30:00,77794.89
 
 library(zoo)
 z - read.zoo(textConnection(Lines), header = TRUE, sep = ,, tz = )
 tt - seq(time(z)[1], time(z)[length(z)], 5*60)
 merge(z, zoo(, tt))
 
 The last statement's output will be:
 
 merge(z, zoo(, tt))
 2008-10-14 08:45:00 2008-10-14 08:50:00 2008-10-14 08:55:00 2008-10-14
 09:00:00
94411.0890745.4582963.35   
 75684.38
 2008-10-14 09:05:00 2008-10-14 09:10:00 2008-10-14 09:15:00 2008-10-14
 09:20:00
78931.82  NA  NA   
 74580.11
 2008-10-14 09:25:00 2008-10-14 09:30:00
69666.4877794.89
 
 
 See the 3 zoo vignettes for use of zoo series and R News 4/1 (for
 date/time info).
 
 On Mon, Mar 30, 2009 at 10:38 AM, j.k kat...@gmx.at wrote:

 Hello alltogheter,
 I have the following problem and maybe someone can help me with it.
 I have a list of values with times. They look like that:

                               V1           V2
 1 2008-10-14 08:45:00 94411.08
 2 2008-10-14 08:50:00 90745.45
 3 2008-10-14 08:55:00 82963.35
 4 2008-10-14 09:00:00 75684.38
 5 2008-10-14 09:05:00 78931.82
 6 2008-10-14 09:20:00 74580.11
 7 2008-10-14 09:25:00 69666.48
 8 2008-10-14 09:30:00 77794.89

 I have these data combined from different series of measurements.
 As you can see the problem is that between these series are gaps which I
 want to fill.

 The format of the time is POSIXct

 Are there any suggestions how I can fill these missing times and
 afterwards
 interpolate/predict their values?

 Thanks in advance
 Johannes
 --
 View this message in context:
 http://www.nabble.com/Add-missing-values-timestamps-tp22784737p22784737.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.
 
 

-- 
View this message in context: 
http://www.nabble.com/Add-missing-values-timestamps-tp22784737p22863325.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] extract tables as data.frames from HTML source

2009-04-03 Thread Dieter Menne


Yihui Xie wrote:
 
 I wonder whether there is any convenient function (or package) to
 extract tables from a HTML page? e.g. from
 http://www.google.com/finance/historical?q=SHE:002251
 

Try a search on R (I prefer markmail search)

http://r-project.markmail.org/search/?q=extract%20html


Dieter
-- 
View this message in context: 
http://www.nabble.com/extract-tables-as-data.frames-from-HTML-source-tp22862641p22863816.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] how to sort and plot data?

2009-04-03 Thread Dieter Menne



Hem wrote:
 
 user_id  website  time
 20google0930
 21yahoo0935
 20facebook1000
 25facebook1015
 61google0940
 ...
 My problem is how to sort the data? So that, I can get information about
 one
 user_id viewed how many website perday?
 
 

Maybe you were looking at the wrong item, because what you want is not
sorting, but a table.

Check the documentation of table or ftable.

Dieter

-- 
View this message in context: 
http://www.nabble.com/how-to-sort-and-plot-data--tp22861661p22863918.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] finding best fitting model

2009-04-03 Thread Dieter Menne



Benedikt Niesterok wrote:
 
 Is there a function in r to find the best fitting model for a set of data?
 I would like to know if my data are related exponentially,linearly or if
 there is a logarithmic correlation between my x and y values.
 

There is no one-stop method to do this. I would suggest that you try the
alternatives by doing the transformation (implicit in lm or explicit on
data) and checking the residuals of the fit.

Check documentation of plot.lm for an example or get the chapter in MASS on
the subject.

Dieter

-- 
View this message in context: 
http://www.nabble.com/finding-best-fitting-model-tp22852224p22864012.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] chaining consensus in cluster analyses

2009-04-03 Thread Penner, Johannes
Dear R-helpers,

conducting different community ecology analyses my main aim is to find
groupings in the data and geographical borders between communities and
to prove them statistically.

So after conducting a global test (Mantel) I am running a NMS and
cluster analyses. These are followed by other tests. However, I have two
questions concerning the cluster analyses which I was not able to solve
so far:

1) I would like to calculate % chaining for specific clusters. How can
I do that in R?

2) I would like to calculate several clusters with different methods and
then merge them in a consensus cluster, similar to a consensus tree
used in genetic analyses. Is this possible and if yes how?

Any help or hint is greatly appreciated!

with kind regards
Johannes

--
Project Coordinator BIOTA West Amphibians

Museum of Natural History
Dep. of Research (Herpetology)
Invalidenstrasse 43
D-10115 Berlin
Tel: +49 (0)30 2093 8708
Fax: +49 (0)30 2093 8565

http://www.biota-africa.org
http://community-ecology.biozentrum.uni-wuerzburg.de

__
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 sort and plot data?

2009-04-03 Thread Umesh Srinivasan
Hi,
There is definitely a more elegant way of doing this which I don't know
about (without a for loop), but try this:

mat - matrix(NA, nrow = max(user_id), ncol = 2)
mat[,1] - 1:max(user_id) # 1st column of matrix is the user ID

for (i in 1:max(user_id)){
temp1 - subset(data, user_id = i)
temp2 - unique(temp1$website)
mat[2,i] - length(temp2)
}

The matrix will give you user id and number of sites visited, provided user
id ranges from 1 to the number of users. There must be a way to do this
using table, but I cant figure it out.

Cheers,
Umesh

On Fri, Apr 3, 2009 at 1:42 PM, Dieter Menne
dieter.me...@menne-biomed.dewrote:




 Hem wrote:
 
  user_id  website  time
  20google0930
  21yahoo0935
  20facebook1000
  25facebook1015
  61google0940
  ...
  My problem is how to sort the data? So that, I can get information about
  one
  user_id viewed how many website perday?
 
 

 Maybe you were looking at the wrong item, because what you want is not
 sorting, but a table.

 Check the documentation of table or ftable.

 Dieter

 --
 View this message in context:
 http://www.nabble.com/how-to-sort-and-plot-data--tp22861661p22863918.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.


[[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] DierckxSpline fitting with different sets of y-values in one time

2009-04-03 Thread Jonckers Elisabeth
Dear R users,

I have a question about the Package DierckxSpline. I have tried to find the 
answer by myself but it didn't worked out.

I wondered if Dierckxspline can use different sets of y values in one time to 
fit a line with knot. I have different sets of Y values representing the same 
thing for different voxels (in an fmri image). I have already fitted the data 
in different graphs and I know now that the plots are comparable for the 
different data sets (so for the different voxels) but I wanted to include all 
the information in one plot, If it's possible. So I want to know the best 
fitting line for the whole cluster of voxels except for one voxel.
If there is no possibility to do this I tought it would be an option to take 
the mean of the different y-values and use those values but I don't know if 
this is mathematical right to do.
I hope someone can help me with this.

Thank you very much,
Elisabeth Jonckers
GIfMI
Ghent University Hospital
Belgium

[[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] [R} seasonal differencing

2009-04-03 Thread Rau, Roland
Hi, 

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Joseph Magagnoli
 Sent: Thursday, April 02, 2009 5:36 PM
 To: r-help@r-project.org
 Subject: [R] [R} seasonal differencing
 
 Hi all,
 I was wondering how to construct a seasonal differenced time series
 variable.
 I used the following code to construct a 12 span seasonal difference
 
 seasonal-diff(V2, lag=12, differences=1)
 
 is this correct?
 
 thank you in advance
 joe
 

I think this is fine. Just playing around (see below), I obtained what I
would expect. :-)

 V2 - rep(x=1:12, times=5)
 seasonal - diff(V2, lag=12, differences=1)
 V2
 [1]  1  2  3  4  5  6  7  8  9 10 11 12  1  2  3  4  5  6  7  8  9 10
11 12  1
[26]  2  3  4  5  6  7  8  9 10 11 12  1  2  3  4  5  6  7  8  9 10 11
12  1  2
[51]  3  4  5  6  7  8  9 10 11 12
 seasonal
 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0
[39] 0 0 0 0 0 0 0 0 0 0
 

Hope this helps,
Roland

--
This mail has been sent through the MPI for Demographic Research.  Should you 
receive a mail that is apparently from a MPI user without this text displayed, 
then the address has most likely been faked. If you are uncertain about the 
validity of this message, please check the mail header or ask your system 
administrator for assistance.

__
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] new line between '}' and 'else' in function body

2009-04-03 Thread Yihui Xie
Thanks, Romain! So I think, for consistency, the following result

 deparse(parse(text = '
+ f = function(x) {
+if (x) {
+1
+} # a new line here!
+else {
+2
+}
+ }
+ ')
+ )
[1] structure(expression(f = function(x) { if (x) {
[3] 1  }
[5] else { 2
[7] }  }), srcfile =
environment)

should be

[1] structure(expression(f = function(x) { if (x) {
[3] 1  } else {
[5] 2 }
[7] }), srcfile = environment)

instead.

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China



On Fri, Apr 3, 2009 at 2:48 PM, Romain Francois
romain.franc...@dbmail.com wrote:
 Hi,

 That's because the parser knows how to deal with that stuff. However, when
 you type the same if/else at the command line, it will be parsed line by
 line, and the evaluator will not wait for the else to evaluate the if. Try
 to copy and paste your if/else to the command line.

 Romain


 Yihui Xie wrote:

 Hi list members,

 ?else tells us

     In particular, you should not have a newline between '}' and
     'else' to avoid a syntax error in entering a 'if ... else'
     construct at the keyboard or via 'source'.

 but there's no syntax error when you break the line between } and
 else in a function, e.g.

 f = function(x) {
    if (x) {
        1
    } # a new line here!
    else {
        2
    }
 }



 f(TRUE)


 [1] 1


 f(FALSE)


 [1] 2

 Seems strange...

 Regards,
 Yihui
 --
 Yihui Xie xieyi...@gmail.com
 Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
 Mobile: +86-15810805877
 Homepage: http://www.yihui.name
 School of Statistics, Room 1037, Mingde Main Building,
 Renmin University of China, Beijing, 100872, China



 --
 Romain Francois
 Independent R Consultant
 +33(0) 6 28 91 30 30
 http://romainfrancois.blog.free.fr




__
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] Odp: finding best fitting model

2009-04-03 Thread Petr PIKAL
Hi

I adopted an idea from Chemical Engineering  where one guy used set of 
functions to check which can fit data well and used Excel for it. So I 
tried if I can do it in R.

It is very rough and needs data to be a two column data frame with x in 
the first column together with list of formulas.

You can use it like

nls.find(modely1, data)

and you can try to give it some starting values but it can arrive to 
results without them. You can also set start=T, which will use default 
method for nls. The result is list of model parameters ordered by residual 
sum of residual sqares. It does not help you to think about your data, it 
does not use any type of diagnostics. 

But you can use it with some care.

regards
Petr

Below is three set of models and the function itself.

modely1 - list(
y~1/(a-x),
y~x^2-a*x,
y~a^x,
y~1-a^x,
y~a^(1/x),
y~x^a,
y~1-1/(x^a),
y~a^(1-log(x)),
y~1-exp(-a*x),
y~a*x^2-log(x),
y~a/cosh(x),
y~a*cosh(x/a))

modely2 - list(
y~a*x+b,
y~1/(a+b*x),
y~a/(b+x),
y~a+b*log(x),
y~a*exp(b*x),
y~a*exp(b/x),
y~a*(1-exp(b*x)),
y~(a/(a-b))*(exp(-b*x)-exp(-a*x)),
y~1/(1+exp(-a*(x-b))),
y~a*x^b,
y~a*(1+x)^b,
y~(a+x)^b,
y~(a-x)^b,
y~1-1/(1+a*x)^b,
y~a*x^(b*x),
y~a*x^(b/x),
y~x/(a+b*x-(a+b)*x^2),
y~a*cos(x-b),
y~a/(sin(x-b))
)

modely3 - list(
y~a+b*x+c*x^2,
y~1/(a+b*x+c*x^2),
y~a+b/x+c/(x^2),
y~a+b*log(x-c),
y~a+b*log(1+c^x),
y~a+b*x^c,
y~a*(x-b)^c,
y~a*(x/b)^c,
y~a*b^x+x^c,
y~a*x^(b*x-c),
y~(a*x^c)/(1+b*x^c),
y~(a*x^c)/(b^c+x^c),
y~a+b*exp(c*x),
y~a-b*exp(-c*x),
y~a*(1-b*exp(c*x)),
y~a*(1-exp(-b*x))^c,
y~a+(b*(exp(c*x)-1))/c,
y~exp(a+b*x+c*x^2),
y~a/(1+exp(-b*(x-c))),
y~a*sin((pi*(x-b))/c)
)



nls.find - function(formula, data, start=NULL, ...){
ll - length(formula)
result2 - vector(list, ll)
result1 - rep(NA, ll)
names(data) - c(x,y)

for(i in 1:ll) {

if (is.null(start)) {
n - length(all.vars(formula[[i]]))-2
start - as.list(rep(mean(data[,2], na.rm=T),n))
names(start) - letters[1:n]
fit-try(nls(formula[[i]], data, start=start, ...))
} else {

if (is.logical(start)) {
fit-try(nls(formula[[i]], data, ...))
} else {
fit-try(nls(formula[[i]], data, start, ...)) }
}


if( class(fit)==try-error) result1[i] - NA  else result1[i] - 
sum(resid(fit)^2, na.rm=T)
if( class(fit)==try-error) result2[[i]] - NA  else result2[[i]] - 
coef(fit)
}
ooo-order(result1)
result - mapply(c, sq.resid = result1, result2, SIMPLIFY=FALSE)
names(result) - paste(1:ll, as.character(formula), sep=/)
result[ooo]
}






Petr Pikal
petr.pi...@precheza.cz
724008364, 581252140, 581252257


r-help-boun...@r-project.org napsal dne 02.04.2009 18:40:43:

 Hello,
 Is there a function in r to find the best fitting model for a set of 
data?
 I would like to know if my data are related exponentially,linearly or if 
there
 is a logarithmic correlation between my x and y values.
 To get a better imagination I've added the graphics at the end of this 
mail
 as an attachment.
 Thanks,  Ben
 -- 
 
 __
 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 pasting string as object name

2009-04-03 Thread Rob Denniker
I have a data frame containing monthly observations of the 'density' of each US 
state, recorded in variables named density.AL, density.AK, density.AZ, 
and so on for all 50 states. The data frame (called d) also contains a variable 
called Date which is encoded as a string in the format Jan-09, Feb-09, 
etc.

I also have a vector st.list-c(AL, AK, AZ,...) of length 50.

I would like a new dataframe with st.list in one column and the value of 
d$density for that state when d$Date==Feb-09 in another column.

How can I do this?

Here is what I have tried:

names - rep(d$density,length(st.list))
templist - as.vector(mapply(paste, names, st.list ,sep=.))

d.2-data.frame()
for (i in 1:length(templist)) {
d.2$density[i] - subset(parse(file=,templist[i]),d$Date==Feb-09)
i-i+1 }   ### hangs!


Thanks for any help!


GET FREE 5GB EMAIL - Check out spam free email with many cool features!
Visit http://www.inbox.com/email 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] plyr and table question

2009-04-03 Thread baptiste auguie

Dear all,

I'm puzzled by the following example inspired by a recent question on  
R-help,



cc - textConnection(user_id  website  time
20google0930
21yahoo0935
20facebook1000
25facebook1015
61google0940)

d - read.table(cc, head=T) ; close(cc)

table(d$user_id) # count the occurrences

# now I'd like to include these results in the original data.frame,

ddply(d, .(website), transform, count = table(user_id)) # why two new  
columns?


I just can't understand how this is different from,

ddply(d, .(website), transform, count = sum(user_id))


Many thanks,

baptiste

__
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] new line between '}' and 'else' in function body

2009-04-03 Thread Wacek Kusnierczyk
you can always wrap the whole if/else statement into innocent braces or
parentheses, as in

y = {
   if (x) 1
   else 2 }

y = (
   if (x) 1
   else 2 )

it doesn't have to be a function, and there is no need for the
assignment either -- you just need to tell the parser that the input
hasn't ended.  that's a matter of taste, but i find

{ if (x) 1
   else 2 }

more readable than something like

if (x) { 1
} else 2

vQ




Yihui Xie wrote:
 Thanks, Romain! So I think, for consistency, the following result

   
 deparse(parse(text = '
 
 + f = function(x) {
 +if (x) {
 +1
 +} # a new line here!
 +else {
 +2
 +}
 + }
 + ')
 + )
 [1] structure(expression(f = function(x) { if (x) {
 [3] 1  }
 [5] else { 2
 [7] }  }), srcfile =
 environment)

 should be

 [1] structure(expression(f = function(x) { if (x) {
 [3] 1  } else {
 [5] 2 }
 [7] }), srcfile = environment)

 instead.

 Regards,
 Yihui


__
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 pasting string as object name

2009-04-03 Thread baptiste auguie

Hi,

Is this what you want?

d - data.frame(density.AL = seq(1, 10),
density.AK = seq(1, 10),  # many others...
Date=letters[1:10]) # dummy example

library(reshape)
melt(subset(d, Date == b), id=Date)


BTW, I spotted a few awkward things in your code,


st - c(AL, AK)
vars - paste(d$density, st, sep=.) # easier than mapply etc.

more importantly, in the for loop you should not be incrementing i  
manually (as in a while loop), it's already taken care of by the for{}  
construct.




HTH,

baptiste

On 3 Apr 2009, at 10:40, Rob Denniker wrote:

I have a data frame containing monthly observations of the 'density'  
of each US state, recorded in variables named density.AL,  
density.AK, density.AZ, and so on for all 50 states. The data  
frame (called d) also contains a variable called Date which is  
encoded as a string in the format Jan-09, Feb-09, etc.


I also have a vector st.list-c(AL, AK, AZ,...) of length 50.

I would like a new dataframe with st.list in one column and the  
value of d$density for that state when d$Date==Feb-09 in another  
column.


How can I do this?

Here is what I have tried:

names - rep(d$density,length(st.list))
templist - as.vector(mapply(paste, names, st.list ,sep=.))

d.2-data.frame()
for (i in 1:length(templist)) {
d.2$density[i] - subset(parse(file=,templist[i]),d$Date==Feb-09)
i-i+1 }   ### hangs!


Thanks for any help!


GET FREE 5GB EMAIL - Check out spam free email with many cool  
features!

Visit http://www.inbox.com/email 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.


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
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] Functions Accessing Databases

2009-04-03 Thread bartjoosen

Hi,

There seems to be something wrong with your function getinfo.

Try first to substitute your dbGetQuery by a print statement, so that you
can see what is going on:
getinfo=function(t){print(the SQL query)}
allinfo=sapply(c(1985:2007),getinfo)

If these results look good, you can change your function back to
dbGetQuery(con, )
If not, show your results, and we will look again

Bart




Bob Roberts-2 wrote:
 
 Hello,
I'm accessing a MySQL database from inside R and had a problem with a
 function. In the database, there is data from years 1985 to 2007 that I
 would like to retrieve. I can easily get the data from one year by the
 following:
 info1985=dbGetQuery(con, statement='the SQL query')
 Inside the statement, I have a column that is set to the desired year
 (e.g. table.column=1985) through a WHERE clause, but when I write a
 function like the following:
 getinfo=function(t){dbGetQuery(con,statement='the SQL query')}
 and instead of using a specific year, I substitute in t (e.g.
 table.column=t) in a WHERE clause
 When I go to do
 allinfo=sapply(c(1985:2007),getinfo)
 I get the following error message: RS-DBI driver: (could not run
 statement: Unknown column 't' in 'where clause')
 Is there anyway around this error? Or is not possible to substitute in
 years with a function and sapply through SQL?
 Thanks so much.
 
 
 
   
   [[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.
 
 

-- 
View this message in context: 
http://www.nabble.com/Functions-Accessing-Databases-tp22860193p22865610.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] course in ecological data analysis

2009-04-03 Thread Capelle, Jacob
Dear all,
 
For my PhD study I'm looking for relevant courses/workshops (short term)
in ecological data anlysis with R in Europe. After 2 days searching I'm
convinced that google is probably not the right medium to find this
information. If anyone can help me I will be most grateful. 
Best regards - J. Capelle

[[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] factorise variables in a data.frame

2009-04-03 Thread baptiste auguie

Dear list,

I often need to convert several variables from numeric or integer into  
factors (before plotting, for instance), as in the following example,



d - data.frame(
x = seq(1, 10),
y = seq(1, 10),
z = rnorm(10),
a = letters[1:10])


d2 -
within(d, {
x = factor(x)
y = factor(y)
 })

str(d)
str(d2)


I'd like to write a function factorise() which takes a data.frame and  
a vector of variable names, and returns the original data.frame with  
the desired variables converted to factor,


factorise - function(d, f)
***ply(d, f, factor) # some apply function

also, perhaps a defactorise() function doing the reverse operation  
with as.numeric.


I played with the plyr package and the base apply family for a while  
but can't find any concise construct.


Best regards,

baptiste



_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
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] extract tables as data.frames from HTML source

2009-04-03 Thread Gabor Grothendieck
If the question is specific to getting stock data from
google finance then check out getSymbols.google
in the quantmod package.

Also note that there exists an r-sig-finance list for questions
pertaining to R and finance.

On Fri, Apr 3, 2009 at 2:18 AM, Yihui Xie xieyi...@gmail.com wrote:
 Hi,

 I wonder whether there is any convenient function (or package) to
 extract tables from a HTML page? e.g. from
 http://www.google.com/finance/historical?q=SHE:002251

 I know we can readLines('URL'), gsub('td...', '...', source), ...
 and at last get the numbers; I'm writing to ask whether someone has
 already contributed a more general function (with the package XML or
 other packages). Thanks!

 Regards,
 Yihui
 --
 Yihui Xie xieyi...@gmail.com
 Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
 Mobile: +86-15810805877
 Homepage: http://www.yihui.name
 School of Statistics, Room 1037, Mingde Main Building,
 Renmin University of China, Beijing, 100872, China

 __
 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] Trouble extracting graphic results from a bootstrap

2009-04-03 Thread Anders Bjorn
Hi,

I'm trying to extract a histogram over the results from a bootstrap. However
I keep receiving the error message Error in hist.default(boot.lrtest$ll,
breaks = scott) : 'x' must be numeric.
The bootstrap I'm running looks like:

 boot.test - function(data, indeces, maxit=20) {
+ y1 - fit1+e1[indeces]
+ mod1 - glm(y1 ~ X1-1, maxit=maxit)
+ y2 - fit2+e2[indeces]
+ mod2 - glm(y2~1, maxit=maxit)
+ ll - 2*(logLik(mod1)-logLik(mod2))
+ ll
+ }
 boot.lrtest - boot(data=M1, statistic=boot.test, R=2000, maxit=100);

 hist(boot.lrtest$ll, breaks=scott)  # This results in the error message
stated above

So my question is: what am I doing wrong?

//Anders

[[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] factorise variables in a data.frame

2009-04-03 Thread Wacek Kusnierczyk
baptiste auguie wrote:
 Dear list,

 I often need to convert several variables from numeric or integer into
 factors (before plotting, for instance), as in the following example,


 d - data.frame(
 x = seq(1, 10),
 y = seq(1, 10),
 z = rnorm(10),
 a = letters[1:10])
 

 d2 -
 within(d, {
 x = factor(x)
 y = factor(y)
  })
 
 str(d)
 str(d2)


 I'd like to write a function factorise() which takes a data.frame and
 a vector of variable names, and returns the original data.frame with
 the desired variables converted to factor,


would this not be good enough:

# dummy data
data = data.frame(x=1:10, y=1:10)

# a factorizer
factorize = function(data, columns=names(data)) {
   data[columns] = lapply(data[columns], as.factor)
   data }

sapply(factorize(data, 'x'), is)
# $x factor ...
# $y integer ...
lapply(factorize(data), is)
# $x factor ...
# $y factor ...
  

 factorise - function(d, f)
 ***ply(d, f, factor) # some apply function

 also, perhaps a defactorise() function doing the reverse operation
 with as.numeric.

then, perhaps,

# an izer
ize = function(data, columns=names(data), izer=as.factor) {
   data[columns] = lapply(data[columns], izer)
   data }

ize(data, 'x', as.logical)
   
or even

ize = function(izer)
   function(data, columns=names(data)) {
  data[columns] = lapply(data[columns], izer)
  data }

logicalize = ize(as.logical)
characterize = ize(as.character)
   
lapply(logicalize(data), is)
# $x logical ...
# $y logical ...
lapply(characterize(data, 'x'), is)
# $x character ...
# $y integer ...

etc.
   
vQ

__
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] Schoenfeld Residuals

2009-04-03 Thread Laura Bonnett
Dear All,

Sorry to bother you again.

I have a model:
coxfita=coxph(Surv(rem.Remtime/365,rem.Rcens)~all.sex,data=nearma)
and I'm trying to do a plot of Schoenfeld residuals using the code:
plot(cox.zph(coxfita))
abline(h=0,lty=3)

The error message I get is:
Error in plot.window(...) : need finite 'ylim' values
In addition: Warning messages:
1: In sqrt(x$var[i, i] * seval) : NaNs produced
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

My data (nearma) has a lot of rem.Remtime entries which are equal i.e
large amounts of tied data.  If I remove the entries where this is the
case from the dataset I get the results I want!

Please can someone explain why removing paients with tied remission
time has such an effect on the code and also how to remedy the problem
without removing patients?

Thank you very much,

Laura.

__
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] factorise variables in a data.frame

2009-04-03 Thread baptiste auguie

Excellent!

I felt it was fairly trivial but i can be quite dense on Friday  
mornings.


I really like the generalisation.

Many thanks,

baptiste


On 3 Apr 2009, at 12:11, Wacek Kusnierczyk wrote:


baptiste auguie wrote:

Dear list,

I often need to convert several variables from numeric or integer  
into

factors (before plotting, for instance), as in the following example,


d - data.frame(
   x = seq(1, 10),
   y = seq(1, 10),
   z = rnorm(10),
   a = letters[1:10])


d2 -
within(d, {
   x = factor(x)
   y = factor(y)
})

str(d)
str(d2)


I'd like to write a function factorise() which takes a data.frame and
a vector of variable names, and returns the original data.frame with
the desired variables converted to factor,



would this not be good enough:

   # dummy data
   data = data.frame(x=1:10, y=1:10)

   # a factorizer
   factorize = function(data, columns=names(data)) {
  data[columns] = lapply(data[columns], as.factor)
  data }

   sapply(factorize(data, 'x'), is)
   # $x factor ...
   # $y integer ...
   lapply(factorize(data), is)
   # $x factor ...
   # $y factor ...



factorise - function(d, f)
***ply(d, f, factor) # some apply function

also, perhaps a defactorise() function doing the reverse operation
with as.numeric.


then, perhaps,

   # an izer
   ize = function(data, columns=names(data), izer=as.factor) {
  data[columns] = lapply(data[columns], izer)
  data }

   ize(data, 'x', as.logical)

or even

   ize = function(izer)
  function(data, columns=names(data)) {
 data[columns] = lapply(data[columns], izer)
 data }

   logicalize = ize(as.logical)
   characterize = ize(as.character)

   lapply(logicalize(data), is)
   # $x logical ...
   # $y logical ...
   lapply(characterize(data, 'x'), is)
   # $x character ...
   # $y integer ...

etc.

vQ

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


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
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] Curve fitting,FDA for biological data

2009-04-03 Thread Triantafyllos Gkikopoulos
Dear all,

 Another newbie just got attracted to this mailing list.

 I am a biologist currently working my way through R, had sort play around with 
python earlier this year.

I have some data exhibiting periodicity ** my data consists of peaks and 
valleys, with peaks arising due to the presence of a repetitive structural 
unit,** with x being a reference grid (position along a chromosome) and y being 
strength of signal (this y signal fluctuates to give rise to the peaks and 
valleys). ie presence of a structural unit along a chromosome gives rise to a 
peak in my data.

I would like to use a curve fitting algorithm (I guess something like a fourier 
analysis and/or splines). Due to the nature of the data I would like to look 
for periodicities at different scales (along the x grid). So say 2-4 different 
splines/curves are probably enough to describe the 40,000 occourences of the 
repetitive structural unit in my data, while say 4-6 of these units could 
exhibit certain patterns in the way they group together.

I assume in my case, I can consider my x axis (position) to be equivalent to a 
time x axis as in signal processing.

I considered using the FDA package (silverman and ramsey I think). Does anyone 
have an ideas if this is the right way to go or suggestions etc

PS I have highlighted in the attached gif with red, the occourence of the 
repetitive signal (differences in the wavelength for example could be important 
but not more than 4 would be required to fit all data), and in yellow a 
hypothetical occourence of a periodicity in a different scale


 Thanks a lot

Dr Triantafyllos Gkikopoulos

The University of Dundee is a registered Scottish charity, No: SC015096
__
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] plyr and table question

2009-04-03 Thread hadley wickham
On Fri, Apr 3, 2009 at 4:43 AM, baptiste auguie ba...@exeter.ac.uk wrote:
 Dear all,

 I'm puzzled by the following example inspired by a recent question on
 R-help,


 cc - textConnection(user_id  website          time
 20        google            0930
 21        yahoo            0935
 20        facebook        1000
 25        facebook        1015
 61        google            0940)

 d - read.table(cc, head=T) ; close(cc)

 table(d$user_id) # count the occurrences

 # now I'd like to include these results in the original data.frame,

 ddply(d, .(website), transform, count = table(user_id)) # why two new
 columns?

Because ddply expects a data frame as output from your aggregation
function.  When the output isn't a data frame, it calls as.data.frame,
which in this case produces a data frame with two columns.

Hadley

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

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


Re: [R] Schoenfeld Residuals

2009-04-03 Thread David Winsemius
I am not sure that ties are the only reason. If I create a few ties in  
the ovarian dataset that Therneau and Lumley provide, all I get are  
some warnings:

 ovarian[4:5, 1] - mean(ovarian[4:5, 1])
 ovarian[6:8, 1] - mean(ovarian[6:8, 1])
 fit - coxph( Surv(futime, fustat) ~ age + rx, ovarian)
 temp- cox.zph(fit)

 plot(temp)
Warning messages:
1: In approx(xx, xtime, seq(min(xx), max(xx), length.out = 17)[2 *  :
  collapsing to unique 'x' values
2: In approx(xtime, xx, temp) : collapsing to unique 'x' values

The error message you get is requesting a finite ylim. Have you  
considered acceding with that request?


Alternative: Assuming the number of tied survival times is modest,  
have you tried jitter-ing the rem.Remtime variable a few times to see  
it the results are stable?


If the number of ties is large, then you need to review Thernaeu   
Gramsch section 3.3


--
David Winsemius

On Apr 3, 2009, at 7:57 AM, Laura Bonnett wrote:


Dear All,

Sorry to bother you again.

I have a model:
coxfita=coxph(Surv(rem.Remtime/365,rem.Rcens)~all.sex,data=nearma)
and I'm trying to do a plot of Schoenfeld residuals using the code:
plot(cox.zph(coxfita))
abline(h=0,lty=3)

The error message I get is:
Error in plot.window(...) : need finite 'ylim' values
In addition: Warning messages:
1: In sqrt(x$var[i, i] * seval) : NaNs produced
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

My data (nearma) has a lot of rem.Remtime entries which are equal i.e
large amounts of tied data.  If I remove the entries where this is the
case from the dataset I get the results I want!

Please can someone explain why removing paients with tied remission
time has such an effect on the code and also how to remedy the problem
without removing patients?

Thank you very much,

Laura.

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Geometric Brownian Motion Process with Jumps

2009-04-03 Thread John-Paul Taylor


Hi,


I have been using maxLik to do some MLE of Geometric Brownian Motion Process 
and everything has been going fine, but know I have tried to do it with jumps. 
I have create a vector of jumps and then added this into my log-likelihood 
equation, know I am getting a message:

NA in the initial gradient

My codes is hear

#
n-length(combinedlr)
j-c(1,2,3,4,5,6,7,8,9,10)
gbmploglik-function(param){
mu-param[1]
sigma-param[2]
lamda-param[3]
nu-param[4]
gama-param[5]
logLikVal- - n*lamda - .5*n*log(2*pi) + sum(log(sum(for(j in 
1:10)(cat((lamda^j/factorial(j))*(1/((sigma^2+j*gama^2)^.5)*exp( - 
(combinedlr-mu-j*nu)^2/2*(sigma^2+j*gama^2
logLikVal
}
rescbj- maxLik(gbmploglik, grad = NULL, hess = NULL, start=c(0,1,1,1,1), 
method = Newton-Raphson)
summary(rescbj)
#

I am also was wondering if anyone know if there was a package that dealt with 
Geometric Brownian Motion Process augmented with jumps. Then I could just put 
that into my code and might resolve the issue. 

Any suggest as to how to resolved this issue, are greatly apprecaited.

Yours truly,

JP

__
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] Linear model, finding the slope

2009-04-03 Thread Melissa2k9

Hi

for some data I working on I am merely plotting time against temperature for
a variable named filmclip. So for example, I have volunteers who watched
various film clips and have used infared camera to monitor the temperature
on their face at every second of the clip. 

The variable names I have used are Normalised ( for the temperature) and
Frame (for the time in seconds).

So I have fitted a linear model

model-lm(Normalised~Frame,data=All,subset=((Subject==1)(Filmclip==Whatever)

and coef(model)

gives me an intercept value and a value for the slope. Now what I want to do
is find out if the slope is significant or not. So far I just have values
such as 0.02211 for example and have no idea if this is to be interpreted as
significant or not. 

Sorry if I haven't been clear but any advice on how to find out what values
are significant would be greatly appreciated.
-- 
View this message in context: 
http://www.nabble.com/Linear-model%2C-finding-the-slope-tp22865254p22865254.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] Titles on lattice colorkey

2009-04-03 Thread r-help . 20 . trevva

Dear R-ers,

I'm not sure if this is a missing feature, a support request, or stupidity on my part, but nevertheless, its a question. Is it possible to add titles to colorkey legends? As far as I can tell, there is a command to do it for normal key legends, but not for colorkeys. 


eg it works for a normal key, created through auto.key

xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
  type = a,
  auto.key = list(space = right, points = FALSE, lines = TRUE,title=Key 
title))

but there is no comparable command for a colorkey

x - seq(pi/4, 5 * pi, length = 100)
y - seq(pi/4, 5 * pi, length = 100)
r - as.vector(sqrt(outer(x^2, y^2, +)))
grid - expand.grid(x=x, y=y)
grid$z - cos(r^2) * exp(-r/(pi^3))
levelplot(z~x*y, grid, cuts = 50, scales=list(log=e), xlab=,
 ylab=, main=Weird Function, sub=with log scales,
 region = TRUE,
 colorkey = list(space=right,title=Doesn't work))


Cheers,

Mark

__
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] plyr and table question

2009-04-03 Thread ts8


baptiste auguie-2 wrote:
 
 
 ddply(d, .(website), transform, count = table(user_id)) # why two new
 columns? 
 
 

Try this to see why:

  as.data.frame(table(d$user_id))

This works more like you expect:

  ddply(d, .(website), transform, count = unclass(table(user_id)))  

- Tom
-- 
View this message in context: 
http://www.nabble.com/plyr-and-table-question-tp22865174p22868047.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] how to do this the R way

2009-04-03 Thread onyourmark

Hi. I am sure there is a better way in R to do this then using a loop but I
am new to it and not sure what to do. I think it might be something about
using a function as an argument but not sure.

I have a 1 x 2000 vector TS2 which has entries from the set {x: x is in Z
and 0x8} (where Z is the set of Integers).

Then I also have a 5050 x 7 matrix called 'perm' whose entries are also from
the set {x: x is in Z and 0x8}

I want to construct the following transformation of TS2 which will still be
a vector of size 1 x 2000 and which I will call 'newTS2' such that:

newTS2 =(perm[100.TS2[1]]. perm[100.TS2[2]]. perm[100.TS2[3]]. ... ,
perm[100.TS2[2000]])

Is there a nice way to do this without a loop?

Thank  you. 
-- 
View this message in context: 
http://www.nabble.com/how-to-do-this-%22the-R-way%22-tp22864354p22864354.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] plyr and table question

2009-04-03 Thread hadley wickham
On Fri, Apr 3, 2009 at 8:43 AM, baptiste auguie ba...@exeter.ac.uk wrote:
 That makes sense, so I can do something like,

 count - function(x){
        as.integer(unclass(table(x)))
 }

 count(d$user_id)

 ddply(d, .(user_id), transform, count = count(user_id))

  user_id  website time count
 1      20   google  930     2
 2      20 facebook 1000     2
 3      21    yahoo  935     1
 4      25 facebook 1015     1
 5      61   google  940     1

 Have I missed a built-in function to obtain this result?

ddply(d, .(user_id), transform, count = nrow)

?

Hadley

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

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


Re: [R] Linear model, finding the slope

2009-04-03 Thread Uwe Ligges



Melissa2k9 wrote:

Hi

for some data I working on I am merely plotting time against temperature for
a variable named filmclip. So for example, I have volunteers who watched
various film clips and have used infared camera to monitor the temperature
on their face at every second of the clip. 


The variable names I have used are Normalised ( for the temperature) and
Frame (for the time in seconds).

So I have fitted a linear model

model-lm(Normalised~Frame,data=All,subset=((Subject==1)(Filmclip==Whatever)

and coef(model)

gives me an intercept value and a value for the slope. Now what I want to do
is find out if the slope is significant or not. So far I just have values
such as 0.02211 for example and have no idea if this is to be interpreted as
significant or not. 


Sorry if I haven't been clear but any advice on how to find out what values
are significant would be greatly appreciated.



See ?lm and ?summary.lm and try the examples.

Uwe Ligges

__
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 factor to double?

2009-04-03 Thread p . silva
Hi!

I'm reading a tab-seperated CVS file with:
test1 - read.table(data.txt, header=TRUE)

It's in the following format:

Date_Time qK qL vL vP  ...
0 30 22 110 88 ...
...

(BTW: It seems to me R shifts the column descriptions by one.)

Anyway, I would like to Fourier-transform one column. So I say:
 fft(test1$vP)
Error in levels(x)[x] : invalid subscript type 'complex'

I guess this is some typing error but I don't know which function I have to use 
for conversion.

Some more Info about the data:

 test1$vP[1:10]
 [1] 110 108 116 118 114 120 117 111 95  118
166 Levels: - 0 1 10 100 101 102 103 104 105 106 107 108 109 11 110 111 ... 99

 class( test1$vPkw)
[1] factor


I would appreciate any hints! Thanks in advance!

Best, Philip
--

__
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] plyr and table question

2009-04-03 Thread baptiste auguie

That makes sense, so I can do something like,

count - function(x){
as.integer(unclass(table(x)))
}

count(d$user_id)

ddply(d, .(user_id), transform, count = count(user_id))


  user_id  website time count
1  20   google  930 2
2  20 facebook 1000 2
3  21yahoo  935 1
4  25 facebook 1015 1
5  61   google  940 1


Have I missed a built-in function to obtain this result?

Thanks,

baptiste

On 3 Apr 2009, at 14:16, hadley wickham wrote:

On Fri, Apr 3, 2009 at 4:43 AM, baptiste auguie ba...@exeter.ac.uk  
wrote:

Dear all,

I'm puzzled by the following example inspired by a recent question on
R-help,


cc - textConnection(user_id  website  time
20google0930
21yahoo0935
20facebook1000
25facebook1015
61google0940)

d - read.table(cc, head=T) ; close(cc)

table(d$user_id) # count the occurrences

# now I'd like to include these results in the original data.frame,

ddply(d, .(website), transform, count = table(user_id)) # why two new
columns?


Because ddply expects a data frame as output from your aggregation
function.  When the output isn't a data frame, it calls as.data.frame,
which in this case produces a data frame with two columns.

Hadley

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


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
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] lme between-group and within-group covariance

2009-04-03 Thread MUHC-Research

I will try to make this more precise. In the lme() function, the
correlation argument allows the user to specify a within-group correlation
structure, i.e. the structure of the Lambda matrix using the mixed model
notation in Pineiro and Bates. What I want to do is specify a distinct
structure for the Psi matrix (same notation), that is, a correlation
structure for the random effects.

If lme() doesn't allow for this, is there any other function that I could
use?



MUHC-Research wrote:
 
 Dear R users,
 
 I would be interested in using the lme() function to fit a linear mixed
 model to a longitudinal dataset. I know this function allows for the
 specification of a within-group covariance structure. However, does it
 allow for the explicit specification of a between-group covariance
 structure?
 
 Being able to specify both separately would be very important in the
 context of my project since, as might be expected, they have different
 implications/interpretations.
 
 For instance, the mixed procedure in SAS allows users to specify the two
 structures separately by adding a value for the type argument after the
 RANDOM statement and the REPEATED statement.
 
 My question is thus if we can do the same with lme().
 
 I thank you most sincerely for your help. 
 

-- 
View this message in context: 
http://www.nabble.com/lme-between-group-and-within-group-covariance-tp22834748p22868945.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] Plotting multiple ablines

2009-04-03 Thread Thomas Levine
I've really been on a roll this week; the formula for the lines that I
presented was completely wrong.

But I'm glad I learned about mapply. I used this:

mapply(abline,
(converge$kY + tan((90-converge$kT) * pi / 180)*(-converge$kX)),
tan((90-converge$kT) * pi / 180))

Tom!

On Thu, Apr 2, 2009 at 8:29 AM, r...@quantide.com r...@quantide.com wrote:

 May be:

 plot(c(-1, 1) , c(-1, 1), type = n)
 n = 4
 a = rep(0, n)
 b = 1:n/n


 fun = function(i, a, b, col = 1 , ...) {
   abline(a[i], b[i], col = col[i], ...)
 }

 lapply(1:n, fun, a=a, b=b, col = 1:n)

 Andrea


 Thomas Levine wrote:

 I really want to do this:

 abline(
 a=tan(-kT*pi/180),
 b=kY-tan(-kT*pi/180)*kX
 )

 where kX,kY and kT are vectors of equal length. But I can't do that
 with abline unless I use a loop, and I haven't figured out the least
 unelegant way of writing the loop yet. So is there a way to do this
 without a loop?

 Or if I am to resort to the loop, what's the best way of doing it
 considering that I have some missing data? Here's the mess that I
 wrote.

 converge - na.omit(data.frame(kX,kY,kT))
 for (z in (length(converge$kT)))
 {abline(
 a=tan(converge$kT[z]*pi/180),
 b=converge$kY[z]-tan(-converge$kT[z]*converge$kX[z]*pi/180)
 )}

 I think the missing data are causing the problem; this happens when I run:

 Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
  'a' and 'b' must be finite

 __
 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] plyr and table question

2009-04-03 Thread baptiste auguie

of course!

Thanks,

baptiste

On 3 Apr 2009, at 14:48, hadley wickham wrote:

On Fri, Apr 3, 2009 at 8:43 AM, baptiste auguie ba...@exeter.ac.uk  
wrote:

That makes sense, so I can do something like,

count - function(x){
   as.integer(unclass(table(x)))
}

count(d$user_id)

ddply(d, .(user_id), transform, count = count(user_id))


 user_id  website time count
1  20   google  930 2
2  20 facebook 1000 2
3  21yahoo  935 1
4  25 facebook 1015 1
5  61   google  940 1


Have I missed a built-in function to obtain this result?


ddply(d, .(user_id), transform, count = nrow)

?

Hadley

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


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
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] Schoenfeld Residuals

2009-04-03 Thread Laura Bonnett
Thank you for your comments.  I have about 200 out of 2000 tied data
points which makes the situation more complicated!  I'll have at look
at the book section you referred to.  With regards to making the ylim
finite, I'm not sure how I can go about that given that I don't
understand why it isn't already!

Thank you for your help,

Laura

2009/4/3 David Winsemius dwinsem...@comcast.net:
 I am not sure that ties are the only reason. If I create a few ties in the
 ovarian dataset that Therneau and Lumley provide, all I get are some
 warnings:
 ovarian[4:5, 1] - mean(ovarian[4:5, 1])
 ovarian[6:8, 1] - mean(ovarian[6:8, 1])
 fit - coxph( Surv(futime, fustat) ~ age + rx, ovarian)
 temp- cox.zph(fit)

 plot(temp)
 Warning messages:
 1: In approx(xx, xtime, seq(min(xx), max(xx), length.out = 17)[2 *  :
  collapsing to unique 'x' values
 2: In approx(xtime, xx, temp) : collapsing to unique 'x' values

 The error message you get is requesting a finite ylim. Have you considered
 acceding with that request?

 Alternative: Assuming the number of tied survival times is modest, have you
 tried jitter-ing the rem.Remtime variable a few times to see it the results
 are stable?

 If the number of ties is large, then you need to review Thernaeu  Gramsch
 section 3.3

 --
 David Winsemius

 On Apr 3, 2009, at 7:57 AM, Laura Bonnett wrote:

 Dear All,

 Sorry to bother you again.

 I have a model:
 coxfita=coxph(Surv(rem.Remtime/365,rem.Rcens)~all.sex,data=nearma)
 and I'm trying to do a plot of Schoenfeld residuals using the code:
 plot(cox.zph(coxfita))
 abline(h=0,lty=3)

 The error message I get is:
 Error in plot.window(...) : need finite 'ylim' values
 In addition: Warning messages:
 1: In sqrt(x$var[i, i] * seval) : NaNs produced
 2: In min(x) : no non-missing arguments to min; returning Inf
 3: In max(x) : no non-missing arguments to max; returning -Inf

 My data (nearma) has a lot of rem.Remtime entries which are equal i.e
 large amounts of tied data.  If I remove the entries where this is the
 case from the dataset I get the results I want!

 Please can someone explain why removing paients with tied remission
 time has such an effect on the code and also how to remedy the problem
 without removing patients?

 Thank you very much,

 Laura.

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

 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT



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


Re: [R] Geometric Brownian Motion Process with Jumps

2009-04-03 Thread Ravi Varadhan
Hi,

The error message is clear in that the gradient cannot be evaluated at your
starting value for the parameters.   

Is your likelihood a smooth function of parameters?  If so, then provide a
different starting value. If it is not smooth, then you may have to use a
method that does not depend on gradients, such as Nelder-Mead.

Can you provide a reproducible example, which would help us dig deeper into
your problem?

Ravi. 


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of John-Paul Taylor
Sent: Friday, April 03, 2009 8:30 AM
To: r-help@r-project.org
Subject: Re: [R] Geometric Brownian Motion Process with Jumps



Hi,


I have been using maxLik to do some MLE of Geometric Brownian Motion Process
and everything has been going fine, but know I have tried to do it with
jumps. I have create a vector of jumps and then added this into my
log-likelihood equation, know I am getting a message:

NA in the initial gradient

My codes is hear

#
n-length(combinedlr)
j-c(1,2,3,4,5,6,7,8,9,10)
gbmploglik-function(param){
mu-param[1]
sigma-param[2]
lamda-param[3]
nu-param[4]
gama-param[5]
logLikVal- - n*lamda - .5*n*log(2*pi) + sum(log(sum(for(j in
1:10)(cat((lamda^j/factorial(j))*(1/((sigma^2+j*gama^2)^.5)*exp( -
(combinedlr-mu-j*nu)^2/2*(sigma^2+j*gama^2
logLikVal
}
rescbj- maxLik(gbmploglik, grad = NULL, hess = NULL, start=c(0,1,1,1,1),
method = Newton-Raphson)
summary(rescbj)
#

I am also was wondering if anyone know if there was a package that dealt
with Geometric Brownian Motion Process augmented with jumps. Then I could
just put that into my code and might resolve the issue. 

Any suggest as to how to resolved this issue, are greatly apprecaited.

Yours truly,

JP

__
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] [R-pkgs] New R graphics package targeting HTML 5 canvas element

2009-04-03 Thread Jeffrey Horner

Hi,

canvas is a new R package implementing a graphics device that emits 
javascript code conforming to the HTML 5 CanvasRenderingContext2D 
interface. Available on CRAN soon, but you can get it here immediately:


http://www.rforge.net/canvas

If you have access to a beta web browser like Firefox 3.1 or later, you 
can see example plots here:


http://www.rforge.net/canvas/plots/index.html

Clicking on one of the plots will take you to a comparator page where 
the plot is rendered twice, once with the canvas package and once with 
the png(type='cairo') function.


The implementation is almost complete, however there are some parts that 
need work like font metrics and dotted/dashed lines. If anyone is 
interested in helping flesh out the remaining bits, I'd be much obliged.


Best,

Jeff

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


Re: [R] Geometric Brownian Motion Process with Jumps

2009-04-03 Thread Ravi Varadhan
Hi,

The error message is clear in that the gradient cannot be evaluated at your
starting value for the parameters.   

Is your likelihood a smooth function of parameters?  If so, then provide a
different starting value. If it is not smooth, then you may have to use a
method that does not depend on gradients, such as Nelder-Mead.

Can you provide a reproducible example, which would help us dig deeper into
your problem?

Ravi. 


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of John-Paul Taylor
Sent: Friday, April 03, 2009 8:30 AM
To: r-help@r-project.org
Subject: Re: [R] Geometric Brownian Motion Process with Jumps



Hi,


I have been using maxLik to do some MLE of Geometric Brownian Motion Process
and everything has been going fine, but know I have tried to do it with
jumps. I have create a vector of jumps and then added this into my
log-likelihood equation, know I am getting a message:

NA in the initial gradient

My codes is hear

#
n-length(combinedlr)
j-c(1,2,3,4,5,6,7,8,9,10)
gbmploglik-function(param){
mu-param[1]
sigma-param[2]
lamda-param[3]
nu-param[4]
gama-param[5]
logLikVal- - n*lamda - .5*n*log(2*pi) + sum(log(sum(for(j in
1:10)(cat((lamda^j/factorial(j))*(1/((sigma^2+j*gama^2)^.5)*exp( -
(combinedlr-mu-j*nu)^2/2*(sigma^2+j*gama^2
logLikVal
}
rescbj- maxLik(gbmploglik, grad = NULL, hess = NULL, start=c(0,1,1,1,1),
method = Newton-Raphson)
summary(rescbj)
#

I am also was wondering if anyone know if there was a package that dealt
with Geometric Brownian Motion Process augmented with jumps. Then I could
just put that into my code and might resolve the issue. 

Any suggest as to how to resolved this issue, are greatly apprecaited.

Yours truly,

JP

__
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 factor to double?

2009-04-03 Thread Uwe Ligges



p.si...@gmx.net wrote:

Hi!

I'm reading a tab-seperated CVS file with:
test1 - read.table(data.txt, header=TRUE)

It's in the following format:

Date_Time qK qL vL vP  ...
0 30 22 110 88 ...
...

(BTW: It seems to me R shifts the column descriptions by one.)


No, look into your data file first.



Anyway, I would like to Fourier-transform one column. So I say:

fft(test1$vP)

Error in levels(x)[x] : invalid subscript type 'complex'

I guess this is some typing error but I don't know which function I have to use 
for conversion.

Some more Info about the data:


test1$vP[1:10]

 [1] 110 108 116 118 114 120 117 111 95  118
166 Levels: - 0 1 10 100 101 102 103 104 105 106 107 108 109 11 110 111 ... 99



Obviously there is some - sign in your data file. You might want to 
fix that prior to importing the data. You cannot convert easily to 
numeric with artifacts like the string - in your data.


Uwe Ligges



class( test1$vPkw)

[1] factor


I would appreciate any hints! Thanks in advance!

Best, Philip
--

__
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] (no subject)

2009-04-03 Thread dirk567
Dear R users,

I am trying to do exact matching on a large dataset (500.000 obs), about equal 
size of treatment and controll group, with replacement: As for the moment I use 
the Match function of the Matching library. I match on 2 covariates and all 
observations in the treatment group have at least one exact counterpart in the 
controllgroup. Now I want to introduce observation weights. I set ties=FALSE, 
as I want exactly one by one matching: Is there a way which makes that I draw 
randomly from the individuals in the controllgroup which have the same values 
of covariates as the individual in the treatmentgroup, setting the 
probabilities to be drawn proportional to the weights of the individual in the 
CT? E.g. I have three individuals which all have the same value for the 
covariates as the one observation I want to find a partner for, and the first 
of the three individuals has a very large weight: Now when drawing randomly 
among those three I want the probability that the first one is dr!
 awn to be very large.

I'd really appreciate any suggestions: the weights option does not do the 
job, this seems to work only if setting ties=TRUE



Thanks
Dirk
--

__
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 do this the R way

2009-04-03 Thread Uwe Ligges



onyourmark wrote:

Hi. I am sure there is a better way in R to do this then using a loop but I
am new to it and not sure what to do. I think it might be something about
using a function as an argument but not sure.

I have a 1 x 2000 vector TS2 which has entries from the set {x: x is in Z
and 0x8} (where Z is the set of Integers).

Then I also have a 5050 x 7 matrix called 'perm' whose entries are also from
the set {x: x is in Z and 0x8}

I want to construct the following transformation of TS2 which will still be
a vector of size 1 x 2000 and which I will call 'newTS2' such that:

newTS2 =(perm[100.TS2[1]]. perm[100.TS2[2]]. perm[100.TS2[3]]. ... ,


Perhaps you can explain what the last line is supposed to do? This is 
invalid R code and also not a known mathematical notation for me 


Uwe Ligges



perm[100.TS2[2000]])

Is there a nice way to do this without a loop?

Thank  you.


__
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] for loop for extracting linear model info

2009-04-03 Thread Uwe Ligges



Melissa2k9 wrote:

Hi,

I have written a for loop as such:

model-lm(Normalised~Frame,data=All,subset=((Subject==1)(Filmclip==Strand)))
summary(model)

###
#To extract just the Adjusted R squared
###

rsq-summary(model)[[9]]

###
#To extract just the slope
###

slope-summary(model)[[4]][[2]]

###
#To extract only the p value from the t test for slope
###

pvalue-summary(model)[[4]][[8]]


data-data.frame(slope,pvalue,rsq)



###
#To extract this info for all films


for (i in c(1:8,10:20,22:29))
{
model_1-lm(Normalised~Frame,data=All,subset=((Subject==i)(Filmclip==Strand)))
summary(model_1)
slope-summary(model_1)[[4]][[2]]
pvalue-summary(model_1)[[4]][[8]]
rsq-summary(model_1)[[9]]
data2-data.frame(slope,pvalue,rsq)
data2-rbind(data,data2)
}

I want this to run for all i but so far I am only getting two entries in my
data frame, one for the first subject, and another.



You are overwriting the old data2 with a new one that consists of those 
two in each iteration of the loop ...



Uwe Ligges



Does anyone know where I am going wrong in my code so I can have this data
for all subjects 1-8,10-20, and 22-29.

Thanks


__
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] course in ecological data analysis

2009-04-03 Thread milton ruser
Try

r-sig-ecol...@r-project.org

bests

miltinho
brazil-toronto

On Fri, Apr 3, 2009 at 6:27 AM, Capelle, Jacob jacob.cape...@wur.nl wrote:

 Dear all,

 For my PhD study I'm looking for relevant courses/workshops (short term)
 in ecological data anlysis with R in Europe. After 2 days searching I'm
 convinced that google is probably not the right medium to find this
 information. If anyone can help me I will be most grateful.
 Best regards - J. Capelle

[[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.htmlhttp://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] embed?

2009-04-03 Thread rkevinburton
I have a question on the function 'embed'. I ran the example

x - 1:10
embed(x, dimension=3)

This gives the output:

 [,1] [,2] [,3]
[1,]321
[2,]432
[3,]543
[4,]654
[5,]765
[6,]876
[7,]987
[8,]   1098

I don't quite understand the output and why it is useful. First, there are only 
8 rows down from 10 and the first element starts with 3. Of course I can think 
of explanations as to what is occuring but I cannot see how this is useful. I 
am sure it has application as i see this command used in much of the source but 
I just cannot see it now.

The documentation states:

Each row of the resulting matrix consists of sequences x[t], x[t-1], ..., 
x[t-dimension+1], where t is the original index of x. If x is a matrix, i.e., x 
contains more than one variable, then x[t] consists of the tth observation on 
each variable. 

This explanation doesn't seem to account for the dimension argument.

Thank you for your comments.

Kevin

__
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] DierckxSpline fitting with different sets of y-values in one time

2009-04-03 Thread spencerg
Dear Elisabeth: 

 Have you tried it?  I have not, but I suspect the answer is no. 

 What problem are you trying to solve?  You might get more useful 
suggestions from this list if you provide commented, minimal, 
self-contained, reproducible code describing your problem and what 
you've tried to solve it, as suggested in the posting guide 
www.R-project.org/posting-guide.html. 

 With fmri images, I might look first at the fields package, 
because it is explicitly designed for curve, surface and function 
fitting with an emphasis on splines, spatial data and spatial 
statistics. The major methods include cubic, robust, and thin plate 
splines, multivariate Kriging and Kriging for large data sets.  I have 
not used it, but it sounds to me like you might want thin plate 
splines.  Paul Dierckx (1993) Curve and Surface Fitting with Splines 
(Oxford Science Publications) discusses thin plate splines, and Dierckx 
wrote Fortran to fit them.  However, the DierckxSpline package does 
not currently connect to those capabilities. 

 If univariate splines would do, I might start with the fda 
package.  The theory behind that is documented in two books by Ramsay 
and Silverman. 

 Hope this helps. 
 Spencer Graves


Jonckers Elisabeth wrote:

Dear R users,

I have a question about the Package DierckxSpline. I have tried to find the 
answer by myself but it didn't worked out.

I wondered if Dierckxspline can use different sets of y values in one time to 
fit a line with knot. I have different sets of Y values representing the same 
thing for different voxels (in an fmri image). I have already fitted the data 
in different graphs and I know now that the plots are comparable for the 
different data sets (so for the different voxels) but I wanted to include all 
the information in one plot, If it's possible. So I want to know the best 
fitting line for the whole cluster of voxels except for one voxel.
If there is no possibility to do this I tought it would be an option to take 
the mean of the different y-values and use those values but I don't know if 
this is mathematical right to do.
I hope someone can help me with this.

Thank you very much,
Elisabeth Jonckers
GIfMI
Ghent University Hospital
Belgium

[[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] embed?

2009-04-03 Thread Gabor Grothendieck
Its lets you perform rolling summaries using apply:

 apply(embed(1:10, 3), 1, mean)
[1] 2 3 4 5 6 7 8 9

Note that 2 is the mean of 1:3, 3 is the mean of 2:4, ...,
9 is the mean of 8:10.

On Fri, Apr 3, 2009 at 11:04 AM,  rkevinbur...@charter.net wrote:
 I have a question on the function 'embed'. I ran the example

 x - 1:10
 embed(x, dimension=3)

 This gives the output:

     [,1] [,2] [,3]
 [1,]    3    2    1
 [2,]    4    3    2
 [3,]    5    4    3
 [4,]    6    5    4
 [5,]    7    6    5
 [6,]    8    7    6
 [7,]    9    8    7
 [8,]   10    9    8

 I don't quite understand the output and why it is useful. First, there are 
 only 8 rows down from 10 and the first element starts with 3. Of course I can 
 think of explanations as to what is occuring but I cannot see how this is 
 useful. I am sure it has application as i see this command used in much of 
 the source but I just cannot see it now.

 The documentation states:

 Each row of the resulting matrix consists of sequences x[t], x[t-1], ..., 
 x[t-dimension+1], where t is the original index of x. If x is a matrix, i.e., 
 x contains more than one variable, then x[t] consists of the tth observation 
 on each variable.

 This explanation doesn't seem to account for the dimension argument.

 Thank you for your comments.

 Kevin

 __
 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] embed?

2009-04-03 Thread Ravi Varadhan
Kevin,

The documentation is quite clear.

What embedding does is that it takes a scalar time series, x[t], and
embeds it in a higher-dimensional space of dimension, dimension.  The
entries in the matrix you see are the indices of the time-series.  

So, for example, if dimension = 2, you embed your time-series on a 2-Dim
space: (x, y), where the points are:  (x[2], x[1]), (x[3], x[2]), ...,
(x[N], x[N-1]).

 embed(x, dimension=2)
  [,1] [,2]
 [1,]21
 [2,]32
 [3,]43
 [4,]54
 [5,]65
 [6,]76
 [7,]87
 [8,]98
 [9,]   109


This is allso known as Ruelle-Takens embedding in non-linear dynamical
systems, where this device is helpful in detecting the existence of a
low-dimensional attractor of the time-series.
 
Ravi.


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of rkevinbur...@charter.net
Sent: Friday, April 03, 2009 11:05 AM
To: r-help@r-project.org
Subject: [R] embed?

I have a question on the function 'embed'. I ran the example

x - 1:10
embed(x, dimension=3)

This gives the output:

 [,1] [,2] [,3]
[1,]321
[2,]432
[3,]543
[4,]654
[5,]765
[6,]876
[7,]987
[8,]   1098

I don't quite understand the output and why it is useful. First, there are
only 8 rows down from 10 and the first element starts with 3. Of course I
can think of explanations as to what is occuring but I cannot see how this
is useful. I am sure it has application as i see this command used in much
of the source but I just cannot see it now.

The documentation states:

Each row of the resulting matrix consists of sequences x[t], x[t-1], ...,
x[t-dimension+1], where t is the original index of x. If x is a matrix,
i.e., x contains more than one variable, then x[t] consists of the tth
observation on each variable. 

This explanation doesn't seem to account for the dimension argument.

Thank you for your comments.

Kevin

__
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] course in ecological data analysis

2009-04-03 Thread Robert A LaBudde

At 05:27 AM 4/3/2009, Capelle, Jacob wrote:

Dear all,

For my PhD study I'm looking for relevant courses/workshops (short term)
in ecological data anlysis with R in Europe. After 2 days searching I'm
convinced that google is probably not the right medium to find this
information. If anyone can help me I will be most grateful.
Best regards - J. Capelle


Try http://www.statistics.com/


Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: r...@lcfltd.com
Least Cost Formulations, Ltd.URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239Fax: 757-467-2947

Vere scire est per causas scire

__
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] Curve fitting,FDA for biological data

2009-04-03 Thread trias

Here is the gif that didn't come through earlier
http://www.nabble.com/file/p22870832/signal.gif signal.gif 
-- 
View this message in context: 
http://www.nabble.com/Curve-fitting%2CFDA-for-biological-data-tp22868069p22870832.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] embed?

2009-04-03 Thread Wacek Kusnierczyk
rkevinbur...@charter.net wrote:
 I have a question on the function 'embed'. I ran the example

 x - 1:10
 embed(x, dimension=3)

 This gives the output:

  [,1] [,2] [,3]
 [1,]321
 [2,]432
 [3,]543
 [4,]654
 [5,]765
 [6,]876
 [7,]987
 [8,]   1098

 I don't quite understand the output and why it is useful. First, there are 
 only 8 rows down from 10 and the first element starts with 3. Of course I can 
 think of explanations as to what is occuring but I cannot see how this is 
 useful. I am sure it has application as i see this command used in much of 
 the source but I just cannot see it now.
   

 The documentation states:

 Each row of the resulting matrix consists of sequences x[t], x[t-1], ..., 
 x[t-dimension+1], where t is the original index of x. If x is a matrix, i.e., 
 x contains more than one variable, then x[t] consists of the tth observation 
 on each variable. 

 This explanation doesn't seem to account for the dimension argument.
   

following this 'explanation', the first row consists of values x[t],
x[t-1], ... x[t-3+1], that is, x[t], x[t-1], x[t-2].  how does t, the
original index of x, relate to positions in the matrix?  does it
correspond to the row number, or the column number?  it can't be the
former, because then the first row would include x[1], x[0], x[-1] --
nonsense.  it can't be the latter, because the first row would include
x[1], x[1], x[1] (nonsense), and so all other rows (nonsense).

for a vector, say x, the output, say matrix, contains values calculated
as follows:

m[i,j] = x[i + dimension - j], with i = 1, ...,
length(x)-dimension+1 and j = 1, ..., dimension

so that you have a rolling window over the vector, with row indices
corresponding to the start of the window, and column indices
corresponding to the position within the window.

arguably, the authors could have done their homework better.

vQ

__
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] Curve fitting,FDA for biological data

2009-04-03 Thread stephen sefick
What is your end goal?  If it is to try and account for the
variability of the timeseries you may want to look at ?spectrum
If it is to model the periodicity...

Stephen Sefick

On Fri, Apr 3, 2009 at 11:30 AM, trias t.gkikopou...@dundee.ac.uk wrote:

 Here is the gif that didn't come through earlier
 http://www.nabble.com/file/p22870832/signal.gif signal.gif
 --
 View this message in context: 
 http://www.nabble.com/Curve-fitting%2CFDA-for-biological-data-tp22868069p22870832.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.




-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
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] embed?

2009-04-03 Thread markleeds

   Hi kevin: one use ( there are probably many others ) is for use inside
   a vector autoregression model where the RHS is
   lags of the independent variable. So, x_t is the 3rd column, x_t-1 is the
   second, x_t-2 is the third etc.

   On Apr 3, 2009, rkevinbur...@charter.net wrote:

 I have a question on the function 'embed'. I ran the example
 x - 1:10
 embed(x, dimension=3)
 This gives the output:
 [,1] [,2] [,3]
 [1,] 3 2 1
 [2,] 4 3 2
 [3,] 5 4 3
 [4,] 6 5 4
 [5,] 7 6 5
 [6,] 8 7 6
 [7,] 9 8 7
 [8,] 10 9 8
 I don't quite understand the output and why it is useful. First, there are
 only 8 rows down from 10 and the first element starts with 3. Of course I
 can think of explanations as to what is occuring but I cannot see how this
 is useful. I am sure it has application as i see this command used in much
 of the source but I just cannot see it now.
 The documentation states:
 Each row of the resulting matrix consists of sequences x[t], x[t-1], ...,
 x[t-dimension+1], where t is the original index of x. If x is a matrix,
 i.e., x contains more than one variable, then x[t] consists of the tth
 observation on each variable.
 This explanation doesn't seem to account for the dimension argument.
 Thank you for your comments.
 Kevin
 __
 [1]r-h...@r-project.org mailing list
 [2]https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 [3]http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

References

   1. mailto:R-help@r-project.org
   2. https://stat.ethz.ch/mailman/listinfo/r-help
   3. http://www.R-project.org/posting-guide.html
__
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 pasting string as object name

2009-04-03 Thread Rob Denniker
What a very useful package! Thanks for pointing out its existence.

Sadly ?melt is basically useless, but I did find the following quasi-vignette 
by the author of the reshape package to be quite useful. 
http://www.jstatsoft.org/v21/i12/paper

Cheers.

 -Original Message-
 From: ba...@exeter.ac.uk
 Sent: Fri, 3 Apr 2009 11:02:31 +0100
 To: bearmarketsr...@inbox.com
 Subject: Re: [R] Help pasting string as object name
 
 Hi,
 
 Is this what you want?
 
 d - data.frame(density.AL = seq(1, 10),
   density.AK = seq(1, 10),  # many others...
   Date=letters[1:10]) # dummy example
 
 library(reshape)
 melt(subset(d, Date == b), id=Date)
 
 
 BTW, I spotted a few awkward things in your code,
 
 
 st - c(AL, AK)
 vars - paste(d$density, st, sep=.) # easier than mapply etc.
 
 more importantly, in the for loop you should not be incrementing i
 manually (as in a while loop), it's already taken care of by the for{}
 construct.
 
 
 
 HTH,
 
 baptiste
 
 On 3 Apr 2009, at 10:40, Rob Denniker wrote:
 
 I have a data frame containing monthly observations of the 'density'
 of each US state, recorded in variables named density.AL,
 density.AK, density.AZ, and so on for all 50 states. The data
 frame (called d) also contains a variable called Date which is
 encoded as a string in the format Jan-09, Feb-09, etc.
 
 I also have a vector st.list-c(AL, AK, AZ,...) of length 50.
 
 I would like a new dataframe with st.list in one column and the
 value of d$density for that state when d$Date==Feb-09 in another
 column.
 
 How can I do this?
 
 Here is what I have tried:
 
 names - rep(d$density,length(st.list))
 templist - as.vector(mapply(paste, names, st.list ,sep=.))
 
 d.2-data.frame()
 for (i in 1:length(templist)) {
 d.2$density[i] - subset(parse(file=,templist[i]),d$Date==Feb-09)
 i-i+1 }   ### hangs!
 
 
 Thanks for any help!
 
 
 GET FREE 5GB EMAIL - Check out spam free email with many cool
 features!
 Visit http://www.inbox.com/email 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.
 
 _
 
 Baptiste Auguié
 
 School of Physics
 University of Exeter
 Stocker Road,
 Exeter, Devon,
 EX4 4QL, UK
 
 Phone: +44 1392 264187
 
 http://newton.ex.ac.uk/research/emag
 __


GET FREE 5GB EMAIL - Check out spam free email with many cool features!
Visit http://www.inbox.com/email 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] Fit unequal variance model in R

2009-04-03 Thread Dieter Menne


Feng Jingyu wrote:
 
 I used gls and it still does not provide me different estimates of
 variance for each treatment group. Did I do anything wrong?
 
 lm3-gls(GSI~treatment,data=z,weights=varIdent(form=~treatment),method=ML)
 

try

weights = varIdent(form~1|treatment)

See the example in library/nlme/scripts/ch05.r ,fm1Orth.gls

Dieter




-- 
View this message in context: 
http://www.nabble.com/Fit-unequal-variance-model-in-R-tp22829549p22873236.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] Constrined dependent optimization.

2009-04-03 Thread rkevinburton
I have decided to use this SANN approach to my problem but to keep the run time 
reasonable instead of 20,000 variables I will randomly sample this space to get 
the number of variables under 100. But I want to do this a number of times. Is 
there someone who could help me set up WINBUGS to repeat this optimization N 
times each time randomly picking 100 of the possible 20,000.

Comments?

Kevin

 Paul Smith phh...@gmail.com wrote: 
 Apparently, the convergence is faster if one uses this new swap function:
 
 swapfun - function(x,N=100) {
  loc - c(sample(1:(N/2),size=1,replace=FALSE),sample((N/2):100,1))
  tmp - x[loc[1]]
  x[loc[1]] - x[loc[2]]
  x[loc[2]] - tmp
  x
 }
 
 It seems that within 20 millions of iterations, one gets the exact
 optimal solution, which does not take too long.
 
 Paul
 
 
 On Mon, Mar 30, 2009 at 5:11 PM, Paul Smith phh...@gmail.com wrote:
  Optim with SANN also solves your example:
 
  ---
 
  f - function(x) sum(c(1:50,50:1)*x)
 
  swapfun - function(x,N=100) {
   loc - sample(N,size=2,replace=FALSE)
   tmp - x[loc[1]]
   x[loc[1]] - x[loc[2]]
   x[loc[2]] - tmp
   x
  }
 
  N - 100
 
  opt1 - 
  optim(fn=f,par=sample(1:N,N),gr=swapfun,method=SANN,control=list(maxit=5,fnscale=-1,trace=10))
  opt1$par
  opt1$value
 
  ---
 
  We need to specify a large number of iterations to get the optimal
  solution. The objective function at the optimum is 170425, and one
  gets a close value with optim and SANN.
 
  Paul
 
 
  On Mon, Mar 30, 2009 at 2:22 PM, Hans W. Borchers
  hwborch...@googlemail.com wrote:
 
  Image you want to minimize the following linear function
 
     f - function(x) sum( c(1:50, 50:1) * x / (50*51) )
 
  on the set of all permutations of the numbers 1,..., 100.
 
  I wonder how will you do that with lpSolve? I would simply order
  the coefficients and then sort the numbers 1,...,100 accordingly.
 
  I am also wondering how optim with SANN could be applied here.
 
  As this is a problem in the area of discrete optimization resp.
  constraint programming, I propose to use an appropriate program
  here such as the free software Bprolog. I would be interested to
  learn what others propose.
 
  Of course, if we don't know anything about the function f then
  it amounts to an exhaustive search on the 100! permutations --
  probably not a feasible job.
 
  Regards,  Hans Werner
 
 
 
  Paul Smith wrote:
 
  On Sun, Mar 29, 2009 at 9:45 PM,  rkevinbur...@charter.net wrote:
  I have an optimization question that I was hoping to get some suggestions
  on how best to go about sovling it. I would think there is probably a
  package that addresses this problem.
 
  This is an ordering optimzation problem. Best to describe it with a
  simple example. Say I have 100 bins each with a ball in it numbered
  from 1 to 100. Each bin can only hold one ball. This optimization is that
  I have a function 'f' that this array of bins and returns a number. The
  number returned from f(1,2,3,4) would return a different number from
  that of f(2,1,3,4). The optimization is finding the optimum order of
  these balls so as to produce a minimum value from 'f'.I cannot use the
  regular 'optim' algorithms because a) the values are discrete, and b) the
  values are dependent ie. when the variable representing the bin
  location is changed (in this example a new ball is put there) the
  existing ball will need to be moved to another bin (probably swapping
  positions), and c) each variable is constrained, in the example above
  the only allowable values are integers from 1-100. So the problem becomes
  finding the optimum order of the balls.
 
  Any suggestions?
 
  If your function f is linear, then you can use lpSolve.
 
  Paul
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
  --
  View this message in context: 
  http://www.nabble.com/Constrined-dependent-optimization.-tp22772520p22782922.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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting 

[R] Conversions From standard to metric units

2009-04-03 Thread stephen sefick
I am starting to use R for almost any sort of calculation that I need.
 I am a biologist that works in the states, and there is often a need
to convert from standard units to metric units.  Is there a package in
R for this already?  If not I believe that I am going to write some of
the most often used in function form.  My question is should I include
this in my StreamMetabolism package.  It is not along the same theme
lines, but could loosely fit.  The reason that I ask is that I don't
want to clutter CRAN with a small package containing some conversion
functions because I am to lazy to source them into R every time that I
use them, but I also don't want the StreamMetabolism package to turn
into StephenMisc Fuctions.  Thoughts, comments, or suggestions would
be appreciated.

-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
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] Trouble extracting graphic results from a bootstrap

2009-04-03 Thread David Winsemius


On Apr 3, 2009, at 7:10 AM, Anders Bjorn wrote:


Hi,

I'm trying to extract a histogram over the results from a bootstrap.  
However
I keep receiving the error message Error in hist.default(boot.lrtest 
$ll,

breaks = scott) : 'x' must be numeric.
The bootstrap I'm running looks like:


boot.test - function(data, indeces, maxit=20) {

+ y1 - fit1+e1[indeces]
+ mod1 - glm(y1 ~ X1-1, maxit=maxit)
+ y2 - fit2+e2[indeces]
+ mod2 - glm(y2~1, maxit=maxit)
+ ll - 2*(logLik(mod1)-logLik(mod2))
+ ll
+ }

boot.lrtest - boot(data=M1, statistic=boot.test, R=2000, maxit=100);


hist(boot.lrtest$ll, breaks=scott)  # This results in the error  
message

stated above

So my question is: what am I doing wrong?


At least two things, possibly 3 or 4:
1) not specifying from which package the function boot comes from,  
and ..

2) not offering a reproducible example. and possibly ..
3) assuming that boot.lrtest$ll will have any meaning, with the  
corollary..

4) not looking at boot.lrtest$ll with the str function.

Regarding 3), when I look at the documentation for boot in package  
boot, I see no component of the value returned from a boot call that  
has the name ll. The name ll will be thrown away after the  
function call and you need to refer to components of the boot object  
by the names that the developers used.


--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Updating a data frame

2009-04-03 Thread Seeliger . Curt
To my earlier question about updating a dataframe, and certainty that this 
has been solved several times before, Dr. Winsemius suggests  (Thanks!):
 I am sure this is not the most elegant method, but it will work.
 
 new - merge(nn,uu, by = c(a,b), all.x=T)
 new$y - with( new, (ifelse(!is.na(x.y), y.y, y.x) )  )
 new$x - with( new, (ifelse(!is.na(x.y), x.y, x.x) ) )
 new[ , c(a, b, x, y)]
 a b   x y
 1  1 1 100.000 -100.
 2  1 2   0.76826360.28821953
 3  1 3   0.62744360.08373154
 4  2 1   0.27503190.55738251
 5  2 2 200.000 -100.
 6  2 3   0.19193330.88803516
 7  3 1   0.36065590.72215405
 8  3 2   0.93962690.10943878
 9  3 3 300.000 -100.
 10 4 1 400.000 -100.
 11 4 2   0.56332170.63063714
 12 4 3   0.37129220.40779830

That was one of the methods I've considered, but the with() function 
cleans it up considerably.  I'll have to get more familiar with that.

I've also tried a merge()-less update that seems to work.  Still not quite 
as transparent as an SQL UPDATE or SAS MERGE step.  Can anyone suggest an 
improvement or alternate to either method?

nn - expand.grid('a'=1:4, 'b'=1:3)
nn$x - runif(nrow(nn))
nn$y - runif(nrow(nn))
uu - rbind(data.frame('a'=1, 'b'=1, 'x'=100, 'y'=-100)
   ,data.frame('a'=2, 'b'=2, 'x'=200, 'y'=-100)
   ,data.frame('a'=4, 'b'=1, 'x'=400, 'y'=-100)
   ,data.frame('a'=3, 'b'=3, 'x'=300, 'y'=-100)
   )

# This works, but it's sensitive to the order of the updates in uu.
corr - nn
corr[paste(corr$a, corr$b) %in% paste(uu$a, uu$b),]$x - uu$x
corr[paste(corr$a, corr$b) %in% paste(uu$a, uu$b),]$y - uu$y

# try updates in a different order, and it puts the updates in the wrong 
rows
uu-uu[c(2,4,3,1),] 
corr - nn
corr[paste(corr$a, corr$b) %in% paste(uu$a, uu$b),]$x - uu$x
corr[paste(corr$a, corr$b) %in% paste(uu$a, uu$b),]$y - uu$y

# ordering the dataframes first seems to work well.
ord.uu - uu[order(uu$a, uu$b),]
corr - nn[order(nn$a, nn$b),]
corr[paste(corr$a, corr$b) %in% paste(ord.uu$a, ord.uu$b),]$x - ord.uu$x
corr[paste(corr$a, corr$b) %in% paste(ord.uu$a, ord.uu$b),]$y - ord.uu$y


Enjoy the days,
cur
-- 
Curt Seeliger, Data Ranger
Raytheon Information Services - Contractor to ORD
seeliger.c...@epa.gov
541/754-4638

[[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] Conversions From standard to metric units

2009-04-03 Thread Duncan Murdoch

stephen sefick wrote:

I am starting to use R for almost any sort of calculation that I need.
 I am a biologist that works in the states, and there is often a need
to convert from standard units to metric units.  Is there a package in
R for this already?  If not I believe that I am going to write some of
the most often used in function form.  My question is should I include
this in my StreamMetabolism package.  It is not along the same theme
lines, but could loosely fit.  The reason that I ask is that I don't
want to clutter CRAN with a small package containing some conversion
functions because I am to lazy to source them into R every time that I
use them, but I also don't want the StreamMetabolism package to turn
into StephenMisc Fuctions.  Thoughts, comments, or suggestions would
be appreciated.

  
RSiteSearch turns up the MedUnits package; maybe your conversions are 
already there, or would fit within that package.


Duncan Murdoch

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


[R] Removing backslashes from data

2009-04-03 Thread Andrew Conway
I am trying to check for backslashes in data, then remove them when I  
find them, but am having a difficult time figuring out the best way to  
do it.  I know the backslash is the escape character in R, and I  
should be able to use 'gsub' to accomplish this, but I all I seem to  
be getting are errors.  For example:

If entry is:
Hello\World

I want:
HelloWorld

There are several entries with backslashes, and I need to find them  
and delete them.  All help is welcome, thank you.

___
Drew Conway
Ph.D. Student
Department of Politics, New York University
agc...@nyu.edu
http://homepages.nyu.edu/~agc282


[[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] Fit unequal variance model in R

2009-04-03 Thread Dieter Menne



Feng Jingyu wrote:
 
 Thanks a lot. The problem is solved. It took me a while to understand the
 output from the R. With little calculation, I am able to match results
 from R to SAS.
 
 

To conserve you sanity, don't try it. They will be different.

Dieter


-- 
View this message in context: 
http://www.nabble.com/Fit-unequal-variance-model-in-R-tp22829549p22873997.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] Conversions From standard to metric units

2009-04-03 Thread baptiste auguie


I had a similar need for conversions in optics. I put together several  
functions and data on r-forge, where it does not clutter CRAN but can  
still be shared conveniently with others.



baptiste


On 3 Apr 2009, at 19:27, Duncan Murdoch wrote:


stephen sefick wrote:
I am starting to use R for almost any sort of calculation that I  
need.

I am a biologist that works in the states, and there is often a need
to convert from standard units to metric units.  Is there a package  
in
R for this already?  If not I believe that I am going to write some  
of
the most often used in function form.  My question is should I  
include

this in my StreamMetabolism package.  It is not along the same theme
lines, but could loosely fit.  The reason that I ask is that I don't
want to clutter CRAN with a small package containing some conversion
functions because I am to lazy to source them into R every time  
that I

use them, but I also don't want the StreamMetabolism package to turn
into StephenMisc Fuctions.  Thoughts, comments, or suggestions would
be appreciated.



RSiteSearch turns up the MedUnits package; maybe your conversions are
already there, or would fit within that package.

Duncan Murdoch

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


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
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] data.frame to array?

2009-04-03 Thread rkevinburton
I have a list of data.frames

 str(bins)

List of 19217
 $ 100026:'data.frame': 1 obs. of  6 variables:
  ..$ Sku  : chr 100026
  ..$ Bin  : chr T149C
  ..$ Count: int 108
  ..$ X: int 20
  ..$ Y: int 149
  ..$ Z: chr 3
 $ 100030:'data.frame': 1 obs. of  6 variables:
...
As you can see one 'column' is Count. This list seems to contain 19217 
data.frames. I would like to create an array of 19217 integers which hold the 
values of the Count column. I have tried the obvious (to me):

bins[[1:3]]$Count

But that returns NULL instead of an array of length 3 that I was expecting. 
Interestingly bins[[1]]$Count returns the first Count in the list of data 
frames. How do I get all of the Counts?

Thank you.

Kevin

__
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] Working with and without formula in function

2009-04-03 Thread dogle

I am attempting to write a function that is flexible enough to respond to the
user providing a formula (with a data= argument) or not (similar to
plot(x,y) versus plot(y~x,data=data)).  I have found a method to work with
this in a simple case but am having trouble determining how to find a
variable from within the data= argument that is not part of the formula. 
The following illustrates my problem ...

# an illustrative function -- I know that plotrix::thigmophobe.labels() does
what this function does
myplot - function(x,y=NULL,data=NULL,label=NULL) {
  if (class(x)==formula) {
mf - model.frame(x,data=data)
x - mf[,2]
y - mf[,1]
  } 
  if (is.null(y)) stop(Y-axis variable is missing)
  plot(x,y)
  if (!is.null(label)) text(x,y,label)
}

# dummy data
df -
data.frame(x=runif(10),y=runif(10),grp=factor(rep(c(Yes,No),each=5)))

# both calls work as expected
with(df,myplot(x,y))
myplot(y~x,data=df)

# only first works as I would hope
with(df,myplot(x,y,label=grp))
myplot(y~x,data=df,label=grp)

# this works but is clumsy
myplot(y~x,data=df,label=df$grp)


Any help with how to make this function recognize the grp variable in df
without having to type df$grp when supplying it to the label= argument
would be greatly appreciated.  Thank you in advance.
-- 
View this message in context: 
http://www.nabble.com/Working-with-and-without-formula-in-function-tp22874005p22874005.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] dendrogram rect.hclust() not working?

2009-04-03 Thread Alex Reynolds
I have tried to use rect.hclust() to draw a rectangle around a set of  
leaves, but am running into trouble.


The rect.hclust() is drawing two rects instead of one, and of the  
wrong size:



scoreClusterObj - hclust(scoreDistanceObj, method=clustMethod)
order - scoreClusterObj$order
orderedLabels - rep(0, length(order))
for (orderIndex in 1:length(order)) {
# this puts a name to the permutation of leaves, done by hclust()
orderedLabels[orderIndex] - classes[order[orderIndex]]
}
scoreDendrogramObj - as.dendrogram(scoreClusterObj)
coloredLeafScoreDendrogramObj - dendrapply(scoreDendrogramObj,  
markColoredLeaves)
scoreDendrogramPlot - plot(coloredLeafScoreDendrogramObj,  
horiz=FALSE, axes=FALSE)
significantClustersInScoreDendrogramObj -  
dendrapply(coloredLeafScoreDendrogramObj, markSignificantClusters)



I have the local functions markColoredLeaves() -- which changes the  
colors of certain leaves, and it works fine -- and another function  
called markSignificantClusters(), in which I try to draw a  
rect.hclust() if a condition is met (i.e. a cluster is statistically  
significant):


markSignificantClusters - function (n) {
if (!is.leaf(n)) {
a - attributes(n)
leafList - unlist(dendrapply(n, listLabels))
if (nodesContainCertainLeaves) {
ma - match(leafList, orderedLabels)
print (paste (min-ma, min(ma), max-ma, max(ma), sep= 
))
			r - rect.hclust(scoreClusterObj, h = a$height, which = c(min(ma),  
max(ma)), border = 2)

print (r)
quit()
}
}
}

For testing, I have a call to quit() the script after the first  
qualifying node has a rect drawn around it.


So I run this script, and when I look at the runtime log output (from  
the print() statements), it finds the correct, qualifying node  
containing the following two items:


[1] clusters
[1] +v_stat3_01 +v_stat1_01

These two leaves are located at positions 5 and 6 of the tree. This is  
correct output from the statistical test. So I should only get one  
rect drawn, of width 2, containing leaves 5 and 6.


Also, the ma variable is returning the correct leaf range (between 5  
and 6, inclusively), so I know I'm passing the correct leaf range to  
the rect.hclust() function.


But in my graphical output, I get two rects at positions 6 and 7:

http://www.flickr.com/photos/alexreynolds/3409263765/sizes/o/

This doesn't seem to be an offset issue, for two reasons:

1. I am getting two rects, not one. Looking at the output from the  
print(r) statement, I see why two rects are drawn:


[[1]]
+v_stat1_01
273

[[2]]
+v_e2f1_q6_01
  326

2. When I re-run the script, I can occasionally get different cluster  
results. In one case, where I should get one rect of size 3  
(containing 3 leaves), instead I get two rects containing 2 and 4  
leaves, resp. separated by several other clusters.


Worse, if I plot the dendrogram horizontally, the rects are drawn of  
completely wrong dimensions:


scoreDendrogramPlot - plot(coloredLeafScoreDendrogramObj, horiz=TRUE,  
axes=FALSE)


yields:

http://www.flickr.com/photos/alexreynolds/3410126060/sizes/o/

Is there a way to use rect.hclust() that works reliably (in both  
orientations, or even in one orientation)?


Alternatively, is there a way to modify the thickness and color of the  
edges that draw down from a significant node?


I tried adding this to my markSignificantClusters() function, within  
the if (nodesContainCertainLeaves) block, to modify the edgePar  
settings of a qualifying node, to no effect:


n - dendrapply(n, function(e) { attr(e, edgePar) - list(lty=3,  
col=red); e })


If you got this far through this message, thanks. :) I would be  
grateful for any advice.


Thanks,
Alex

__
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] Removing backslashes from data

2009-04-03 Thread markleeds

   Below  works but it has two backslashes in the word. maybe someone can
   explain why the 4 and 2 works but 2 1 doesn't ? thanks.
   gsub(,,Hello\\World,perl=TRUE)

   On Apr 3, 2009, Andrew Conway agc...@nyu.edu wrote:

 I am trying to check for backslashes in data, then remove them when I
 find them, but am having a difficult time figuring out the best way to
 do it. I know the backslash is the escape character in R, and I
 should be able to use 'gsub' to accomplish this, but I all I seem to
 be getting are errors. For example:
 If entry is:
 Hello\World
 I want:
 HelloWorld
 There are several entries with backslashes, and I need to find them
 and delete them. All help is welcome, thank you.
 ___
 Drew Conway
 Ph.D. Student
 Department of Politics, New York University
 [1]agc...@nyu.edu
 [2]http://homepages.nyu.edu/~agc282
 [[alternative HTML version deleted]]
 __
 [3]r-h...@r-project.org mailing list
 [4]https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 [5]http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

References

   1. mailto:agc...@nyu.edu
   2. http://homepages.nyu.edu/~agc282
   3. mailto:R-help@r-project.org
   4. https://stat.ethz.ch/mailman/listinfo/r-help
   5. http://www.R-project.org/posting-guide.html
__
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] Removing backslashes from data

2009-04-03 Thread Duncan Murdoch

On 4/3/2009 2:33 PM, Andrew Conway wrote:
I am trying to check for backslashes in data, then remove them when I  
find them, but am having a difficult time figuring out the best way to  
do it.  I know the backslash is the escape character in R, and I  
should be able to use 'gsub' to accomplish this, but I all I seem to  
be getting are errors.  For example:


If entry is:
Hello\World

I want:
HelloWorld

There are several entries with backslashes, and I need to find them  
and delete them.  All help is welcome, thank you.


This gets a little confusing because print() automatically doubles 
backslashes.  To see what's really going on, you need to use cat.  Then 
the following can be seen to work:


input - \Hello\\World\
cat(input, \n)
output - gsub(, , input)
cat(output, \n)

Duncan Murdoch



___
Drew Conway
Ph.D. Student
Department of Politics, New York University
agc...@nyu.edu
http://homepages.nyu.edu/~agc282


[[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] Fit unequal variance model in R

2009-04-03 Thread Dieter Menne


Feng Jingyu wrote:
 
 Hi For my purpose, I need to match variance estimates for each group from
 R and SAS. They do match now. 
 
Consider yourself a lucky man!

Dieter


-- 
View this message in context: 
http://www.nabble.com/Fit-unequal-variance-model-in-R-tp22829549p22874048.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] R. A. Fisher Test for value of periodorgam

2009-04-03 Thread Peterko

Is there in some pacakage this test? i mean that input will be only the value
of periodogram, and the function will say that are significant.

or is there only the way to calcule Fishers statistics W =Vi/V1 + · · · +
Vm, for i =1 m and test it step by step ?
thanks
-- 
View this message in context: 
http://www.nabble.com/R.-A.-Fisher-Test-for-value-of-periodorgam-tp22874210p22874210.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] Weighted principal components analysis?

2009-04-03 Thread Alan Cohen
Hello R-ers,

I'm trying to do a weighted principal components analysis.  I couldn't find any 
such option with princomp or prcomp.  Does anyone know of a package or way to 
do this?

More specifically, the observations I'm working with are averages from 
populations of varying sizes.  I thus need to weight the observations by sample 
size.  Ideally I could apply these weights at the cell level (i.e., allowing 
sample size to vary within observations across variables), but even applying 
them just to the observations would get me most of the way there.

I'm using R v2.8.1 on Windows XP.  I've searched Help and the R site and had no 
luck.  Thanks for any help you can provide.

Cheers,
Alan Cohen
Centre for Global Health Research
Toronto, Ontario

__
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] data.frame to array?

2009-04-03 Thread Gavin Simpson
On Fri, 2009-04-03 at 11:45 -0700, rkevinbur...@charter.net wrote:
 I have a list of data.frames
 
  str(bins)
 
 List of 19217
  $ 100026:'data.frame':   1 obs. of  6 variables:
   ..$ Sku  : chr 100026
   ..$ Bin  : chr T149C
   ..$ Count: int 108
   ..$ X: int 20
   ..$ Y: int 149
   ..$ Z: chr 3
  $ 100030:'data.frame':   1 obs. of  6 variables:
 ...
 As you can see one 'column' is Count. This list seems to contain 19217 
 data.frames. I would like to create an array of 19217 integers which hold the 
 values of the Count column. I have tried the obvious (to me):
 
 bins[[1:3]]$Count

sapply(bins, `[[`, Count)

will get you this as a vector.

HTH

G

 But that returns NULL instead of an array of length 3 that I was
 expecting. Interestingly bins[[1]]$Count returns the first Count in
 the list of data frames. How do I get all of the Counts?
 
 Thank you.
 
 Kevin
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



signature.asc
Description: This is a digitally signed message part
__
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] compute effect sizes (partial eta)

2009-04-03 Thread Martin Batholdy

hi,

is there a function that calculates and prints out the partial etas of  
every independent variable in a linear model?




thanks for any help!

__
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] data.frame to array?

2009-04-03 Thread David Winsemius

I do not think that the form [[1:3]] is legit.

 ltest - list( a, b, c, d)
 ltest[[1:3]]
Error in ltest[[1:3]] : recursive indexing failed at level 2

You might try with single brackets:
 ltest[1:3]
[[1]]
[1] a

[[2]]
[1] b

[[3]]
[1] c

--  
David Winsemius




On Apr 3, 2009, at 2:45 PM, rkevinbur...@charter.net wrote:


I have a list of data.frames


str(bins)


List of 19217
$ 100026:'data.frame':  1 obs. of  6 variables:
 ..$ Sku  : chr 100026
 ..$ Bin  : chr T149C
 ..$ Count: int 108
 ..$ X: int 20
 ..$ Y: int 149
 ..$ Z: chr 3
$ 100030:'data.frame':  1 obs. of  6 variables:
...
As you can see one 'column' is Count. This list seems to contain  
19217 data.frames. I would like to create an array of 19217 integers  
which hold the values of the Count column. I have tried the  
obvious (to me):


bins[[1:3]]$Count

But that returns NULL instead of an array of length 3 that I was  
expecting. Interestingly bins[[1]]$Count returns the first Count  
in the list of data frames. How do I get all of the Counts?


Thank you.

Kevin


__
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] data.frame to array?

2009-04-03 Thread hadley wickham
On Fri, Apr 3, 2009 at 1:45 PM,  rkevinbur...@charter.net wrote:
 I have a list of data.frames

 str(bins)

 List of 19217
  $ 100026:'data.frame': 1 obs. of  6 variables:
  ..$ Sku  : chr 100026
  ..$ Bin  : chr T149C
  ..$ Count: int 108
  ..$ X    : int 20
  ..$ Y    : int 149
  ..$ Z    : chr 3
  $ 100030:'data.frame': 1 obs. of  6 variables:
 ...
 As you can see one 'column' is Count. This list seems to contain 19217 
 data.frames. I would like to create an array of 19217 integers which hold the 
 values of the Count column. I have tried the obvious (to me):

 bins[[1:3]]$Count

 But that returns NULL instead of an array of length 3 that I was expecting. 
 Interestingly bins[[1]]$Count returns the first Count in the list of data 
 frames. How do I get all of the Counts?

Why not turn your list of data frames into a single data frame?

bindf - do.call(rbind, bins)
bindf$Count

Hadley

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

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


[R] US county map question

2009-04-03 Thread Smith, Phil (CDC/CCID/NCIRD)

Hi R-help:

I'm just an old guy and new to this list... But have been using R for
years now.

I want to make a map of counties in the US with shaded colors that
depend on the level of variable Y that I want to map.

I have the US county and state fips codes and the Y variable.

How do I do this?

Please reply to p...@cdc.gov

Thanks,
Phil Smith
p...@cdc.gov
 


[[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] data.frame to array?

2009-04-03 Thread Wacek Kusnierczyk
David Winsemius wrote:
 I do not think that the form [[1:3]] is legit.

sure it is. 


  ltest - list( a, b, c, d)
  ltest[[1:3]]
 Error in ltest[[1:3]] : recursive indexing failed at level 2

read the error message:  *recursive* indexing failed.  that's because
ltest[[1]] has only one element while you wanted its second element (and
that element's third element).

ltest = list(list(2, as.list(1:3)))
ltest[[1:3]]
# 3

is just fine.

vQ

__
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] Discriminant Analysis - Obtaining Classification Functions

2009-04-03 Thread Pavel Kúr
Hello!

I need some help with the linear discriminant analysis in R.
I have some plant samples (divided into several groups) on which I
measured a few quantitative characteristics. Now, I need to infer some
classification rules usable for identifying new samples.
I have used the function lda from the MASS library in a usual fashion:

lda.1 - lda(groups~char1+char2+char3, data=xxx)

I'd like to obtain the classification functions for the particular
groups, with the aid of which I could classify unknown samples. I know
I can use predict.lda to classify such samples, but I need to obtain
some equations into which I could simply put the measured values of an
unknown sample manually and the result would predict which group the
sample most probably belongs to (like in eg. STATISTICA).
I haven't found out how to extract these functions from the lda output.
Could somebody give me some advice?

Thank you in advance,

Pavel Kur

__
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] Changing the y-axis units of a lattice histogram

2009-04-03 Thread Judith Flores

Hello,

   I need to multiply the number of counts in the y-axis of a lattice histogram 
by a constant factor, such that the plot would represent a different type of 
variable plotted in the y-axis, not counts. Can this be done?

Thank you,

Judith

__
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] Changing the y-axis units of a lattice histogram

2009-04-03 Thread Sundar Dorai-Raj
Try:

library(lattice)
histogram( ~ height | voice.part,
  data = singer, type = c,
  scales = list(y =
list(at = seq(0, 20, 5),
 labels = seq(0, 200, 50

HTH,

--sundar

On Fri, Apr 3, 2009 at 2:01 PM, Judith Flores jur...@yahoo.com wrote:

 Hello,

   I need to multiply the number of counts in the y-axis of a lattice 
 histogram by a constant factor, such that the plot would represent a 
 different type of variable plotted in the y-axis, not counts. Can this be 
 done?

 Thank you,

 Judith

 __
 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] Multiple use of par()

2009-04-03 Thread Hesen Peng
Hi all,

I created a plot function which used par(mfcol=c(2,1)) so that I could
have two plots together using just one command.

For exampe:

plot.foo - function(data){
 par(mfcol=c(2,1))
 hist(data)
 plot(data)
}

Later I wanted to show 4 of these foo objects in the same picture. So
I used par(mfcol=c(2,2)) again at the beginning of the code like:

par(mfcol=c(2,2))
plot(foo.1)
plot(foo.2)
plot(foo.3)
plot(foo.4)

but this time the par() command inside of the functions seem to be
overwriting the par() command at the very begining. Can anyone please
give me some advise on dealing with this? I guess that I may either
need to change the way I plot foo, e.g. using some function rather
than par(), or use some parameters at the beginning. Thank you very
much,

Best wishes,



-- 
彭河森 Hesen Peng
http://hesen.peng.googlepages.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] Weighted principal components analysis?

2009-04-03 Thread Stéphane Dray

see the row.w argument of the function dudi.pca in the ade4 package.

Cheers.

Alan Cohen wrote:

Hello R-ers,

I'm trying to do a weighted principal components analysis.  I couldn't find any 
such option with princomp or prcomp.  Does anyone know of a package or way to 
do this?

More specifically, the observations I'm working with are averages from 
populations of varying sizes.  I thus need to weight the observations by sample 
size.  Ideally I could apply these weights at the cell level (i.e., allowing 
sample size to vary within observations across variables), but even applying 
them just to the observations would get me most of the way there.

I'm using R v2.8.1 on Windows XP.  I've searched Help and the R site and had no 
luck.  Thanks for any help you can provide.

Cheers,
Alan Cohen
Centre for Global Health Research
Toronto, Ontario

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


  


--
Stéphane DRAY (d...@biomserv.univ-lyon1.fr )
Laboratoire BBE-CNRS-UMR-5558, Univ. C. Bernard - Lyon I
43, Bd du 11 Novembre 1918, 69622 Villeurbanne Cedex, France
Tel: 33 4 72 43 27 57   Fax: 33 4 72 43 13 88
http://pbil.univ-lyon1.fr/members/dray/

__
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] Linear model, finding the slope

2009-04-03 Thread Charles Annis, P.E.
I'm not sure what you are doing when you Normalize.  Would you explain?

To see if the slope is significant, look at the model summary, in your
example:

summary(model)




Charles Annis, P.E.

charles.an...@statisticalengineering.com
phone: 561-352-9699
eFax:  614-455-3265
http://www.StatisticalEngineering.com
 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Melissa2k9
Sent: Friday, April 03, 2009 5:51 AM
To: r-help@r-project.org
Subject: [R] Linear model, finding the slope


Hi

for some data I working on I am merely plotting time against temperature for
a variable named filmclip. So for example, I have volunteers who watched
various film clips and have used infared camera to monitor the temperature
on their face at every second of the clip. 

The variable names I have used are Normalised ( for the temperature) and
Frame (for the time in seconds).

So I have fitted a linear model

model-lm(Normalised~Frame,data=All,subset=((Subject==1)(Filmclip==Whateve
r)

and coef(model)

gives me an intercept value and a value for the slope. Now what I want to do
is find out if the slope is significant or not. So far I just have values
such as 0.02211 for example and have no idea if this is to be interpreted as
significant or not. 

Sorry if I haven't been clear but any advice on how to find out what values
are significant would be greatly appreciated.
-- 
View this message in context:
http://www.nabble.com/Linear-model%2C-finding-the-slope-tp22865254p22865254.
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.


Re: [R] Discriminant Analysis - Obtaining Classification Functions

2009-04-03 Thread Emmanuel Charpentier
reauire(MASS) ; ?predict.lda should enlighten you. Glancing at VR4
might be a bit more illuminating...

HTH

Emmanuel Charpentier

Le vendredi 03 avril 2009 à 22:29 +0200, Pavel Kúr a écrit :
 Hello!
 
 I need some help with the linear discriminant analysis in R.
 I have some plant samples (divided into several groups) on which I
 measured a few quantitative characteristics. Now, I need to infer some
 classification rules usable for identifying new samples.
 I have used the function lda from the MASS library in a usual fashion:
 
 lda.1 - lda(groups~char1+char2+char3, data=xxx)
 
 I'd like to obtain the classification functions for the particular
 groups, with the aid of which I could classify unknown samples. I know
 I can use predict.lda to classify such samples, but I need to obtain
 some equations into which I could simply put the measured values of an
 unknown sample manually and the result would predict which group the
 sample most probably belongs to (like in eg. STATISTICA).
 I haven't found out how to extract these functions from the lda output.
 Could somebody give me some advice?
 
 Thank you in advance,
 
 Pavel Kur
 
 __
 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] [OT ?] rant (was : Re: Conversions From standard to metric units)

2009-04-03 Thread Emmanuel Charpentier
Le vendredi 03 avril 2009 à 14:17 -0400, stephen sefick a écrit :
 I am starting to use R for almost any sort of calculation that I need.
  I am a biologist that works in the states, and there is often a need
 to convert from standard units to metric units.

rant

US/Imperial units are *not* standard units. The former metric system
is now called Système International (International System) for a
reason, which is *not* gallocentrism of a few 6e7 frogs, but rather
laziness of about 5.6e9 losers who refuse to load their memories with
meaningless conversion factors...

/rant

Emmanuel Charpentier
who has served his time with
pounds per cubic feet, furlongs
per fortnight, BTU and other
figments of British/American
sadistic imagination, thank you
very much...

/rant # Again, didn't work the first time...

  Is there a package in
 R for this already?  If not I believe that I am going to write some of
 the most often used in function form.  My question is should I include
 this in my StreamMetabolism package.  It is not along the same theme
 lines, but could loosely fit.  The reason that I ask is that I don't
 want to clutter CRAN with a small package containing some conversion
 functions because I am to lazy to source them into R every time that I
 use them, but I also don't want the StreamMetabolism package to turn
 into StephenMisc Fuctions.  Thoughts, comments, or suggestions would
 be appreciated.
 

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


Re: [R] [OT ?] rant (was : Re: Conversions From standard to metric units)

2009-04-03 Thread Rolf Turner


On 4/04/2009, at 10:37 AM, Emmanuel Charpentier wrote:


Le vendredi 03 avril 2009 à 14:17 -0400, stephen sefick a écrit :
I am starting to use R for almost any sort of calculation that I  
need.

 I am a biologist that works in the states, and there is often a need
to convert from standard units to metric units.


rant

US/Imperial units are *not* standard units. The former metric system
is now called Système International (International System) for a
reason, which is *not* gallocentrism of a few 6e7 frogs, but rather
laziness of about 5.6e9 losers who refuse to load their memories with
meaningless conversion factors...

/rant


snip

Right on, Red Freak!!!

cheers,

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


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

##

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


Re: [R] [OT ?] rant (was : Re: Conversions From standard to metric units)

2009-04-03 Thread Duncan Murdoch

On 03/04/2009 5:37 PM, Emmanuel Charpentier wrote:

Le vendredi 03 avril 2009 à 14:17 -0400, stephen sefick a écrit :

I am starting to use R for almost any sort of calculation that I need.
 I am a biologist that works in the states, and there is often a need
to convert from standard units to metric units.


rant

US/Imperial units are *not* standard units. 


But they are fun:  you should see the arguments you can have about 
whether imperial fluid ounces are the same volume as US fluid ounces. 
(They're not: US ounces are bigger.  But not big enough so that their 
gallons catch up!)


Duncan Murdoch


The former metric system

is now called Système International (International System) for a
reason, which is *not* gallocentrism of a few 6e7 frogs, but rather
laziness of about 5.6e9 losers who refuse to load their memories with
meaningless conversion factors...

/rant

Emmanuel Charpentier
who has served his time with
pounds per cubic feet, furlongs
per fortnight, BTU and other
figments of British/American
sadistic imagination, thank you
very much...

/rant # Again, didn't work the first time...


 Is there a package in
R for this already?  If not I believe that I am going to write some of
the most often used in function form.  My question is should I include
this in my StreamMetabolism package.  It is not along the same theme
lines, but could loosely fit.  The reason that I ask is that I don't
want to clutter CRAN with a small package containing some conversion
functions because I am to lazy to source them into R every time that I
use them, but I also don't want the StreamMetabolism package to turn
into StephenMisc Fuctions.  Thoughts, comments, or suggestions would
be appreciated.



__
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] [OT ?] rant (was : Re: Conversions From standard to metricunits)

2009-04-03 Thread Murray Cooper

For science yes. For pleasure I'll still take a pint instead of 570ml!

Murray

- Original Message - 
From: Rolf Turner r.tur...@auckland.ac.nz

To: Emmanuel Charpentier charp...@bacbuc.dyndns.org
Cc: r-h...@stat.math.ethz.ch
Sent: Friday, April 03, 2009 6:18 PM
Subject: Re: [R] [OT ?] rant (was : Re: Conversions From standard to 
metricunits)




On 4/04/2009, at 10:37 AM, Emmanuel Charpentier wrote:


Le vendredi 03 avril 2009 à 14:17 -0400, stephen sefick a écrit :

I am starting to use R for almost any sort of calculation that I  need.
 I am a biologist that works in the states, and there is often a need
to convert from standard units to metric units.


rant

US/Imperial units are *not* standard units. The former metric system
is now called Système International (International System) for a
reason, which is *not* gallocentrism of a few 6e7 frogs, but rather
laziness of about 5.6e9 losers who refuse to load their memories with
meaningless conversion factors...

/rant


snip

Right on, Red Freak!!!

cheers,

Rolf
##
Attention:\ This e-mail message is privileged and confid...{{dropped:15}}

__
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] error in trmesh (alphahull package)

2009-04-03 Thread Murray Richardson

Hello R community,

I have cross-posted with r-sig-geo as this issue could fall under either 
interest group I believe. 

I just came accross the alphahull package and am very pleased I may not 
need to use CGAL anymore for this purpose.   However, I am having a 
problem computing alpha shapes with my point data, and it seems to have 
to do with the spatial configuration of my points (which form long, 
skinny, contiguous clusters).  If I use rnorm to generate the same 
sample size with the same mean and SD, I can compute the alpha shape 
without trouble (which is why I think it might have to do with the 
spatial arrangement of my points).  See below:


# first here's a quick sample of my data (UTM coordinates)
 xcoords[1:5]
[1] 670080.2 670080.2 670080.2 670080.2 670080.2
 ycoords[1:5]
[1] 5005501 5005499 5005498 5005497 5005495
 xcoords[1:5]
#try the ashape routine with error
 alpha.shape-ashape(xcoords,ycoords,15)
Error in tri.mesh(X) : error in trmesh

#get statistics to generate a similar dataset to test against
 length(xcoords)
[1] 26257
 length(ycoords)
[1] 26257
 mean(xcoords)
[1] 670462.4
 mean(ycoords)
[1] 5005382
 sd(xcoords)
[1] 149.3114
 sd(ycoords)
[1] 181.5950

#generate the test data
 xtest-rnorm(26257,670462.4,149.3)
 ytest-rnorm(26257,5005382,181.60)

# try ashape routine with success
 alpha.shape-ashape(xtest,ytest,15)
 class(alpha.shape)
[1] ashape

Thanks for any insight into this!

Murray

ps I am able to compute the alpha shapes for this same dataset without 
problem using CGAL but I find it a pain to work with


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


Re: [R] [OT ?] rant (was : Re: Conversions From standard to metricunits)

2009-04-03 Thread Berwin A Turlach
G'day Murray,

On Fri, 3 Apr 2009 20:01:30 -0400
Murray Cooper myrm...@earthlink.net wrote:

 For science yes. For pleasure I'll still take a pint instead of 570ml!

And you might experience a disappointment then if you order it in the
US where the pint is apparently 450ml; at least, I won several bets
on whether a pint is less or more than half a litre against American
visitors  The stake being, of course, the next round of drinks. :)

And, if memory serves correctly, here in Singapore I once ordered a
pint of draught beer and was served half a litre...  Confused me
completely...  That's when I thought that the metric system is so much
safer until I ordered my next beer, according to the menu a bottled
beer of 400ml, it came in a 333ml bottle...  

Cheers,

Berwin

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

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