Re: [R] How to make a prior graph

2012-12-16 Thread Rui Barradas

Hello,

I believe that you're talking about beta-binomial models and that the 
Jeffrey's prior you're talking about is a Beta(1/2, 1/2). If so, try the 
following.


jeffrey - function(x) dbeta(x, shape1 = 1/2, shape2 = 1/2)

curve(dunif, from = 0, to = 1)
curve(jeffrey, from = 0, to = 1, add = TRUE)

Hope this helps,

Rui Barradas
Em 16-12-2012 04:02, Tania escreveu:

Hello, could you tell me which is the command for create graphics of this prior 
distributions:

Uniform (flat prior)
Jeffrey's

Thanks,

Tania

Sent from my iPod
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] averaging X of specific Y (latitude)

2012-12-16 Thread David L Carlson
It is better to use dput() in R to create a text version of your data for us
to work with. The aggregate command below gives you the mean ranges by
butterfly species and latititude and saves the result as Bfly. The
colnames() command simply renames the columns:

 dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1,

+ Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1, 
+ Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5, 
+ Butterfly C1, Butterfly C2), class = factor), Range = c(130.5, 
+ 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78, 
+ 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87, 
+ 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range, 
+ Latitude), class = data.frame, row.names = c(NA, -11L))
 Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
 colnames(Bfly) - c(Species, Latitude, Mean)
 Bfly
Species LatitudeMean
1  Butterfly A19  130.50
2  Butterfly A39 1102.38
3  Butterfly A2   10  450.68
4  Butterfly B1   10  820.20
5  Butterfly B2   10  872.20
6  Butterfly B5   12  982.78
7  Butterfly C1   12  720.32
8  Butterfly A4   16  893.34
9  Butterfly B3   16  488.20
10 Butterfly B4   18  620.11
11 Butterfly C2   18  912.20

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Elaine Kuo
 Sent: Saturday, December 15, 2012 10:15 PM
 To: r-help@r-project.org; r-sig-geo
 Subject: [R] averaging X of specific Y (latitude)
 
 Hello
 
 
 
 I have a table describing butterfly range traits.
 
 It is composed of three columns as below
 
 
 
 Species name  range size (X)latitude of range midpoint (Y)
 
 
 
 There are 11 kinds of butterflies.
 
 Each has its range size, and the latitude of each range midpoint ranges
 from 9 to 19.
 
 I would like to have the average range size of every degree of
 latitude.
 
 For example, the average range size of latitude degree 10 (10.0-10.99:
 Butterfly A2, B1, B2)
 
 Please kindly help with R code to calculate the average values.
 
 Thank you.
 
 
 Elaine
 
 
 The details are as followed.
 
 
 
 Butterfly A1  130.5 9.45
 
 Butterfly A2  450.68   10.2
 
 Butterfly A3  1102.389.3
 
 Butterfly A4893.34 16.4
 
 Butterfly B1   820.2   10.54
 
 Butterfly B2872.2   10.87
 
 Butterfly B3488.2   16.79
 
 Butterfly B4620.11 18.3
 
 Butterfly B5982.78 12.98
 
 Butterfly C1   720.32 12.67
 
 Butterfly C2912.2   18.07
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


[R] interfacing with .Call

2012-12-16 Thread Shangru Li
Hi

My code is as following:

#include R.h
#include Rinternals.h

//* the Projector part  *//
void Projector(double *L, int *dimL, double *G, int *dimG, double *W, int
*dimW, int *xymod, int *dimxy, double *modif, int *dimif, double *Lsum)
{ ...}

//* the interface part *//
#define getDim(A) INTEGER(coerceVector(getAttrib(A,R_DimSymbol), INTSXP))

SEXP Projector5(SEXP L, SEXP G, SEXP W, SEXP xymod, SEXP modif)
{
//* digest SEXPs from R *//
int *dimL, *dimG, *dimW, *dimxy, *dimif;
double *lptr, *gptr, *wptr, *ifptr;
int *xyptr;
dimL=getDim(L);
PROTECT(L=coerceVector(L, REALSXP));
lptr=REAL(L);
dimG=getDim(G);
PROTECT(G=coerceVector(G, REALSXP));
gptr=REAL(G);
dimW=getDim(W);
PROTECT(W=coerceVector(W, REALSXP));
wptr=REAL(W);
dimxy=getDim(xymod);
PROTECT(xymod=coerceVector(xymod, INTSXP));
xyptr=INTEGER(xymod);
dimif=getDim(modif);
PROTECT(modif=coerceVector(modif, REALSXP));
ifptr=REAL(modif);

//* create SEXP to hold the answer *//
SEXP ans;
double *ansptr;
PROTECT(ans=allocMatrix(REALSXP, dimG[1], dimG[0]));
ansptr=REAL(ans);

//* calculate the result *//
Projector(lptr, dimL, gptr, dimG, wptr, dimW, xyptr, dimxy, ifptr,
dimif, ansptr);

//* wrap up and return the result to R *//
UNPROTECT(6);
return(ans);
}

The function Projector works well and actually the interface with .C
works OK.
The question is that I can compile it in R, but .Call returns different
result each time with same inputs. Could anybody tell me why? Thanks!

Regards
Shangru

-- 
Department of Mathematics,
National University of Singapore,
Blk S17, 10 Lower Kent Ridge Road,
119076





-- 
Department of Mathematics,
National University of Singapore,
Blk S17, 10 Lower Kent Ridge Road,
119076

[[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] interfacing with .Call

2012-12-16 Thread R. Michael Weylandt
On Sun, Dec 16, 2012 at 6:20 PM, Shangru Li lishan...@gmail.com wrote:
 Hi
 The function Projector works well and actually the interface with .C
 works OK.
 The question is that I can compile it in R, but .Call returns different
 result each time with same inputs. Could anybody tell me why? Thanks!


I haven't read through your code but .C and .Call are actually pretty
different -- is there any reason you'd expect code written for one
interface to work for the other? You might just be seeing random bits
of memory returned by .Call

MW

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


Re: [R] interfacing with .Call

2012-12-16 Thread William Dunlap
The problem almost certainly lies in the parts of the code that you have
not shown, the R-language code including the .Call or, more likely in my
opinion, the C++ code for Projector.   You can get different values in
Projector's Lsum matrix if
   (a) Projector doesn't assign values to all of them (allocMatrix allocates 
memory
 with random contents - you must fill it with values)
   (b) Projector reads or writes memory that it doesn't own.
Using valgrind can help find both sorts of errors.

I am suspicious about your reversal of the dimensions of Lsum when
you allocate it, using dimG[1],dimG[0].  Does this mean you are doing
some odd pointer arithmetic in Projector that doesn't agree with R's
conventions?

I tried adding a simple Projector() and saw no problems aside from
the random numbers in the unassigned elements of Lsum and some
of the usual unassign values in the guts of Rprintf's formatting code.

extern C {
SEXP Projector5(SEXP L, SEXP G, SEXP W, SEXP xymod, SEXP modif);
}

//* the Projector part  *//
void Projector(double *L, int *dimL, double *G, int *dimG, double *W, int *dimW,
 int *xymod, int *dimxy, double *modif, int *dimif, double *Lsum)
{
Rprintf(dimG=c(%d,%d)\n, dimG[0], dimG[1]);
double* pLsum = Lsum;
bool even = true ;
for(int j=0 ; j  dimG[0] ; j++) {
for(int i=0 ; i  dimG[1] ; i++) {
if (even) {
*pLsum = 1000 * (i+1) + (j+1);
} else {
// do not touch odd elements of pLsum
}
even = !even;
pLsum++;
}
}
}

called with
 .Call(Projector5, matrix(1:6,2,3), matrix(701:720,4,5), 
 matrix(2^(1:12),2,6), 1:7, 1:10)
dimG=c(4,5)
 [,1]   [,2] [,3]   [,4]
[1,] 1001 7.954e-322 1003 4.002e-322
[2,]0  2.002e+030  2.004e+03
[3,] 3001  0.000e+00 3003  0.000e+00
[4,]0  4.002e+030  4.004e+03
[5,] 5001  0.000e+00 5003  0.000e+00

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Shangru Li
 Sent: Sunday, December 16, 2012 10:20 AM
 To: r-help@r-project.org
 Subject: [R] interfacing with .Call
 
 Hi
 
 My code is as following:
 
 #include R.h
 #include Rinternals.h
 
 //* the Projector part  *//
 void Projector(double *L, int *dimL, double *G, int *dimG, double *W, int
 *dimW, int *xymod, int *dimxy, double *modif, int *dimif, double *Lsum)
 { ...}
 
 //* the interface part *//
 #define getDim(A) INTEGER(coerceVector(getAttrib(A,R_DimSymbol), INTSXP))
 
 SEXP Projector5(SEXP L, SEXP G, SEXP W, SEXP xymod, SEXP modif)
 {
 //* digest SEXPs from R *//
 int *dimL, *dimG, *dimW, *dimxy, *dimif;
 double *lptr, *gptr, *wptr, *ifptr;
 int *xyptr;
 dimL=getDim(L);
 PROTECT(L=coerceVector(L, REALSXP));
 lptr=REAL(L);
 dimG=getDim(G);
 PROTECT(G=coerceVector(G, REALSXP));
 gptr=REAL(G);
 dimW=getDim(W);
 PROTECT(W=coerceVector(W, REALSXP));
 wptr=REAL(W);
 dimxy=getDim(xymod);
 PROTECT(xymod=coerceVector(xymod, INTSXP));
 xyptr=INTEGER(xymod);
 dimif=getDim(modif);
 PROTECT(modif=coerceVector(modif, REALSXP));
 ifptr=REAL(modif);
 
 //* create SEXP to hold the answer *//
 SEXP ans;
 double *ansptr;
 PROTECT(ans=allocMatrix(REALSXP, dimG[1], dimG[0]));
 ansptr=REAL(ans);
 
 //* calculate the result *//
 Projector(lptr, dimL, gptr, dimG, wptr, dimW, xyptr, dimxy, ifptr,
 dimif, ansptr);
 
 //* wrap up and return the result to R *//
 UNPROTECT(6);
 return(ans);
 }
 
 The function Projector works well and actually the interface with .C
 works OK.
 The question is that I can compile it in R, but .Call returns different
 result each time with same inputs. Could anybody tell me why? Thanks!
 
 Regards
 Shangru
 
 --
 Department of Mathematics,
 National University of Singapore,
 Blk S17, 10 Lower Kent Ridge Road,
 119076
 
 
 
 
 
 --
 Department of Mathematics,
 National University of Singapore,
 Blk S17, 10 Lower Kent Ridge Road,
 119076
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


[R] sweave and lessR

2012-12-16 Thread Scott Cushman

Hello

I am using sweave with the Density() function from lessR package. However, 
unlike the older color.density() function, Density() does not work with 
the standard graphic output functions in R, such as pdf. Is there away to 
include figures fgenerated rom lessR in sweave documents?

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] averaging X of specific Y (latitude)

2012-12-16 Thread arun
Hi,
You could also use ?ave():
dta$Lat1-floor(dta$Latitude) # ?trunc(), ?round(), ?signif() could also 
replace ?floor()
dta$Mean-ave(dta$Range,dta$Species,dta$Lat1,FUN=mean)
dta
A.K.




- Original Message -
From: David L Carlson dcarl...@tamu.edu
To: 'Elaine Kuo' elaine.kuo...@gmail.com; r-help@r-project.org; 'r-sig-geo' 
r-sig-...@stat.math.ethz.ch
Cc: 
Sent: Sunday, December 16, 2012 11:32 AM
Subject: Re: [R] averaging X of specific Y (latitude)

It is better to use dput() in R to create a text version of your data for us
to work with. The aggregate command below gives you the mean ranges by
butterfly species and latititude and saves the result as Bfly. The
colnames() command simply renames the columns:

 dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1,

+ Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1, 
+ Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5, 
+ Butterfly C1, Butterfly C2), class = factor), Range = c(130.5, 
+ 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78, 
+ 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87, 
+ 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range, 
+ Latitude), class = data.frame, row.names = c(NA, -11L))
 Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
 colnames(Bfly) - c(Species, Latitude, Mean)
 Bfly
        Species Latitude    Mean
1  Butterfly A1        9  130.50
2  Butterfly A3        9 1102.38
3  Butterfly A2       10  450.68
4  Butterfly B1       10  820.20
5  Butterfly B2       10  872.20
6  Butterfly B5       12  982.78
7  Butterfly C1       12  720.32
8  Butterfly A4       16  893.34
9  Butterfly B3       16  488.20
10 Butterfly B4       18  620.11
11 Butterfly C2       18  912.20

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Elaine Kuo
 Sent: Saturday, December 15, 2012 10:15 PM
 To: r-help@r-project.org; r-sig-geo
 Subject: [R] averaging X of specific Y (latitude)
 
 Hello
 
 
 
 I have a table describing butterfly range traits.
 
 It is composed of three columns as below
 
 
 
 Species name  range size (X)    latitude of range midpoint (Y)
 
 
 
 There are 11 kinds of butterflies.
 
 Each has its range size, and the latitude of each range midpoint ranges
 from 9 to 19.
 
 I would like to have the average range size of every degree of
 latitude.
 
 For example, the average range size of latitude degree 10 (10.0-10.99:
 Butterfly A2, B1, B2)
 
 Please kindly help with R code to calculate the average values.
 
 Thank you.
 
 
 Elaine
 
 
 The details are as followed.
 
 
 
 Butterfly A1      130.5                 9.45
 
 Butterfly A2      450.68                           10.2
 
 Butterfly A3      1102.38                        9.3
 
 Butterfly A4            893.34                             16.4
 
 Butterfly B1           820.2                               10.54
 
 Butterfly B2            872.2                               10.87
 
 Butterfly B3            488.2                               16.79
 
 Butterfly B4            620.11                             18.3
 
 Butterfly B5            982.78                             12.98
 
 Butterfly C1           720.32                             12.67
 
 Butterfly C2            912.2                               18.07
 
     [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


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


Re: [R] sweave and lessR

2012-12-16 Thread Duncan Murdoch

On 12-12-16 12:42 PM, Scott Cushman wrote:


Hello

I am using sweave with the Density() function from lessR package. However, 
unlike the older color.density() function, Density() does not work with
the standard graphic output functions in R, such as pdf. Is there away to 
include figures fgenerated rom lessR in sweave documents?


Tell Density to write to foo.pdf, then just use \includegraphics{foo} 
in your Sweave document.  (This assumes you're using pdflatex; it looks 
as though you can't do it at all if you can't handle PDF figures.)


Duncan Murdoch

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


Re: [R] sweave and lessR

2012-12-16 Thread Duncan Murdoch

On 12-12-16 3:12 PM, Scott Cushman wrote:

Thank you for the reply. With many calls to Density() I miss Sweave taking care 
of the naming of the files and the generating of the \includegraphics 
statements, but I guess this will work.


You (or the lessR author) could possibly write your own custom graphics 
device driver to work with Sweave; see Graphics devices in the Sweave 
vignette.  Or perhaps lessR could be configured to use the regular pdf() 
graphics driver.


Duncan Murdoch



On Dec 16, 2012, at 2:54 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote:


On 12-12-16 12:42 PM, Scott Cushman wrote:


Hello

I am using sweave with the Density() function from lessR package. However, 
unlike the older color.density() function, Density() does not work with
the standard graphic output functions in R, such as pdf. Is there away to 
include figures fgenerated rom lessR in sweave documents?


Tell Density to write to foo.pdf, then just use \includegraphics{foo} in your 
Sweave document.  (This assumes you're using pdflatex; it looks as though you can't do it 
at all if you can't handle PDF figures.)

Duncan Murdoch





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


Re: [R] sweave and lessR

2012-12-16 Thread Scott Cushman
Thank you for the reply. With many calls to Density() I miss Sweave taking care 
of the naming of the files and the generating of the \includegraphics 
statements, but I guess this will work.

On Dec 16, 2012, at 2:54 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote:

 On 12-12-16 12:42 PM, Scott Cushman wrote:
 
 Hello
 
 I am using sweave with the Density() function from lessR package. However, 
 unlike the older color.density() function, Density() does not work with
 the standard graphic output functions in R, such as pdf. Is there away to 
 include figures fgenerated rom lessR in sweave documents?
 
 Tell Density to write to foo.pdf, then just use \includegraphics{foo} in 
 your Sweave document.  (This assumes you're using pdflatex; it looks as 
 though you can't do it at all if you can't handle PDF figures.)
 
 Duncan Murdoch
 

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


Re: [R] kruskalmc, significant differences while median values are the same

2012-12-16 Thread Thomas Lumley
On Sat, Dec 15, 2012 at 10:04 PM, Omphalodes Verna 
omphalodes.ve...@yahoo.com wrote:

 Dear list!

 I work with multiple Kruskal-Wallis test (kruskalmc, package pgirmess),
 which evaluates differences in medians among groups (5 groups). A result of
 a test is significant differences among some groups, while median values
 are the same for 4 groups (using tapply). Why?


The Kruskal-Wallis test *doesn't* evaluate differences in medians, so there
is quite likely nothing wrong in a formal sense.

However, this does suggest that your groups may not be stochastically
ordered, which means the results of the Kruskal-Wallis test could be quite
misleading.  I'd suggest that you at least look at pairwise Wilcoxon tests
to make sure the direction agrees with what the Kruskal-Wallis test
implies. Box plots might also be a good idea.

Or, if you really want differences in medians, look at differences in
medians. A permutation test or a bootstrap confidence interval is probably
the best way to do this.


   -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

[[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] averaging X of specific Y (latitude)

2012-12-16 Thread Elaine Kuo
Thank you, David.

Your answer reminded me of rearranging the order according to the latitude
before running the calculation.

One more question,
please kindly help with the code to calculate the mean of the ranges of the
same latitude?
Or should any re-arrangement be noticed before the mean calculation?

Thank you.

Elaine




 - Original Message -
 From: David L Carlson dcarl...@tamu.edu
 To: 'Elaine Kuo' elaine.kuo...@gmail.com; r-help@r-project.org;
 'r-sig-geo' r-sig-...@stat.math.ethz.ch
 Cc:
 Sent: Sunday, December 16, 2012 11:32 AM
 Subject: Re: [R] averaging X of specific Y (latitude)

 It is better to use dput() in R to create a text version of your data for
 us
 to work with. The aggregate command below gives you the mean ranges by
 butterfly species and latititude and saves the result as Bfly. The
 colnames() command simply renames the columns:

  dta - structure(list(Species = structure(1:11, .Label = c(Butterfly
 A1,

 + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
 + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
 + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
 + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
 + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
 + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
 + Latitude), class = data.frame, row.names = c(NA, -11L))
  Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
  colnames(Bfly) - c(Species, Latitude, Mean)
  Bfly
 Species LatitudeMean
 1  Butterfly A19  130.50
 2  Butterfly A39 1102.38
 3  Butterfly A2   10  450.68
 4  Butterfly B1   10  820.20
 5  Butterfly B2   10  872.20
 6  Butterfly B5   12  982.78
 7  Butterfly C1   12  720.32
 8  Butterfly A4   16  893.34
 9  Butterfly B3   16  488.20
 10 Butterfly B4   18  620.11
 11 Butterfly C2   18  912.20

 --
 David L Carlson
 Associate Professor of Anthropology
 Texas AM University
 College Station, TX 77843-4352

  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
  project.org] On Behalf Of Elaine Kuo
  Sent: Saturday, December 15, 2012 10:15 PM
  To: r-help@r-project.org; r-sig-geo
  Subject: [R] averaging X of specific Y (latitude)
 
  Hello
 
 
 
  I have a table describing butterfly range traits.
 
  It is composed of three columns as below
 
 
 
  Species name  range size (X)latitude of range midpoint (Y)
 
 
 
  There are 11 kinds of butterflies.
 
  Each has its range size, and the latitude of each range midpoint ranges
  from 9 to 19.
 
  I would like to have the average range size of every degree of
  latitude.
 
  For example, the average range size of latitude degree 10 (10.0-10.99:
  Butterfly A2, B1, B2)
 
  Please kindly help with R code to calculate the average values.
 
  Thank you.
 
 
  Elaine
 
 
  The details are as followed.
 
 
 
  Butterfly A1  130.5 9.45
 
  Butterfly A2  450.68   10.2
 
  Butterfly A3  1102.389.3
 
  Butterfly A4893.34 16.4
 
  Butterfly B1   820.2   10.54
 
  Butterfly B2872.2   10.87
 
  Butterfly B3488.2   16.79
 
  Butterfly B4620.11 18.3
 
  Butterfly B5982.78 12.98
 
  Butterfly C1   720.32 12.67
 
  Butterfly C2912.2   18.07
 
  [[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.



[[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] nls for sum of exponentials

2012-12-16 Thread Diviya Smith
Hi there,

I am trying to fit the following model with a sum of exponentials -

y ~ Ae^(-md) + B e^(-nd) + c

the model has 5 parameters A, b, m, n, c

I am using nls to fit the data and I am using DEoptim package to pick the
most optimal start values -

fm4 - function(x) x[1] + x[2]*exp(x[3] * -dist) + x[4]*exp(x[5] * -dist)

fm5 - function(x) sum((wcorr-fm4(x))^2)

fm6 - DEoptim(fm5, lower=c(0,0.1,1,0.1,1), upper=c(10e7, 100, 300,100, 300
), control=list(trace=FALSE))

par2 - fm6$optim$bestmem

names(par2) - c(c, A, n1, B, n2)

fit2 - nls(wcorr ~ (c + A*exp(n1 * -dist) + B*exp(n2 * -dist)),
start=par2,control
=list(maxiter=1000, warnOnly=TRUE))

However, I keep getting the following error -

Error in numericDeriv(form[[3L]], names(ind), env) :

  Missing value or an infinity produced when evaluating the model

OR

In nls(wcorr ~ (c + A * exp(n1 * -dist) + B * exp(n2 * -dist)),  :

  singular gradient


Can anyone suggest how to resolve the problem?


Thanks,

Priya

[[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] non-numeric argument to binary operator

2012-12-16 Thread Shrupa Sumaria
Hello,


I wish to carry out the following:


factor_classes - as.factor(sample(c(BM, SM, F), 10, replace = TRUE))


C - 5


k - matrix(0, length(factor_classes), 1)


for (i in length(factor_classes)) {


k[i] - C*factor_classes[i]


}


I get the following error message:

non-numeric argument to binary operator


I wish to store the results of C*factor_classes[i] in matrix k. 
Is there any way I can multiply the factor with the numeric variable? 


Thanks for your help in advance.


Cheers,

sumaria 
[[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] non-numeric argument to binary operator

2012-12-16 Thread Rui Barradas
Hello,

Try

C*as.integer(factor_classes)

And note that you don't need the loop.

Hope this helps,

Rui Barradas
Em 16-12-2012 23:56, Shrupa Sumaria escreveu:
 Hello,


 I wish to carry out the following:


 factor_classes - as.factor(sample(c(BM, SM, F), 10, replace = TRUE))


 C - 5


 k - matrix(0, length(factor_classes), 1)


 for (i in length(factor_classes)) {


 k[i] - C*factor_classes[i]


 }


 I get the following error message:

 non-numeric argument to binary operator


 I wish to store the results of C*factor_classes[i] in matrix k.
 Is there any way I can multiply the factor with the numeric variable?


 Thanks for your help in advance.


 Cheers,

 sumaria
   [[alternative HTML version deleted]]



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


[[alternative HTML version deleted]]

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


Re: [R] non-numeric argument to binary operator

2012-12-16 Thread Duncan Murdoch

On 12-12-16 6:56 PM, Shrupa Sumaria wrote:

Hello,


I wish to carry out the following:


factor_classes - as.factor(sample(c(BM, SM, F), 10, replace = TRUE))


C - 5


k - matrix(0, length(factor_classes), 1)


for (i in length(factor_classes)) {


k[i] - C*factor_classes[i]


}


I get the following error message:

non-numeric argument to binary operator


I wish to store the results of C*factor_classes[i] in matrix k.
Is there any way I can multiply the factor with the numeric variable?


What do you expect to get from 5*BM?

Duncan Murdoch




Thanks for your help in advance.


Cheers,

sumaria
[[alternative HTML version deleted]]



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



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


[R] Fw: simulate time data

2012-12-16 Thread Jichun Chan



- Forwarded Message -
From: Jichun Chan jic...@y7mail.com
To: David Winsemius dwinsem...@comcast.net 
Sent: Friday, 14 December 2012 5:30 PM
Subject: Re: [R] simulate time data


Hi David,
Thank you for replying my email. I have to apology that I haven't been very 
clear with my question. 
I am actually trying to simulate a set of data with two correlated variables 
(e.g. x1 and x2) , one of which (says x1) is associated with the outcome with a 
predefined OR. Then, I want to calculate the HR of the other variable in 
relation to the outcome using Cox's regression. But I don't know how to 
simulate the time data as it is not normally distributed. 
I tried to treat it like normally distributed and put it the covariance matrix, 
it somehow produced the HR that is closely resembled that of real data. Am I 
doing the right thing. The following is the Rcommond I used:
 
 
 set.seed(12345)
 for (i in 1:1000) {
 sim - rmvnorm( n = 1000, mean = c(0.81,26.5,88.07), sigma = matrix(c(0.019, 
 0.41*sqrt(0.48), 1.27,
  0.41*sqrt(0.48), 25.48, -23.82, 1.27, -23.82, 5297.64),3,3)) 
 
 x1 - sim[,1]   
 x2 - sim[,2] 
 time- sim[,3]
 
 L - log(1.89) * (x1/0.14) #0.14 is the SD and 1.89 is the preset OR
 event - ifelse(runif(1000)  plogis(L), 1, 0)
 
 sdata- data.frame(x1, x2, event)
 m1- coxph(Surv(time, event) ~ x2, data=sdata)   
 
 
I also tried to simulate the time using Weibull distribution from the R help as 
follows, but I don't quite understand what they are doing. And I don't know how 
to combine it to the dataset so that the time variable is related to the 
outcome. I hope you know what I mean. 
 
 n = 1000
 beta1 =0.18 ; beta2 = -0.65
 lambdaT = .007 # baseline hazard
 lambdaC = .003  # hazard of censoring
 
 T = rweibull(n, shape=1, scale=lambdaT*exp(-beta1*bmi-beta2*fnbmd)) 
 C = rweibull(n, shape=1, scale=lambdaC)   #censoring time
 time = pmin(T,C)  #observed time is minimum of censored and true
 event = time==T   # set to 1 if event is observed
 
Would you please kindly help me with this and forgive me if I ask silly 
question as I am still new to statistics.
Regards
Scomet
 
 
From: David Winsemius dwinsem...@comcast.net
To: Jichun Chan jic...@y7mail.com 
Cc: r-help@r-project.org r-help@r-project.org 
Sent: Thursday, 13 December 2012 3:10 PM
Subject: Re: [R] simulate time data


On Dec 12, 2012, at 6:34 PM, Jichun Chan wrote:

 Hi,
 Does anyone know how to write a command to generate time-to-event data for 
 Cox's regression?
 

There are examples in the rms package for the cph function. I also see example 
in the help pages for the survival package.


--David Winsemius, MD
Alameda, CA, USA
[[alternative HTML version deleted]]

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


Re: [R] interfacing with .Call

2012-12-16 Thread Thomas Lumley
On Mon, Dec 17, 2012 at 8:02 AM, William Dunlap wdun...@tibco.com wrote:

 The problem almost certainly lies in the parts of the code that you have
 not shown, the R-language code including the .Call or, more likely in my
 opinion, the C++ code for Projector.


I would have blamed the unPROTECTed coerceVector() result in the getDim
macro.

   -thomas



 You can get different values in
 Projector's Lsum matrix if
(a) Projector doesn't assign values to all of them (allocMatrix
 allocates memory
  with random contents - you must fill it with values)
(b) Projector reads or writes memory that it doesn't own.
 Using valgrind can help find both sorts of errors.

 I am suspicious about your reversal of the dimensions of Lsum when
 you allocate it, using dimG[1],dimG[0].  Does this mean you are doing
 some odd pointer arithmetic in Projector that doesn't agree with R's
 conventions?

 I tried adding a simple Projector() and saw no problems aside from
 the random numbers in the unassigned elements of Lsum and some
 of the usual unassign values in the guts of Rprintf's formatting code.

 extern C {
 SEXP Projector5(SEXP L, SEXP G, SEXP W, SEXP xymod, SEXP modif);
 }

 //* the Projector part  *//
 void Projector(double *L, int *dimL, double *G, int *dimG, double *W, int
 *dimW,
  int *xymod, int *dimxy, double *modif, int *dimif, double *Lsum)
 {
 Rprintf(dimG=c(%d,%d)\n, dimG[0], dimG[1]);
 double* pLsum = Lsum;
 bool even = true ;
 for(int j=0 ; j  dimG[0] ; j++) {
 for(int i=0 ; i  dimG[1] ; i++) {
 if (even) {
 *pLsum = 1000 * (i+1) + (j+1);
 } else {
 // do not touch odd elements of pLsum
 }
 even = !even;
 pLsum++;
 }
 }
 }

 called with
  .Call(Projector5, matrix(1:6,2,3), matrix(701:720,4,5),
 matrix(2^(1:12),2,6), 1:7, 1:10)
 dimG=c(4,5)
  [,1]   [,2] [,3]   [,4]
 [1,] 1001 7.954e-322 1003 4.002e-322
 [2,]0  2.002e+030  2.004e+03
 [3,] 3001  0.000e+00 3003  0.000e+00
 [4,]0  4.002e+030  4.004e+03
 [5,] 5001  0.000e+00 5003  0.000e+00

 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com


  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf
  Of Shangru Li
  Sent: Sunday, December 16, 2012 10:20 AM
  To: r-help@r-project.org
  Subject: [R] interfacing with .Call
 
  Hi
 
  My code is as following:
 
  #include R.h
  #include Rinternals.h
 
  //* the Projector part  *//
  void Projector(double *L, int *dimL, double *G, int *dimG, double *W, int
  *dimW, int *xymod, int *dimxy, double *modif, int *dimif, double *Lsum)
  { ...}
 
  //* the interface part *//
  #define getDim(A) INTEGER(coerceVector(getAttrib(A,R_DimSymbol), INTSXP))
 
  SEXP Projector5(SEXP L, SEXP G, SEXP W, SEXP xymod, SEXP modif)
  {
  //* digest SEXPs from R *//
  int *dimL, *dimG, *dimW, *dimxy, *dimif;
  double *lptr, *gptr, *wptr, *ifptr;
  int *xyptr;
  dimL=getDim(L);
  PROTECT(L=coerceVector(L, REALSXP));
  lptr=REAL(L);
  dimG=getDim(G);
  PROTECT(G=coerceVector(G, REALSXP));
  gptr=REAL(G);
  dimW=getDim(W);
  PROTECT(W=coerceVector(W, REALSXP));
  wptr=REAL(W);
  dimxy=getDim(xymod);
  PROTECT(xymod=coerceVector(xymod, INTSXP));
  xyptr=INTEGER(xymod);
  dimif=getDim(modif);
  PROTECT(modif=coerceVector(modif, REALSXP));
  ifptr=REAL(modif);
 
  //* create SEXP to hold the answer *//
  SEXP ans;
  double *ansptr;
  PROTECT(ans=allocMatrix(REALSXP, dimG[1], dimG[0]));
  ansptr=REAL(ans);
 
  //* calculate the result *//
  Projector(lptr, dimL, gptr, dimG, wptr, dimW, xyptr, dimxy, ifptr,
  dimif, ansptr);
 
  //* wrap up and return the result to R *//
  UNPROTECT(6);
  return(ans);
  }
 
  The function Projector works well and actually the interface with .C
  works OK.
  The question is that I can compile it in R, but .Call returns different
  result each time with same inputs. Could anybody tell me why? Thanks!
 
  Regards
  Shangru
 
  --
  Department of Mathematics,
  National University of Singapore,
  Blk S17, 10 Lower Kent Ridge Road,
  119076
 
 
 
 
 
  --
  Department of Mathematics,
  National University of Singapore,
  Blk S17, 10 Lower Kent Ridge Road,
  119076
 
[[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.




-- 
Thomas 

Re: [R] averaging X of specific Y (latitude)

2012-12-16 Thread David L Carlson
It is not necessary to rearrange the order. The aggregate function will do
that. To get the mean Range for a latitude combining species within a
latitude just remove Species:

 aggregate(Range~floor(Latitude), dta, mean)
  floor(Latitude)   Range
1   9 616.440
2  10 714.360
3  12 851.550
4  16 690.770
5  18 766.155

---
David 


From: Elaine Kuo [mailto:elaine.kuo...@gmail.com] 
Sent: Sunday, December 16, 2012 5:17 PM
To: dcarl...@tamu.edu; r-help@r-project.org; r-sig-...@stat.math.ethz.ch
Subject: Re: [R] averaging X of specific Y (latitude)

Thank you, David.

Your answer reminded me of rearranging the order according to the latitude 
before running the calculation.

One more question, 
please kindly help with the code to calculate the mean of the ranges of the
same latitude?
Or should any re-arrangement be noticed before the mean calculation?

Thank you.

Elaine



- Original Message -
From: David L Carlson dcarl...@tamu.edu
To: 'Elaine Kuo' elaine.kuo...@gmail.com; r-help@r-project.org;
'r-sig-geo' r-sig-...@stat.math.ethz.ch
Cc:
Sent: Sunday, December 16, 2012 11:32 AM
Subject: Re: [R] averaging X of specific Y (latitude)

It is better to use dput() in R to create a text version of your data for us
to work with. The aggregate command below gives you the mean ranges by
butterfly species and latititude and saves the result as Bfly. The
colnames() command simply renames the columns:

 dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1,

+ Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
+ Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
+ Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
+ 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
+ 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
+ 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
+ Latitude), class = data.frame, row.names = c(NA, -11L))
 Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
 colnames(Bfly) - c(Species, Latitude, Mean)
 Bfly
        Species Latitude    Mean
1  Butterfly A1        9  130.50
2  Butterfly A3        9 1102.38
3  Butterfly A2       10  450.68
4  Butterfly B1       10  820.20
5  Butterfly B2       10  872.20
6  Butterfly B5       12  982.78
7  Butterfly C1       12  720.32
8  Butterfly A4       16  893.34
9  Butterfly B3       16  488.20
10 Butterfly B4       18  620.11
11 Butterfly C2       18  912.20

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Elaine Kuo
 Sent: Saturday, December 15, 2012 10:15 PM
 To: r-help@r-project.org; r-sig-geo
 Subject: [R] averaging X of specific Y (latitude)

 Hello



 I have a table describing butterfly range traits.

 It is composed of three columns as below



 Species name  range size (X)    latitude of range midpoint (Y)



 There are 11 kinds of butterflies.

 Each has its range size, and the latitude of each range midpoint ranges
 from 9 to 19.

 I would like to have the average range size of every degree of
 latitude.

 For example, the average range size of latitude degree 10 (10.0-10.99:
 Butterfly A2, B1, B2)

 Please kindly help with R code to calculate the average values.

 Thank you.


 Elaine


 The details are as followed.



 Butterfly A1      130.5                 9.45

 Butterfly A2      450.68                           10.2

 Butterfly A3      1102.38                        9.3

 Butterfly A4            893.34                             16.4

 Butterfly B1           820.2                               10.54

 Butterfly B2            872.2                               10.87

 Butterfly B3            488.2                               16.79

 Butterfly B4            620.11                             18.3

 Butterfly B5            982.78                             12.98

 Butterfly C1           720.32                             12.67

 Butterfly C2            912.2                               18.07

     [[alternative HTML version deleted]]

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

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

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

[R] save to file

2012-12-16 Thread Felipe Carrillo
 Hi,
What's the equivalent of Save to File from the R console File menu on an R 
routine? Just trying
to capture the whole R console into a text file when my code fails.




Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx

[[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] averaging X of specific Y (latitude)

2012-12-16 Thread arun
HI,
Not sure if this what you meant.
ave(dta$Range,floor(dta$Latitude),FUN=mean)
# [1] 616.440 714.360 616.440 690.770 714.360 714.360 690.770 766.155 851.550
#[10] 851.550 766.155
A.K.




- Original Message -
From: Elaine Kuo elaine.kuo...@gmail.com
To: dcarl...@tamu.edu; r-help@r-project.org; r-sig-...@stat.math.ethz.ch
Cc: 
Sent: Sunday, December 16, 2012 6:16 PM
Subject: Re: [R] averaging X of specific Y (latitude)

Thank you, David.

Your answer reminded me of rearranging the order according to the latitude
before running the calculation.

One more question,
please kindly help with the code to calculate the mean of the ranges of the
same latitude?
Or should any re-arrangement be noticed before the mean calculation?

Thank you.

Elaine




 - Original Message -
 From: David L Carlson dcarl...@tamu.edu
 To: 'Elaine Kuo' elaine.kuo...@gmail.com; r-help@r-project.org;
 'r-sig-geo' r-sig-...@stat.math.ethz.ch
 Cc:
 Sent: Sunday, December 16, 2012 11:32 AM
 Subject: Re: [R] averaging X of specific Y (latitude)

 It is better to use dput() in R to create a text version of your data for
 us
 to work with. The aggregate command below gives you the mean ranges by
 butterfly species and latititude and saves the result as Bfly. The
 colnames() command simply renames the columns:

  dta - structure(list(Species = structure(1:11, .Label = c(Butterfly
 A1,

 + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
 + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
 + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
 + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
 + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
 + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
 + Latitude), class = data.frame, row.names = c(NA, -11L))
  Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
  colnames(Bfly) - c(Species, Latitude, Mean)
  Bfly
         Species Latitude    Mean
 1  Butterfly A1        9  130.50
 2  Butterfly A3        9 1102.38
 3  Butterfly A2       10  450.68
 4  Butterfly B1       10  820.20
 5  Butterfly B2       10  872.20
 6  Butterfly B5       12  982.78
 7  Butterfly C1       12  720.32
 8  Butterfly A4       16  893.34
 9  Butterfly B3       16  488.20
 10 Butterfly B4       18  620.11
 11 Butterfly C2       18  912.20

 --
 David L Carlson
 Associate Professor of Anthropology
 Texas AM University
 College Station, TX 77843-4352

  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
  project.org] On Behalf Of Elaine Kuo
  Sent: Saturday, December 15, 2012 10:15 PM
  To: r-help@r-project.org; r-sig-geo
  Subject: [R] averaging X of specific Y (latitude)
 
  Hello
 
 
 
  I have a table describing butterfly range traits.
 
  It is composed of three columns as below
 
 
 
  Species name  range size (X)    latitude of range midpoint (Y)
 
 
 
  There are 11 kinds of butterflies.
 
  Each has its range size, and the latitude of each range midpoint ranges
  from 9 to 19.
 
  I would like to have the average range size of every degree of
  latitude.
 
  For example, the average range size of latitude degree 10 (10.0-10.99:
  Butterfly A2, B1, B2)
 
  Please kindly help with R code to calculate the average values.
 
  Thank you.
 
 
  Elaine
 
 
  The details are as followed.
 
 
 
  Butterfly A1      130.5                 9.45
 
  Butterfly A2      450.68                           10.2
 
  Butterfly A3      1102.38                        9.3
 
  Butterfly A4            893.34                             16.4
 
  Butterfly B1           820.2                               10.54
 
  Butterfly B2            872.2                               10.87
 
  Butterfly B3            488.2                               16.79
 
  Butterfly B4            620.11                             18.3
 
  Butterfly B5            982.78                             12.98
 
  Butterfly C1           720.32                             12.67
 
  Butterfly C2            912.2                               18.07
 
      [[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.



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

Re: [R] save to file

2012-12-16 Thread Felipe Carrillo
I did check that link but it doesn't do what I want..thanks for trying though. 


Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: arun smartpink...@yahoo.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Sent: Sunday, December 16, 2012 6:55 PM
Subject: Re: [R] save to file

Hi,
sink() gives only the output to be saved in the foo.txt, but txtStart(), 
txtStop() gets the codes and the output.  Sorry, I misunderstood your question.

You can also check this link (if you haven't already seen)
http://r.789695.n4.nabble.com/Capturing-R-console-output-into-a-file-sink-savehistory-td2227013.html
A.K.  






From: Felipe Carrillo mazatlanmex...@yahoo.com
To: arun smartpink...@yahoo.com 
Sent: Sunday, December 16, 2012 9:47 PM
Subject: Re: [R] save to file


What you did That's what sink() does but I mean the entire R console screen 
including the R statement below
I just want to be able to capture everything during the R session

R version 2.15.0 (2012-03-30)
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
  Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R. 

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



From: arun smartpink...@yahoo.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Sent: Sunday, December 16, 2012 6:37 PM
Subject: Re: [R] save to file

Hi,
I am using Ubuntu 12.04.

My sessionInfo() if that helps:
sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-linux-gnu (64-bit)

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

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

other attached packages:
[1] TeachingDemos_2.8 stringr_0.6   reshape_0.8.4 plyr_1.7.1   

loaded via a namespace (and not attached):
[1] tcltk_2.15.0 tools_2.15.0
A.K.








From: Felipe Carrillo mazatlanmex...@yahoo.com
To: arun smartpink...@yahoo.com 
Sent: Sunday, December 16, 2012 9:28 PM
Subject: Re: [R] save to file


My text file is created but its empty. Did you start
library(TeachingDemos)
txtStart(foo.txt,commands=TRUE,results=TRUE,append=FALSE)
on you R.profile to capture the R statement?

Felipe D.
Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



From: arun smartpink...@yahoo.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Sent: Sunday, December 16, 2012 6:16 PM
Subject: Re: [R] save to file



Hi,
If there are comments in your code, you need to ?txtComment() from 
library(TeachingDemos).  I did a trial run and was able to get the snapshot 
in the output file.

A.K.



From: Felipe Carrillo
mazatlanmex...@yahoo.com
To: arun smartpink...@yahoo.com 
Sent: Sunday, December 16, 2012 9:13 PM
Subject: Re: [R] save to file


I know about sink() and capture.output() but these functions don't capture 
the entire console. I basically
want a snapshot of all the text on the R console saved to a file. I am the 
users to send me the file so that I can
see where the R crashed. I will check the Teaching Demos. Thanks

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



From: arun smartpink...@yahoo.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Cc: R help r-help@r-project.org 
Sent: Sunday, December 16, 2012 6:07 PM
Subject: Re: [R] save to file

HI,

I guess ?sink() may not work for you as you need  the whole R console.

Have you tried library(TeachingDemos) ?txtStart(), ?txtStop()
?

txtStart(foo.txt,commands=TRUE,results=TRUE,append=FALSE)
codes
txtStop()

A.K.



- Original Message -
From: Felipe
Carrillo mazatlanmex...@yahoo.com
To: r-h...@stat.math.ethz.ch r-h...@stat.math.ethz.ch
Cc: 
Sent: Sunday, December 16, 2012 8:30 PM
Subject: [R] save to file

 Hi,

[R] forecasting accuracy problem in R

2012-12-16 Thread Leo
Hi,

A few weeks back I used the following command:

accuracy(train,test)

where train and test are training and test data respectively. Last
night I updated R and the forecast package and used the same command
and I got error. After trying a little I used the following command

accuracy(train,test[1:30])

and it worked. (I was checking the accuracy of 30 forecasted values).

Is there some change in the forecast package or did I do something wrong?

regards Leo

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] forecasting accuracy problem in R

2012-12-16 Thread Jeff Newmiller
Please read the posting guide. Packages have their own developers, as well as 
their own change logs [in this case 
http://cran.r-project.org/web/packages/forecast/ChangeLog].
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Leo spee...@gmail.com wrote:

Hi,

A few weeks back I used the following command:

accuracy(train,test)

where train and test are training and test data respectively. Last
night I updated R and the forecast package and used the same command
and I got error. After trying a little I used the following command

accuracy(train,test[1:30])

and it worked. (I was checking the accuracy of 30 forecasted values).

Is there some change in the forecast package or did I do something
wrong?

regards Leo

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] forecasting accuracy problem in R

2012-12-16 Thread Leo
Thanks. Could be the following reason given in the changelog.
 accuracy() can now figure out overlapping times for x and f.

best regards
Leo

On Mon, Dec 17, 2012 at 10:11 AM, Jeff Newmiller
jdnew...@dcn.davis.ca.us wrote:
 Please read the posting guide. Packages have their own developers, as well as 
 their own change logs [in this case 
 http://cran.r-project.org/web/packages/forecast/ChangeLog].
 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 Leo spee...@gmail.com wrote:

Hi,

A few weeks back I used the following command:

accuracy(train,test)

where train and test are training and test data respectively. Last
night I updated R and the forecast package and used the same command
and I got error. After trying a little I used the following command

accuracy(train,test[1:30])

and it worked. (I was checking the accuracy of 30 forecasted values).

Is there some change in the forecast package or did I do something
wrong?

regards Leo

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] save to file

2012-12-16 Thread arun
HI,

I guess ?sink() may not work for you as you need  the whole R console.

Have you tried library(TeachingDemos) ?txtStart(), ?txtStop() ?

txtStart(foo.txt,commands=TRUE,results=TRUE,append=FALSE)
codes
txtStop()

A.K.



- Original Message -
From: Felipe Carrillo mazatlanmex...@yahoo.com
To: r-h...@stat.math.ethz.ch r-h...@stat.math.ethz.ch
Cc: 
Sent: Sunday, December 16, 2012 8:30 PM
Subject: [R] save to file

 Hi,
What's the equivalent of Save to File from the R console File menu on an R 
routine? Just trying
to capture the whole R console into a text file when my code fails.




Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx

    [[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] save to file

2012-12-16 Thread vivek kumar singh
On 17/12/2012 11:03, Felipe Carrillo wrote:
 I did check that link but it doesn't do what I want..thanks for trying though.


 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx


 From: arun smartpink...@yahoo.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Sent: Sunday, December 16, 2012 6:55 PM
 Subject: Re: [R] save to file

 Hi,
 sink() gives only the output to be saved in the foo.txt, but txtStart(), 
 txtStop() gets the codes and the output.  Sorry, I misunderstood your 
 question.

 You can also check this link (if you haven't already seen)
 http://r.789695.n4.nabble.com/Capturing-R-console-output-into-a-file-sink-savehistory-td2227013.html
 A.K.





 
 From: Felipe Carrillo mazatlanmex...@yahoo.com
 To: arun smartpink...@yahoo.com
 Sent: Sunday, December 16, 2012 9:47 PM
 Subject: Re: [R] save to file


 What you did That's what sink() does but I mean the entire R console screen 
 including the R statement below
 I just want to be able to capture everything during the R session

 R version 2.15.0 (2012-03-30)
 Copyright (C) 2012 The R Foundation for Statistical Computing
 ISBN 3-900051-07-0
 Platform: i386-pc-mingw32/i386 (32-bit)
 R is free software and comes with ABSOLUTELY NO WARRANTY.
 You are welcome to redistribute it under certain conditions.
 Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
 R is a collaborative project with many contributors.
 Type 'contributors()' for more information and
 'citation()' on how to cite R or R packages in publications.
 Type 'demo()' for some demos, 'help()' for on-line help, or
 'help.start()' for an HTML browser interface to help.
 Type 'q()' to quit R.

 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx



 From: arun smartpink...@yahoo.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Sent: Sunday, December 16, 2012 6:37 PM
 Subject: Re: [R] save to file

 Hi,
 I am using Ubuntu 12.04.

 My sessionInfo() if that helps:
 sessionInfo()
 R version 2.15.0 (2012-03-30)
 Platform: x86_64-pc-linux-gnu (64-bit)

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

 attached base packages:
 [1] stats graphics  grDevices utils datasets
 methods   base
 other attached packages:
 [1] TeachingDemos_2.8 stringr_0.6   reshape_0.8.4 plyr_1.7.1

 loaded via a namespace (and not attached):
 [1] tcltk_2.15.0 tools_2.15.0
 A.K.







 
 From: Felipe Carrillo mazatlanmex...@yahoo.com
 To: arun smartpink...@yahoo.com
 Sent: Sunday, December 16, 2012 9:28 PM
 Subject: Re: [R] save to file


 My text file is created but its empty. Did you start
 library(TeachingDemos)
 txtStart(foo.txt,commands=TRUE,results=TRUE,append=FALSE)
 on you R.profile to capture the R statement?

 Felipe D.
 Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx



 From: arun smartpink...@yahoo.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Sent: Sunday, December 16, 2012 6:16 PM
 Subject: Re: [R] save to file



 Hi,
 If there are comments in your code, you need to ?txtComment() from 
 library(TeachingDemos).  I did a trial run and was able to get the 
 snapshot in the output file.

 A.K.


 
 From: Felipe Carrillo
 mazatlanmex...@yahoo.com
 To: arun smartpink...@yahoo.com
 Sent: Sunday, December 16, 2012 9:13 PM
 Subject: Re: [R] save to file


 I know about sink() and capture.output() but these functions don't capture 
 the entire console. I basically
 want a snapshot of all the text on the R console saved to a file. I am the 
 users to send me the file so that I can
 see where the R crashed. I will check the Teaching Demos. Thanks

 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx



 From: arun smartpink...@yahoo.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Cc: R help r-help@r-project.org
 Sent: Sunday, December 16, 2012 6:07 PM
 Subject: Re: [R] save to file

 HI,

 I guess ?sink() may not work for you as you need  the whole R console.

 Have you tried library(TeachingDemos) ?txtStart(), ?txtStop()
 ?
 txtStart(foo.txt,commands=TRUE,results=TRUE,append=FALSE)
 codes
 txtStop()

 A.K.



 - Original Message -
 From: Felipe
 Carrillo mazatlanmex...@yahoo.com
 To: r-h...@stat.math.ethz.ch 

Re: [R] save to file

2012-12-16 Thread arun


Hi,

This is what I did:
library(TeachingDemos)
 txtStart(foo1.txt,commands=TRUE,results=TRUE,append=FALSE)
Output being copied to text file,
use txtStop to end
txt ave(dta$Range,dta$Lat1,FUN=mean)
 [1] 616.440 714.360 616.440 690.770 714.360 714.360 690.770 766.155 851.550
[10] 851.550 766.155
txt txtStop()


#Output in foo1.txt
 ave(dta$Range, dta$Lat1, FUN = mean)
 [1] 616.440 714.360 616.440 690.770 714.360 714.360 690.770 766.155 851.550
[10] 851.550 766.155


A.K.

From: Felipe Carrillo mazatlanmex...@yahoo.com
To: arun smartpink...@yahoo.com 
Sent: Sunday, December 16, 2012 9:28 PM
Subject: Re: [R] save to file


My text file is created but its empty. Did you start
library(TeachingDemos)
txtStart(foo.txt,commands=TRUE,results=TRUE,append=FALSE)
on you R.profile to capture the R statement?

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



From: arun smartpink...@yahoo.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Sent: Sunday, December 16, 2012 6:16 PM
Subject: Re: [R] save to file



Hi,
If there are comments in your code, you need to ?txtComment() from 
library(TeachingDemos).  I did a trial run and was able to get the snapshot in 
the output file.

A.K.



From: Felipe Carrillo
mazatlanmex...@yahoo.com
To: arun smartpink...@yahoo.com 
Sent: Sunday, December 16, 2012 9:13 PM
Subject: Re: [R] save to file


I know about sink() and capture.output() but these functions don't capture the 
entire console. I basically
want a snapshot of all the text on the R console saved to a file. I am the 
users to send me the file so that I can
see where the R crashed. I will check the Teaching Demos. Thanks

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



From: arun smartpink...@yahoo.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Cc: R help r-help@r-project.org 
Sent: Sunday, December 16, 2012 6:07 PM
Subject: Re: [R] save to file

HI,

I guess ?sink() may not work for you as you need  the whole R console.

Have you tried library(TeachingDemos) ?txtStart(), ?txtStop()
?

txtStart(foo.txt,commands=TRUE,results=TRUE,append=FALSE)
codes
txtStop()

A.K.



- Original Message -
From: Felipe Carrillo mazatlanmex...@yahoo.com
To: r-h...@stat.math.ethz.ch r-h...@stat.math.ethz.ch
Cc: 
Sent: Sunday, December 16, 2012 8:30 PM
Subject: [R] save to file

 Hi,
What's the equivalent of Save to File from the R console File menu on an R 
routine? Just trying
to capture the whole R console into a text file when my code fails.




Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California,
USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx

   
[[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] Mixed Anova

2012-12-16 Thread Stephen Sammut
I am new to R and have been doing my utmost to learn it in order to teach my
students how to use it as an alternative to programs you have to purchase ­
and I am very grateful for the program and what it can doŠ.but I am having a
slight problem as I also am not very much into programming ­ though willing
to learn.

I have been trying to apply a mixed model ANOVA to some data I have. In
short ­ one repeated measure (behavior being observed with 8 levels), one
independent measure (Age with 2 levels - classified as 21 or =21) and then
the dependent variable is the score that the subjects obtained for the
specific behavior (Frequency).

I have been trying to use the aov model set up in the following way based on
what I have searched online:
aov(Frequency~Behavior*Age+Error(Subject/Behavior)+Age, dataframe). My data
is organized such that I have the data in the long format ­ Subject,  Age,
Behavior, Frequency.

All this gives me the following error:

Warning message:
In aov(Frequency~Behavior*Age+Error(Subject/Behavior)+Age,  :
  Error() model is singular

If you would kindly excuse my ignorance, would someone please guide me as to
what I am doing wrong.

Thank you in advance.
Stephen 



[[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] save to file

2012-12-16 Thread Felipe Carrillo
Well, I am going to give copies of an application to different offices and want 
to be able to generate an output file
in the event that an error would ocurr while running the different R routines. 
By saving the entire R console along with the
R version, I should be able to see where the error ocurred. I've seen text 
files with every single text from the R console but can't find
the way to capture that. 

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: arun smartpink...@yahoo.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Sent: Sunday, December 16, 2012 7:13 PM
Subject: Re: [R] save to file

As a workaround, you could copy manually the R statements R version 2.15.0 
(2012-03-30)--- 
Type 'q()' to quit R. and then use txtStart()..txtStop().  Would it work?  
The reason I am saying is that with 1000s of lines of code, this will be still 
easier. 
A.K.







From: Felipe Carrillo mazatlanmex...@yahoo.com
To: arun smartpink...@yahoo.com; r-h...@stat.math.ethz.ch 
r-h...@stat.math.ethz.ch 
Sent: Sunday, December 16, 2012 10:03 PM
Subject: Re: [R] save to file


I did check that link but it doesn't do what I want..thanks for trying though. 


Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



From: arun smartpink...@yahoo.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Sent: Sunday, December 16, 2012 6:55 PM
Subject: Re: [R] save to file

Hi,
sink() gives only the output to be saved in the foo.txt, but txtStart(), 
txtStop() gets the codes and the output.  Sorry, I misunderstood your 
question.

You can also check this link (if you haven't already
seen)
http://r.789695.n4.nabble.com/Capturing-R-console-output-into-a-file-sink-savehistory-td2227013.html
A.K.  






From: Felipe Carrillo mazatlanmex...@yahoo.com
To: arun smartpink...@yahoo.com 
Sent: Sunday, December 16, 2012 9:47 PM
Subject: Re: [R] save to file


What you did That's what sink() does but I mean the entire R console screen 
including the R statement below
I just want to be able to capture everything during the R session

R version 2.15.0 (2012-03-30)
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome
to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
  Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R. 

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



From: arun smartpink...@yahoo.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Sent: Sunday, December 16, 2012 6:37 PM
Subject: Re: [R] save to file

Hi,
I am using Ubuntu 12.04.

My sessionInfo() if that helps:
sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-linux-gnu (64-bit)

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

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

other attached packages:
[1] TeachingDemos_2.8 stringr_0.6   reshape_0.8.4 plyr_1.7.1   

loaded via a namespace (and not attached):
[1] tcltk_2.15.0 tools_2.15.0
A.K.








From: Felipe Carrillo mazatlanmex...@yahoo.com
To: arun smartpink...@yahoo.com 
Sent: Sunday, December 16, 2012 9:28 PM
Subject: Re: [R] save to file


My text file is created but its empty. Did you start
library(TeachingDemos)
txtStart(foo.txt,commands=TRUE,results=TRUE,append=FALSE)
on you R.profile to capture the R statement?

Felipe D.
Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



From: arun smartpink...@yahoo.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Sent: Sunday, December 16, 2012 6:16 PM
Subject: Re: [R] save to file



Hi,
If there are comments in your code, you need to ?txtComment() from 
library(TeachingDemos).  I did a trial run and was able to get the snapshot 
in the output file.

A.K.



[R] User defined functions error - where is it ?

2012-12-16 Thread edoardo baldoni
Hello, I have a written a couple of functions (states.trends(.) and
trend.generator(.))
to create monthly aggregated time series from disaggregated data. They seem
to work pretty
fine with all the data I provide, but they give me the following error in
one the case I use
a particular table (per.after.sub):

 states.trends(per.after.sub,'CUST_SINCE')
Error in if (d.length%%d.length2 != 0) { :
  missing value where TRUE/FALSE needed
 traceback()
5: update.POSIXct(x, mdays = 1, hours = 0, minutes = 0, seconds = 0)
4: update(x, mdays = 1, hours = 0, minutes = 0, seconds = 0)
3: floor_date(x[[w]], month) at #15
2: trend.generator(x, STATE, vec.states[i, 1], y) at #4
1: states.trends(per.after.sub, CUST_SINCE)

I use several tables:
1) full1, which contains data from 2009 to 2012
2) per2012.sub, which is a subset of full1 based on the criterion:
{  date_per = '2012-01-01'
   date_per = as.POSIXct(date_per,tz='', %Y-%m-%d)
   per2012.sub = subset(full1, CUST_SINCE = date_per)}
3) per.after.sub, which is a subset of full1 based on the criterion:
{  date_per1 = '2012-08-01'
   date_per1 = as.POSIXct(date_per1,tz='',%Y-%m-%d)
   per.after.sub = subset(full1, CUST_SINCE = date_per1)  }

All the procedures works fine with the tables 'full1' and 'per2012.sub' but
it gives me the
error when using the table 'per.after.sub'. What has this data set
different from the other two ?

Can you help me ? Where can the error be ?


Thank you


Edoardo

[[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] nls for sum of exponentials

2012-12-16 Thread Bert Gunter
1. Fit a simpler model -- you're probably overfitting.
2. Consult your local statistician.
3. Post to stats.stackexchange.com, as this appears to be primarily a
statistical issue, not an R issue. But 2) would probably be better.

Cheers,
Bert

On Sun, Dec 16, 2012 at 3:57 PM, Diviya Smith diviya.sm...@gmail.comwrote:

 Hi there,

 I am trying to fit the following model with a sum of exponentials -

 y ~ Ae^(-md) + B e^(-nd) + c

 the model has 5 parameters A, b, m, n, c

 I am using nls to fit the data and I am using DEoptim package to pick the
 most optimal start values -

 fm4 - function(x) x[1] + x[2]*exp(x[3] * -dist) + x[4]*exp(x[5] * -dist)

 fm5 - function(x) sum((wcorr-fm4(x))^2)

 fm6 - DEoptim(fm5, lower=c(0,0.1,1,0.1,1), upper=c(10e7, 100, 300,100, 300
 ), control=list(trace=FALSE))

 par2 - fm6$optim$bestmem

 names(par2) - c(c, A, n1, B, n2)

 fit2 - nls(wcorr ~ (c + A*exp(n1 * -dist) + B*exp(n2 * -dist)),
 start=par2,control
 =list(maxiter=1000, warnOnly=TRUE))

 However, I keep getting the following error -

 Error in numericDeriv(form[[3L]], names(ind), env) :

   Missing value or an infinity produced when evaluating the model

 OR

 In nls(wcorr ~ (c + A * exp(n1 * -dist) + B * exp(n2 * -dist)),  :

   singular gradient


 Can anyone suggest how to resolve the problem?


 Thanks,

 Priya

 [[alternative HTML version deleted]]

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




-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

[[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] Mixed Anova

2012-12-16 Thread Vivek Singh
please check this:

http://stats.stackexchange.com/questions/11079/problem-with-anova-repeated-measures-error-model-is-singular


On Mon, Dec 17, 2012 at 12:11 PM, Stephen Sammut ssam...@gmail.com wrote:

 model is singular




-- 
Thanks and Regards,

Vivek Kumar Singh

Alcatel-Lucent,
Bangalore

(91)9886317184, 8123951698

[[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] Mixed Anova

2012-12-16 Thread Bert Gunter
What you are doing wrong:

1. You haven't read the posting guide, and so have not posted with
sufficient clarity for people to help (at least I can't -- what's your data
look like?);

2. You've posted to the wrong list: mixed models posts are better answered
on the r-sig-mixed-models list.

3. I am not even sure that this is an R question, and not just a
statistical question. But I'll leave that for the experts on the mixed
models list.

-- Bert

On Sun, Dec 16, 2012 at 8:11 PM, Stephen Sammut ssam...@gmail.com wrote:

 I am new to R and have been doing my utmost to learn it in order to teach
 my
 students how to use it as an alternative to programs you have to purchase ­
 and I am very grateful for the program and what it can doÅ .but I am having
 a
 slight problem as I also am not very much into programming ­ though willing
 to learn.

 I have been trying to apply a mixed model ANOVA to some data I have. In
 short ­ one repeated measure (behavior being observed with 8 levels), one
 independent measure (Age with 2 levels - classified as 21 or =21) and
 then
 the dependent variable is the score that the subjects obtained for the
 specific behavior (Frequency).

 I have been trying to use the aov model set up in the following way based
 on
 what I have searched online:
 aov(Frequency~Behavior*Age+Error(Subject/Behavior)+Age, dataframe). My data
 is organized such that I have the data in the long format ­ Subject,  Age,
 Behavior, Frequency.

 All this gives me the following error:

 Warning message:
 In aov(Frequency~Behavior*Age+Error(Subject/Behavior)+Age,  :
   Error() model is singular

 If you would kindly excuse my ignorance, would someone please guide me as
 to
 what I am doing wrong.

 Thank you in advance.
 Stephen



 [[alternative HTML version deleted]]


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




-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

[[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] kruskalmc, significant differences while median values are the same

2012-12-16 Thread Omphalodes Verna
Thank for help!

My ''problem'' is a little bit complicated. I have a dataset of trees (five 
tree species) and I need to calculate if there are the significant differences 
in the period of suppressed growth among tree species (length in years, e.g. 1, 
2, 3, 6, 10, 50, 80, etc.). Because data are not normally distributed (Levene 
test), my idea was to use kruskalmc test. 
 
So, my question is, how to evaluate the differences in the duration of 
suppressed growth among groups? Is ''bootstrap confidence interval'' for each 
tree species right solution? 

thanks, OV





From: Thomas Lumley tlum...@uw.edu
To: Omphalodes Verna omphalodes.ve...@yahoo.com 
Cc: R Help r-help@r-project.org 
Sent: Sunday, December 16, 2012 11:59 PM
Subject: Re: [R] kruskalmc, significant differences while median values are the 
same


On Sat, Dec 15, 2012 at 10:04 PM, Omphalodes Verna omphalodes.ve...@yahoo.com 
wrote:

Dear list!

I work with multiple Kruskal-Wallis test (kruskalmc, package pgirmess), which 
evaluates differences in medians among groups (5 groups). A result of a test 
is significant differences among some groups, while median values are the same 
for 4 groups (using tapply). Why?



The Kruskal-Wallis test *doesn't* evaluate differences in medians, so there is 
quite likely nothing wrong in a formal sense.

However, this does suggest that your groups may not be stochastically ordered, 
which means the results of the Kruskal-Wallis test could be quite misleading.  
I'd suggest that you at least look at pairwise Wilcoxon tests to make sure the 
direction agrees with what the Kruskal-Wallis test implies. Box plots might 
also be a good idea. 

Or, if you really want differences in medians, look at differences in medians. 
A permutation test or a bootstrap confidence interval is probably the best way 
to do this.

   -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland     

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] looping through spatial points and getting counts of spatial points in spatial grid in R

2012-12-16 Thread Tilottama Ghosh
Hi,
I am stuck in a looping problem. It might be an easy problem for experienced R 
users but I have been unable to do it. Any kind of help or advice will be great 
appreciated.
I am creating a spatial grid and have a list of spatial points in a folder. I 
can read the spatial points separately and get a count of the points in the 
spatial grid in R. The output should be a table showing the counts of points in 
the spatial grid. However, since there are many of these spatial points, I want 
this process to be automated. Can someone help me with this? All my spatial 
points are in one folder. 
# Creating spatial points in R - reading the POI shapefiles as 
SpatialPointsDataFrame in R autopts.rg - readOGR(., AutoSvc)class 
(autopts.rg)

# Getting a count of the Spatial Points in the Spatial Data Frame in.cell - 
overlay(SpatialGrid_LS,FinInstq2) newdata - 
data.frame(table(in.cell))View(newdata)
SpatialGrid_LS is the spatial grid that I had created in R. 
I guess a For loop would help, but although I tried several things, I haven't 
been successful yet.
Thanks!
Tilo


[[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] save to file

2012-12-16 Thread David Winsemius

On Dec 16, 2012, at 7:35 PM, Felipe Carrillo wrote:

 Well, I am going to give copies of an application to different offices and 
 want to be able to generate an output file
 in the event that an error would ocurr while running the different R 
 routines. By saving the entire R console along with the
 R version, I should be able to see where the error ocurred. I've seen text 
 files with every single text from the R console but can't find
 the way to capture that. 

Most consoles will accept cmd-A or similar to select all text in a console 
session. Figure out what that keystroke combo is for your OS and then ctl- or 
cmd-C and paste into text editor.

-- 
David Winsemius
Alameda, CA, USA

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


Re: [R] save to file

2012-12-16 Thread Vivek Singh
try the following. it works for linux:

$ R|tee log.txt

I stored the log for a small period.

*R version 2.15.1 (2012-06-22) -- Roasted Marshmallows
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

 q()
Save workspace image? [y/n/c]: n*


On Mon, Dec 17, 2012 at 3:23 PM, David Winsemius dwinsem...@comcast.netwrote:


 On Dec 16, 2012, at 7:35 PM, Felipe Carrillo wrote:

  Well, I am going to give copies of an application to different offices
 and want to be able to generate an output file
  in the event that an error would ocurr while running the different R
 routines. By saving the entire R console along with the
  R version, I should be able to see where the error ocurred. I've seen
 text files with every single text from the R console but can't find
  the way to capture that.

 Most consoles will accept cmd-A or similar to select all text in a console
 session. Figure out what that keystroke combo is for your OS and then ctl-
 or cmd-C and paste into text editor.

 --
 David Winsemius
 Alameda, CA, USA

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




-- 
Thanks and Regards,

Vivek Kumar Singh

Alcatel-Lucent,
Bangalore

(91)9886317184, 8123951698

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