[R] problems with geom_vline, histograms, scale=free and facets in ggplot

2011-06-10 Thread Julian Burgos
Dear list,

I´m having a little trouble with adding vertical lines to a histogram.
 I need to draw a matrix of histograms (using facets), and in each
histogram add a vertical line indicating the mean value of the data in
each facet.  According to the last example in the geom_hline help, to
display different lines in each facet I need to provide a data frame.
I modified this example to make a plot similar to what I need:


# BEGIN R CODE 
# This example works and does exactly what I need
library(reshape)
library(ggplot2)

# First, create a data frame with the mean value, to add to each facet
mean.data=tapply(mtcars$wt,INDEX=list(mtcars$vs,mtcars$am),mean)
mean.data=melt(mean.data)
colnames(mean.data)=c(vs,am,wt.mean)

# Now do the plot
p - qplot(wt, data=mtcars)
p - p + facet_grid(vs ~ am,scale=free)
p - p + geom_vline(aes(xintercept = wt.mean), mean.data,col=red)
p
###

###
# This one does not work
# Create a test data set
set.seed(100)
my.data=data.frame(code1=rep(c(A,B,C),each=30),
  code2=rep(rep(c(D,E,F),each=10),3),
  n=runif(90))

# Create a data frame with the mean value, to add to each facet
mean.data=tapply(my.data$n,INDEX=list(my.data$code1,my.data$code2),mean)
mean.data=melt(mean.data)
colnames(mean.data)=c(code1,code2,n.mean)

# Now do the plot
p = qplot(n, data=my.data) +
  facet_grid(code2 ~ code1, scales=free)
p + geom_vline(aes(xintercept = n.mean), mean.data,col=red)

#With this I get the following error: Error in if (length(range) == 1
|| diff(range) == 0) { :   missing value where TRUE/FALSE needed.

# If I remove the scales=free argument. I get the lines but also a
lot of extra empty facets.

p = qplot(n, data=my.data) +
  facet_grid(code2 ~ code1)
p + geom_vline(aes(xintercept = n.mean), mean.data,col=red)

# END R CODE ##

I can´t figure out why the second example does not work when having
the scales=free argument, and why I get the extra facets when
removing it.  Is this a bug?  Any help will be very welcomed.

Julian

--
Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: jul...@hafro.is, jmbur...@uw.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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-/Text-editor for Windows?

2011-01-31 Thread Julian Burgos
 I've tried Emacs Speaks Statistics and found it just confusing, to say
 the least (by the way, I'm puzzled by why so many people adhere to
 this one. Maybe it's a matter of getting used to it...?)

You are right... it is confusing, and it takes some time to get used
to, and it is not for everyone.  But, it is totally customizable, and
combined with org mode and org babel it becomes a tool as no other.
I´ve tried about every editor, including Tinn-R, Notepad++, and
Eclipse with StatEt, but after switching to Emacs/ESS there is no
turning back.

Julian
-- 
Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: jul...@hafro.is, jmbur...@uw.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] post-hoc comparisons in GAMs (mgcv) with parametric terms

2011-01-25 Thread Julian Burgos
Dear list,

I´m wondering if there is something analogous to the TukeyHSD function
that could be used for parametric terms in a GAM.  I´m using the mgcv
package to fit models that have some continuous predictors (modeled as
smooth terms) and a single categorical predictor.  I would like to do
post hoc test on the categorical predictor in the models where it is
significant.
Any suggestions?

Thanks,

Julian

-- 
Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: jul...@hafro.is, jmbur...@uw.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 me understand how things work.

2010-09-16 Thread Julian Burgos
Hi Alex,

What is happening is that the ´dist´function calculates a distance matrix,
and returns an object of the ´dist´ class.

 temp - rbind (c(10,1),c(99,98))
 x=dist(temp)
 x
 1
2 131.6435
 class(x)
[1] dist

You can see a description of the ´dist´class at the end of the function´s
help file.  Do this:
?dist

So when you do dist(temp) you do not just get a number.  You get an object
that has the distance between the points, plus additional information (i.e.
the method used to calculate the distance, if the matrix contains only the
lower triangle or also the upper triangle and the diagonal, etc.).  If you
do sqrt() or 1/ over this object it is still of the ´dist´ class:

 x=dist(temp)
 x=sqrt(x)
 class(x)
[1] dist
 x=1/x
 class(x)
[1] dist

Notice that you still the right answer (0.08715662).  For some reason R
prints the attributes of the object when you do the inverse but not when you
do the square root (I´m curious about why...If anyone has an answer please
pitch in).

If you only want to get a number, do this:
 x=as.numeric(dist(temp))
 class(x)
[1] numeric
 1/sqrt(as.numeric(dist(temp)))
[1] 0.08715662

All the best,

Julián

Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: jul...@hafro.is, jmbur...@uw.edu


On Thu, Sep 16, 2010 at 10:02 AM, Alaios ala...@yahoo.com wrote:

 Hello I have some strange output from R and I try to understand how R
 works.

 Could you please help me with that?

 temp - rbind (c(10,1),c(99,98))
  temp
 [,1] [,2]
 [1,]   101
 [2,]   99   98


  dist(temp)
 1
 2   131.6435


  sqrt(dist(temp))
 1
 2   11.47360

 so far so good.

 until the nex line: when I try to do what i did before but adding the
 1/(what I
 did before). I was expecting a number as a result of the division but
 unfortunately I took the following:

  1/sqrt(dist(temp))
 [1] 0.08715662
 attr(,Size)
 [1] 2
 attr(,Diag)
 [1] FALSE
 attr(,Upper)
 [1] FALSE
 attr(,method)
 [1] euclidean
 attr(,call)
 dist(x = temp)
 attr(,class)
 [1] dist


 Could you please help me understand what is this about?

 I would like to thank you in advance for your help
 Best REgards
 Alex




[[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] Strange behaviour when using diff with POSIXt and POSIXlt objects

2010-05-21 Thread Julian Burgos
Hi Brian,

This is really odd.  I keep getting the NA secs answer, only by running
these three lines of code in a new session.


 time3=strptime(2009 06 01 00 47 00,format=%Y %m %d %H %M)
 time4=strptime(2009 06 01 00 57 00,format=%Y %m %d %H %M)
 diff(c(time3,time4))
Time difference of NA secs

Here is the information you requested:

 dput(time3)
structure(list(sec = 0, min = 47L, hour = 0L, mday = 1L, mon = 5L,
year = 109L, wday = 1L, yday = 151L, isdst = -1L), .Names = c(sec,
min, hour, mday, mon, year, wday, yday, isdst
), class = c(POSIXt, POSIXlt))
 dput(time4)
structure(list(sec = 0, min = 57L, hour = 0L, mday = 1L, mon = 5L,
year = 109L, wday = 1L, yday = 151L, isdst = -1L), .Names = c(sec,
min, hour, mday, mon, year, wday, yday, isdst
), class = c(POSIXt, POSIXlt))
 sessionInfo()
R version 2.11.0 (2010-04-22)
i386-pc-mingw32

locale:
[1] LC_COLLATE=Icelandic_Iceland.1252  LC_CTYPE=Icelandic_Iceland.1252
[3] LC_MONETARY=Icelandic_Iceland.1252 LC_NUMERIC=C
[5] LC_TIME=Icelandic_Iceland.1252

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

other attached packages:
[1] svSocket_0.9-48 TinnR_1.0.3 R2HTML_2.0.0Hmisc_3.7-0.1
[5] survival_2.35-8

loaded via a namespace (and not attached):
[1] cluster_1.12.3 grid_2.11.0lattice_0.18-5 svMisc_0.9-57
tools_2.11.0

Thanks,

Julian

[[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] Strange behaviour when using diff with POSIXt and POSIXlt objects

2010-05-20 Thread Julian Burgos
Dear list,

I´m calculating time differences between series of time stamps and I noticed
something odd:

If I do this...

 time1=strptime(2009 05 31 22 57 00,format=%Y %m %d %H %M)
 time2=strptime(2009 05 31 23 07 00,format=%Y %m %d %H %M)

 diff(c(time1,time2),units=mins)
Time difference of 10 mins

.. I get the correct response in minutes.  But if I try the same thing with
different values, say..

 time3=strptime(2009 06 01 00 47 00,format=%Y %m %d %H %M)
 time4=strptime(2009 06 01 00 57 00,format=%Y %m %d %H %M)

 diff(c(time3,time4))
Time difference of NA secs

...which is not what I´m looking for. The difference should also be 10
minutes.

I burned a few neurons (and searched the documentation) and I cannot figure
why this happens.  Any ideas?

All the best,

Julian

Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: jul...@hafro.is, jmbur...@uw.edu

[[alternative HTML version deleted]]

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


Re: [R] Strange behaviour when using diff with POSIXt and POSIXlt objects

2010-05-20 Thread Julian Burgos
Hi Jim

I´m using R 2.11.0, on Windows XP.

On Thu, May 20, 2010 at 4:55 PM, jim holtman jholt...@gmail.com wrote:

 Please provide information as to what version you are using;  works fine
 for me:

  time3=strptime(2009 06 01 00 47 00,format=%Y %m %d %H %M)
  time4=strptime(2009 06 01 00 57 00,format=%Y %m %d %H %M)
 
  diff(c(time3,time4))
 Time difference of 10 mins
 

 I have version 2.10.1

 On Thu, May 20, 2010 at 12:36 PM, Julian Burgos jmbur...@uw.edu wrote:
  Dear list,
 
  I´m calculating time differences between series of time stamps and I
 noticed
  something odd:
 
  If I do this...
 
  time1=strptime(2009 05 31 22 57 00,format=%Y %m %d %H %M)
  time2=strptime(2009 05 31 23 07 00,format=%Y %m %d %H %M)
 
  diff(c(time1,time2),units=mins)
  Time difference of 10 mins
 
  .. I get the correct response in minutes.  But if I try the same thing
 with
  different values, say..
 
  time3=strptime(2009 06 01 00 47 00,format=%Y %m %d %H %M)
  time4=strptime(2009 06 01 00 57 00,format=%Y %m %d %H %M)
 
  diff(c(time3,time4))
  Time difference of NA secs
 
  ...which is not what I´m looking for. The difference should also be 10
  minutes.
 
  I burned a few neurons (and searched the documentation) and I cannot
 figure
  why this happens.  Any ideas?
 
  All the best,
 
  Julian
 
  Julian Mariano Burgos
  Hafrannsóknastofnunin/Marine Research Institute
  Skúlagata 4, 121 Reykjavík, Iceland
  Sími/Telephone : +354-5752037
  Bréfsími/Telefax:  +354-5752001
  Netfang/Email: jul...@hafro.is, jmbur...@uw.edu
 
 [[alternative HTML version deleted]]
 
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 



 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem that you are trying to solve?




-- 
Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: jul...@hafro.is, jmbur...@uw.edu

[[alternative HTML version deleted]]

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


[R] GAM for non-integer proportions

2010-02-14 Thread Julian Burgos
Dear list,

I´m using the mgcv package to model the proportion by weight of certain prey
on the stomach content of a predator.  This proportion is the ratio of two
weights (prey weight over stomach weight), and ranges between 0 and 1.  The
variance is low when proportion is close to 0 and 1, and higher at
intermediate values.

It seems that the best way to go is to model this using the quasi family
with a logit link and a mu(1-mu) variance.  Or I am missing something
obvious?  I will be thankful for any input.

All the best,

Julian

-- 
Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: jul...@hafro.is, jmbur...@uw.edu

[[alternative HTML version deleted]]

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


[R] linear models with variance in dependent and independent variables

2010-01-31 Thread Julian Burgos
Dear list,

I need to fit a multiple regression in which individual data point in the
independent and the dependent variables have an associated variance or
standard deviation.  To make things clear, instead of having just a table of
dependent (X) and independent (Y1, Y2) variable values like this:


X Y1Y2
2.2  3.4   4.5
4.1  2.6   5.2
7.4  1.4   4.6


I have a table in which each value has an associated standard deviation:


X Y1  Y2
2.2 (0.31) 3.4 (0.45)4.5 (0.21)
4.1 (0.28) 2.6 (0.23)5.2 (0.54)
7.4 (0.45) 1.4 (0.63)4.6 (0.37)


What would be the best way to fit a multiple regression taking into account
the variance of the individual values of the independent and dependent
variables? Any references to methods or R packages will be greatly welcomed.

Julian

-- 
Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: jul...@hafro.is, jmbur...@uw.edu

[[alternative HTML version deleted]]

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


Re: [R] SOM library - where do I find it

2009-11-18 Thread Julian Burgos
You have to download it from CRAN and install it.  From the GUI, do
Packages-Install package(s).

Pretty basic stuff...you should check the documentation before posting.

Julian




 R version 2.9.2 (2009-08-24) - for windows

 library(SOM)
 Error in library(SOM) : there is no package called 'SOM'

 Where can I get the SOM library from?

 Thanks in advance
 --
 View this message in context:
 http://old.nabble.com/SOM-library---where-do-I-find-it-tp26415633p26415633.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] compute differences

2009-09-21 Thread Julian Burgos

Here is an approach...probably there are more elegant ways

mydata=data.frame(ID=c(A,B,C,D,E),val=c(.3,1.2,3.4,2.2,2.0))

index=expand.grid(1:nrow(mydata),1:nrow(mydata))
dif=data.frame(difference=mydata$val[index$Var2]-mydata$val[index$Var1])
rownames(dif)=paste(mydata$ID[index$Var2],-,mydata$ID[index$Var1]) 



  
alessandro carletti wrote:

Hi,
I have a problem.
I have a data frame looking like:

ID val

A  .3
B  1.2
C  3.4
D  2.2
E  2.0

I need to CREATE the following TABLE:

CASE   DIFF

A-A0
A-B-0.9
A-C-3.1
A-D-1.9
A-E-1.7
B-A...
B-B...
B-C
B-D
B-E
C-A
C-B
C-C
C-D
C-E
D-A
D-B
D-C
D-D
D-E
E-A
E-B
E-C
E-D
E-E

WHERE CASE IS THE COUPLE OF ELEMENTS CONSIDEREDM AND DIFF IS THE computed 
DIFFERENCE between their values.

Could you give me suggestions?

Alessandro Carletti




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



--
Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: jul...@hafro.is, jmbur...@u.washington.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] ggplot2 legend text....a basic question

2009-09-14 Thread Julian Burgos
Hello fellow R's, 

I´ve been learning to use the ggplot2 library, and after a full day of 
work I still have a couple of basic questions.

Here is an example:

mydata=data.frame(x=runif(20),y=runif(20),n=runif(20))
mydata2=data.frame(x=c(0.4,0.6,0.5),y=c(0.4,0.4,0.6))
ggplot(mydata, aes(x, y))   + geom_point(aes(size = n)) + 
geom_polygon(data=mydata2,aes(x,y,alpha=0.5))


In this plot, the points are labeled as n (the name of the variable) 
and the polygon is labeled as 0.5 (the alpha value used).   My 
questions are:
a) How to change the text  in the legend (for example, number instead 
of n).

b) How to avoid having a  legend for the polygon?
Many thanks,

Julian

--
Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: jul...@hafro.is, jmbur...@u.washington.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Out of memory issue

2009-04-24 Thread Julian Burgos
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html and provide commented, 
minimal, self-contained, reproducible code.

Otherwise...the only other possible suggestion is to use a smaller file.

Julian

Neotropical bat risk assessments wrote:

Hi all,

I am trying to run some plots on data, but when loading he CSV data 
file R is stopping and I am getting an out of memory error.


Anyway to tweak this somehow to get it to run?

Using WinXP with 4 GB RAM

Tnx

Bruce

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Forcing the extrapolation of loess through the origin

2009-04-14 Thread Julian Burgos

Hi Torsten,

If you are fitting a line, why are you using loess?  Why not simply 
use lm to fit a regression line that goes through the origin? (i.e. 
with no intercept).


Julian

jimm-pa...@gmx.de wrote:

Hi all,

I'm fitting a line to my dataset. Later I want to predict missing values that exceed the 
[min,max] interval of my empirical data, therefore I choose surface=direct 
for extrapolation.

l1-loess(y1~x1,span=0.1,data.frame(x=x1,y=y1),control=loess.control(surface=direct))

In my application it is highly important that the fitted line intercepts at the 
point of origin. Is it possible to do this in R?

Thanks in advance.

Cheers,
Torsten
--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] coalesce columns within a data frame

2008-10-22 Thread Julian Burgos

You could do something like this:

 Name.x=c('nx1','nx2',NA,NA)
 Name.y=c('ny1','NA','ny3',NA)

 Name=Name.x
 Name[is.na(Name.x)]=Name.y[is.na(Name.x)]

 Name
[1] nx1 nx2 ny3 NA


Julian


Ivan Alves wrote:

Dear all,

I searched the mail archives and the R site and found no guidance (tried 
merge, cbind and terms like coalesce with no success).  There 
surely is a way to coalesce (like in SQL) columns in a dataframe, 
right?  For example, I would like to go from a dataframe with two 
columns to one with only one as follows:


From

Name.x Name.y
nx1 ny1
nx2 NA
NA ny3
NA NA
...

To

Name
nx1
nx2
ny3
NA
...

where column Name.x is taken if there is a value, and if not then column 
Name.y


Any help would be appreciated

Kind regards,
Ivan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] 3 curves / 1 plot

2008-10-06 Thread Julian Burgos
You can use the points() and lines() functions to add points and lines 
to an existing plot.


Julian

Michel PETITJEAN wrote:

I am a new user of R.
Please does somebody knows how to plot 3 datasets
(x1,a1),...,(xn,an), (x1,b1),...,(xn,bn), and (x1,c1),...,(xn,cn)
on a single x,y plot, each of the three datasets being plotted with
its own character pch() ?
(three calls to plot() erase the two first datasets).
Thank you very much.

Michel Petitjean,
DSV/iBiTec-S/SB2SM (CNRS URA 2096), CEA Saclay, bat. 528,
91191 Gif-sur-Yvette Cedex, France.
Phone: +331 6908 4006 / Fax: +331 6908 4007
E-mail: [EMAIL PROTECTED]
http://petitjeanmichel.free.fr/itoweb.petitjean.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.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Inverting data frame...row wise

2008-09-25 Thread Julian Burgos

How about something like

my.data=my.data[,4:1]

Julian

milicic.marko wrote:

Hi,

I have the data.frame with 4 columns. I simply want to invert dataset
so that last row becomes first...

I tried with rev(my_data-frame) but I got my columns inverted... not
my rows


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.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Question about col.names in write.csv

2008-09-05 Thread Julian Burgos

Hi Luz,
No entiendo bien tu pregunta.  Querés grabar una tabla con nombres en 
las columnas y tambien en la primera fila?  Si es asi, tenés que 
asignarle los nombres a la tabla antes de grabar.  Por ejemplo:


mi.tabla=matrix(runif(30),ncol=3)

colnames(mi.tabla)=c(A,B,C)
rownames(mi.tabla)=c(D,rep(,9))

write.csv(mi.tabla,file=mi.archivo.csv)

Cuando asignás nombres a las filas o columnas, el vector tiene que tener 
la misma longitud que el numero de filas o columnas.  Entonces, para 
darle un nombre solamente a la primera fila, hice un vector con el 
nombre y nueve espacios en blanco (para completar las diez filas que 
tiene mi tabla).


Al grabar la tabla usando write.csv, el comportamiento default es 
guardar los nombres de las columnas y filas.



Saludos,

Julian

Luz Milena Zea Fernandez wrote:

Dear support, I don't ignore col.names in write.csv. I want to write names for 
the firts row. How can I do?

Thanks in advance

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


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


Re: [R] Mclust - which cluster is each observation in?

2008-07-21 Thread Julian Burgos
Well, you are dealing with probability based clustering, so for each 
bird you will get a probability of belonging to each cluster.  If your 
clusters are well defined, then each bird should have a very high 
probability of belonging to one of the clusters.  You can get this 
probability matrix from your mclust object.


For the iris dataset example,

my.clusters=Mclust(iris[,-5])

This will give you the probability matrix

my.clusters$z

You can assign membership based on these probabilities (i.e. each bird 
belongs to the cluster with highest probability).  You can obtain this 
membership by doing


my.clusters$membership

Hope this helps,

Julian

cnagy wrote:

I'm trying to test a method of identifying individuals (birds) based on
measured data (their calls).  


I have test data from known individual birds, and I am using the Mclust
package to see if the program can correctly identify which calls come from
different birds.

So far, mclust has correctly ID'd the number of birds in the test data set
(i.e., the correct # of clusters).  However I also need to correctly assign
each call to the right bird (i.e., data rows (calls) 1 - 10 are in cluster
(bird) 1; rows 2 - 20 are in cluster 2, etc.).

Is there a way to get mclust to show the cluster assignments of each
observation?  


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] using which to identify a range of values

2008-07-18 Thread Julian Burgos

Do simply

which(a100  a=200)

Julian

sj wrote:

Hello, I am trying to identify values that  fall within a certain range. I
thought that I might be able to use the which function to do this but I have
been unable to figure out a way to do it. Perhaps a little code will
illustrate what i am trying to do.


a - rnorm(1000, 100, 50)
which( 100  a = 200)


of course this doesn't work but illustrates what I ma trying to do, If
anyone has  suggestions I would greatly appreciate it

Best,

Spencer

[[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] Problemas usando jri0.4-1 y R 2.7.0

2008-06-02 Thread Julian Burgos

Hola Borja,

Creo que vas a tener muy pocas respuestas a menos que escribas a la 
lista en inglés.  Lamentablemente yo conozco poco de Java y no puedo 
responder tu pregunta.


Saludos,

Julian

Borja Soto Varela wrote:

Hola, es la primera vez que mando un correo a cualquiera de las listas de
correo de R y no se si esta consulta se ajusta al próposito de la r-help
list o debería haberlo mandado a otra de las listas que hay.

Mi problema es el siguiente: Estoy desarrollando un programa en java con
llamadas a R y no puedo usar jri 0.4-1 con la version 2.7 o 2.6 de R.
Curiosamente si me funciona si uso jri 0.4 o la propia 0.4-1 con la version
2.4.

El problema que me da al usar la ultima versión de R es el siguiente:

Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in
java.library.path.


java.lang.UnsatisfiedLinkError: C:\JRI_0.4-1\JRI\jri.dll: No se encontró 

el proceso especificado

   at java.lang.ClassLoader$NativeLibrary.load(Native Method)
   at java.lang.ClassLoader.loadLibrary0(Unknown Source)
   at java.lang.ClassLoader.loadLibrary(Unknown Source)
   at java.lang.Runtime.loadLibrary0(Unknown Source)
   at java.lang.System.loadLibrary(Unknown Source)
   at org.rosuda.JRI.Rengine.clinit(Rengine.java:9)
   at vista.main.Main.main(Main.java:12)


El directorio donde tengo jri.dll lo incluí en el path del sistema en esa
ruta (de hecho con 2.4 funciona sin hacer nada más). Me preguntaba si a
alguien también le ha pasado esto y como se puede solucionar.
Gracias

[[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] more columns that column names

2008-06-02 Thread Julian Burgos

Hi Paul,

The easiest thing to to is to open the file using a text editor (Notepad 
will do) and examine the first few lines.  You can add add a column name 
if needed.


Julian

Paul Adams wrote:

Hello to everyone,
I have gotten my file to print to screen but when I use read.table I am getting 
an error message that
says there are more columns than column names.This is a file that was not created by me so I am 
not sure how to investigate and solve this problem.I looked in the help file and it suggested an auxilliary function called count.fieldsThe code that was used was:

read.table(file=C:\\Documents and Settings\\Owner\\My Documents\\colon 
cancer1.txt,header=T,row.names=1)
Any help would be appreciated
paul


  
	[[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] Plot colors

2008-05-30 Thread Julian Burgos

You could do something like this:

mydata=c(1,2,1,1,6,7,-1,-1,5,-1)
color= as.numeric(mydata== -1) +1
plot(mydata,col=color)

This will give you a plot where the -1's are in red (color = 2) and the 
other numbers in black (color=1).


Julian


uv wrote:

Hi. I am plotting graphs for values ranging between -1 and 10, for example:
(1,2,1,1,6,7,-1,-1,5,-1)
I am trying to plot the graphs so that the points with value of -1 will be
in one specific color, and the rest of the points will be in one different
specific color. I would be grateful for any idea of how to do that in two
colors.
Thanks for any hint.
  


--
Julian M. Burgos

Fisheries Acoustics Research Lab
School of Aquatic and Fishery Science
University of Washington

1122 NE Boat Street
Seattle, WA  98105 


Phone: 206-221-6864

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Excluding/removing row and column names on text output files

2008-05-30 Thread Julian Burgos

Hi Steve,

You can use write.table:

write.table(x, file=/Users/Desktop/Data.txt, 
sep=,row.names=F,col.names=F)


Cheers,

Julian


Stropharia wrote:

Dear R users,

I've had no joy finding a solution to this online or in any of my R books.
Many thanks in advance for any help you can give.

I'm seeking to output a data frame (or matrix - it doesn't matter which for
my purposes) to a .txt file, but omit any row or column names. The data
frame that I'm using doesn't actually have column or row names to start with
as it has been coerced into its present form from a matrix. When I use:

capture.output(x, file=/Users/Desktop/Data.txt, append=TRUE)

I get the following (this is a small fraction of the actual data frame):

1 2 3 4 5 
X1 0 0 0 0 2 
X2 0 0 0 2 0 
X3 1 1 2 0 0


If the data frame is transformed into a matrix, I still get row and column
'names' (or at least numbers like v1, etc.). Using the sink function
also produces the exact same result. I've tried using row.names=FALSE (as
you would when writing to a .csv file), in the capture.output function,
but it doesn't work.

I would also like the remove the horizontal spaces between numbers on the
same row, to produce:

2 
00020 
11200


But, I want each row to remain a separate entity (not be concatenated with
the others). I know I can remove the blank spaces by doing Find and Replace
in a text editor, but is it possible to remove the row and column names, and
the row spaces, directly in R so that it outputs like the above example?

Thanks,

Steve

~~
Steven Worthington
Ph.D. Candidate
New York Consortium in
Evolutionary Primatology 
Department of Anthropology
New York University
25 Waverly Place
New York, NY 10003
U.S.A.
~~
  


--
Julian M. Burgos

Fisheries Acoustics Research Lab
School of Aquatic and Fishery Science
University of Washington

1122 NE Boat Street
Seattle, WA  98105 


Phone: 206-221-6864

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 on nested FOR loops

2008-05-19 Thread Julian Burgos

Hey Philip,

I'm not sure if I understand what your x11, x12, etc. are.  You can 
combine the values of your two vectors using the expand.grid function. 
There is no need to do nester FOR loops:


 i=c(1,2,3,4,5)
 j=c(1,2,3)
 x=expand.grid(i,j)
 print (x)

   Var1 Var2
1 11
2 21
3 31
4 41
5 51
6 12
7 22
8 32
9 42
1052
1113
1223
1333
1443
1553

Hope this helps,

Julian

Philip Twumasi-Ankrah wrote:

I am new to more radical programming in R. I am trying to write a nested 'for' 
loop to produce output that takes subscripts like:

for i taking values 1,2,3,4,5 and 
j taking values 1,2,3


I want to output for a computation using the combination values of i and j a 
value x like this;

i   jx
1  1   x11
1  2   x12
1  3   x13
2  1   x21
 2  2   x22
 2  3   x23
3  1   x31
 3  2   x32
 3  3   x33

...

Need help urgently.

Thanks.

Philip


A Smile costs Nothing  


 But Rewards Everything

Happiness is not perfected until it is shared
  -Jane Porter



   
	[[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] wavlet analysis

2008-05-14 Thread Julian Burgos

Hi Stephen,

Your link doesn't work.  In any case, check out the wavCWT function in 
the wmtsa package.


Julian

stephen sefick wrote:

http://ion.researchsystems.com/cgi-bin/ion-p
I would like a continuous wavelet transform.  I have downloaded wavethresh,
Rwave, and waveslim.  I would like an output very similar to the above
website.  any suggestions?



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] A very simple question

2008-05-14 Thread Julian Burgos

Try this:

k=c(1,1,1,2,2,1,1,1)

 k[(k!=1)]
[1] 2 2

 k[(k!=2)]
[1] 1 1 1 1 1 1

 k[(k!=3)]
[1] 1 1 1 2 2 1 1 1

Julian


Shubha Vishwanath Karanth wrote:

Hi R,

 


Suppose

l=c(1,1,1,2,2,1,1,1)

 


k[-which(k==1)]

[1] 2 2

 


k[-which(k==2)]

[1] 1 1 1 1 1 1

 


But,

 


k[-which(k==3)]

numeric(0)

 


I do not want this numeric(0), instead the whole k itself should be my
result... How do I do this?

 

 


Thanks,

Shubha

 


This e-mail may contain confidential and/or privileged i...{{dropped:13}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Can R handle large dataset?

2008-05-14 Thread Julian Burgos
Depends on the RAM in your machine.  And in your definition of 'handle'. 
 You may be able to load a very large dataset into R, but won't be able 
to use some functions that require additional memory.


A vague answer to a vague question... :)

Julian


Mingjun Huang wrote:

Hello,

   I am new to R, can anyone give me an idea of how R handle a large dataset
   (e.g. couple of Gbytes)? Thanks a lot!


   Best,
   Mingjun

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] use list elements to subtract values from the dataframe

2008-05-07 Thread Julian Burgos

Try
get(paste(wf$,fl[[1]],sep=))

See ?get

Julian


Dirkheld wrote:

Hi,

I have a dataframe wf existing of a header with different labels and beneath
the values of those labels :
wf:
label1  label2  ...
0,450,21
0,100,45 
  


I have a list
fl - c(label2,label3,..)

Isn't possible to use the list elements in the list in order to subtract
values from the dataframe? like :
wf$fl[[1]] 
When I do in R I get :NULL

fl[[1]] gives  label2  so no problem here...

While wf$label1 works fine.





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 count the overlapped in two vectors

2008-05-01 Thread Julian Burgos

See
?match

ss wrote:

Dear list,

If I have two vector, t1 and t2, of different lengths.  Is there an easy way
to count
the number of the overlapped in two vectors and show the result in the
graph?

Thanks much,

Alex

[[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] How do you test for consecutivity?

2008-04-29 Thread Julian Burgos

Hey Anthony,
There must be many ways to do this.  This is one of them:

#First, define a function to calculate the proportion of consecutive 
numbers in a vector.


prop.diff=function(x){
d=diff(sort(x))
prop=(sum(d==1)+1)/length(x)
return(prop)}

#Note that I am counting both numbers in a consecutive pair.  For 
example, the vector c(1,2,6,9,10) will contain 4 consecutive numbers.  I 
think this is what you wanted do do, right?


#Next, generate a matrix with 1000 columns (one for each experiment) and 
5 rows (the five numbers in each experiment).  Note the use of the 
'replicate' function to generate multiple sets of random numbers


selection=replicate(1000,sort(sample(1:30,5)))

#Third, use the apply function to apply the function we defined above to 
each column of the matrix


diffs=apply(selection,2,prop.diff)

# This will give you a vector with the 1000 proportions of consecutive 
numbers


Julian


Anthony28 wrote:

I need to use R to model a large number of experiments (say, 1000). Each
experiment involves the random selection of 5 numbers (without replacement)
from a pool of numbers ranging between 1 and 30.

What I need to know is what *proportion* of those experiments contains two
or more numbers that are consecutive. So, for instance, an experiment that
yielded the numbers 2, 28, 31, 4, 27 would be considered a consecutive =
true experiment since 28 and 27 are two consecutive numbers, even though
they are not side-by-side.

I am quite new to R, so really am puzzled as to how to go about this. I've
tried sorting each experiment, and then subtracting adjacent pairs of
numbers to see if the difference is plus or minus 1. I'm also unsure about
whether to use an array to store all the data first.

Any assistance would be much 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] How do you test for consecutivity?

2008-04-29 Thread Julian Burgos

Hey Anthony,
My previous function may not work in all cases.  Say one of the 
experiments yields these numbers:


1,2,3,6,7

Would you say that the proportion of consecutive numbers is 100%?  If 
so, this will work:


prop.diff=function(x){
d=diff(sort(x))
prop=sum((c(0,d==1)+c(d==1,0))0)
prop=prop/length(x)
return(prop)}

This function first identifies which numbers in your original vector are 
part of a sequence of consecutive numbers.


Julian



Julian Burgos wrote:

Hey Anthony,
There must be many ways to do this.  This is one of them:

#First, define a function to calculate the proportion of consecutive 
numbers in a vector.


prop.diff=function(x){
d=diff(sort(x))
prop=(sum(d==1)+1)/length(x)
return(prop)}

#Note that I am counting both numbers in a consecutive pair.  For 
example, the vector c(1,2,6,9,10) will contain 4 consecutive numbers.  I 
think this is what you wanted do do, right?


#Next, generate a matrix with 1000 columns (one for each experiment) and 
5 rows (the five numbers in each experiment).  Note the use of the 
'replicate' function to generate multiple sets of random numbers


selection=replicate(1000,sort(sample(1:30,5)))

#Third, use the apply function to apply the function we defined above to 
each column of the matrix


diffs=apply(selection,2,prop.diff)

# This will give you a vector with the 1000 proportions of consecutive 
numbers


Julian


Anthony28 wrote:

I need to use R to model a large number of experiments (say, 1000). Each
experiment involves the random selection of 5 numbers (without 
replacement)

from a pool of numbers ranging between 1 and 30.

What I need to know is what *proportion* of those experiments contains 
two
or more numbers that are consecutive. So, for instance, an experiment 
that

yielded the numbers 2, 28, 31, 4, 27 would be considered a consecutive =
true experiment since 28 and 27 are two consecutive numbers, even though
they are not side-by-side.

I am quite new to R, so really am puzzled as to how to go about this. 
I've

tried sorting each experiment, and then subtracting adjacent pairs of
numbers to see if the difference is plus or minus 1. I'm also unsure 
about

whether to use an array to store all the data first.

Any assistance would be much 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] means and variances of several groups in the matrix

2008-04-24 Thread Julian Burgos
Hy Katie,

There are many ways to do this.  A simple one is to create a vector of 
the same length than your 'x' vector, containing a group label.

  group=rep(c(1,2,3),times=nr[1,])

Then you can use tapply to apply a function (in this case mean and 
variance) of the values of x within each group.

  means=tapply(x,group,mean)
  vars=tapply(x,group,var)

  means
   1   2   3
-0.14711206  0.28314274 -0.07861427
  vars
 1 2 3
1.4584971 0.3611996 0.6300624

Julian


kathie wrote:
 Dear R users, 
 
 I have 32 observations in data x.  After sorting this, I want to compute
 means and variances of 3 groups divided by nr.
 
 Actually, the number of groups is flexible.  Any suggestion will be greatly
 appreciated. 
 
 Kathryn Lord
 
 ---
 x=rnorm(32)
 y=sort(x)
 
 nr=matrix(c(12,11,10,10,10,11),2,3)
 nr
  [,1] [,2] [,3]
 [1,]   12   10   10- sum=32
 [2,]   11   10   11- sum=32
 
 For the 1st row in nr, index of y = (1,..,12,   13,...,23,   24,...32)
 
 I want to compute means and variances for 3 groups 
 
 (1st group is 1 through 12; 2nd group is 13-23; 3rd group is 24-32)
 
 
 For the 2nd row in nr, index of y = (1,..,11,   12,...,22,   23,...32)
 
 also, I want to compute means and variances for 3 groups 
 
 (1st group is 1 through 11; 2nd group is 12-22; 3rd group is 23-32)
 
 


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

2008-03-13 Thread Julian Burgos
In this case you can simply do

cumsum(a[x,]+a[y,])

Julian


yoo wrote:
 Hi all, i have the following.. 
 
 a - data.frame(data = seq(1,10))
 
 i have indices:
 x - c(1, 5, 3, 9)
 y - c(2, 7, 4, 10)
 
 I want the cumsum of a[1:2], a[5:7], a[3:4]... 
 
 is there an elegant way to do it without any loop? 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] I need to buy a book in R

2008-03-03 Thread Julian Burgos
Hello Kayj,

There are very good tutorials at the R website.  See here:

http://cran.r-project.org/other-docs.html

Julian

kayj wrote:
 Hi All,
 
  I am a new user in R and I would like to buy a book that teaches me how to
 use R. In addition, I may nees to do some advanced statistical analysis.
 Does anyone recommend some books or websites where I can learn R. 
 
 
 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] how to go to a line in R

2008-01-15 Thread Julian Burgos
Tinn-R also has this option.  I suspect most editors will also do.

Julian

-Halcyon- wrote:
  RWinEdt has line indication. You might want to try that.
 
 
 Uwe Ligges-3 wrote:
 This depends on the editor you use for writing R code rather than on R.

 Uwe Ligges

 Jack Luo wrote:
 Hi, List

 When I was writing R code, I notice that there is no number indicating
 how
 many lines of codes you are writing. Is there a way to go to a line with
 defined number? say I want to go to the 20th line.

 Thanks,

 Jack

 [[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] bootstrap sampling

2008-01-15 Thread Julian Burgos
See rnorm().  If you are sampling from a continuous normal distribution, 
it makes no sense to define a sample with replacement, because the 
probability of sampling twice the same number is zero.

Julian

sigalit mangut-leiba wrote:
 Hello,
 How do I sample observations with replacement from a normal distribution
 with a specific mean and s.d?
 (I want to see the sample, not only the statistic.)
 Thank you,
 Sigalit.
 
   [[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] Great looking plot - but what does it mean?

2008-01-07 Thread Julian Burgos
Hi Mika03,

It would be useful to know what function you used to create your plot. 
Assuming you used boxplot, do this:

?boxplot
?boxplot.stats

Julian



mika03 wrote:
 
 http://www.nabble.com/file/p14668788/paragraphs.png 
 
 Hi,
 
 R is is world full of wonders... I created the attached plot, and I think
 it's exactly what I need! Well, actually I think it is more that wht I
 need...
 
 I wanted R to show the mean values of the categories on the x-axis and maybe
 the standard derivation as well.
 
 I am pretty confident that the bold horrizontal lines in the plot show the
 mean values. But what are the white boxes and the dashed lines? And what's
 that one small circle on the Section column supposed to mean.
 
 And if I would like to get rid of that small circle, how can I?
 
 Thanks a lot!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] vernacular names for circular diagrams

2007-12-13 Thread Julian Burgos
I should say that the name of this chart varies even among 
Spanish-speaking countries.  In Argentina is diagrama de torta which 
is something like cake-chart.

Julian


ahimsa campos-arceiz wrote:
 Two non-eatable examples from Spain and Japan:
 
 in Spanish we call them diagrama de sectores or gráfico de sectores. As
 you can imagine it means sectors diagram (or graph).
 
 in Japanese it is called 円グラフ (en gurafu), which means circular 
 graph
 
 a link with its name in other languages:
 http://isi.cbs.nl/glossary/term550.htm
 
 Cheers,
 
 Ahimsa
 
 
 
 On Dec 13, 2007 3:01 AM, R Heberto Ghezzo, Dr [EMAIL PROTECTED]
 wrote:
 
 From Montreal,
 Some people here call it the 'pizza diagram'
 ?some not eatable names?
 salut



 -Original Message-
 From: [EMAIL PROTECTED] on behalf of Peter Dalgaard
 Sent: Wed 12/12/2007 9:33 AM
 To: Jean lobry
 Cc: r-help@r-project.org
 Subject: Re: [R] [OT] vernacular names for circular diagrams

 Jean lobry wrote:
 Dear useRs,

 by a circular diagram representation I mean what you will get by
 entering
 this at your R promt:

 pie(1:5)

 Nice to have R as a lingua franca :-)

 The folowing quote is from page 360 in this very interesting paper:

 @article{SpenceI2005,
  title = {No Humble Pie: The Origins and Usage of a Statistical
 Chart},
  author = {Spence, I.},
  journal = {Journal of Educational and Behavioral Statistics},
  volume = {30},
  pages = {353-368},
  year = {2005}
 }

 QUOTE
 Like us, the French employ a gastronomical metaphor when
 they refer to Playfair's pie chart, but they have preferred
 instead to invoke the name of the wonderful round soft
 cheese from Normandy - the camembert. When I spent 4 months
 in Paris a few years ago, a friend invited my wife and me to
 lunch with her elderly father who lives in Rouen, Normandy,
 about an hour North of Paris. Her father inquired -
 coincidentally during the cheese course - what work I was
 doing in Paris; I replied that I was researching the
 activities of a Scot, William Playfair, during the
 revolutionary period. I told him that Playfair had invented
 several statistical graphs, including the pie chart, which I
 referred to, in French, as le camembert. After a stunned
 silence of perhaps a couple of seconds, the distinguished
 elderly gentleman looked me in the eye and exclaimed, Mon
 Dieu ! Notre camembert?
 UNQUOTE

 So, I'm just curious: how do you refer in your own language to
 this kind of graphic? How do you call it?

 Best,

 Jean


 Grin

 In Danish it is Lagkagediagram as in the layer cakes that are
 traditional at birthday parties (and thrown at eachother's faces in
 slapstick comedy).

 --
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45)
 35327918
 ~~ - ([EMAIL PROTECTED])  FAX: (+45)
 35327907

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

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

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Importing Large Dataset into Excel

2007-12-12 Thread Julian Burgos
Hi Wayne,

I'm assuming that you file is really a comma-separated file (*.csv) and 
not an Excel workbook (*.xls) saved with a .csv extension, right?  That 
(in my experience) is a common mistake.
You should open your file with a simple text editor (notepad will do if 
the file is not too large) and review line 528, instead of reviewing the 
spreadsheet in Excel.  You should be able to spot the problem right away.

Julian


Wayne Aldo Gavioli wrote:
 Hello all,
 
 
 I seem to be having a problem importing a data set from Excel into R.  I'm 
 using
 the read.table command to import the data with the following line of code:
 
 newborn-read.table(newborn edit.csv, header=T, sep=,)
 
 
 where newborn edit.csv is the name of the file.  Unfortunately, I'm getting
 back the following error message:
 
 
 Error in scan(file,, what, nmax, sep, dc, quote, skip, nlines, na.string, :
 line 528 did not have 44 elements
 
 
 As far as I can tell, line 528 of the spreadsheet table does have the same
 number of elements as the other rows - by chance can this error message mean
 anything else?  Also, is there an easier way to import data from R into Excel
 using a single line of R code?
 
 
 Thanks,
 
 
 Wayne
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] combine variables to matrix

2007-12-12 Thread Julian Burgos
Hi Andre,

I don't quite understand what you are trying to do.  Why you are using 
cbind to join columns of a dataset that it is already in table form?  It 
is true that read.table will give you a data.frame instead of a matrix, 
but if for some reason you need a matrix you can do simply

data.matrix=as.matrix(data)

Julian


Andre Jung wrote:
 I just got stuck with a quite simple question. I've just read in an 
 ASCII table from a plain text file with read.table(). It's a 1200x1200 
 table. R has assigned variables for each column: V1,V2,V3,V4,...
 For small data sets
 
 data - read.table(data.txt);
 data.matrix - cbind(V1,V2,V3);
 
 works. But how could I put together 1200 columns?
 
 I've searched the R mailing help and stumbled upon this entry:
 https://stat.ethz.ch/pipermail/r-help/2007-July/137121.html
 which doesn't help me.
 
 thanks for your help.
 
 andre
 
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] matrix graph

2007-12-12 Thread Julian Burgos
The basic functions you need are
image()
contour()

although I like better the plot.surface() function in the 'fields' package.

Julian

threshold wrote:
 Hi All, simple question: 
 do you know how to graph the following object/matrix in a 'surface manner':
 
   [,1] [,2] [,3][,4]   [,5][,6]
 [1,] -0.154 -0.065 0.129 0.637 0.780 0.221
 [2,]  0.236  0.580 0.448 0.729 0.859 0.475
 [3,]  0.401  0.506 0.310 0.650 0.822 0.448
 [4,]  0.548  0.625 0.883 0.825 0.945 0.637
 [5,]  0.544  0.746 0.823 0.877 0.861 0.642
 [6,]  0.262  0.399 0.432 0.620 0.711 0.404
 
 will be very grateful for hints.
 
 rob

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 rewriting looping structure?

2007-12-10 Thread Julian Burgos
Hi TLowe,

I'm not quite sure if I understand what you are trying to do.  If you 
are trying to get the cumulative sum of your data frame along each 
column you can simply do

rcumsum=function(x){cumsum(x)/sum(x)}
apply(tdat,2,rcumsum)

Yet that is not what your code is doing.  With a bit of clarification I 
may help you some more.

Julian


TLowe wrote:
 Hey Folks,
 
 Could somebody help me rewrite the following code?
 
 I am looping through all records across 5 fields to calculate the cumulative
 percentage of each record (relative to each individual field).
 
 Is there a way to rewrite it so I don't have to loop through each individual
 record?
 
 # tdat is my data frame
 # j is my field index
 # k is my record index
 # tsum is the sum of all values in field j
 # tmp is a vector containing the values in field j
 # tdat[k,paste(cpct,j,sep=)] creates new fields cpct1,...,cpct5 
 
 
for(j in 1:5) {
  tsum- sum(tdat[,j]);
for(k in 1:nrow(tdat)) {
  td- tdat[k,j];
  tmp-tdat[,j];
  # sum values = to current value and divide by the total sum
tdat[k,paste(cpct,j,sep=)]- sum(tmp[tmp = td]) / tsum;
}
}
 
 
 Thanks,
 TLowe

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] if/else for plot/lines?

2007-12-07 Thread Julian Burgos
The simplest way would be to have a flag, an indicator variable that 
stores a value that indicates if a plot has been done before.  Something 
like this

plot (do my first plot here...)
is.plot=T

 later in the code...

if (is.plot) {plot (do new plot here)} else {lines(add lines to the 
previous plot)}


Julian


Roger Levy wrote:
 I'm interested in writing a function that constructs a new plot on the
 current graphics device if no plot exists there yet, but adds lines to
 the existing plot if a plot is already there.  How can I do this?  It
 seems to me that the exists() function might be co-opted to do this, but
 it's not obvious how.

 Many thanks,

 Roger

   

-- 
Julian M. Burgos

Fisheries Acoustics Research Lab
School of Aquatic and Fishery Science
University of Washington

1122 NE Boat Street
Seattle, WA  98105 

Phone: 206-221-6864

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] image() plot with z not in matrix format

2007-11-29 Thread Julian Burgos
Hello Marc,

Well, image() requires data values in a regular grid.  So you need to 
interpolate your data to a regular grid before you do your plot.  There 
are many interpolation methods, but a good place to start is to do 
linear interpolation.  You should first use expand.grid() to create the 
regular grid where to interpolate your data.  Then use the interp() 
function (in the akima package) to do the interpolation.  Finally, to do 
the plot you can use image() or better yet, the plot.surface() function 
in the 'fields' package, which is an improved version of the image() 
function.

I hope that helps,

Julian


[EMAIL PROTECTED] wrote:
 Hello R cracks
 
 The image() function requires strictly increasing x and y values and z as a 
 matrix.
 
 Actually, I don't have equally spaced variables, but anyway want to plot an 
 colored image() (with z-information).
 
 An example of my problem is here:
 
 a-data.frame(rnorm(100), rnorm(100), runif(100)*100)
 
 How can I plot this data as an image (x=a[,1], y=a[,2] and z=a[,3])- 
 according to ?image.
 It has to be possible to adapt the grid size so that every grid cell in the 
 plot is coloured consequently.
 
 Thanks for your help
 
 Marc
 --
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Filling in a Zero Matrix

2007-11-26 Thread Julian Burgos
Hi Amy,
Many (perhaps most) of the people on the list do not receive emails with 
html...so we can't see colored text.  Also it would be helpfully to have 
a bit of your data, so we can run your code (see the posting guide in 
this regard,http://www.R-project.org/posting-guide.html).

Please explain what are the 'xlabel' and the 'ylabel' that you 
mentioned.  I don't see those variables in your code.

Julian



Amit Patel wrote:
 Hi
 I am very new to R and statistical programming in general. I am trying to 
 reorder data from a .csv file. I have managed to import the data and create a 
 zero matrix. I am now trying to fill the matrix. There seems to be some 
 problem with this section of my code. I have highlighted the dodgy code in 
 red. Please help if possible.
 
 ##
 ###  Create matrix ###
 ##
 
 #Open the csv file
 OGSdata - read.table(MG3199.csv,sep=,,header=TRUE)
 
 #creates 3 separate vectors
 sample - OGSdata[,1]
 mci - OGSdata[,2]
 pct - OGSdata[,3]
 
 #change mci range 
 offset - min(mci)-1
 mci - (mci - offset)
 
 #matrix sizes
 mci_count - max(mci)
 sample_count - max(sample)
 
 #creates a zero matrix 
 OGS - mat.or.vec(mci_count,sample_count)
 
 #Create labels
 sample_lab - (A-9,B-9, C-9, D-9, E-9,A-12,B-12, C-12, 
 D-12, E-12)
 
 #add data
 for (i in 1:length(pct)) {
 OGS(mci(i),sample(i))- pct(i);
 }
 
 
 What I want is to have colum1 from original data to be the xlabel, column 2 
 to be the ylabel and the 3rd colum to be the values in the matrix
 Any help is appreciated.
 
 Kind Regards
 Amit Patel
 
 
 
 
   ___
 
 now.
 
   [[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] Filling in a Zero Matrix

2007-11-26 Thread Julian Burgos
My mistake, by xlabel and ylabel you are refering to the row and column 
names of your matrix, right?  To label a matrix you can simply use 
colnames() and rownames().

Still its not clear to me what you are trying to do with your code. 
Perhaps if you give us a sample of your data and explain clearly what 
you are trying to achieve, we can help you to simplify your code.

Julian

Julian Burgos wrote:
 Hi Amy,
 Many (perhaps most) of the people on the list do not receive emails with 
 html...so we can't see colored text.  Also it would be helpfully to have 
 a bit of your data, so we can run your code (see the posting guide in 
 this regard,http://www.R-project.org/posting-guide.html).
 
 Please explain what are the 'xlabel' and the 'ylabel' that you 
 mentioned.  I don't see those variables in your code.
 
 Julian
 
 
 
 Amit Patel wrote:
 Hi
 I am very new to R and statistical programming in general. I am trying to 
 reorder data from a .csv file. I have managed to import the data and create 
 a zero matrix. I am now trying to fill the matrix. There seems to be some 
 problem with this section of my code. I have highlighted the dodgy code in 
 red. Please help if possible.

 ##
 ###  Create matrix ###
 ##

 #Open the csv file
 OGSdata - read.table(MG3199.csv,sep=,,header=TRUE)

 #creates 3 separate vectors
 sample - OGSdata[,1]
 mci - OGSdata[,2]
 pct - OGSdata[,3]

 #change mci range 
 offset - min(mci)-1
 mci - (mci - offset)

 #matrix sizes
 mci_count - max(mci)
 sample_count - max(sample)

 #creates a zero matrix 
 OGS - mat.or.vec(mci_count,sample_count)

 #Create labels
 sample_lab - (A-9,B-9, C-9, D-9, E-9,A-12,B-12, C-12, 
 D-12, E-12)

 #add data
 for (i in 1:length(pct)) {
 OGS(mci(i),sample(i))- pct(i);
 }


 What I want is to have colum1 from original data to be the xlabel, column 2 
 to be the ylabel and the 3rd colum to be the values in the matrix
 Any help is appreciated.

 Kind Regards
 Amit Patel




   ___

 now.

  [[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] better curve

2007-11-21 Thread Julian Burgos
Hello Mysimbaa,

If you want to fit a smooth line to your data, there are many ways to do 
it.  One option is to use splines.  See the smooth.spline() function. 
If you only want to add a line to highlight the trend in your data, that 
should be enough.  But if you want to do more serious analytical work, 
it is probably a good idea to learn about the different methods, its 
assumptions and limitations.

Julian

mysimbaa wrote:
 http://www.nabble.com/file/p13880048/Fluctuation.jpeg 
 
 Hi R users,
 
 I have collected data which I plot(x,y).The problem it has oscillations.
 Now i'm trying to make better this curve with a smooth line. And then
 collect my new datas.
 But I don't know how doing this.
 
 Perhaps a linear regression ??
 
 See .jpeg foto.
 
 Thanks for any help it will be given.

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

2007-11-21 Thread Julian Burgos
Hey Marc,

You can use the function scan() directly to read your file as a single 
vector.  Then, as Rob suggested, use the matrix function to give it the 
dimensions you want.

Other option (perhaps less elegant) is to do something like this.

x=read.table (myfile,...etc.etc.)
x=as.vector(as.matrix(x))
x=matrix(x,ncol=11,byrow=T)

Julian

marcg wrote:
 This was my intention, but I'm not able to read it in as a vector (because i 
 don't know the function, neither I can convert the read in table to a vector 
 and then to matrix or directly.
 
 What did I miss or where do I have to look up?
 
 thanks alot
 
 marc
  Original-Nachricht 
 Datum: Wed, 21 Nov 2007 14:17:41 -
 Von: Rob Robinson [EMAIL PROTECTED]
 An: \'marcg\' [EMAIL PROTECTED]
 CC: [EMAIL PROTECTED]
 Betreff: RE: [R] Reconstruct array dataset
 
 Can you not read it into a single vector and then use as.matrix to shape
 it
 into a an appropriate sized matrix?
 Cheers
 rob

 *** Wan==t to know about Britain's birds? Try  www.bto.org/birdfacts ***

 Dr Rob Robinson, Senior Population Biologist
 British Trust for Ornithology, The Nunnery, Thetford, Norfolk, IP24 2PU
 Ph: +44 (0)1842 750050 E: [EMAIL PROTECTED]
 Fx: +44 (0)1842 750030 W: http://www.bto.org

  How can anyone be enlightened, when truth is so poorly lit =
   

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:] On Behalf Of marcg
 Sent: 21 November 2007 14:08
 To: [EMAIL PROTECTED]
 Subject: [R] Reconstruct array dataset

 Hi there

 I have an interesting problem:

 My csv file is of array dimensions [12,50], but it was saved 
 the wrong way: there should be only 11 colums. What happens 
 now if I read it into R is that the whole data set is shifted 
 ( in the first row, the last column contains already the 
 first value of the supposed second row and so on...)

 how can I tell R to switch after 11 read values to the next 
 row, taking the value from column 12 as first in the new row 
 (for row 3 the two second last of the upper row etc...)

 Thanks for suggestions

 marc
 --
 Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten

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

2007-11-20 Thread Julian Burgos
Hi Loren,

It wasn't my intention to sound arrogant, cruel or off putting.
English is not my first language, and perhaps my message had a tone I
did not intended.  The person posting the message I responded was
literally asking for somebody on the list to do his/hers homework (there
are even references to hints from the textbook).  This is not only
academically non-kosher, is also not the purpose of the R-help list.  I
pointed this to this person and invited him/her to come back with
specific questions on R coding.

The posting guidelines are easily accessible.  The first line in the
Mailing Lists section of the R website
(http://www.r-project.org/mail.html) states Please read the
instructions below and the posting guide before sending anything to any
mailing list!, and displays a link to the guide.  There also a link to
the guide at the bottom of every message send through this list.  The
posting guide is not hard to find, and (in my opinion) it isn't long or
difficult to understand (in particular for anyone taking college level
statistics).

Julian

Loren Engrav wrote:
 I am a newbie to R and Bio emails and
 
 It is clear that newbies make mistakes, I made several which were pointed
 out and I am trying to fix them, and as I fix one I make another, in time
 perhaps I will know it all, but if it is like surgery, I will make
 mistakes until I retire
 
 But the response of the old-timers to these mistakes seems arrogant and
 cruel and off putting and does NOT encourage more participation. In fact
 it takes real stuff to continue after this putdown and that putdown.
 
 There are 3,783 links to posting guidelines, which took 1.5 hours to find
 and read and understand.
 
 Why not a link on how the mistakes of the newbies will be dealt with?
 
 Or a kindly response from the moderator personal to the newbie rather than
 to the entire world?
 
 Or a kindly general response as from Ben Bolker to my last infraction which
 was You might have better luck with this on the Bioconductor mailing list
 ...
 
 Rather than to the universe...
 Using the wrong list: this is for R-sig-mac, and the topic occcurred
 there recently.
 
 All in an effort to encourage promote useful and increasing exchange
 participation
 
 Or not
 
 Loren Engrav, MD
 Univ Washington
 
 
 From: Julian Burgos [EMAIL PROTECTED]
 Date: Mon, 19 Nov 2007 10:44:49 -0800
 To: Epselon [EMAIL PROTECTED]
 Cc: r-help@r-project.org
 Subject: Re: [R] Trying to get around R

 Hello Epselon (if that is your name),
 
 This sounds like homework questions.
 From the R-help posting guide: 
 Basic statistics and classroom homework:
 R-help is not intended for 
 these.
 
 If you have a specific question on R
 coding, do ask it (and provide 
 reproducible code).  But you should not expect
 for people on the list to 
 do your homework for you.  That is a big
 no-no.
 
 Cheers,
 
 Julian
 
 
 Epselon wrote:
 I have three problems I am trying to
 simulate, that I am having difficulty
 getting around with.

 Problem 1.
 I want to determine the 85 percentile (the x value for which the sum of

 probabilities becomes 0.85) of the following distributions (two binomials
 and a Poisson with rate Lmbda= np of the two binomials): X ~B(10, 0.3),
 Y~P(3) , 
 Z~B(30, 0.1). I want to show that  that Y is a good approximation
 for Z but
 not for X...(by examining these distributions for few
 different
 percentiles)
 Problem 2:
 For a binomial distribution X ~ B(20, 0.4), I
 want to use R to calculate
 P{|X - μ|  2} and verify that it is near or
 larger than 0.95. (Hint from
 the text book: Since μ = 8 and   2.3 then
 you 
 may want to read the
 weights, or probabilities, of the values 6:10, into a
 vector v and then use
 the command sum(v) to
 calculate the sum.) Repeat
 this for another set of parameters of your
 choice.

 Problem 3:
 Draw a
 sample of size 10, from a Poisson with Lambda= 5, and calculate the
 mean
 and 
 the standard deviation of this sample, Repeat this calculation with
 size 20
 and 30 and demonstrate
 that ¯X gets closer to μ as the sample size
 increases.
 Thanks.

 I would appreciate it if someone accompanied the
 codes with a brief
 explanation so I can be able to replicate it
 myself.
 
 __
 R-help@r-project.org
 mailing list
 https://stat.ethz.ch/mailman/listinfo/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

Re: [R] Logarithmic axis

2007-11-20 Thread Julian Burgos
Hey John,

You can do simply

plot(reizstaerke, kennlinie1, ylim=c(0, max(kennlinie1, 
kennlinie2)),log=x)

but if you want to fine tune where the tick marks are, you can do it by 
hand.

kennlinie1 -  c(8.0746909, 3.9916973, 9.9789444, 19.962869);
kennlinie2 -  c(6.0994206, 8.9661081, 19.924883, 31.879496);
reizstaerke - c(76, 92, 108, 124);
plot(log10(reizstaerke), kennlinie1, ylim=c(0, max(kennlinie1, 
kennlinie2)),axes=F)
box()
axis(1,at=log10(seq(75,125,by=5)),label=seq(75,125,by=5))
axis(2)

The obvious reason that you are getting a plot with a single 100 and 
nothing else is that the range of the values in the reizstaerke vector 
is away from 10 and from 1000.  If you really want to have the log scale 
in the way you described, you could do something like this:

plot(log10(reizstaerke), kennlinie1, ylim=c(0, max(kennlinie1, 
kennlinie2)),axes=F,xlim=log10(c(1,1000)))
box()
axis(1,at=log10(c(1,10,100,1000)),label=c(1,10,100,1000))
axis(2)

Julian


John Wiedenhoeft wrote:
 Hi there,
 
 I guess this must be a standard issue, but I'm starting to go crazy with it. 
 I 
 simply want a plot with the x axis being logarithmic, having labels 1, 10, 
 100..., and ten unlabelled ticks between each of them - just as they 
 introduce logarithmic axis at school. I've played around a bit with log=x, 
 xlog=T (where exactly is the difference here?), xaxp, and xaxt (unfortunately 
 xaxt=l isn't implemented). The best I get is a plot with an axis having a 
 single 100 and nothing else...
 
 here is what I've tried:
 
 pdf(file=kennlinien.pdf);
 par(log=x, xlog=TRUE);
 kennlinie1 -  c(8.0746909, 3.9916973, 9.9789444, 19.962869);
 kennlinie2 -  c(6.0994206, 8.9661081, 19.924883, 31.879496);
 reizstaerke - c(76, 92, 108, 124);
 #plot(reizstaerke, kennlinie1, ylim=c(0, max(kennlinie1, kennlinie2)), 
 xlim=c(0, max(reizstaerke)), log=x, xlog=TRUE, xaxp=c(1, 2, 1), type=b);
 #plot(reizstaerke, kennlinie1, type=b, log=x, xlog=TRUE, xaxp=c(1, 2, 3));
 plot(reizstaerke, kennlinie1, type=b,usr=c(min(reizstaerke), 
 max(reizstaerke), min(kennlinie1, kennlinie2), max(kennlinie1, kennlinie2)), 
 log=x, xlog=TRUE, xaxp=c(1, 2, 3));
 #points(reizstaerke, kennlinie2, xlog=TRUE, xaxp=c(1, 3, 3), type=b);
 dev.off();
 
 Certainly I've missed something, but I can't figure it out.
 
 Any help appreciated,
 Cheers, 
 John
 
 
 
 platform   i486-pc-linux-gnu
 arch   i486
 os linux-gnu
 system i486, linux-gnu
 status
 major  2
 minor  4.1
 year   2006
 month  12
 day18
 svn rev40228
 language   R
 version.string R version 2.4.1 (2006-12-18)
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Logarithmic axis

2007-11-20 Thread Julian Burgos
Like always, there is much to be learned from the R-help list!  Another 
message had a much simpler approach.

plot(xy.coords(reizstaerke, kennlinie1, log=x), log=x)

Julian


Julian Burgos wrote:
 Hey John,
 
 You can do simply
 
 plot(reizstaerke, kennlinie1, ylim=c(0, max(kennlinie1, 
 kennlinie2)),log=x)
 
 but if you want to fine tune where the tick marks are, you can do it by 
 hand.
 
 kennlinie1 -  c(8.0746909, 3.9916973, 9.9789444, 19.962869);
 kennlinie2 -  c(6.0994206, 8.9661081, 19.924883, 31.879496);
 reizstaerke - c(76, 92, 108, 124);
 plot(log10(reizstaerke), kennlinie1, ylim=c(0, max(kennlinie1, 
 kennlinie2)),axes=F)
 box()
 axis(1,at=log10(seq(75,125,by=5)),label=seq(75,125,by=5))
 axis(2)
 
 The obvious reason that you are getting a plot with a single 100 and 
 nothing else is that the range of the values in the reizstaerke vector 
 is away from 10 and from 1000.  If you really want to have the log scale 
 in the way you described, you could do something like this:
 
 plot(log10(reizstaerke), kennlinie1, ylim=c(0, max(kennlinie1, 
 kennlinie2)),axes=F,xlim=log10(c(1,1000)))
 box()
 axis(1,at=log10(c(1,10,100,1000)),label=c(1,10,100,1000))
 axis(2)
 
 Julian
 
 
 John Wiedenhoeft wrote:
 Hi there,

 I guess this must be a standard issue, but I'm starting to go crazy 
 with it. I simply want a plot with the x axis being logarithmic, 
 having labels 1, 10, 100..., and ten unlabelled ticks between each of 
 them - just as they introduce logarithmic axis at school. I've played 
 around a bit with log=x, xlog=T (where exactly is the difference 
 here?), xaxp, and xaxt (unfortunately xaxt=l isn't implemented). The 
 best I get is a plot with an axis having a single 100 and nothing else...

 here is what I've tried:

 pdf(file=kennlinien.pdf);
 par(log=x, xlog=TRUE);
 kennlinie1 -  c(8.0746909, 3.9916973, 9.9789444, 19.962869);
 kennlinie2 -  c(6.0994206, 8.9661081, 19.924883, 31.879496);
 reizstaerke - c(76, 92, 108, 124);
 #plot(reizstaerke, kennlinie1, ylim=c(0, max(kennlinie1, kennlinie2)), 
 xlim=c(0, max(reizstaerke)), log=x, xlog=TRUE, xaxp=c(1, 2, 1), 
 type=b);
 #plot(reizstaerke, kennlinie1, type=b, log=x, xlog=TRUE, xaxp=c(1, 
 2, 3));
 plot(reizstaerke, kennlinie1, type=b,usr=c(min(reizstaerke), 
 max(reizstaerke), min(kennlinie1, kennlinie2), max(kennlinie1, 
 kennlinie2)), log=x, xlog=TRUE, xaxp=c(1, 2, 3));
 #points(reizstaerke, kennlinie2, xlog=TRUE, xaxp=c(1, 3, 3), type=b);
 dev.off();

 Certainly I've missed something, but I can't figure it out.

 Any help appreciated,
 Cheers, John



 platform   i486-pc-linux-gnu
 arch   i486
 os linux-gnu
 system i486, linux-gnu
 status
 major  2
 minor  4.1
 year   2006
 month  12
 day18
 svn rev40228
 language   R
 version.string R version 2.4.1 (2006-12-18)

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

2007-11-19 Thread Julian Burgos
Hello Epselon (if that is your name),

This sounds like homework questions.  From the R-help posting guide: 
Basic statistics and classroom homework:  R-help is not intended for 
these.

If you have a specific question on R coding, do ask it (and provide 
reproducible code).  But you should not expect for people on the list to 
do your homework for you.  That is a big no-no.

Cheers,

Julian

Epselon wrote:
 I have three problems I am trying to simulate, that I am having difficulty
 getting around with.
 
 Problem 1. 
 I want to determine the 85 percentile (the x value for which the sum of
 probabilities becomes 0.85) of the following distributions (two binomials
 and a Poisson with rate Lmbda= np of the two binomials): X ~B(10, 0.3),
 Y~P(3) , 
 Z~B(30, 0.1). I want to show that  that Y is a good approximation for Z but
 not for X...(by examining these distributions for few
 different percentiles)
 
 Problem 2:
 For a binomial distribution X ~ B(20, 0.4), I want to use R to calculate
 P{|X − μ|  2} and verify that it is near or larger than 0.95. (Hint from
 the text book: Since μ = 8 and   2.3 then you may want to read the
 weights, or probabilities, of the values 6:10, into a vector v and then use
 the command sum(v) to
 calculate the sum.) Repeat this for another set of parameters of your
 choice.
 
 Problem 3:
 Draw a sample of size 10, from a Poisson with Lambda= 5, and calculate the
 mean and the standard deviation of this sample, Repeat this calculation with
 size 20 and 30 and demonstrate
 that ¯X gets closer to μ as the sample size increases.
 
 Thanks.
 
 I would appreciate it if someone accompanied the codes with a brief
 explanation so I can be able to replicate it myself.

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

2007-11-19 Thread Julian Burgos
Something like this?

  a=matrix(1:9, ncol=3)
  print(a)
  [,1] [,2] [,3]
[1,]147
[2,]258
[3,]369
  a=a[-2,]
  print(a)
  [,1] [,2] [,3]
[1,]147
[2,]369

You can use negative numbers to reference rows and/or columns, and 
you'll get everything except the rows/columns referenced.

Julian



Barb, Jennifer (NIH/CIT) [E] wrote:
 Can anyone tell me how to delete a row in a matrix?  I have searched
 around and couldn't find a straightforward way to do this.
 
 Thanks, any help will be greatly appreciated.
 
 Jennifer
 
  
 
 
  
 
  
 
  
 
 
   [[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] About print a label in plot

2007-11-16 Thread Julian Burgos


affy snp wrote:
 Dear list,

 Hello! I have a question about how to print a label in the plot.
 I am using the following code:

 pdf(mel4_chr3_11cancer_cghFLasso.pdf, height=6,
 width=5);plot(Disease.FL, index=i, type=Single,main=Plot of
 Labels);dev.off();

 But Plot of Labels has not been printed. Any suggestions?

 Thanks a lot!
   Allen

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

-- 
Julian M. Burgos

Fisheries Acoustics Research Lab
School of Aquatic and Fishery Science
University of Washington

1122 NE Boat Street
Seattle, WA  98105 

Phone: 206-221-6864

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] a repetition of simulation

2007-11-15 Thread Julian Burgos
summary(log_v)

Julian

sigalit mangut-leiba wrote:
 Hello,
 In addition to my question a few days ago,
 Now I have a matrix of the coefficients,
 how can I see all the P.Values (Pr(|z|)) of the covariates from the 1000
 iterations?
 I tried names(log_v) and couldn'n find it.
 Thank you,
 Sigalit.
 
 
 On 11/13/07, Julian Burgos [EMAIL PROTECTED] wrote:
 Well, the obvious (but perhaps not the most elegant) solution is put
 everything in a loop and run it 600 times.

 coefficients=matrix(NA,ncol=3,nrow=600)

 for (loop in 1:600){

 [all your code here]

 coefficients[loop,]=coef(log_v)

 }

 That will give you a matrix with the coefficients of each model run in
 each row.

 Julian


 sigalit mangut-leiba wrote:
 I want to repeat the simulation 600 times and to get a vector of 600
 coefficients for every covariate: aps and tiss.
 Sigalit.


 On 11/13/07, Julian Burgos [EMAIL PROTECTED] wrote:
 And what is your question?

 Julian

 sigalit mangut-leiba wrote:
 Hello,
 I have a simple (?) simulation problem.
 I'm doing a simulation with logistic model and I want to reapet it 600
 times.
 The simulation looks like this:

 z - 0
 x - 0
 y - 0
 aps - 0
 tiss - 0
 for (i in 1:500){
 z[i] - rbinom(1, 1, .6)
 x[i] - rbinom(1, 1, .95)
 y[i] - z[i]*x[i]
 if (y[i]==1) aps[i] - rnorm(1,mean=13.4, sd=7.09) else aps[i] -
 rnorm(1,mean=12.67, sd=6.82)
 if (y[i]==1) tiss[i] - rnorm(1,mean=20.731,sd=9.751) else  tiss[i] -
 rnorm(1,mean=18.531,sd=9.499)
 }
 v - data.frame(y, aps, tiss)
 log_v - glm(y~., family=binomial, data=v)
 summary(log_v)

 I want to do a repetition of this 600 times (I want to have 600
 logistic
 models), and see all the coefficients of the covariates aps  tiss.
 Thanks in advance,
 Sigalit.

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

 
   [[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] Plot problem

2007-11-15 Thread Julian Burgos
Hi Allen,

Its difficult to know what is the problem without knowing what type of 
object is 'Disease.FL'.  plot() is a generic function and it will act 
differently depending on the type of object you are passing to it.  As 
always, you should provide 'provide commented, minimal, self-contained, 
reproducible code' so we can find the problem.

As a general comment, you can do any number of plots on a device (a 
window or a pdf file).  The limit is only given by the number and size 
of the plots and the size of the device.

Julian


affy snp wrote:
 Dear list,
 
 I have a question about using plot().
 
 I tried the code:
 pdf(mel_chr_all_13cancer_cghFLasso_all.pdf, height=6, width=11);plot(
 Disease.FL, index=1:4, type=All);dev.off();
 and it went through well which outputed 4 plots for 4 samples in one page.
 
 But if I increase the numbers of plots(samples) which I want, saying to 11,
 pdf(mel_chr_all_13cancer_cghFLasso_all.pdf, height=6, width=11);plot(
 Disease.FL, index=1:11, type=All);dev.off();
 then I got an error message as:
 Error in segments((1:n)[y  0], jp, (1:n)[y  0], jp + y[y  0], col =
 downcol) :invalid first argument
 
 I suspect that it has sth to do with the maxium plots which can be outputed
 on one page, which means less or equal to 4 will be fine but beyond that
 there will be a problem. I have tried the number 5 yet.
 
 Is there a way that I could specify that the plots can be put on multiple
 pages with 4 plots per one.
 
 Thank you very much for your help!
 
 Best,
   Allen
 
   [[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] How to get row numbers of a subset of rows

2007-11-14 Thread Julian Burgos
One way to do this is

range(which(B[,2]==1))

Julian

affy snp wrote:
 Hello list,
 
 I read in a txt file using
 
 B-read.table(file=data.snp,header=TRUE,row.names=NULL)
 
 by specifying the row.names=NULL so that the rows are numbered.
 Below is an example after how the table looks like using
 B[1:10,1:3]
 
 
   SNPChromosome  PhysicalPosition
 1 SNP_A-1909444  1   7924293
 2 SNP_A-2237149  1   8173763
 3 SNP_A-4303947  1   8191853
 4 SNP_A-2236359  1   8323433
 5 SNP_A-2205441  1   8393263
 6 SNP_A-1909445  1   7924293
 7 SNP_A-2237146  2   8173763
 8 SNP_A-4303946  2   8191853
 9 SNP_A-2236357  2   8323433
 10 SNP_A-2205442 2   8393263
 
 I am wondering if there is a way to return the start and end row numbers
 for a subset of rows.
 
 For example, If I specify B[,2]=1, I would like to get
 start=1 and end=6
 
 if B[,2]=2, then start=7 and end=10
 
 Is there any way in R to quickly do this?
 
 Thanks a bunch!
 
 Allen
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Log random number

2007-11-14 Thread Julian Burgos
Hi Tobias,

You'll have to explain what you mean with log transformed values.  If 
your question is if it is possible to generate random numbers from a 
normal distribution (using rnorm()) and then getting their logarithm, 
then you can do that with the obvious caveat that the logarithm is not 
defined for negative numbers.

Julian


Wensui Liu wrote:
 dont think so, unless i miss something here.
 please do check the range of normal random number and the domain of
 log function.
 
 On 11/14/07, Tobias Schlottmann [EMAIL PROTECTED] wrote:

Dear R users,

   Simply my question is that how it is possible to generate some random 
 numbers using rnorm( ) but in log transformed values.

   Thank you,

   Tobias


 -

 [[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] factors levels ?

2007-11-13 Thread Julian Burgos
What you are looking for is the findInterval() function.

Julian

W Eryk Wolski wrote:
 Hi,
 
 It's just some example code.. The application is uninteresting. I am
 searching for some functionality.
 
 X - rnorm(100) //my data
 
 Y - seq(-3,3,by=0.1) // bin boundaries.
 
 Now I would like to generate a - list of factors,  length as X...
 i.e.: all values in the range [-3,-2.9) have the same factor... [-3,-2.9) etc.
 
 I would assume R has such a function but I cant recall which one it is.
 


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] a repetition of simulation

2007-11-13 Thread Julian Burgos
Well, the obvious (but perhaps not the most elegant) solution is put 
everything in a loop and run it 600 times.

coefficients=matrix(NA,ncol=3,nrow=600)

for (loop in 1:600){

[all your code here]

coefficients[loop,]=coef(log_v)

}

That will give you a matrix with the coefficients of each model run in 
each row.

Julian


sigalit mangut-leiba wrote:
 I want to repeat the simulation 600 times and to get a vector of 600
 coefficients for every covariate: aps and tiss.
 Sigalit.
 
 
 On 11/13/07, Julian Burgos [EMAIL PROTECTED] wrote:
 And what is your question?

 Julian

 sigalit mangut-leiba wrote:
 Hello,
 I have a simple (?) simulation problem.
 I'm doing a simulation with logistic model and I want to reapet it 600
 times.
 The simulation looks like this:

 z - 0
 x - 0
 y - 0
 aps - 0
 tiss - 0
 for (i in 1:500){
 z[i] - rbinom(1, 1, .6)
 x[i] - rbinom(1, 1, .95)
 y[i] - z[i]*x[i]
 if (y[i]==1) aps[i] - rnorm(1,mean=13.4, sd=7.09) else aps[i] -
 rnorm(1,mean=12.67, sd=6.82)
 if (y[i]==1) tiss[i] - rnorm(1,mean=20.731,sd=9.751) else  tiss[i] -
 rnorm(1,mean=18.531,sd=9.499)
 }
 v - data.frame(y, aps, tiss)
 log_v - glm(y~., family=binomial, data=v)
 summary(log_v)

 I want to do a repetition of this 600 times (I want to have 600 logistic
 models), and see all the coefficients of the covariates aps  tiss.
 Thanks in advance,
 Sigalit.

   [[alternative HTML version deleted]]

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

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] TRUNCATED error with data frame

2007-11-13 Thread Julian Burgos
Hi Amit,

Please read carefully the Mailing List Posting Guide (available at 
http://www.r-project.org/posting-guide.html).  In particular, this section:

For new subjects, compose a new message and include the 
'[EMAIL PROTECTED]' (or '[EMAIL PROTECTED]') address 
specifically. (Replying to an existing post and then changing the 
subject messes up the threading in the archives and in many people's 
mail readers.)

About your question.  You have a mistake in your model formula.  The 
basic way to code a formula in R is by doing y ~ 'model', where y is 
your dependent variable and 'model'.  Notice that '~' is not the same as 
'-'.  For details, see ?formula, or read the manual titled An 
introduction to R that can be found here 
http://cran.r-project.org/manuals.html.

Julian

apsawant wrote:
 Hi ,
 
 I am trying to modify the same example script to calculate AOV.
 Below is the script file (aov.R) I am trying to execute:
 aov.R
 --
 data1-c(49,47,46,47,48,47,41,46,43,47,46,45,48,46,47,45,49,44,44,45,42,45,45,40
 ,49,46,47,45,49,45,41,43,44,46,45,40,45,43,44,45,48,46,40,45,40,45,47,40)
 
 matrix(data1, ncol= 4, dimnames = list(paste(subj, 1:12),
 c(Shape1.Color1,
 Shape2.Color1, Shape1.Color2, Shape2.Color2)))
 
 Hays.df-data.frame(rt = data1,
 subj=factor(rep(paste(subj, 1:12, sep=), 4)),
 shape=factor(rep(rep(c(shape1,shape2), c(12, 12)), 2)),
 color=factor(rep(c(color1,color2), c(24, 24
 
 aov(rt - shape * color + Error(subj/(shape * color)), data=Hays.df)
 
 summary(aov(rt - shape * color + Error(subj/(shape * color)), data=Hays.df))
 
 
 Here is the error I get:
 source(aov.R)
 Error in terms(formula, Error, data = data) :
 Object shape not found
 
 I would appreciate your help as to why I am getting this error message.
 
 Thanks,
 Amit.
 
 
 
 Prof Brian Ripley wrote:
 Try ?source: it is not an 'error'.

 max.deparse.length: integer; is used only if 'echo' is 'TRUE' and gives
the maximal length of the printout of a single expression.

 So the 'echo' has been truncated at 150 characters, not the expression 
 used.

 On Mon, 12 Nov 2007, apsawant wrote:

 Hi ,

 I am new to R.
 I am trying to run a simple R script as shown below:

 aov.R
 --
 data1-c(49,47,46,47,48,47,41,46,43,47,46,45,48,46,47,45,49,44,44,45,42,45,45,40
 ,49,46,47,45,49,45,41,43,44,46,45,40,45,43,44,45,48,46,40,45,40,45,47,40)

 matrix(data1, ncol= 4, dimnames = list(paste(subj, 1:12),
 c(Shape1.Color1,
 Shape2.Color1, Shape1.Color2, Shape2.Color2)))

 Hays.df-data.frame(rt = data1,
 subj=factor(rep(paste(subj, 1:12, sep=), 4)),
 shape=factor(rep(rep(c(shape1,shape2), c(12, 12)), 2)),
 color=factor(rep(c(color1,color2), c(24, 24

 I am getting the following error message:

 Output at the R prompt
 --

 source(aov.R,echo=T)
 data1 - c(49, 47, 46, 47, 48, 47, 41, 46, 43, 47,
46, 45, 48, 46, 47, 45, 49, 44, 44, 45, 42, 45, 45, 40, 49,
46, 47, 45, 49, 45, 41, 43, 4  [TRUNCATED]

 matrix(data1, ncol = 4, dimnames = list(paste(subj,
1:12), c(Shape1.Color1, Shape2.Color1, Shape1.Color2,
Shape2.Color2)))
Shape1.Color1 Shape2.Color1 Shape1.Color2 Shape2.Color2
 subj 1 49484945
 subj 2 47464643
 subj 3 46474744
 subj 4 47454545
 subj 5 48494948
 subj 6 47444546
 subj 7 41444140
 subj 8 46454345
 subj 9 43424440
 subj 1047454645
 subj 1146454547
 subj 1245404040

 Hays.df - data.frame(rt = data1, subj = factor(rep(paste(subj,
1:12, sep = ), 4)), shape = factor(rep(rep(c(shape1,
shape2), c(12,   [TRUNCATED]

 I would appreciate if anyone could point out as to why I am getting this
 TRUNCATED message.
 Eventually, I want to run the following command:
 aov(rt - shape * color + Error(subj/(shape * color)), data=Hays.df)
 summary(aov(rt - shape * color + Error(subj/(shape * color)),
 data=Hays.df))

 Thanks,
 Amit.



 -- 
 Brian D. Ripley,  [EMAIL PROTECTED]
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595

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

Re: [R] How to subset a portion of columns from a matrix

2007-11-09 Thread Julian Burgos
There are many ways. For example, you can do something like

A[seq(1,dim(A)[2],2)]

Julian
 
Julian M. Burgos

Fisheries Acoustics Research Lab
School of Aquatic and Fishery Science
University of Washington

1122 NE Boat Street
Seattle, WA  98105 

Phone: 206-221-6864



affy snp wrote:
 Dear List,

 Hi! I am wondering what is the simplest way to subset a portion of columns
 from a matrix.

 For example, there is a matrix A (238,304*243). What is the simplest
 way to get a sub-matrix B which comprises of column 1, 3, 5, 7,9,...(odd 
 column
 number) from matrix A?

 Thank you very much for your help!

 Best,
  Allen

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] How to subset a portion of columns from a matrix

2007-11-09 Thread Julian Burgos
No problem.  Actually, I missed a comma.  You should do

A[,seq(1,dim(A)[2],2)]

Julian


affy snp wrote:
 Hi Julian,

 Thanks for the help!

 Best,
   Allen



 On Nov 9, 2007 11:08 PM, Julian Burgos [EMAIL PROTECTED] wrote:
   
 There are many ways. For example, you can do something like

 A[seq(1,dim(A)[2],2)]

 Julian

 Julian M. Burgos

 Fisheries Acoustics Research Lab
 School of Aquatic and Fishery Science
 University of Washington

 1122 NE Boat Street
 Seattle, WA  98105

 Phone: 206-221-6864




 affy snp wrote:
 
 Dear List,

 Hi! I am wondering what is the simplest way to subset a portion of columns
 from a matrix.

 For example, there is a matrix A (238,304*243). What is the simplest
 way to get a sub-matrix B which comprises of column 1, 3, 5, 7,9,...(odd 
 column
 number) from matrix A?

 Thank you very much for your help!

 Best,
  Allen

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

   


 

-- 
Julian M. Burgos

Fisheries Acoustics Research Lab
School of Aquatic and Fishery Science
University of Washington

1122 NE Boat Street
Seattle, WA  98105 

Phone: 206-221-6864

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

2007-11-08 Thread Julian Burgos
Hi Azadeh,

As the warning message is telling you, it seems that your initial 
parameters for the covariance functions are not very good.  Something 
that you can do is to use the eyefit() function (package geoR) to fit 
your variogram by eye and get a first approximation for your 
covariance parameter values (or to test if the values you are using do 
generate a variogram curve that is close to your data).  Then you can 
use these parameters values as initial values in the variofit() function.

Julian

azadeh sadeghian wrote:
 I have thise problem in work with the function variofit and nls and dont know 
 how to solve it.
 var1-variog(data,option=bin)
 var2-variog(data,option=cloud)
 v1-var1$v
 u1-var1^u
 v2-var2$v
 u2-var2$u
   
 variofit(var1,ini.cov.pars=c(0.005,1.5),cov.model=power,fix.nugget=F,weight=equal)
 variofit: weights used: equal 
 variofit: minimisation function used: optim 
 Error in if (loss  (.Machine$double.xmax^0.5) | loss == Inf | loss ==  : 
 missing value where TRUE/FALSE needed
 In addition: Warning message:
 unreasonable initial value for sigmasq + nugget (too low) in: variofit(var1, 
 ini.cov.pars = c(0.005, 1.5), cov.model = power, 
 ...
 variofit(var2,ini.cov.pars=c(0.005,1.5),cov.model=power,fix.nugget=F,weight=equal)
 variofit: weights used: equal 
 warning: minimisation function nls can not be used with given cov.model.
   changing for optim.
 variofit: minimisation function used: optim 
 Error in if (loss  (.Machine$double.xmax^0.5) | loss == Inf | loss ==  : 
   missing value where TRUE/FALSE needed
 In addition: Warning message:
 In variofit(var2, ini.cov.pars = c(0.005, 1.5), cov.model = power,  :
   unreasonable initial value for sigmasq + nugget (too low)
 ...
  nls(v2~c0+ce*(1-exp(-(u2^2)/(ae^2))),start=list(c0=0,ae=3,ce=2))
 Error in nls(v2 ~ c0 + ce * (1 - exp(-(u2^2)/(ae^2))), start = list(c0 = 0,  
 : 
   number of iterations exceeded maximum of 50
   best regards.
   Sadeghian.

 
  __
 
 
 
   [[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] Extract correlations from a matrix

2007-11-08 Thread Julian Burgos
Hey Christoph,

It is not clear what do you want to extract.
w[w0.6] does give you the correlation values above 0.6.  What is your 
question?

Julian

Christoph Scherber wrote:
 Dear R users,
 
 suppose I have a matrix of observations for which I calculate all 
 pair-wise correlations:
 
 m=matrix(sample(1:100,replace=T),10,10)
 w=cor(m,use=pairwise.complete.obs)
 
 How do I extract only those correlations that are 0.6?
 
 w[w0.6] #obviously doesn´t work,
 
 and I can´t find a way around it.
 
 I would very much appreciate any help!
 
 Best wishes
 Christoph
 
 
 (using R 2.5.1 on Windows XP)
 
 
 


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] partially sum variable of a dataframe

2007-11-07 Thread Julian Burgos
I'm assuming that you want to add b if 3a5.25.  If so, there are many 
ways.  One of them is

sum (b[a3  a5.25])

This is very simple R coding.  I recommend you spend some time learning 
the basics.  There are very good tutorials at the R website.

Julian

[EMAIL PROTECTED] wrote:
 Hello,
 
 A stupid question:
 
 I have an array with two columns, the first a acting as my index in 0.25 
 steps, the second one b the column of interest. How can i sum up b only 
 for a specified window in a (as the window command for time series)
 
 a=seq(0,10,0.25)
 b=runif(41)
 c=data.frame(a,b)
 
 Sum up c if 3a5.25
 
 How to do that? thanks
 
 marc

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


Re: [R] Can I replace NA by 0 (if yes, how) ?

2007-11-07 Thread Julian Burgos
Do this:

pfit$coefficients[is.na(pfit$coefficients)]=0

Julian

Ptit_Bleu wrote:
 Hello,
 
 I'm trying to fit some points with a 8-degrees polynom (result of lm is
 stored in pfit).
 In most of the case, it is ok but for some others, some coefficients are
 NA.
 I don't really understand the meaning of these NA.
 
 And the problem is that I can't perform a derivation
 (pderiv-as.function((deriv(polynomial(pfit$coefficients) on pfit due to
 the presence of these NA.
 
 I tried the functions na.omit and na.exclude but NA are still there.
 I tried to replace manually NA by 0. The fit seems ok and then I can
 derive the polynom.
 
 But can I do this and, if yes, how can I detect and automatically replace
 these NA ?
 
 To conclude, I must say that I read some posts on NA but I must confess that
 it is still not clear to me (maybe because I'm french and R-newbie ...)
 
 Thanks in advance for your help,
 Ptit Bleu.
 
 
 pfit
 
 Call:
 lm(formula = pfitmax ~ poly(vfitmax, 8, raw = T))
 
 Coefficients:
(Intercept)  poly(vfitmax, 8, raw = T)1  poly(vfitmax, 8, raw
 = T)2  poly(vfitmax, 8, raw = T)3  poly(vfitmax, 8, raw = T)4  
 -2.790e+04   6.276e+03 
 -5.645e+02   2.591e+01  -6.241e-01  
 poly(vfitmax, 8, raw = T)5  poly(vfitmax, 8, raw = T)6  poly(vfitmax, 8, raw
 = T)7  poly(vfitmax, 8, raw = T)8  
  6.681e-03  NA 
 -3.942e-07  NA  
 
 
 pderiv-as.function((deriv(polynomial(pfit$coefficients
 Erreur dans while ((la - length(a))  1  a[la] == 0) a - a[-la] : 
 valeur manquante là où TRUE / FALSE est requis


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

2007-11-01 Thread Julian Burgos
Hi Garth,

Your code is really confusing! You should start by reading the help file 
on the for() function and understanding what it does:

?for

Your line
for(i in 1:nboot){

}

is simply starting a loop around the variable 'i', which will change 
values following the sequence 1:nboot.

It seems that the problem (or part of it) is that your are calling the 
sample() function using a 'n' variable that is not defined anywhere.

Also, what nboot is supposed to be?  The numbers of samples to be taken 
(10, 20, etc.) or the number of iterations (1000).  In your example, you 
are calling your function as

bt.cor - npboot.function(nboot=10)

so in this case your function will loop around 10 times.

Here is a function that will do what you want:

npboot.function - function(data,nboot){
boot.cor - vector(length=1000)
for (i in 1:1000){
abc2=data[-(1:nboot),] #Remove the first 'nboot' rows
my.sample=sample(1:(250-nboot),nboot,replace=T) # Sample rows
abc2=rbind(abc2,abc2[my.sample,]) # Add the sampled rows to the 
truncated dataset
model - lm(asin(sqrt(abc2$y/100)) ~ abc2$x1 + abc2$x2) #Fit the model
boot.cor[i]=cor(abc2$y,model$fit)  #Get correlation
}
return (boot.cor)}

bt.cor - npboot.function(abc,nboot=120)
bootmean - mean(bt.cor)




[EMAIL PROTECTED] wrote:
 Hi,
 
  
 
 I'm new to R (and statistics) and my boss has thrown me in the deep-end with 
 the following task: 
 
  
 
 We want to evaluate the impact that sampling size has on our ability to 
 create a robust model, or evaluate how robust the model is to sample size for 
 the purpose of cross-validation i.e. in our current project we have collected 
 a series of independent data at 250 locations, from which we have built a 
 predictive model, we want to know whether we could get away with collecting 
 fewer samples and still build a decent model; for the obvious operational 
 reasons of cost, time spent in the field etc.. 
 
  
 
 Our thinking was that we could apply a bootstrap type procedure:
 
  
 
 We would remove 10 records or samples from the total n=250 and then replace 
 those 10 removed with replacements (or copies) from the remaining 240. With 
 this new data-frame we would apply our model and calculate an r², we would 
 then repeat through looping 1000 times before generating the mean r² from 
 those 1000 r² values generated. After which we would start the process again 
 by remove 20 samples from our data with replacements from the remaining 230 
 records and so on... 
 
  
 
 Below is a simplified version of the real code which contains most of the 
 basic elements. My main problem is I'm not sure what the 'for(i in 1:nboot)' 
 line is doing, originally I though what this meant was that it removed 1 
 sample or record from the data which was replaced by a copy of one of the 
 records from the remaining n, such that 'for(i in 10:nboot)' when used in the 
 context of the below code removed 10 samples with replacements as I have said 
 above. I'm almost positive that this isn't happening and if not how can I 
 make the code below for example do what we want it to? 
 
  
 
 library(utils)
 
 #data
 
 a - c(5.5, 2.3, 8.5, 9.1, 8.6, 5.1)
 
 b - c(5.2, 2.2, 8.6, 9.1, 8.8, 5.7)
 
 c - c(5.0,14.6, 8.9, 9.0, 9.1, 5.5)
 
 #join
 
 abc - data.frame(a,b,c)
 
 #set column names
 
 names(abc)[1]-y
 
 names(abc)[2]-x1
 
 names(abc)[3]-x2
 
 abc2 - abc
 
 #sample
 
 abc3 - as.data.frame(t(as.matrix(data.frame(abc2
 
 n - length(abc2)
 
 npboot.function - function(nboot)
 
 {
 
 boot.cor - vector(length=nboot)
 
 for(i in 1:nboot){
 
 rdata - sample(abc3,n,replace=T)
 
 abc4 - as.data.frame(t(as.matrix(data.frame(rdata
 
 model - lm(asin(sqrt(abc4$y/100)) ~ I(abc4$x1^2) + abc4$x2)
 
 boot.cor[i] - cor(abc4$y, model$fit)}
 
 boot.cor
 
 }
 
 bt.cor - npboot.function(nboot=10)
 
 bootmean - mean(bt.cor)
 
  
 
  
 
 Any assistance would be greatly appreciated, also the sooner the better as we 
 are under pressure to reach a conclusion.
 
  
 
 Cheers,
 
  
 
 Garth
 
 
   [[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] Some problem in opening connection with .dat extention file in matrix(scan) function of R 2.5

2007-11-01 Thread Julian Burgos
The error message is telling you that R cannot find your file.  Is your 
'motives_pc.dat' file in your R working directory?  If not, you have to 
give a complete path to the scan() function.

Julian


[EMAIL PROTECTED] wrote:
 Dear helpers please provide me some helpful answer to my problem while I m
 trying to run a program .I m attaching both the program and the data to
 which I have to obtain my estimation results.
 Motives.dat is the data file, and OBTfile4.3 is the complete code of
 program. by Running this
  //
 rawdata-matrix(scan(inputFile, n = nsubj*ncomp), nsubj, ncomp, byrow = TRUE)
  \\
 The error appears to be
 //
 Error in file(file, r) : unable to open connection
 In addition: Warning message:
 cannot open file 'motives_pc.dat', reason 'No such file or directory' in:
 file(file, r)
 \\
 where # name of preferences data file is assigned as,
inputFile - motives_pc.dat
 Thanking Regards
 
 SYED ADIL HUSSAIN (+923455205402)
 QUAID-E-AZAM UNIVERSITY
 ISLAMABAD, PAKISTAN.
 
 This is Virus Free Email Scanned by QAU's McAfee Virus Scanner
 THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
 MATERIAL
 and is thus for use only by the intended recipient. If you received this in 
 error, please contact the sender and delete the e-mail
 and its attachments from all computers.
 www.qau.edu.pk
 
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] How to switch off accepting the shortcut of column names

2007-10-30 Thread Julian Burgos
You cannot call a column on a dataframe using the first letter (or first 
few letters) if the letters match more than one name.  Extraction 
methods for data frames allow partially matching row names, but if the 
result is undefined you get NULL in return.

  Try this.

 first_item - seq(1,10)
 second_item - seq(11,20)
 dat - data.frame(first_item, second_item)
 dat$s
  [1] 11 12 13 14 15 16 17 18 19 20

 #Now add an extra column with matching name
 ssecond_item - seq(21,30)
 dat - data.frame(dat,ssecond_item)
 dat$s
NULL

Julian



P. Olsson wrote:
 Dear R-users,
 
 currently I am working with the R version 2.4.1.
 I realized it has a feature,  which might be wonderful (as so many things in
 R), but in this case might be a bit dangerous as well. It seems that columns
 of a data frame can be called just by indicating the first letter of the
 name of the column.
 
 For example:
 first_item - seq(1,10)
 second_item - seq(11,20)
 dat - data.frame(first_item, second_item)
 names(dat)
 # [1] first_item  second_item
 dat$f
 # [1]  1  2  3  4  5  6  7  8  9 10
 dat$s
 #  [1] 11 12 13 14 15 16 17 18 19 20
 
 The good thing is, that if there is more than one column starting with the
 same letter(s), more than one letter has to be given to call the column.
 However, I would appreciate if I could choose an option in my workspace,
 whether this type of shortcut is allowed or not.
 
 Is there such an option?
 
 Thanks for any potential hints.
 
 Best wishes,
 
 P. Olsson
 
   [[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] data format

2007-10-30 Thread Julian Burgos
There are many ways.  A simple one is to use split() to divide your 
'Value' column using your 'Label' column as index.  For example,

# Create dataset
mydata=data.frame(Label=c('Good','Bad','Good','Good','Good','Bad','Bad'),
Value=c(10,12,15,18,12,15,10))

# Split the data
mydata=split(mydata$Value,mydata$Label)

# Do a ks test
ks.test(mydata[[1]],mydata[[2]])


Julian




Emre Unal wrote:
 Hi,
 
 How can I analyze the data collected in database formatting (with labels)
 rather than splitted by individual columns (almost in excel)?
 
 For example (comma separated data);
 
 Label,Value
 Good,10
 Bad,12
 Good,15
 Good,18
 Good,12
 Bad,15
 Bad,10
 etc...
 
 ks.test or chisq.test can be done.
 Splitting the data into new columns is not applicable cos' I'll use
 R-integration in another software.
 
 
 
 Thanks for your concern
 Emre
 
 
 
 
 
 
 
 
 
 
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] gam for longitudinal data?

2007-10-29 Thread Julian Burgos
You can use the gamm function (in the mgcv package) to fit generalized 
additive mixed models and specify your covariance structure.

Julian

gallon li wrote:
 I used gam for data analysis a lot. Is it possible to use gam to analyze
 longitudinal data? I mean, besides the working independence assumption, can
 i specify other more reasonable covariance structure in gam?
 
   [[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] Adding pagebreaks on files???

2007-10-29 Thread Julian Burgos
I do this all the time.  Simply,

a) Open your pdf file using the pdf function.
b) Do a bunch of plots.  Because now the pdf file is your active device,
every time you call a new plot you should get a new page.  You can also
use par(mfrow=...) to split the page (the same way you do it on a
window), etc.
c) Close the connection to the pdf using dev.off().

Julian

Tom.O wrote:
 Hi 
 Does anyone know if its possible to add pagebreaks to an pdf through an R
 command? I'm running a loop  where each session exports an pdf graph. Each
 image becomes a separate file, but I would like to have them in the same
 document but on separate pages.
 
 Does anyone know a solution or workaround?
 
 Regards, Tom

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


Re: [R] Converting a string

2007-10-29 Thread Julian Burgos
I'm not sure what you mean.  You should provide an example (i.e. some code).

Julian

Gang Chen wrote:
 This must be very simple, but I'm stuck. I have a command line in R  
 defined as a variable of a string of characters. How can I convert  
 the variable so that I can execute it in R?
 
 Really appreciate any help,
 Gang
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] data frame usage

2007-10-25 Thread Julian Burgos
Check out the tapply function.
?tapply

Julian

Bernd Jagla wrote:
 Hi, 
 I am new to R and couldn't find any information on how to handle my table
 data that I just read in the way I want to use it..
 
 I read in a table from a file:
 x - read.delim(filenam, header=TRUE)
 
 one column (x$label) hold the class labels. Another holds some values
 (x$val).
 I want to calculate summary statistics for different classes.
 
 How would I do this?
 
 Thanks,
 
 Bernd
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Spatial autocorrelation

2007-10-22 Thread Julian Burgos
Hi Geertje,

You should look into linear mixed-effects models.  In these you can 
incorporate spatial correlation explicitly.  The basic function to use 
is lme(), but you should do some reading about this type of models 
before jumping into it.  An excellent resource is the book Mixed 
Effects Models in S and S-Plus by Jose Pinheiro and Douglas Bates.

Good Luck!

Julian

Geertje Van der Heijden wrote:
 Hi,
 
 I have collected data on trees from 5 forest plots located within the
 same landscape. Data within the plots are spatially autocorrelated
 (calculated using Moran's I). I would like to do a ANCOVA type of
 analysis combining these five plots, but the assumption that there is no
 autocorrelation in the residuals is obviously violated. Does anyone have
 any ideas how to incorporate these spatial effects in my analysis? I
 have been reading up on autoregressive techniques, but I am not sure if
 it works with more than one plot.
 
 All help is greatly appreciated!
 
 Many thanks,
 Geertje van der Heijden
 
 
 
 
   [[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] Looped t.test results according to a subset variable

2007-10-22 Thread Julian Burgos
See by()

Matthew Dubins wrote:
 Hi all,
 
 I wrote a simple function that gives me multiple t.test results 
 according to a subset variable and am wondering whether or not I 
 reinvented the wheel.  Observe:
 
 t.test.sub - function (formula, data, sub, ...)
 {
 for(i in 1:max(sub))
 {
 print(t.test(formula, data = subset(data, sub == i), ...))
 }
 }
 
 Is there already a similar function in some package?
 
 Thanks,
 Matthew Dubins
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Looped t.test results according to a subset variable

2007-10-22 Thread Julian Burgos
Could you post some of your data and your initial test, and explain why 
it didn't worked?  It is difficult to figure out what is the problem 
with your call to by().

Julian

Matthew Dubins wrote:
 I've tried to use by(), but the closest i got to it doing what I wanted 
 was using the following:
 
 by(percent, quiz, function(percent) {t.test(percent~group, 
 data=marks.long)})
 
 But the results it gave me weren't t.tests of percent by group according 
 to quiz number.
 
 
 Julian Burgos wrote:
 See by()

 Matthew Dubins wrote:
 Hi all,

 I wrote a simple function that gives me multiple t.test results 
 according to a subset variable and am wondering whether or not I 
 reinvented the wheel.  Observe:

 t.test.sub - function (formula, data, sub, ...)
 {
 for(i in 1:max(sub))
 {
 print(t.test(formula, data = subset(data, sub == i), 
 ...))
 }
 }

 Is there already a similar function in some package?

 Thanks,
 Matthew Dubins

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] variance explained by each term in a GAM

2007-10-12 Thread Julian Burgos
Dear Prof. Wood,

Just another quick question.  I am doing model selection following Wood 
and Augustin (2002).  One of the criteria for retaining a term is to see 
if removing it causes an increase in the GCV score.  When doing this, do 
I also need to fix the smooth parameters?

Thanks,

Julian Burgos

Fisheries Acoustics Research Lab
School of Aquatic and Fishery Science
University of Washington

1122 NE Boat Street
Seattle, WA  98105 


Simon Wood wrote:

 I think that your approach is reasonable, except that you should use the same 
 smoothing parameters throughout. i.e the reduced models should use the same 
 smoothing parameters as the full model. Otherwise you get in trouble if x1 
 and x2 are correlated, since the smoothing parameters will then tend to 
 change alot when terms are dropped as one smooth tries to `do the work' of 
 the other. Here's an example, (which is modifiable to illustrate the problem 
 with not fixing the sp's)

  ## simulate some data
 set.seed(0)
 n-400
 x1 - runif(n, 0, 1)
 ## to see problem with not fixing smoothing parameters
 ## remove the `##' from the next line, and the `sp'
 ## arguments from the `gam' calls generating b1 and b2. 
 x2 - runif(n, 0, 1) ## *.1 + x1 
 f1 - function(x) exp(2 * x)
 f2 - function(x) 0.2*x^11*(10*(1-x))^6+10*(10*x)^3*(1-x)^10
 f - f1(x1) + f2(x2)
 e - rnorm(n, 0, 2)
 y - f + e
 ## fit full and reduced models...
 b - gam(y~s(x1)+s(x2))
 b1 - gam(y~s(x1),sp=b$sp[1])
 b2 - gam(y~s(x2),sp=b$sp[2])
 b0 - gam(y~1)
 ## calculate proportions deviance explained...
 (deviance(b1)-deviance(b))/deviance(b0) ## prop explained by s(x2)
 (deviance(b2)-deviance(b))/deviance(b0) ## prop explained by s(x1)





 On Monday 08 October 2007 20:19, Julian M Burgos wrote:
   
 Hello fellow R's,

 I do apologize if this is a basic question.  I'm doing some GAMs using the
 mgcv package, and I am wondering what is the most appropriate way to
 determine how much of the variability in the dependent variable is
 explained by each term in the model.  The information provided by
 summary.gam() relates to the significance of each term (F, p-value) and to
 the wiggliness of the fitted smooth (edf), but (as  far as I understand)
 there is no information on the proportion of variance explained.

 One alternative may be to fit alternative models without each term, and
 calculate the reduction in deviance.  For example:

 m1=gam(y~s(x1) + s(x2)) # Full model
 m2=gam(y~s(x2))
 m3=gam(y~s(x1))

 ddev1=deviance(m1)-deviance(m2)
 ddev2=deviance(m1)-deviance(m3)

 Here, ddev1 would measure the relative proportion of the variability in y
 explained by x1, and ddev2 would do the same for x2.  Does this sound like
 an appropriate approach?

 Julian

 Julian Burgos
 FAR lab
 University of Washington

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] combining vectors on unequal length

2007-10-04 Thread Julian Burgos
Well, if you bind two vectors you form an array with dimensions 2 x 
length of the longest vector.  So you need to decide how to fill up the 
'empty' spacies corresponding to the shorter vector.  Recycling the 
shorter vector is the default action.

If you just want to save the data, you could create a list and save it 
as a R object.

my.list=list(X,Y)
save(my.list)

Julian


Nair, Murlidharan T wrote:
 If I have two vectors
 X-1:10
 Y-1:5
 When I combine them using cbind, the shorter one is repeated and both are 
 made of the same length. Is there a methods that does this without 
 duplicating the shorter one. I want to use this to store the data back to a 
 file.
 Thanks ../Murli
 
 
 
 
   [[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.