[R] comparing vectors with condition

2012-02-13 Thread arunkumar1111
Hi

I have two vector

x=c(10,30,40,50)
total=c(20,20,0,10)

Var_exceeding_total=sum(as.numeric(x total))

This will compare the vectors x and total a gives the result.

if i want to compare only if the y  0 .
can we apply condition in the comparison ?
 

-
Thanks in Advance
Arun
--
View this message in context: 
http://r.789695.n4.nabble.com/comparing-vectors-with-condition-tp4382946p4382946.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Reading in csv with footer

2012-02-13 Thread chuck.01
I believe this should work

d - read.table(foo.csv, header=T, sep=,, comment=T)

although its spitting back a warning... this used to work for me.  




Noah Silverman wrote
 
 Hi,
 
 I have a CSV file that is formatted well, except that the last line is a
 summary not is CSV format.
 
 Toy example:
 
 label_1, label_2, label_3
 1,2,3
 3,2,4
 2,3,4
 Total Rows: 3
 
 
 When I try to import this into R with:  d - read.table(foo.csv,
 header=T, sep=,)
 It fails to import properly because of the last line.
 
 Currently, I have a shell script that strips the last line from the file,
 then it imports to R cleanly.  I don't like this extra layer of
 processing.
 
 Is there a way to import something like this cleanly in R.
 
 Thanks!
 
 --
 Noah
 __
 R-help@ mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Reading-in-csv-with-footer-tp4382441p4382980.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] comparing vectors with condition

2012-02-13 Thread chuck.01
sum(ifelse(x*total!=0, as.numeric(x total), 0))


arunkumar wrote
 
 Hi
 
 I have two vector
 
 x=c(10,30,40,50)
 total=c(20,20,0,10)
 
 Var_exceeding_total=sum(as.numeric(x total))
 
 This will compare the vectors x and total a gives the result.
 
 if i want to compare only if the y  0 .
 can we apply condition in the comparison ?
 


--
View this message in context: 
http://r.789695.n4.nabble.com/comparing-vectors-with-condition-tp4382946p4383000.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Assigning a function to the 'times' argument of rep()

2012-02-13 Thread Petr Savicky
On Sun, Feb 12, 2012 at 07:56:48PM -0800, z2.0 wrote:
 Question: 
 
 I'm trying to use paste() with rep() to reformat a series of values as zip
 codes. e.g., if column 1 looks like:
 
 52775
 83111
 99240
 4289
 112
 57701
 20001
 
 I want rows 4 and 5 to read,
 
 04289
 00112
 
 My thought was this:
 
  perry_frame$zip - ifelse(nchar(as.character(perry_frame$zip))5,
  
 paste(rep(0,times=(5-nchar(as.character(perry_frame$zip,perry_frame$zip,sep=''),
   as.character(perry_frame$zip))
 
 But R throws the following:
 
 Error in rep(0, times = (5 - nchar(as.character(perry_frame$zip : 
   invalid 'times' argument
 
 Is there a reason this doesn't work?

Hi.

Working solutions were suggested by others. The answer
to your question is that times argument should either
be a single number or a vector of the same length as the
first argument. However,

  0 has length 1

  5 - nchar(as.character(perry_frame$zip))
  [1] 0 0 0 1 2 0 0

Hope this helps.

Petr Savicky.

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

2012-02-13 Thread Suranga Kasthurirathne


 Hi everyone,



 I tried writing this data into a file using the save(myList,
 file=test1.bin) command, but unfortunately, the numerical values seem
 to get garbled when I do so.



 The numbers in my RGui look like



 0, 0.5, 0, 1 etc. etc.



 But when I stored it into a .bin file, and retrieved it using java code,
 it returns data such as,



 2272919233031569408

 1701436416123530

 -2278152494445862686

 7161955281552955800



 Etc. etc.



 I also tried the second method (using a # Open a file connection)

 Unfortunately, here too the data gets extremely garbled.

 Has anyone faced such a situation before?



 Any help / comments / useful links would be much appreciated





 Thanks and best regards,

 Suranga




 On Mon, Feb 13, 2012 at 10:37 AM, Suranga Kasthurirathne 
 suranga...@gmail.com wrote:


 Hi,

 Thank you very much for sharing these ideas. I really appreciate them.
 Let me go try them out :-)



 On Mon, Feb 13, 2012 at 4:37 AM, Rui Barradas rui1...@sapo.pt wrote:

 Hello

 One way is

 # Write the file
 save(myList, file=test1.bin)

 # Reload the data, under the same name, 'myList'
 load(file=test1.bin)

 Another way is a bit more complicated

 # Open a file connection and write the list to it (using  comma as
 separator)
 fileCon - file(test2.txt, open=wt)
 lapply(myList, function(x) writeLines(paste(x, collapse=,),
 con=fileCon))
 close(fileCon)

 # Load the data, maybe under another name
 strsplit(readLines(con=test2.txt), split=,)

 If you use the first method, the list is retrieved as it was.
 If you use the second, you lose the list's members' names.

 Hope this helps,

 Rui Barradas


 --
 View this message in context:
 http://r.789695.n4.nabble.com/Writing-output-into-a-file-tp4382243p4382310.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.




 --
 Best Regards,

 Suranga




 --
 Best Regards,

 Suranga




-- 
Best Regards,

Suranga

[[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] Retrieve by Id from an R list

2012-02-13 Thread Suranga Kasthurirathne
Hi everyone,

I'm using the poLCA module for some analysis work.
Basically, Im using the command poLCA(f, data=response,nclass=2)

This returns a poLCA object (a list)

From this data, I need to retrieve certain indexes, such as[[5]] as seen
below.

[[5]]
   Pr(1)   Pr(2)   Pr(3)
class 1:  01.00.0
class 2:  00.50.5


1) The structure shown in [[5]] above is a matrix, isn't it ?
2) how can I specifically retrieve this matrix (retrieve by ID, I guess) ?

Any help / suggestions or helpful links would be very much welcome :-)

-- 
Thanks and Best Regards,

Suranga

[[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] finding and describing missing data runs in a time series

2012-02-13 Thread Ted Harding

On 13-Feb-2012 Durant, James T. (ATSDR/DTEM/PRMSB) wrote:
 Hi -
 I am trying to find and describe missing data in a time series.
 For instance, in the library openair, there is a data frame
 called mydata:
 library(openair)
 head(mydata)
 
   date   ws  wd nox no2 o3 pm10so2  co pm25
 1 1998-01-01 00:00:00 0.60 280 285  39  1   29 4.7225  3.3725   NA
 2 1998-01-01 01:00:00 2.16 230  NA  NA NA   37 NA  NA   NA
 3 1998-01-01 02:00:00 2.76 190  NA  NA  3   34 6.8300  9.6025   NA
 4 1998-01-01 03:00:00 2.16 170 493  52  3   35 7.6625 10.2175   NA
 5 1998-01-01 04:00:00 2.40 180 468  78  2   34 8.0700  8.9125   NA
 6 1998-01-01 05:00:00 3.00 190 264  42  0   16 5.5050  3.0525   NA
 
 
 So for example, I would like to be able to detect for pm25,
 I would like to be able to detect that there are NA's starting
 at 1998-01-01 0:00:00 and runs for 2887 hourly observations.
 Then I would be able to know that there is an NA at 2910 and
 so on. The key information I am looking for is when the NA's
 start and their length. The closest thing I can use that I
 know about is timePlot in the openair package with
 statistic=frequency but it only gives monthly summary data,
 and does not tell me if the missing data are clumped together
 or are dispersed.
 
 VR
 Jim
 
 James T. Durant, MSPH CIH
 Emergency Response Coordinator
 US Agency for Toxic Substances and Disease Registry
 Atlanta, GA 30341
 770-378-1695

You might consider an approach based on

  rle(is.na(mydata$pm25))

See ?rle

Example:

  X - c(1,2,3,NA,NA,NA,4,5,NA,6,7,8,NA,NA,NA,NA,NA)
  X
  # [1]  1  2  3 NA NA NA  4  5 NA  6  7  8 NA NA NA NA NA
  rle(is.na(X))
  # Run Length Encoding
  #   lengths: int [1:6] 3 3 2 1 3 5
  #   values : logi [1:6] FALSE TRUE FALSE TRUE FALSE TRUE

Ted.

-
E-Mail: (Ted Harding) ted.hard...@wlandres.net
Date: 13-Feb-2012  Time: 08:51:19
This message was sent by XFMail

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Release plans for 2.14.2 and 2.15.0

2012-02-13 Thread Peter Dalgaard
It is the intention of the R Core Team to release the finalized version of the 
2.14.x series at the end of February, and soon thereafter to start the run-in 
for 2.15.0. I.e.,

2.14.2 Gift-Getting Season on Feb 29 (3rd anniversary of R-1.0.0!)
2.15.0 Easter Beagle on Mar 30

(We'll see about getting the nicknames into the actual sources this time.)

Further details to follow.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

___
r-annou...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-announce

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Is it possible to run multiple instances of Tinn-R?

2012-02-13 Thread RNoob
Dear All,

is there anyone using Tinn R, who knows if it's possible to run more than
one instance of Tinn R on one machine? I'd like to run more than one R
process (R Term) at a time from Tinn R.

Any help will be appreciated.

Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/Is-it-possible-to-run-multiple-instances-of-Tinn-R-tp4383244p4383244.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] dotplots with error bars

2012-02-13 Thread Jim Lemon

On 02/13/2012 09:51 AM, Colin Wahl wrote:

Does anyone have any recommendations for producing dotplots with error
bars? Are there packages available for this? I searched far and wide
and cannot find a suitable option.

I am trying to produce publication-quality figures for my thesis
results. Dotplots (Cleveland dotplots) are a much better form of
summarizing barchart-type data. It does not appear that any of the
main plotting packages in r support dotplots with error bars.
Considering the benefit of these plots, I find it difficult to believe
that they have not been fully integrated into R.

I did find a function dotplots.errors available here:
http://agrobiol.sggw.waw.pl/~cbcs/articles/CBCS_5_2_2.pdf.

However, I have found this function absurdly difficult to use when
customizing figures (ordering displays properly, or just simple
getting the function to work.)

I've been struggling for the last few hours to figure out the error:
error using packet 1 sum not meaningful for factors. Unlike other
packages, this function doesnt have a ?dotplots.errors to help guide
troubleshooting. I presume this is a technicality due to the a numeric
variable being identified as a factor. However, I've double checked
that all the numeric columns in the data frame are not factors, and
the error persists.

I'd really prefer not just calling it quits and resorting to
old-school sloppy bar charts, but if thats what I need to do to finish
this in a timely manner, then so be it.


Hi Colin,
I am grateful that Marcin Kozak gave plotrix a plug in the paper, and to 
show my gratitude, I'll explain how to use centipede.plot to get the 
illustration in the paper. Assume that you have the data frame shown on 
p70 of the paper:


plant_height-read.csv(plant_height.csv)

Now, to echo Marcin, let us produce the plot:

library(plotrix)
centipede.plot(t(plant_height[,c(3,2,4)]),
 left.labels=plant_height$group,bg=black,
 right.labels=rep(,13),xlab=Mean plant height (cm) +- SE)

If you want the mean value line:

abline(v=mean(plant_height$est),col=lightgray)

The grid lines are a bit more difficult. You could insert a line into 
the function just after the call to box() to draw grid lines under each dot:


abline(h=1:dim(x)[2],col=lightgray,lty=2)

However, this looks like such a good idea that I will add two arguments 
to the function to do the vertical line(s) and horizontal grid 
automatically, and this option will appear in the next version of plotrix.


Jim

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


Re: [R] dotplots with error bars

2012-02-13 Thread Matthieu Dubois
Colin Wahl biowahl at gmail.com writes:

 
 Does anyone have any recommendations for producing dotplots with error
 bars? Are there packages available for this? I searched far and wide
 and cannot find a suitable option.

Dear Colin, 

have a look at this page from the R wiki:
http://rwiki.sciviews.org/doku.php?id=tips:graphics-base:errbars

Also, if you want more details on how to do it with ggplot2, 
a very nice graphic package, you can have a look here:
http://wiki.stdout.org/rcookbook/Graphs/Plotting%20means%20and%20error%20bars%20(ggplot
2)/

HTH

Matthieu

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

2012-02-13 Thread Soheila Khodakarim
Dear All
I want to chose just spacial columns in R. (read table)

data1- read.table(/home/Documents/data.txt,header=F,sep = \t, as.is =F)
data.2-data1[sub.data[,1],]


The dimension of data.2 is correct but my data are transformed NA

head(data.2)

  V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18
V19 V20 V21 V22 V23 V24
NA   NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.1 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.2 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.3 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.4 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.5 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA



when I used as.is =T

Error in read.table(/home/Documents/data.txt,  :
  invalid numeric 'as.is' expression


I will appreciate if you help me.

Soheila

[[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] Retrieve by Id from an R list

2012-02-13 Thread Petr Savicky
On Mon, Feb 13, 2012 at 02:13:41PM +0530, Suranga Kasthurirathne wrote:
 Hi everyone,
 
 I'm using the poLCA module for some analysis work.
 Basically, Im using the command poLCA(f, data=response,nclass=2)
 
 This returns a poLCA object (a list)
 
 From this data, I need to retrieve certain indexes, such as[[5]] as seen
 below.
 
 [[5]]
Pr(1)   Pr(2)   Pr(3)
 class 1:  01.00.0
 class 2:  00.50.5

 1) The structure shown in [[5]] above is a matrix, isn't it ?
 2) how can I specifically retrieve this matrix (retrieve by ID, I guess) ?

Hi.

If the list is in the variable poLCA, then try

  a - poLCA[[5]]
  a

Whether this is a matrix may be checked using

  class(a)

Hope this helps.

Petr Savicky.

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

2012-02-13 Thread Uwe Ligges
GHard to tell given the file is not available nor do we see the first 
lines of it.


Uwe Ligges


On 13.02.2012 10:51, Soheila Khodakarim wrote:

Dear All
I want to chose just spacial columns in R. (read table)

data1- read.table(/home/Documents/data.txt,header=F,sep = \t, as.is =F)
data.2-data1[sub.data[,1],]


The dimension of data.2 is correct but my data are transformed NA

head(data.2)

   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18
V19 V20 V21 V22 V23 V24
NANA  NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.1NA  NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.2NA  NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.3NA  NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.4NA  NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.5NA  NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA



when I used as.is =T

Error in read.table(/home/Documents/data.txt,  :
   invalid numeric 'as.is' expression


I will appreciate if you help me.

Soheila

[[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] logical operator for different dimensions

2012-02-13 Thread uday

I have some dataset 


 sci.pre - 0.300.380.500.650.801.031.331.72   
2.22
  2.873.815.066.759.00   11.97   14.15   16.34   19.04
  22.27   25.49   29.72   34.67   40.47   47.29   55.29   64.67   75.6
   88.50  103.50  121.10  141.70  165.80  194.00  227.00  265.00  308.00
356.50  411.00  441.60  472.20  506.35  540.50  578.55  616.60  637.75
  658.90  680.05  701.20  724.65  748.10  771.55  795.00  820.95  846.90
  872.85  898.80  927.35  955.90  984.45 1013.00  ( length is 60)

sci.avgkernal  - 0.300.380.500.650.801.031.33   
1.722.22
2.873.815.066.759.00   11.97   14.15   16.34   19.04
 22.27   25.49   29.72   34.67   40.47   47.29   55.29   64.67   75.65
 88.50  103.50  121.10  141.70  165.80  194.00  227.00  265.00  308.00
356.50  411.00  441.60  472.20  506.35  540.50  578.55  616.60  637.75
658.90  680.05  701.20  724.65  748.10  771.55  795.00  820.95  846.90
  872.85  898.80  927.35  955.90  984.45 1013.00 ( length is 60)

pres.interptimes -  [,1]  [,2] [,3] [,4] [,5]
[,6] [,7] [,8]
[1,] 1016.1267 1005.9741 989.9127 970.0237 945.6067 880.5082 790.4647
675.8315
[2,]  875.6320  866.8767 853.0258 835.8741 814.8176 758.6784 681.0275
582.1712
[3,]  996.0351  986.0758 970.3201 950.8098 926.8576 862.9984 774.6692
662.2184
[4,]  996.0353  986.0760 970.3203 950.8100 926.8578 862.9987 774.6694
662.2187
[5,] 1008.0222  997.9431 981.9978 962.2527 938.0123 873.3847 783.9926
670.1888
[6,]  999.8343  989.8371 974.0214 954.4367 930.3932 866.2906 777.6247
664.7453
 [,9][,10][,11][,12][,13][,14][,15][,16]
[1,] 544.3248 410.3611 289.4130 237.2794 191.5622 152.3020 119.1842 91.68080
[2,] 468.7636 353.2371 248.9350 203.9765 164.5513 130.6945 102.1346 78.41645
[3,] 533.2153 401.8020 283.1566 232.0154 187.1686 148.6559 116.1686 89.18875
[4,] 533.2155 401.8022 283.1568 232.0157 187.1688 148.6561 116.1688 89.18898
[5,] 539.6334 406.6388 286.5657 234.8092 189.4227 150.4466 117.5683 90.26387
[6,] 535.2505 403.3363 284.2386 232.9026 187.8848 149.2253 116.6141 89.53148
[,17][,18][,19] [,20]
[1,] 69.12170 50.81654 24.30808 0.8657024
[2,] 58.96213 43.17629 20.31615 0.1001228
[3,] 67.05913 49.10247 23.09867 0.1025881
[4,] 67.05936 49.10270 23.09890 0.1028196
[5,] 67.86797 49.69524 23.37854 0.1057444
[6,] 67.31751 49.29240 23.18949 0.1057560 ( dim is 6 20) 

sci.prediff   - diff(sci.pre) 
sci.prediff   - c(sci.pre[1],sci.prediff) 
sum(sci.avgkernal*sci.prediff )/sum(sci.prediff )
pres.interptimes  - pres.interptime[,-20]#skip last level
tm3.avgkernal -array(NA,c(length(1:nobs),19))
for (k in 1:nobs){
   for (h in 1:19){
  sel- sci.pre = pres.interptimes[k,h]  sci.pre 
pres.interptimes[k,h+1]
  tm3.avgkernal[k,h] - sum((sci.avgkernal * sci.prediff)[sel]) /
sum(sci.prediff[sel])
}
   }

after running code I get error 

Error: subscript out of bounds

How to fix this error ?


--
View this message in context: 
http://r.789695.n4.nabble.com/logical-operator-for-different-dimensions-tp4383316p4383316.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] Error from GNLS (undefined columns selected)

2012-02-13 Thread Louis Salomon
 Dear R-helpers,

I'm a new R-user and I was trying to gain some experience with the GNLS 
function of the NLME package.

 This is an extract from my dataset (it's a 432x6 data.frame) called input, 
in the first column I have the values that I need to fit, while the remaining 
columns are input variables for the theoretical model, the function mymodel 
(which returns a 432x1 vector of fitted values):

V0V1V2V3 V4 V5
0.56374863838.6875400.1041095890.0572495640
1.47392252639.125400.2767123290.0553929370
0.51704068441.0625450.1808219180.0532145910
1.38181318737.5625400.3534246580.0505213210

and this is my call of gnls:

fm1 - gnls(V0 ~ 
mymodel(V1,V2,V3,V4,V5,par1,par2,par3,par4,par5,par6,par7,par8), 
data=input,start=list(par1=0.2,par2=0.4,par3=0.8,par4=0.2,par5=10,par6=0.8,par7=0.9,par8=-0.5))

and I get the following error:

Error in `[.data.frame`(eval(model, data.frame(data, getParsGnls(plist,  : 
  undefined columns selected

 My guess is that R is not able to create that data.frame since getParsGnls, 
an internal function of gnls, does not provide its output (obviously the error 
is mine, but I can't clearly identify it). Indeed, in the previous lines of the 
gnls code, I don't have any problems when R creates a data.frame using the 
dataframe data and pars, as follows:

res - eval(model, data.frame(data, pars))

I would be grateful to receive any help or hint.

Best regards,
Louis Salomon

[[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] Discrete Event Simulation problem

2012-02-13 Thread jism7690
I have made some chances and I believe now the only problem  is making the
system reorder. Please any help would be great


test - function(seed = 123456789, maxStock= 100, minStock =
20,t.max=1100,inventory =50)
{

LAST = t.max
START = 0
t.demand = START
t.supply = START
t.current = START

GetDemand-function()
{
t.demand - t.demand + runif(1,min=0,max=5)
return(t.demand)
}
GetSupply -function(){
if (inventory  minStock)
{
t.supply - t.supply + 1.0
}
else
t.supply - Inf
return(t.supply)
 }
 
main - function(seed)
{
  if(seed  0)
set.seed(seed)
index = 0
  t.current = START   Starting
Conditions
t.demand = START
t.supply = START
minStock = 20
maxStock = 100
inventory = 50
order_costs = 0
storage_costs = 0
sum = list(inventory = 50,order_costs = 0,storage_costs = 0)


while(index  LAST){
index = index + 1
t.demand = GetDemand()  ### expected time to next sale
t.supply = GetSupply()  ### expected time to arrival of order, 
Infinity as
order has not been placed
t.next =min(t.demand,t.supply)###next event either sale or supply is
the one with imminent arrival
k = maxStock - inventory
t.current = t.next -min(t.demand,t.max)
  if(inventory  0) {
  storage_costs = (t.next-t.current)*0.10*inventory
  }

 if (inventory  minStock)
   {###Need to 
Order
 k = maxStock - inventory
 order_costs = 50 + 0.02*k
 sum$order_costs = sum$order_costs + order_costs
 t.supply =  GetSupply()
}
if(t.next ==t.demand)
  { 
inventory - inventory - 1 
Sale made
sum$inventory = sum$inventory - 1.0
t.demand = GetDemand()
}

if(t.next == t.supply)
  { 
Order Arrives
sum$inventory = sum$inventory + k
k = 0
t.supply = GetSupply()
}

  if(inventory  maxStock)
  {
  k = maxStock - inventory
  sum$storage_costs = sum$storage_costs + storage_costs
  sum$order_costs = sum$order_costs + order_costs
  }

}
  options(digits = 5)
sis = list(Time = index,StorageCosts =sum$storage_costs,OrderCosts=
sum$order_costs,AverageCosts =((sum$order_costs +
sum$storage_costs)/index),Inventory = sum$inventory)
return(sis)
}
return(main(seed))
}


--
View this message in context: 
http://r.789695.n4.nabble.com/Discrete-Event-Simulation-problem-tp4377276p4383464.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] R-help Digest, Vol 108, Issue 13

2012-02-13 Thread 丁飞
dear:
i want to know how to get a survival curve of the Cox proportional risk 
regression, thank you. 





 
[[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] logical operator for different dimensions

2012-02-13 Thread Petr Savicky
On Mon, Feb 13, 2012 at 02:08:52AM -0800, uday wrote:
 
 I have some dataset 
 
 
  sci.pre - 0.300.380.500.650.801.031.331.72   
 2.22
   2.873.815.066.759.00   11.97   14.15   16.34   19.04
   22.27   25.49   29.72   34.67   40.47   47.29   55.29   64.67   75.6
88.50  103.50  121.10  141.70  165.80  194.00  227.00  265.00  308.00
 356.50  411.00  441.60  472.20  506.35  540.50  578.55  616.60  637.75
   658.90  680.05  701.20  724.65  748.10  771.55  795.00  820.95  846.90
   872.85  898.80  927.35  955.90  984.45 1013.00  ( length is 60)
 
 sci.avgkernal  - 0.300.380.500.650.801.031.33   
 1.722.22
 2.873.815.066.759.00   11.97   14.15   16.34   19.04
  22.27   25.49   29.72   34.67   40.47   47.29   55.29   64.67   75.65
  88.50  103.50  121.10  141.70  165.80  194.00  227.00  265.00  308.00
 356.50  411.00  441.60  472.20  506.35  540.50  578.55  616.60  637.75
 658.90  680.05  701.20  724.65  748.10  771.55  795.00  820.95  846.90
   872.85  898.80  927.35  955.90  984.45 1013.00 ( length is 60)
 
 pres.interptimes -  [,1]  [,2] [,3] [,4] [,5]
 [,6] [,7] [,8]
 [1,] 1016.1267 1005.9741 989.9127 970.0237 945.6067 880.5082 790.4647
 675.8315
 [2,]  875.6320  866.8767 853.0258 835.8741 814.8176 758.6784 681.0275
 582.1712
 [3,]  996.0351  986.0758 970.3201 950.8098 926.8576 862.9984 774.6692
 662.2184
 [4,]  996.0353  986.0760 970.3203 950.8100 926.8578 862.9987 774.6694
 662.2187
 [5,] 1008.0222  997.9431 981.9978 962.2527 938.0123 873.3847 783.9926
 670.1888
 [6,]  999.8343  989.8371 974.0214 954.4367 930.3932 866.2906 777.6247
 664.7453
  [,9][,10][,11][,12][,13][,14][,15][,16]
 [1,] 544.3248 410.3611 289.4130 237.2794 191.5622 152.3020 119.1842 91.68080
 [2,] 468.7636 353.2371 248.9350 203.9765 164.5513 130.6945 102.1346 78.41645
 [3,] 533.2153 401.8020 283.1566 232.0154 187.1686 148.6559 116.1686 89.18875
 [4,] 533.2155 401.8022 283.1568 232.0157 187.1688 148.6561 116.1688 89.18898
 [5,] 539.6334 406.6388 286.5657 234.8092 189.4227 150.4466 117.5683 90.26387
 [6,] 535.2505 403.3363 284.2386 232.9026 187.8848 149.2253 116.6141 89.53148
 [,17][,18][,19] [,20]
 [1,] 69.12170 50.81654 24.30808 0.8657024
 [2,] 58.96213 43.17629 20.31615 0.1001228
 [3,] 67.05913 49.10247 23.09867 0.1025881
 [4,] 67.05936 49.10270 23.09890 0.1028196
 [5,] 67.86797 49.69524 23.37854 0.1057444
 [6,] 67.31751 49.29240 23.18949 0.1057560 ( dim is 6 20) 
 
 sci.prediff   - diff(sci.pre) 
 sci.prediff   - c(sci.pre[1],sci.prediff) 
 sum(sci.avgkernal*sci.prediff )/sum(sci.prediff )
 pres.interptimes  - pres.interptime[,-20]#skip last level
 tm3.avgkernal -array(NA,c(length(1:nobs),19))
 for (k in 1:nobs){
for (h in 1:19){
 sel- sci.pre = pres.interptimes[k,h]  sci.pre 
 pres.interptimes[k,h+1]
 tm3.avgkernal[k,h] - sum((sci.avgkernal * sci.prediff)[sel]) /
 sum(sci.prediff[sel])
   }
}
 
 after running code I get error 
 
 Error: subscript out of bounds
 
 How to fix this error ?

I suspect that the error is generated at

  pres.interptimes[k,h+1]

since h+1 goes up to 20 and pres.interptimes was restricted to 19
columns in 

  pres.interptimes  - pres.interptime[,-20]#skip last level

(assuming that pres.interptime is a typo and is pres.interptimes
in fact).

Hope this helps.

Petr Savicky.

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

2012-02-13 Thread Chosid, David (MISC)
 Indeed.  Thanks for the solution :)

-Original Message-
From: Sarah Goslee [mailto:sarah.gos...@gmail.com] 
Sent: Friday, February 10, 2012 1:01 PM
To: Chosid, David (FWE); r-help
Subject: Re: [R] function arrows.circular not working

It's a good idea to acknowledge that you've found a solution on the R-help 
list, rather than just to me.

That way the answer appears in the list archives, and other people will know 
you no longer need help with this problem.

Sarah

On Fri, Feb 10, 2012 at 12:57 PM, Chosid, David (MISC) 
david.cho...@state.ma.us wrote:
 Ah.  Thanks.  I didn't realize that I needed an updated R... Just the 
 library.  Works now.

 -Original Message-
 From: Sarah Goslee [mailto:sarah.gos...@gmail.com]
 Sent: Friday, February 10, 2012 12:32 PM
 To: Chosid, David (FWE); r-help
 Subject: Re: [R] function arrows.circular not working

 Hi,

 On Fri, Feb 10, 2012 at 12:15 PM, Chosid, David (MISC) 
 david.cho...@state.ma.us wrote:
 Yes, sorry for not being more clear.  Here is the sessionInfo():

 sessionInfo()
 R version 2.9.1 (2009-06-26)
 i386-pc-mingw32

 That is definitely the place to start. Your version of R is 2.5 years 
 old, and circular is up to version 0.4-3 on CRAN. I just checked, and 
 circular
 0.3-8 doesn't *have* arrows.circular. So you must be using some documentation 
 from the internet for a newer version, rather than using the docs that go 
 with what you have installed on your computer.

 You need to update R and your packages.

 Sarah


 locale:
 LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
 States.1252;LC_MONETARY=English_United
 States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

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

 other attached packages:
 [1] relimp_1.0-1    Rcmdr_1.4-10    car_1.2-14      circular_0.3-8 
 [5]
 boot_1.2-37     lattice_0.17-25 RODBC_1.3-0




 -Original Message-
 From: Sarah Goslee [mailto:sarah.gos...@gmail.com]
 Sent: Friday, February 10, 2012 12:02 PM
 To: Chosid, David (FWE)
 Cc: r-help@r-project.org
 Subject: Re: [R] function arrows.circular not working

 Your sessionInfo() would be helpful. Also, just to check: you did do
 library(circular)
 right?

 Sarah

 On Fri, Feb 10, 2012 at 11:55 AM, Chosid, David (MISC) 
 david.cho...@state.ma.us wrote:
 I have started using the circular package but it is not recognizing the 
 function arrows.circular.  I attempted to use the example provided in the 
 circular manual.  Here is the example code using the circular package:

  plot(rvonmises(10, circular(0), kappa=1))
  arrows.circular(rvonmises(10, circular(0), kappa=1))
  arrows.circular(rvonmises(10, circular(0), kappa=1), y=runif(10),
 col=2)
  arrows.circular(rvonmises(10, circular(0), kappa=1), y=runif(10),
    x0=runif(10, -1, 1), y0=runif(10, -1, 1), col=3)

 My error is:  Error: could not find function arrows.circular

 Any help would be greatly appreciated.  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] Any package for best subset selection on random effects model?

2012-02-13 Thread Ben Bolker
zbleach zt020200 at gmail.com writes:

 
 Hi Pros,
  I know leaps() computes the best subset selection for linear model, and
 the bestglm() computes the best subset selection for generalized linear
 model. Is there any package for best subset selection on random effects
 model, or mixed effects model?
 

  glmmLasso on CRAN ; possibly try the MuMIn package (specifically
the dredge command).  You might have better luck with this question
on the r-sig-mixed-mod...@r-project.org list.

  Ben Bolker

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] best option for big 3D arrays?

2012-02-13 Thread Djordje Bajic
I've been investigating and I partially respond myself. I tried the
packages 'bigmemory' and 'ff' and for me the latter did the work I need
pretty straightforward. I create the array in filebacked form with the
function ff, and it seems that the usual R indexing works well. I have yet
to see the limitations, but I hope it helps.

a foo example:

myArr - ff(NA, dim=rep(904,3), filename=arr.ffd, vmode=double)
myMat - matrix(1:904^2, ncol=904)
for ( i in 1:904 ) {
myArr[,,i] - myMat
}

Thanks all,

2012/2/11 Duncan Murdoch murdoch.dun...@gmail.com

 On 12-02-10 9:12 AM, Djordje Bajic wrote:

 Hi all,

 I am trying to fill a 904x904x904 array, but at some point of the loop R
 states that the 5.5Gb sized vector is too big to allocate. I have looked
 at
 packages such as bigmemory, but I need help to decide which is the best
 way to store such an object. It would be perfect to store it in this
 cube
 form (for indexing and computation purpouses). If not possible, maybe the
 best is to store the 904 matrices separately and read them individually
 when needed?

 Never dealed with such a big dataset, so any help will be appreciated

 (R+ESS, Debian 64bit, 4Gb RAM, 4core)


 I'd really recommend getting more RAM, so you can have the whole thing
 loaded in memory.  16 Gb would be nice, but even 8Gb should make a
 substantial difference.  It's going to be too big to store as an array
 since arrays have a limit of 2^31-1 entries, but you could store it as a
 list of matrices, e.g.

 x - vector(list, 904)
 for (i in 1:904)
  x[[i]] - matrix(0, 904,904)

 and then refer to entry i,j,k as x[[i]][j,k].

 Duncan Murdoch




[[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] kernlab - rvm error message: Error in if (length(data) != vl)

2012-02-13 Thread Martin Batholdy
Hi,

I am trying to perform relevance vector machines with the rvm-function from 
kernlab.

On one dataset I get this message:

Setting default kernel parameters  

Error in if (length(data) != vl) { : 
RMate stopped at line 0 of selection
  missing value where TRUE/FALSE needed
Calls: rvm ... .local - backsolve - as.matrix - chol - diag - array


can someone explain this error message?

It works for other data-sets with the same feature / example-space.
But for one particular trainingset I get this error message...

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] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread Martin Batholdy
Hi,

For another trainingset I get this error message, which again is rather cryptic 
to me:


 Setting default kernel parameters  

Error in array(0, c(n, p)) : 'dim' specifies too large an array
RMate stopped at line 0 of selection
Calls: rvm ... .local - backsolve - as.matrix - chol - diag - array



thanks for 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] see NA

2012-02-13 Thread David Winsemius


On Feb 13, 2012, at 4:51 AM, Soheila Khodakarim wrote:


Dear All
I want to chose just spacial columns in R. (read table)

data1- read.table(/home/Documents/data.txt,header=F,sep = \t,  
as.is =F)

data.2-data1[sub.data[,1],]


What is sub.data? are you migrating to R from a language where  
sub. would be some kind of operation on data?


--
David.




The dimension of data.2 is correct but my data are transformed NA

head(data.2)

 V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18
V19 V20 V21 V22 V23 V24
NA   NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.1 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.2 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.3 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.4 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.5 NA NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA



when I used as.is =T

Error in read.table(/home/Documents/data.txt,  :
 invalid numeric 'as.is' expression


I will appreciate if you help me.

Soheila

[[alternative HTML version deleted]]

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread Martin Batholdy

I am using a linear kernel (vanilladot).
By switching the kernel, I actually get rid of the error message, but I would 
like to stick to the linear one ...


On 13.02.2012, at 16:23, Martin Batholdy wrote:

 Hi,
 
 For another trainingset I get this error message, which again is rather 
 cryptic to me:
 
 
 Setting default kernel parameters  
 
 Error in array(0, c(n, p)) : 'dim' specifies too large an array
 RMate stopped at line 0 of selection
 Calls: rvm ... .local - backsolve - as.matrix - chol - diag - array
 
 
 
 thanks for 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] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread David Winsemius


On Feb 13, 2012, at 10:23 AM, Martin Batholdy wrote:


Hi,

For another trainingset I get this error message, which again is  
rather cryptic to me:



Just imagine how it seems to us!


Setting default kernel parameters

Error in array(0, c(n, p)) : 'dim' specifies too large an array
RMate stopped at line 0 of selection
Calls: rvm ... .local - backsolve - as.matrix - chol - diag -  
array


You are on you way to the prize for the greatest number of cryptic  
(your word) postings in a short interval. (And this one doesn't even  
have the context of your posting of 8 minutes ago.)



thanks for any suggestions!


More details about data and code.

--
David Winsemius, MD
West Hartford, CT

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


Re: [R] R-help Digest, Vol 108, Issue 13

2012-02-13 Thread Milan Bouchet-Valat
Le lundi 13 février 2012 à 19:48 +0800, 丁飞 a écrit :
 dear:
 i want to know how to get a survival curve of the Cox proportional risk 
 regression, thank you. 
See the relevant part of the Survival Task View here:
http://cran.r-project.org/web/views/Survival.html

And more specifically, see the coxph() function in the survival package.
A tutorial is available from:
http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-cox-regression.pdf


(But RSiteSearch(coxph) or a simple Google search will give you many
more results.)

Cheers

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] multi-regression with more than 50 independent variables

2012-02-13 Thread R DF
Hi R Users,

I am going to run a multiple linear regression with around 57 independent
variables. Each time I run the model with just 11 variables, the results
are reasonable. With increasing the number of independent variables more
than 11, the coefficients will get “NA” in the output.  Is there any
limitation for the number of independent variables in multiple linear
regressions in R? I attached my dataset as well as R codes below:



mlr.data- read.table(./multiple.txt,header=T)

mlr.output- lm(formula = CaV ~ SHG +  TrD+  CrH+ SPAD+ FlN+ FrN+   YT+
LA+ LDMP+B+Cu+  Zn+   Mn +   Fe+   K +  P+   N +Clay30 +Silt30 +Sand30
+Clay60 +Silt60 +Sand60 +ESP30 +NaEx30+ CEC30+Cl30+ SAR30 +KSol30+ NaSol30
+CaMgSol3 +ZnAv30 +FeAv30 +OC30 +PAv30 +KAv30 +TNV30+ pH30+ EC30 +SP30
+ESP60 +NaEx60 +CEC60  +Cl60 +SAR60 +KSol60 +NaSol60 +CaMgSol6
+ZnAv60+FeAv60 +OC60 +PAv60 +KAv60 +TNV60 +pH60 + EC60 +SP60, data=mlr.data)

summary (mlr.output)




Regards,

Reza
CaV SHG TrD CrH SPADFlN FrN YT  LA  LDMP
B   Cu  Zn  Mn  Fe  K   P   N   Clay30  Silt30  
Sand30  Clay60  Silt60  Sand60  ESP30   NaEx30  CEC30   Cl30SAR30   KSol30  
NaSol30 CaMgSol3ZnAv30  FeAv30  OC30PAv30   KAv30   TNV30   pH30
EC30SP30ESP60   NaEx60  CEC60   Cl60SAR60   KSol60  NaSol60 
CaMgSol6ZnAv60  FeAv60  OC60PAv60   KAv60   TNV60   pH60EC60
SP60
49.83   15.822.32   45.882.7126 5   55.834.757.7
17.98.4 14.750.5144.7   0.9 0.1 1.7 14  50  
36  10  26  64  3.2 0.3 11.987.75.6 2.5 
25.769.82.9 3.1 0.6664.4360 14.89.940.6 
39.64.8 0.2 12.251.46.9 1.4 33.469.91.8 
3.4 0.2 3.5 290 11.57.193.2140.1
37.85   18.920.89   53.275.9169 4   67.440.158.6
15.87.9 12.153.2141.6   0.7 0.1 1.9 13  51  
34  11  28  64.01.9 0.2 12.545.77.8 3.8 
22.977.93.1 2.5 0.6945.6390 14.87.2 1.1 
40.15.4 0.1 13.359.97.9 1.7 56.658.91.5 
5.5 0.6 1.9 350 10.27.1 3.7 42.1
64.12   20.719.04   43.974.3133 5   55.938.760.0
12.16.3 12.647.4159.5   1.0 0.1 1.6 12  48  
33  13  26  62.06.4 1.1 12.633.210.11.8 
43.899.31.5 2.8 0.5720.5470 15.17.1 0.7 
39.84.9 0.3 10.965.57.1 2.3 42.166.41.1 
3.9 0.7 2.9 288.9   12.27.2 4.1 35.6
90.28   14.619.52   56.961.9145 7   66.533.259.1
13.74.7 10.052.1241.1   0.8 0.1 1.9 13  47  
32  10  30  57.05.5 0.3 11.731.23.5 2.4 
50.465.71.9 2.5 0.8841.9398 14.37   2.4 
38.73.1 0.5 14.171.98.4 1.9 36.759.10.9 
2.6 0.5 2.7 290.7   13.67   2.6 43.7
111.18  13.216.53   61.378  127 6   49.941.751.6
14.74.7 10.055.8148.9   0.7 0.1 1.9 14  46  
37  11  28  60.03.9 0.7 11  21.74.3 0.9 
33.773.62.3 2.7 0.7833.4349 15.27.4 0.9 
39.12.8 0.1 12.576.68.9 3.1 32.171.40.5 
6.9 0.5 2.5 256.9   15.17.5 1.7 36.7
59.11   12.921.34   45.378.9178 6   63.339.852.0
19.54.2 8.9 54.7229.5   0.7 0.1 1.7 13  46  
36  12  30  62.02.7 0.7 12.919.52.6 2.8 
61.286.92.2 3.7 0.8627.8400.5   17.17.1 2.1 
39.93.9 0.3 11.957.46.7 1.6 30.189.91.8 
5.8 0.3 3.7 224.8   12.97.3 5.5 34.9
80.89   17.915.86   40.366.8154 7   45.636.847.8
21.63.7 12.654.7162.1   0.7 0.1 1.9 11  50  
35  13  31  61.02.9 0.4 10.937.97.1 1.9 
19.555.82.8 2.9 0.6645.1459 15.67.2 0.8 
36.15.1 0.4 13.185.55.7 2.1 29.192.11.9 
7.8 0.7 2.8 278.9   11.87.2 6.1 32.7
122.74  16.617.29   43  77.8140 6   32.937.755.6
20.04.2 12.147.4152.6   0.9 0.1 1.7 14  49  
36  11  25  58.03.2 1.5 11.524.53.9 3.7 
20.856.91.9 2.6 0.7240.7

[R] Wavelet and inverse wavelet to filter data

2012-02-13 Thread bergdepp
Dear Friends of R,

I would like to filter high frequent turbulence data with wavelet analysis.
Therefore i want to calculate the wavelet coefficients of the raw data.
And then the inverse for a special frequency band.

How can i do this in the best and easiest way?

Many thanks for your answers and help,

Best regards



[[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] Error in apply(x2, 1, diff) : dim(X) must have a positive length

2012-02-13 Thread hithit168
Thank you for your help, David. I was trying to run bootrapping on the
dataset shoes from MASS package. But I still have some problem here.

 as.matrix(data.frame(shoes),nrows=10,ncols=2,byrow=T)
A B
[1,] 13.2 14.0
[2,] 8.2 8.8
[3,] 10.9 11.2
[4,] 14.3 14.2
[5,] 10.7 11.8
[6,] 6.6 6.4
[7,] 9.5 9.8
[8,] 10.8 11.3
[9,] 8.8 9.3
[10,] 13.3 13.6
 y=as.matrix(data.frame(shoes),nrows=10,ncols=2,byrow=T)
 class(y)
[1] matrix
 apply(y,1,diff)
[1] 0.8 0.6 0.3 -0.1 1.1 -0.2 0.3 0.5 0.5 0.3
 dif.mns - function(x2,tr1=.1,tr2=.2){
+ diffs=apply(x2,1,diff) 
+ mn1=mean(diffs)
+ mn2=mean(diffs,tr=.1)
+ mn3=mean(diffs,tr=.2)
+ mn4=median(diffs)
+ mns=c(mn1,mn2,mn3,mn4) 
+ list(mnds=round(mns,3))}
 dif.mns(y,tr1=.1,tr2=.2)
$mnds
[1] 0.410 0.400 0.417 0.400

 bootstrap(y,nboot=1000,theta=dif.mns)
Error in apply(x2, 1, diff) : dim(X) must have a positive length

I am not sure what I am doing wrong. When I run apply(y,1,diff) I am able to
get output, and when I run dif.mns with just the original dataset, I am also
able to get output.



--
View this message in context: 
http://r.789695.n4.nabble.com/Error-in-apply-x2-1-diff-dim-X-must-have-a-positive-length-tp4382435p4384129.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Writing output into a file

2012-02-13 Thread Rui Barradas
Hello,

 I tried writing this data into a file using the save(myList,
 file=test1.bin) command, but unfortunately, the numerical values seem
 to get garbled when I do so.

 The numbers in my RGui look like

 0, 0.5, 0, 1 etc. etc.

 But when I stored it into a .bin file, and retrieved it using java code,
 it returns data such as,


The problem should be in the use of java, 'save' uses a R format , RDA.
You can use 'ascii=TRUE'and see it with a text editor. Also see

?save

 I also tried the second method (using a # Open a file connection)

 Unfortunately, here too the data gets extremely garbled.

Don't understand why, check the output file with a text editor and let us
know
what is wrong.

The problem I've seen is that the use of 'strsplit' coerses the numeric data
to character,
but this is easy to solve.

Does your list have sub-lists?

Rui Barradas

--
View this message in context: 
http://r.789695.n4.nabble.com/Writing-output-into-a-file-tp4382243p4383741.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] logical operator for different dimensions

2012-02-13 Thread uday
Hi  Petr,

You were correct ,  thats was the mistake . I am sorry for last reply. now
its working. 


Cheers 
Uday  

--
View this message in context: 
http://r.789695.n4.nabble.com/logical-operator-for-different-dimensions-tp4383316p4384143.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to import time-series data

2012-02-13 Thread RichardSmith

Gabor Grothendieck wrote
 
 Try this xyplot.zoo lattice graph.   Time series are represented in
 columns so we transpose the data and convert it to zoo.  The screen=
 argument available in xyplot.zoo groups series into panels:
 
 Lines - plant,aphid,1,2,3,4
 pumpkin,1-2,0.065566,0.057844,0.08,0.086879
 pumpkin,1-3,0.107612,0.097272,0.11663,0.160499
 squash,1-4,0.126939,0.115003,0.140275,0.188829
 
 library(zoo)
 library(lattice)
 DF - read.csv(text = Lines)
 z - zoo(t(DF[3:6]))
 colnames(z) - DF$aphid
 xyplot(z, screen = DF$plant)
 

Thank you! That gets the data in exactly the shape I was expecting. I was
hoping to get the graph showing all lines on one plot, but coloured
according to plant. I tried to change screen=DF$plant for groups=DF$plant,
but it doesn't work, and I can't figure out from the documentation why it
doesn't work (I think I need to more thoroughly understand data types
first). Could you point me in the right direction?

Thanks so much for your help so far.

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-import-time-series-data-tp4381372p4383740.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] non linear quantile regression - Median not plotting where it should

2012-02-13 Thread Dan Morovitz
Hi,


I'm attempting to calculate the 0.25 and 0.97 quantiles for tree height (0-50 
meters) against tree age (0-300 years) and I am running into some difficulty 
with the plotted grafic. I've run the examples in the quantreg help and can get 
those to work properly and by plugging in my data I can also get the lines 
plotted on my dataset. Unfortunately I'm running into a problem with the median 
and other regression lines with tree age younger than 50 years, basically the 
median is in this range overestimated and even comes out of the rage of 
oberservations. here is the code I'm using.


# then fit the median using nlrq

spruce.nlrq - nlrq(height ~ SSlogis(age, Asym, mid, scal),data=spruce, 
tau=0.5, trace=TRUE)
lines(1:200, predict(spruce.nlrq, newdata=list(age=1:200)), col=2)


I believe  this has something to do with the SSlogis, as this gives the 
parameters for an S curve.  My data set does not have the typical S curve 
shape, instead you could image it as starting at the inflection point of an S 
curve. This is what I expect the .025 quantile to be similar to:

x - seq(1,100,1)
plot(log(x))


the 0,975 should also have a logarithmic shape but no such a steep incline.  
Ive tried using different self starting models as found under:

apropos(^ss)

      
however I have not gotten them to work, or at least to fix the problem. Curves 
similar to mine look like these site index curves:
http://www.extension.umn.edu/distribution/naturalresources/components/3473-13.html

In the example from the nlrq help the lines of the median and the various 
quantiles all start from the same location, tha is basically (x=0, y=0) in the 
coodinate plane.  With my problem, the lines start to be drawn from various 
different positions ( the lines always start at age(x)=0, but the height(y) can 
range between 0 and 15).
Additionally, the data set is quite large. with about 50,000 oberservations on 
age and height.
Does anyone have a suggestion on how to fix this problem?
Thanks in advance
Dan

[[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] Two surfaces in one plot with visibility

2012-02-13 Thread Sebastian Schubert
Hi,

I would like plot two surfaces which are each given by vectors x and y,
and a matrix m(x,y) representing the z coordinate. With persp() I can
plot both, using par(new=TRUE) I can put it in one plot. However, I
would like to have the visibility of the surfaces taken into account as
if they are solid thin surfaces, so that for example the order of the
plot commands does not matter.

Any idea how to do that?

Thanks a lot,

Sebastian



signature.asc
Description: OpenPGP digital signature
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] MCMCglmm with cross-classified random effects

2012-02-13 Thread Agostino Moro
Dear R-users,

I would like to fit  a glmm with cross-classified random effects with
the function MCMCglmm. Something along the lines:

model1-MCMCglmm(response~pred1, random=~re1+re2, data=data)

where re1 and re2 should be crossed random effects. I was wondering
whether you could tell me specifying cross-classified random effects
in MCMCglmm requires a particular syntax? Are there any examples
somewhere? I have had a look at the manual and the package vignette,
but I have not been able to find any examples relevant to what I want
to do.

Thanks,

Agostino

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Deleting rows and columns containing NA's and only

2012-02-13 Thread syrvn
Hello,

I use read.xls from the gdata package to read in xlsx files. Sometimes these
data.frames contain NA columns
and rows only. I know how to get rid of those ones but here is the R output
of a test data set read in with read.xls

 t1
 A  B X D   X.1 X.2
1 test  1 NANA
2 NA   asdNA  asdasdNA
3  NA  asdasdNA
4  NANA NA

t1[1,2], t1[4,5] and t1[4,6] are NA in text form in the excel sheet. I don't
understand why in the first column it is NA while in the last two is not.
I basically want to get rid of column 5 and 6 and row 4 as they do not
contain any relevant information. If i do a is.na.data.frame(t1):

 is.na.data.frame(t1)
 A BX D  X.1   X.2
[1,] FALSE FALSE TRUE FALSE TRUE FALSE
[2,]  TRUE FALSE TRUE FALSE TRUE FALSE
[3,] FALSE FALSE TRUE FALSE TRUE FALSE
[4,] FALSE FALSE TRUE FALSE TRUE FALSE

does not give me the result I hoped to get.

It seems that NA and NA are treated as NA but in t1[4,6] it is treated as
FALSE because if I do

 as.character(t1[4,6])
[1] NA 

one can see that there is a whitespace after NA which is, however, not in
the excel sheet for sure.

I do not know how to deal with that...

Cheers

--
View this message in context: 
http://r.789695.n4.nabble.com/Deleting-rows-and-columns-containing-NA-s-and-only-tp4384173p4384173.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread Martin Batholdy
Ok, I am sorry,

My trainingset consists of a 60 x 204 matrix (independent_training – 204 
features).
I have 60 continuous labels (dependent_training, ranging from 2.25 to 135).

this is all the code I use:

library(kernlab)
rvm(as.matrix(independent_training), dependent_training, type=regression, 
kernel = vanilladot)



On 13.02.2012, at 16:40, David Winsemius wrote:

 
 On Feb 13, 2012, at 10:23 AM, Martin Batholdy wrote:
 
 Hi,
 
 For another trainingset I get this error message, which again is rather 
 cryptic to me:
 
 Just imagine how it seems to us!
 
 Setting default kernel parameters
 
 Error in array(0, c(n, p)) : 'dim' specifies too large an array
 RMate stopped at line 0 of selection
 Calls: rvm ... .local - backsolve - as.matrix - chol - diag - array
 
 You are on you way to the prize for the greatest number of cryptic (your 
 word) postings in a short interval. (And this one doesn't even have the 
 context of your posting of 8 minutes ago.)
 
 thanks for any suggestions!
 
 More details about data and code.
 
 -- 
 David Winsemius, MD
 West Hartford, CT
 

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


Re: [R] Writing output into a file

2012-02-13 Thread Suranga Kasthurirathne
Hi,

many thanks for the reply. I really appreciate it.
Since I'm still very new to R, I think I should take some time to research
what you suggested.
(I don't want to keep posting basic questions to the list all the time)

But still, thank you so much for being helpful...



On Mon, Feb 13, 2012 at 7:23 PM, Rui Barradas rui1...@sapo.pt wrote:

 Hello,

  I tried writing this data into a file using the save(myList,
  file=test1.bin) command, but unfortunately, the numerical values seem
  to get garbled when I do so.
 
  The numbers in my RGui look like
 
  0, 0.5, 0, 1 etc. etc.
 
  But when I stored it into a .bin file, and retrieved it using java code,
  it returns data such as,
 

 The problem should be in the use of java, 'save' uses a R format , RDA.
 You can use 'ascii=TRUE'and see it with a text editor. Also see

 ?save

  I also tried the second method (using a # Open a file connection)
 
  Unfortunately, here too the data gets extremely garbled.

 Don't understand why, check the output file with a text editor and let us
 know
 what is wrong.

 The problem I've seen is that the use of 'strsplit' coerses the numeric
 data
 to character,
 but this is easy to solve.

 Does your list have sub-lists?

 Rui Barradas

 --
 View this message in context:
 http://r.789695.n4.nabble.com/Writing-output-into-a-file-tp4382243p4383741.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.




-- 
Best Regards,

Suranga

[[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] Two surfaces in one plot with visibility

2012-02-13 Thread Duncan Murdoch

On 13/02/2012 9:24 AM, Sebastian Schubert wrote:

Hi,

I would like plot two surfaces which are each given by vectors x and y,
and a matrix m(x,y) representing the z coordinate. With persp() I can
plot both, using par(new=TRUE) I can put it in one plot. However, I
would like to have the visibility of the surfaces taken into account as
if they are solid thin surfaces, so that for example the order of the
plot commands does not matter.

Any idea how to do that?


That's really hard in persp().   You'd have to plot the facets of the 
surfaces from back to front, and there's no easy way to do that.
I'd recommend using rgl::persp3d, where your graphics hardware will do 
the computations of which surface is in front.


Duncan Murdoch

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


Re: [R] how to plot a nice legend?

2012-02-13 Thread William Stockhausen
Jonas,

A relatively simple way to get the legend to plot beside a graph is to use
the layout function to create two plot areas, create the graph in the
first area and the legend in the second area.  You can fool around with the
location of the legend by changing the parameters to layout:

layout(matrix(c(1,2,1,3),nrow=2,ncol=2,byrow=TRUE),widths=c(8,4),heights=c(5,10));
plot(1:10,1:10,lty=1); #main graph
plot(c(0,1),c(0,1),type='n',bty='n',ann=FALSE,xaxt='n',yaxt='n');
legend('topleft',c('txt 1','txt 2'),pch=c(21,22));
Note that you can use 'layout.show(n=3)' (no quotes, of course) after
calling layout above to let you see the 3 plot areas (you only use the
1st two in the example above).  You can spcify the plot widths/heights in
absolute units in layout using lcm().

Hope this helps.

Buck Stockhausen
***
* Dr. William T. Stockhausen  *
***
* Resource Ecology and Fisheries Management   *
* Alaska Fisheries Science Center *
* National Marine Fisheries Service   *
* National Oceanic and Atmospheric Administration *
* 7600 Sand Point Way N.E.*
* Seattle, Washington 98115-6349  *
***
* email: william.stockhau...@noaa.gov *
* voice: 206-526-4241 fax: 206-526-6723   *
* web  : http://www.afsc.noaa.gov *
***
All models are wrong, some are useful.--G.E.P. Box
Beware of geeks bearing equations.--W. Buffett
***
Disclaimer: The opinions expressed above are personal
and do not necessarily reflect official NOAA policy.




On Sun, Feb 12, 2012 at 4:07 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 On 12-02-11 9:07 PM, Jonas Stein wrote:

 Wrong? Nothing. You told R to put the legend at c(1,3)
 so it did. If you want it elsewhere you need to specify that.
 legend(-1,3, legend=c(one, two), inset=-1, xpd=NA)
 maybe, or some other location?


 ok that works fine. Now i understand how to use it.
 If i create several plots it would be nice if all legends would
 have the same distance to plots with different scaling.

 Can the legend be placed vertically centered, 1cm right to the plot aera?


 I'm not sure what position you mean, but legend(top, ...) puts it on the
 top edge of the plot, and the inset argument gives detailed positioning.
  The units aren't cm, but the grDevices package (or is it grid?) has
 functions to convert between units.

 Duncan Murdoch



  Can i include a legend like this in a standard plot like
 plot(1:10) too?
 http://www.r-bloggers.com/wp-**content/uploads/2011/03/**heatmap.pnghttp://www.r-bloggers.com/wp-content/uploads/2011/03/heatmap.png


 Yes.

 What part of that do you want to duplicate?


 The coloured squares.
 for the reader who got to this article and had the same question:
 I have just found another nice solution for a colour legend a minute ago
 http://www.r-bloggers.com/**rethinking-loess-for-binomial-**
 response-pitch-fx-strike-zone-**maps/http://www.r-bloggers.com/rethinking-loess-for-binomial-response-pitch-fx-strike-zone-maps/

 You can specify colors, symbols, labels, etc. in legend().


 can i even invent my own symbols?

 Also, please link to the original blog post, not just the figure, so that
 the author gets some credit and we can see the code used.


 sure
 http://www.r-bloggers.com/**ggheat-a-ggplot2-style-**heatmap-function/http://www.r-bloggers.com/ggheat-a-ggplot2-style-heatmap-function/

 kind regards,


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


[[alternative HTML version deleted]]

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


Re: [R] multi-regression with more than 50 independent variables

2012-02-13 Thread David L Carlson
You need to spend some time reading about multiple regression. In statistics
there is always what is possible and what is advisable. I'm not going to
address whether a regression of 57 independent variables is advisable, only
possible. For your data, it is not possible. The attached data contain only
13 observations so the maximum number of independent variables you can use
is 13. Consider the following example:

example - data.frame(y=rnorm(3), x1=rnorm(3), x2=rnorm(3), x3=rnorm(3))
lm(y~x1 + x2, example)
lm(y~x1 + x2 + x3, example)

We create four variables using random normal numbers for 3 cases (rows). The
first regression (2 independent variables works (i.e. there are no NA's).
The second produces an NA for the third independent variable. In my example,
the three random variables are not correlated with one another. In your data
there must be correlations among the 57 variables so that you are only
getting slope values for 11.

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



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of R DF
Sent: Monday, February 13, 2012 9:19 AM
To: r-help@r-project.org
Subject: [R] multi-regression with more than 50 independent variables

Hi R Users,

I am going to run a multiple linear regression with around 57 independent
variables. Each time I run the model with just 11 variables, the results
are reasonable. With increasing the number of independent variables more
than 11, the coefficients will get NA in the output.  Is there any
limitation for the number of independent variables in multiple linear
regressions in R? I attached my dataset as well as R codes below:



mlr.data- read.table(./multiple.txt,header=T)

mlr.output- lm(formula = CaV ~ SHG +  TrD+  CrH+ SPAD+ FlN+ FrN+   YT+
LA+ LDMP+B+Cu+  Zn+   Mn +   Fe+   K +  P+   N +Clay30 +Silt30 +Sand30
+Clay60 +Silt60 +Sand60 +ESP30 +NaEx30+ CEC30+Cl30+ SAR30 +KSol30+ NaSol30
+CaMgSol3 +ZnAv30 +FeAv30 +OC30 +PAv30 +KAv30 +TNV30+ pH30+ EC30 +SP30
+ESP60 +NaEx60 +CEC60  +Cl60 +SAR60 +KSol60 +NaSol60 +CaMgSol6
+ZnAv60+FeAv60 +OC60 +PAv60 +KAv60 +TNV60 +pH60 + EC60 +SP60, data=mlr.data)

summary (mlr.output)




Regards,

Reza

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


Re: [R] non linear quantile regression - Median not plotting where it should

2012-02-13 Thread Roger Koenker
Dan,

It is hard to say without being able to reproduce your example.  If you send me 
the data
I could try to advise something.

Roger

url:www.econ.uiuc.edu/~rogerRoger Koenker
emailrkoen...@uiuc.eduDepartment of Economics
vox: 217-333-4558University of Illinois
fax:   217-244-6678Urbana, IL 61801

On Feb 13, 2012, at 7:50 AM, Dan Morovitz wrote:

 Hi,
 
 
 I'm attempting to calculate the 0.25 and 0.97 quantiles for tree height (0-50 
 meters) against tree age (0-300 years) and I am running into some difficulty 
 with the plotted grafic. I've run the examples in the quantreg help and can 
 get those to work properly and by plugging in my data I can also get the 
 lines plotted on my dataset. Unfortunately I'm running into a problem with 
 the median and other regression lines with tree age younger than 50 years, 
 basically the median is in this range overestimated and even comes out of the 
 rage of oberservations. here is the code I'm using.
 
 
 # then fit the median using nlrq
 
 spruce.nlrq - nlrq(height ~ SSlogis(age, Asym, mid, scal),data=spruce, 
 tau=0.5, trace=TRUE)
 lines(1:200, predict(spruce.nlrq, newdata=list(age=1:200)), col=2)
 
 
 I believe  this has something to do with the SSlogis, as this gives the 
 parameters for an S curve.  My data set does not have the typical S curve 
 shape, instead you could image it as starting at the inflection point of an S 
 curve. This is what I expect the .025 quantile to be similar to:
 
 x - seq(1,100,1)
 plot(log(x))
 
 
 the 0,975 should also have a logarithmic shape but no such a steep incline.  
 Ive tried using different self starting models as found under:
 
 apropos(^ss)
 
   
 however I have not gotten them to work, or at least to fix the problem. 
 Curves similar to mine look like these site index curves:
 http://www.extension.umn.edu/distribution/naturalresources/components/3473-13.html
 
 In the example from the nlrq help the lines of the median and the various 
 quantiles all start from the same location, tha is basically (x=0, y=0) in 
 the coodinate plane.  With my problem, the lines start to be drawn from 
 various different positions ( the lines always start at age(x)=0, but the 
 height(y) can range between 0 and 15).
 Additionally, the data set is quite large. with about 50,000 oberservations 
 on age and height.
 Does anyone have a suggestion on how to fix this problem?
 Thanks in advance
 Dan
 
   [[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] Suggests/Enhances or .onLoad for S3-methods for optional package

2012-02-13 Thread Jon Olav Skoien

Hi,

I am developing a package B that, among other things, also offers some 
extra S3-methods for functions in package A if the user has installed A. 
I do not want to list A under Depends of B, as the dependency list of A 
is rather long, and most potential users of B will not be interested in 
package A. Unfortunately I struggle with doing this right. So far I have 
listed A under Suggests, and had a .onLoad function in B with
if (require(A)) registerS3methods(newMethodsMatrix, package = A, env = 
environment(B))
But starting with R 2.13 or R 2.14, R CMD check complain about this 
require call in .onLoad, referring to the good practice-section of 
.onAttach. I guess this could also be a problem when uploading the 
package to CRAN, so I am trying to find another solution.


So far I have tried:
List A under Suggest of B, with a conditional import in NAMESPACE.
If I build a Windows-binary from this when A is installed, this package 
can be installed but not loaded on computers where A is not installed.


List A under Enhances of B.
This seems to be the right thing, as the R extensions manual says: the 
‘Enhances’ field lists packages “enhanced” by the package at hand, e.g., 
by providing methods for classes from these packages.
However, although it seems I can install and load package B when I 
conditionally import package A in the NAMESPACE, R CMD check stops with 
the error: Namespace dependency not required: A
If I remove the import, R CMD check is happier, but I cannot load the 
package after installing.


I have read about the use of Suggest, Enhances etc in Writing R 
Extensions, but could not figure out the right way to do this. I am 
sure there is something I am missing here.


Thanks,
Jon

--
Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Land Resource Management Unit

Via Fermi 2749, TP 440,  I-21027 Ispra (VA), ITALY

jon.sko...@jrc.ec.europa.eu
Tel:  +39 0332 789206

Disclaimer: Views expressed in this email are those of the individual and do 
not necessarily represent official views of the European Commission.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread Steve Lianoglou
Hi,

On Mon, Feb 13, 2012 at 10:53 AM, Martin Batholdy
batho...@googlemail.com wrote:
 Ok, I am sorry,

 My trainingset consists of a 60 x 204 matrix (independent_training – 204 
 features).
 I have 60 continuous labels (dependent_training, ranging from 2.25 to 135).

 this is all the code I use:

 library(kernlab)
 rvm(as.matrix(independent_training), dependent_training, type=regression, 
 kernel = vanilladot)

Can you call `traceback()` after you get the error to see if you can
follow the code path that results in the explosion?

Downloading the kernlab src package will be helpful while your smoking
out the error so you can look at the entire source code, too.

In my .Rprofile, I actually have something like so:

options(error=utils:::dum.frames)

Which allows me to call `debugger()` after an error is thrown and
drops me into the location that threw the error (most of the time (I
think)), allowing me to poke around and see who's who, and what's
what.

HTH,
-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread Steve Lianoglou
Sorry, this:

 options(error=utils:::dum.frames)

Should be:

options(error=utils:::dump.frames)

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


Re: [R] Two surfaces in one plot with visibility

2012-02-13 Thread Sebastian Schubert
Hi!

On 13/02/12 17:15, Duncan Murdoch wrote:
 I would like plot two surfaces which are each given by vectors x and y,
 and a matrix m(x,y) representing the z coordinate.
[..]
 I
 would like to have the visibility of the surfaces taken into account as
 if they are solid thin surfaces, so that for example the order of the
 plot commands does not matter.

 That's really hard in persp().   You'd have to plot the facets of the
 surfaces from back to front, and there's no easy way to do that.
 I'd recommend using rgl::persp3d, where your graphics hardware will do
 the computations of which surface is in front.

Thanks a lot! Works really well and created a wow effect (especially
when comparing to the manual tuning of the theta and phi angles in
persp() ).

Great job!

Sebastian



signature.asc
Description: OpenPGP digital signature
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 import time-series data

2012-02-13 Thread Gabor Grothendieck
On Mon, Feb 13, 2012 at 8:23 AM, RichardSmith richardsmith...@gmail.com wrote:

 Gabor Grothendieck wrote

 Try this xyplot.zoo lattice graph.   Time series are represented in
 columns so we transpose the data and convert it to zoo.  The screen=
 argument available in xyplot.zoo groups series into panels:

 Lines - plant,aphid,1,2,3,4
 pumpkin,1-2,0.065566,0.057844,0.08,0.086879
 pumpkin,1-3,0.107612,0.097272,0.11663,0.160499
 squash,1-4,0.126939,0.115003,0.140275,0.188829

 library(zoo)
 library(lattice)
 DF - read.csv(text = Lines)
 z - zoo(t(DF[3:6]))
 colnames(z) - DF$aphid
 xyplot(z, screen = DF$plant)


 Thank you! That gets the data in exactly the shape I was expecting. I was
 hoping to get the graph showing all lines on one plot, but coloured
 according to plant. I tried to change screen=DF$plant for groups=DF$plant,
 but it doesn't work, and I can't figure out from the documentation why it
 doesn't work (I think I need to more thoroughly understand data types
 first). Could you point me in the right direction?


1. Try this which uses lattice zoo graphics:

xyplot(z, screen = 1, col = DF$plant)

or with a legend:

key - list(space = top,  text = levels(DF$plant), points = FALSE,
lines = TRUE, col = 1:nlevels(DF$plant))
xyplot(z, screen = 1, col = DF$plant, auto.key = key)

2. or using classic zoo graphics

plot(z, screen = 1, col = DF$plant)

To add a legend:

legend(topleft, legend = levels(DF$plant), col = 1:nlevels(DF$plant), lty = 1)

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Deleting rows and columns containing NA's and only

2012-02-13 Thread Petr Savicky
On Mon, Feb 13, 2012 at 07:48:11AM -0800, syrvn wrote:
 Hello,
 
 I use read.xls from the gdata package to read in xlsx files. Sometimes these
 data.frames contain NA columns
 and rows only. I know how to get rid of those ones but here is the R output
 of a test data set read in with read.xls
 
  t1
  A  B X D   X.1 X.2
 1 test  1 NANA
 2 NA   asdNA  asdasdNA
 3  NA  asdasdNA
 4  NANA NA
 
 t1[1,2], t1[4,5] and t1[4,6] are NA in text form in the excel sheet. I don't
 understand why in the first column it is NA while in the last two is not.
 I basically want to get rid of column 5 and 6 and row 4 as they do not
 contain any relevant information. If i do a is.na.data.frame(t1):
 
  is.na.data.frame(t1)
  A BX D  X.1   X.2
 [1,] FALSE FALSE TRUE FALSE TRUE FALSE
 [2,]  TRUE FALSE TRUE FALSE TRUE FALSE
 [3,] FALSE FALSE TRUE FALSE TRUE FALSE
 [4,] FALSE FALSE TRUE FALSE TRUE FALSE
 
 does not give me the result I hoped to get.
 
 It seems that NA and NA are treated as NA but in t1[4,6] it is treated as
 FALSE because if I do
 
  as.character(t1[4,6])
 [1] NA 

Hi.

I do not know, how NA  appeared, however, it is possible
to change them to real NA as follows.

  # some data frame
  df - structure(list(a = c(NA, 2L, 3L, 4L), b = c(a, NA, c, NA ),
c = structure(c(1L, 2L, NA, 4L), .Label = c(e, f, g, h),
class = factor)), .Names = c(a, b, c), row.names = c(NA, -4L),
class = data.frame)
  df

 abc
  1 NAae
  2  2 NAf
  3  3c NA
  4  4  NA h

  df[4, 2] # this is not NA, but NA 

  [1] NA 

  # replace all NA  by NA in column 2

  df[which(df[,2] == NA ), 2] - NA
  df

 abc
  1 NAae
  2  2 NAf
  3  3c NA
  4  4 NAh

Hope this helps.

Petr Savicky.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Error in apply(x2, 1, diff) : dim(X) must have a positive length

2012-02-13 Thread R. Michael Weylandt
What package is the bootstrap() function from? There are many
functions by that name

My hunch is that it takes a vector at a time and puts it through
dif.mns so that leads to the error in the apply() call but I can't
verify.

Michael

On Mon, Feb 13, 2012 at 10:34 AM, hithit168 ccchri...@live.com wrote:
 Thank you for your help, David. I was trying to run bootrapping on the
 dataset shoes from MASS package. But I still have some problem here.

 as.matrix(data.frame(shoes),nrows=10,ncols=2,byrow=T)
 A B
 [1,] 13.2 14.0
 [2,] 8.2 8.8
 [3,] 10.9 11.2
 [4,] 14.3 14.2
 [5,] 10.7 11.8
 [6,] 6.6 6.4
 [7,] 9.5 9.8
 [8,] 10.8 11.3
 [9,] 8.8 9.3
 [10,] 13.3 13.6
 y=as.matrix(data.frame(shoes),nrows=10,ncols=2,byrow=T)
 class(y)
 [1] matrix
 apply(y,1,diff)
 [1] 0.8 0.6 0.3 -0.1 1.1 -0.2 0.3 0.5 0.5 0.3
 dif.mns - function(x2,tr1=.1,tr2=.2){
 + diffs=apply(x2,1,diff)
 + mn1=mean(diffs)
 + mn2=mean(diffs,tr=.1)
 + mn3=mean(diffs,tr=.2)
 + mn4=median(diffs)
 + mns=c(mn1,mn2,mn3,mn4)
 + list(mnds=round(mns,3))}
 dif.mns(y,tr1=.1,tr2=.2)
 $mnds
 [1] 0.410 0.400 0.417 0.400

 bootstrap(y,nboot=1000,theta=dif.mns)
 Error in apply(x2, 1, diff) : dim(X) must have a positive length

 I am not sure what I am doing wrong. When I run apply(y,1,diff) I am able to
 get output, and when I run dif.mns with just the original dataset, I am also
 able to get output.



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Error-in-apply-x2-1-diff-dim-X-must-have-a-positive-length-tp4382435p4384129.html
 Sent from the R help mailing list archive at Nabble.com.

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

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


[R] Including .exe files in an R package

2012-02-13 Thread sahir bhatnagar
I am in the process of creating a package in R which calls
pre-compiled C code i.e. '.exe' files

In reading the manual, I came across this:

A source package if possible should not contain binary executable
files: they are not portable, and a security risk if they are of the
appropriate architecture. R CMD check will warn about them2 unless
they are listed (one filepath per line) in a file ‘BinaryFiles’ at the
top level of the package. Note that CRAN will no longer accept
submissions containing binary files even if they are listed.

From my understanding, the .exe files are a subset of binary files,
which are no longer accepted by CRAN. If this is the case for my
situation, is there any other way to include the C code, so that CRAN
will accept the package?

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] pairwise comparisons with multcomp package

2012-02-13 Thread gaiarrido
Hi,
I've got this model and following Hothorn et al advices, I used glht for a
post hoc comparison


 modezqM-glm(rojos~estacion*zona3,quasipoisson,subset=(edadysexo==M))
 anova(modezqM,test=F) 
 Df  Deviance  Resid. Df Resid.
Dev   F   Pr(F)
NULL293 41148  
estacion  1 3647.0   292 37501  
 
23.6250  1.927e-06 ***
zona3  2   931.4   290 36569
 
3.0167   0.050510.  
estacion:zona3  2 2421.7   28834148 
7.84380.000482 ***  


 summary(glht(modezqM,linfct=mcp(zona3=Tukey,interaction_average=T))) 
   Estimate   Std. Error  z-value  
Pr(|z|)  
norte - turist == 0 -0.051820.23701  -0.219 0.9727  
occid - turist == 0 -1.059700.41618  -2.546 0.0271 *
occid - norte == 0 -1.007880.45830  -2.199 0.0665 .

I'm trying to understanding the way this command made pairwise comparisons,
but, where does this z-value comes from?  
I'm suspected this not come from Tukey's test, but i don't know it's Wald or
something i've never use
I know it is not an habitual doubt.
Sorry and thanks in advance

I suspect it


-
Mario Garrido Escudero
PhD student
Dpto. de Biología Animal, Ecología, Parasitología, Edafología y Qca. Agrícola
Universidad de Salamanca
--
View this message in context: 
http://r.789695.n4.nabble.com/pairwise-comparisons-with-multcomp-package-tp4384499p4384499.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] Cumulative density (kernel smoothing)

2012-02-13 Thread francogrex
Hi, in R there is the function density which computes kernel density
estimates. Is there a cumulative version of it? Something like they have
in Matlab:
http://www.mathworks.nl/help/toolbox/stats/ksdensity.html
I know there is ecdf, but I'm not sure it's based on kernel density
smoothing. Thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/Cumulative-density-kernel-smoothing-tp4384652p4384652.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Deleting rows and columns containing NA's and only

2012-02-13 Thread syrvn
Hi,

thanks for you suggestion.

I finally solved it in a different way using apply and is.na for TRUE NA's
and if(as.character(x) == NA) etc.

However, I just spotted that read.xls seems to have problems reading in
special characters such as  or .

Is there any workaround for that?

--
View this message in context: 
http://r.789695.n4.nabble.com/Deleting-rows-and-columns-containing-NA-s-and-only-tp4384173p4384663.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Including .exe files in an R package

2012-02-13 Thread Prof Brian Ripley

On 13/02/2012 17:15, sahir bhatnagar wrote:

I am in the process of creating a package in R which calls
pre-compiled C code i.e. '.exe' files


Which are only used on Windows, so presumably you forgot to mention that OS.


In reading the manual, I came across this:

A source package if possible should not contain binary executable
files: they are not portable, and a security risk if they are of the
appropriate architecture. R CMD check will warn about them2 unless
they are listed (one filepath per line) in a file ‘BinaryFiles’ at the
top level of the package. Note that CRAN will no longer accept
submissions containing binary files even if they are listed.


From my understanding, the .exe files are a subset of binary files,

which are no longer accepted by CRAN. If this is the case for my
situation, is there any other way to include the C code, so that CRAN
will accept the package?


CRAN will neither accept packages with binary code files, nor will it 
accept packages tied to one architecture and OS (as such files would 
be).  You can do what you like provided you do not want to distribute 
the package: at that point you need to meet the conditions of the 
license and of the repository.


There are several examples of CRAN packages which compile up 
executables: arulesSequences is one.  But note that this is tricky as 
platforms such as Windows and OS X support multiple architectures in the 
same package installation.



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.


And that does make clear that this is (or would rapidly become) a 
R-devel topic.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
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 code.


[R] Logistic regression with non-gaussian random effects

2012-02-13 Thread Line Skotte
Hi,
does anyone know of an implementation of generalized linear models with random 
effects, where the random effects are non-gaussian?

Actually, what I need is to do a logistic regression (or binomial regression) 
where the linear predictor in addition to fixed effects and gaussian random 
effects also has a term

b*z

where z is a random effect variable with p(z=1)=p(z=-1)=0.5 and b is a 
parameter of interest. 

I am very grateful to you for any help or comments.

Sincerely,
Line
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Error in apply(x2, 1, diff) : dim(X) must have a positive length

2012-02-13 Thread hithit168
Thanks.

I use the bootstrap() function from the bootstrap package. Let me try it
again to see if I get any luck :)

--
View this message in context: 
http://r.789695.n4.nabble.com/Error-in-apply-x2-1-diff-dim-X-must-have-a-positive-length-tp4382435p4384608.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] non-isomorphic sequences

2012-02-13 Thread zheng wei
Dear All,

Sorry for the typoes earlier, let me repost the question.

Suppose I want to generate sequences of length 3 from two symbols {1,2}, we get 
the following 8 sequences
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2

However, I do not want all these 8 sequences. I call two sequencs to be 
isomorphic if one sequence could be obtained from the other by relabelling the 
symbols. For example, 111 is isomorphic to 222, 112 is isomorphic to 221. By 
eliminating all these isomorphic ones, what I want is the following
1 1 1
1 1 2
1 2 1
2 1 1

In general, I need to generate non-isomorphic sequences of length p from t 
distinct symbols. For example, when p=3, t=3 we have
matrix(c(1,2,3,1,1,2,2,1,1,1,2,1,1,1,1),3,5)

[1,]    1    1    2    1    1
[2,]    2    1    1    2    1
[3,]    3    2    1    1    1

When p=4, t=4 we have
matrix(c(1,2,3,4,1,1,2,3,1,2,1,3,1,2,3,1,2,1,1,3,2,3,1,1,2,1,3,1,1,1,2,2,1,2,1,2,1,2,2,1,1,1,1,2,1,1,2,1,1,2,1,1,2,1,1,1,1,1,1,1),4,15)

[1,]    1    1    1    1    2    2    2    1    1 1 1 1 1 
2 1
[2,]    2    1    2    2    1    3    1    1    2 2 1 1 2 
1 1
[3,]    3    2    1    3    1    1    3    2    1 2 1 2 1 
1 1
[4,]    4    3    3    1    3    1    1    2    2 1 2 1 1 
1 1


In general, I need to do this for arbitrary choices of p and t.

Thaks a lot,
Wei
[[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] best subset selection on random effects model

2012-02-13 Thread ilai
The question is where do your models come from? Passing nested models
to ?anova.lme in nlme package or lme4 results in a likelihood ratio
test. Are you looking for something else/more ?


On Sun, Feb 12, 2012 at 8:02 PM, Tao Zhang zt020...@gmail.com wrote:
 Hi,
     I know leaps() computes the best subset selection for linear model,
 and the bestglm() computes the best subset selection for generalized linear
 model.
 Is there any package for best subset selection on random effects model, or
 mixed effects model?

 Thank you so much.

 Tao

        [[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] Cumulative density (kernel smoothing)

2012-02-13 Thread David Winsemius


On Feb 13, 2012, at 1:01 PM, francogrex wrote:


Hi, in R there is the function density which computes kernel density
estimates. Is there a cumulative version of it? Something like  
they have

in Matlab:


I'm not aware of one, but you could use `integrate`. You will need to  
limit your range or use the version in package  logspline if your  
range is fixed. You will also need to account for the fact that the  
inteegral will only be approximately == 1. Searching the Archives will  
bring up several similar questions from prior years.\

http://www.mathworks.nl/help/toolbox/stats/ksdensity.html
I know there is ecdf, but I'm not sure it's based on kernel density
smoothing. Thanks



`ecdf` is not based on density.

--

David Winsemius, MD
West Hartford, CT

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


[R] for loop

2012-02-13 Thread eddie smith
Hi guys,

This is a very beginner question. Anybody willing to help?

for(i in 1:1000)
x=29.5 + i/500
y=2x
plot(y,x)

The idea is to produce 1000 values of x and y then plot them.

Cheers,
Eddie

[[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] for loop

2012-02-13 Thread jim holtman
x - 29.5 + (1:1000)/500
y - 2 * x
plot(y,x)

On Mon, Feb 13, 2012 at 1:34 PM, eddie smith eddie...@gmail.com wrote:
 Hi guys,

 This is a very beginner question. Anybody willing to help?

 for(i in 1:1000)
 x=29.5 + i/500
 y=2x
 plot(y,x)

 The idea is to produce 1000 values of x and y then plot them.

 Cheers,
 Eddie

        [[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
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Deleting rows and columns containing NA's and only

2012-02-13 Thread David Winsemius


On Feb 13, 2012, at 1:05 PM, syrvn wrote:


Hi,

thanks for you suggestion.

I finally solved it in a different way using apply and is.na for  
TRUE NA's

and if(as.character(x) == NA) etc.

However, I just spotted that read.xls seems to have problems reading  
in

special characters such as  or .


Or could it be that you have problems in not reading the help pages  
carefully?


 read.table(text=NA)
V1
1 NA

 read.table(text=NA, na.strings=c(NA,NA))
  V1
1 NA

--

David Winsemius, MD
West Hartford, CT

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


[R] meboot - can it handle outliers and missing values?

2012-02-13 Thread isabella
 

Hi everyone, 

I would like to use your meboot package in R in a power simulation
study, where meboot stands for Maximum Entropy Bootstrap.

In this study, each time series that will be bootstrapped includes
both missing values and outliers.

Can meboot accomodate these two features, which are the hallmark of
many real time series?  If yes, I would very much appreciate your
thoughts on how this can be achieved in R.   

Many thanks and kind regards,  

Isabella  

Isabella R. Ghement, Ph.D. 
 Ghement Statistical Consulting Company 
 301-7031 Blundell Road, Richmond, B.C., Canada, V6Y 1J5 
 Tel: 604-767-1250 
 Fax: 604-270-3922 
 E-mail: isabe...@ghement.ca 
 Web: www.ghement.ca 
 
[[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] only 0s may be mixed with negative subscripts

2012-02-13 Thread Hasan Diwan
I'd like to get the sum of every other row in a data.frame. When I
actually set about doing this, I get the error in the subject line of
this message. A sample of my data is below, followed by the function
call that should give me the results I want:

 dput(head(sens2))
structure(list(Time = c(1328565067, 1328565067.05, 1328565067.1,
1328565067.15, 1328565067.2, 1328565067.25), Y = c(0.0963890795246276,
0.227296347215609, 0.240972698811569, 0.221208948983498, 0.230898231782485,
0.203282153087549), X = c(0.0245045248243853, 0.0835679411703579,
0.0612613120609633, 0.058568910563872, 0.0511868450318788, 0.0557714205674231
), rownumber = 1:6), .Names = c(Time, Y, X, rownumber
), row.names = c(NA, 6L), class = data.frame)
 speedX - sapply(sens2[sens2$rownumber %% 2 == 0,], function(row) { 
 cumsum(c(sens2[row+1,3], sens2[row,3]))}, simplify=TRUE)
Error in xj[i] : only 0's may be mixed with negative subscripts
Help?
-- 
Sent from my mobile device
Envoyait de mon portable

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

2012-02-13 Thread rmailbox
This is how I get a whole SPSS data files into R. You specifically asked about 
the codebook, so this may not be exactly what you are after. 
 
spssFileInfo - spss.system.file ( file = path to my SPSS file )
spssDataSet - as.data.set ( spssFileInfo)
spssDataFrame - as.data.frame ( spssDataSet )

(Not tested. Adapted from working code.) 

memisc documentation has more info about doing this and how it works.

eRic




- Original message -
From: barny garyb.dav...@btinternet.com
To: r-help@r-project.org
Date: Sat, 11 Feb 2012 10:04:16 -0800 (PST)
Subject: Re: [R] Getting codebook data into R

Hi Eric - after seeing the difficulty of inputting this kind of data into R I
decided to use your method. It was rather painless using PSPP to do what I
wanted - however, how do I now create an SPSS file and then use the memisc
package to read it in?

--
View this message in context: 
http://r.789695.n4.nabble.com/Getting-codebook-data-into-R-tp4374331p4379433.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] Deleting rows and columns containing NA's and only

2012-02-13 Thread syrvn
Hi David,

I am using read.xls not read.table.

--
View this message in context: 
http://r.789695.n4.nabble.com/Deleting-rows-and-columns-containing-NA-s-and-only-tp4384173p4384866.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] Puzzling... puzzling... puzzling...

2012-02-13 Thread Michael
 Hi all,

I made sure that it's env$sRes1$nPositionsOptimizedM that's correct...

not the env$sRes1$nPositionsOptimized...

But it seems both point to the same memory area...

This is very dangerous because I have used naming conventions such as:

MyLongVariableNameForA
 MyLongVariableNameForB
 MyLongVariableNameForC
...
...

Then if internally they are actually the same thing then all my programs
messed up...

Any thoughts?

env=new.env()

load(MyResults.rData, env)

identical(env$sRes1$nPositionsOptimized, env$sRes1$nPositionsOptimizedM)

[1] TRUE

[[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] Deleting rows and columns containing NA's and only

2012-02-13 Thread David Winsemius


On Feb 13, 2012, at 1:57 PM, syrvn wrote:


Hi David,

I am using read.xls not read.table.


Please read the help page for read.xls more carefully.



--
View this message in context: 
http://r.789695.n4.nabble.com/Deleting-rows-and-columns-containing-NA-s-and-only-tp4384173p4384866.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.


David Winsemius, MD
West Hartford, CT

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


Re: [R] for loop

2012-02-13 Thread Ted Harding
In addition to Jim's neat solution (see also below),
some comments on your original code.

Your for loop executes x=29.5 + i/500 100 times,
producing a single value each time and replacing the
previous value which was in x. So, at the end of the loop,
you have a single value of x. Then you compute y=2x;
that, as it stands, would prokoke an error:

  Error: unexpected symbol in y=2x

since variable names cannort start with a digit. You
need, of course, the mutltiplaction operator * as
in Jim's y - 2 * x.

The scope of your for loop (i.e. the set of commands
that is executed for each round of the loop) is solely
the command x=29.5 + i/500. The y - 2 * x is not
part of the scope of the loop, and would only be executed
once, when the loop was finished. You would need

   for(i in 1:1000) {
 commands
   }

to cause the execution of several commands in each round
of the loop.

Finally, even if you did think that your entire series of
commands (re-written):

  for(i in 1:1000)
  x=29.5 + i/500
  y=2*x
  plot(y,x)

would all be executed (down to and including the plot() command)
in each round of the loop, nevertheless each call to plot()
creates a new graph, discarding the previous one, so only a single
point would be plotted each time.

The solution (as in Jim's suggestion) is to create the full vector
of x-values and y-values, and then use plot(x,y) where x and y are
now vectors.

There are all sorts of little details about how R puts things
together, which will become familiar as you use R. However,
you do need to get hold of the basics of how R operates, so
I would suggest having R for Beginners

  http://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf

to hand while you learn R. It is very good about how the basics
work. The next step up would be the more systematic exposition
of how R works in  An Introduction to R:

  http://cran.r-project.org/doc/manuals/R-intro.html
  http://cran.r-project.org/doc/manuals/R-intro.pdf

Hoping this helps!
Ted.

On 13-Feb-2012 jim holtman wrote:
 x - 29.5 + (1:1000)/500
 y - 2 * x
 plot(y,x)
 
 On Mon, Feb 13, 2012 at 1:34 PM, eddie smith eddie...@gmail.com wrote:
 Hi guys,

 This is a very beginner question. Anybody willing to help?

 for(i in 1:1000)
 x=29.5 + i/500
 y=2x
 plot(y,x)

 The idea is to produce 1000 values of x and y then plot them.

 Cheers,
 Eddie

 _ _ _ _[[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
 Data Munger Guru
 
 What is the problem that you are trying to solve?
 Tell me what you want to do, not how you want to do it.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

-
E-Mail: (Ted Harding) ted.hard...@wlandres.net
Date: 13-Feb-2012  Time: 19:12:47
This message was sent by XFMail

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

2012-02-13 Thread Duncan Murdoch

On 13/02/2012 2:00 PM, Michael wrote:

  Hi all,

I made sure that it's env$sRes1$nPositionsOptimizedM that's correct...

not the env$sRes1$nPositionsOptimized...

But it seems both point to the same memory area...


How did you determine that?  The test below just shows that they contain 
the same thing.



This is very dangerous because I have used naming conventions such as:

MyLongVariableNameForA
  MyLongVariableNameForB
  MyLongVariableNameForC
...
...

Then if internally they are actually the same thing then all my programs
messed up...

Any thoughts?

env=new.env()

load(MyResults.rData, env)

identical(env$sRes1$nPositionsOptimized, env$sRes1$nPositionsOptimizedM)

[1] TRUE


Changing one of them and seeing the other one change would show that 
they point to the same memory area.  This can happen with environments:  
if you create env1 and set env2 - env1, then changes to either 
environment will affect the other, because that's how environments 
work.   That's not true of most of the other kinds of objects in R.  
(The exceptions are fairly exotic things that you are unlikely to use.)


Duncan Murdoch

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


[R] R's AIC values differ from published values

2012-02-13 Thread david hamer
Using the Cement hardening data in Anderson (2008) Model Based Inference in
the Life Sciences. A Primer on Evidence, and working with the best model
which is
lm  (  y  ~   x1   +   x2,data = cement  )
the AIC value from R is

model-lm  ( formula   =   y   ~   x1   +  x2  ,   data =
cement  )
AIC ( model )

64.312

which can be converted to AICc by adding the bias correction factor
2*K*(K+1)/(n-K-1) to give the AICc value of
69.312
(addition of 5, where n=13 and K=4).

This same value, 69.31, can be obtained using R package
AICcmodavg

   library  (  AICcmodavg  )
   data (cement)
   cement
   Cand.models   -   list( )
   Cand.models[[1]]   -   lm  (  y  ~   x1   +   x2,data = cement  )
   Cand.models[[2]]   -   lm  (  y~   x3   +   x4, data = cement  )
   Cand.models[[3]]   -   lm  (  y   ~   x1 + x2 + x1 * x2,   data =
cement  )
   Cand.models[[4]]   -   lm  (  y   ~   x3  +  x4  +  x3 * x4,   data =
cement  )
 ##   vector of model names
   Modnames   -   paste(MODEL, 1:4, sep= )
 ##   AICc
   aictab   (  cand.set   =   Cand.models,   modnames  =  Modnames  )

However, the AICc value reported by Anderson (2008) is
32.41.
The AICc value obtained using RSS value (i.e., calculating AICc manually
from the output of linear regression) is
32.41.

Thanks for any help.
David
New R user, minimal familiarity with statistics.

[[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] Question scatterplot axis cut point

2012-02-13 Thread Michael Methlagl
Hi everybody,
i made a scatterplot using the command
plot (datafile1, xlim=c(0,10), ylim=c(0.001, 1), log=y, xlab=x Achse, 
ylab=y Achse, frame.plot=FALSE, axes = TRUE).
Now i  have a problem. There is a gap between the x and the y axis. I want that 
the x and y axis cut at 0 and 0.001 without having this gap.
Is this possible?
thanks for your help!
nice greetings michi
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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's AIC values differ from published values

2012-02-13 Thread Bert Gunter
This is answered in ?AIC. Have you read it?

-- Bert

On Mon, Feb 13, 2012 at 10:22 AM, david hamer j.david.ha...@gmail.com wrote:
 Using the Cement hardening data in Anderson (2008) Model Based Inference in
 the Life Sciences. A Primer on Evidence, and working with the best model
 which is
    lm  (  y  ~   x1   +   x2,    data = cement  )
 the AIC value from R is

    model    -    lm  ( formula   =   y   ~   x1   +  x2  ,   data =
 cement  )
    AIC ( model )

 64.312

 which can be converted to AICc by adding the bias correction factor
 2*K*(K+1)/(n-K-1) to give the AICc value of
 69.312
 (addition of 5, where n=13 and K=4).

 This same value, 69.31, can be obtained using R package
 AICcmodavg

   library  (  AICcmodavg  )
   data (cement)
   cement
   Cand.models   -   list( )
   Cand.models[[1]]   -   lm  (  y  ~   x1   +   x2,    data = cement  )
   Cand.models[[2]]   -   lm  (  y    ~   x3   +   x4,     data = cement  )
   Cand.models[[3]]   -   lm  (  y   ~   x1 + x2 + x1 * x2,   data =
 cement  )
   Cand.models[[4]]   -   lm  (  y   ~   x3  +  x4  +  x3 * x4,   data =
 cement  )
     ##   vector of model names
   Modnames   -   paste(MODEL, 1:4, sep=     )
     ##   AICc
   aictab   (  cand.set   =   Cand.models,   modnames  =  Modnames  )

 However, the AICc value reported by Anderson (2008) is
 32.41.
 The AICc value obtained using RSS value (i.e., calculating AICc manually
 from the output of linear regression) is
 32.41.

 Thanks for any help.
 David
 New R user, minimal familiarity with statistics.

        [[alternative HTML version deleted]]

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


Re: [R] Puzzling... puzzling... puzzling...

2012-02-13 Thread William Dunlap
Replace the syntax List$Name with List[[Name]]
and see if things work better.

'[[' does not do the partial matching that '$' does.
E.g.,
   x - list(AB=10, BC=20, CD=30)
   x$A # returns 10 because A is the initial part of exactly one name in x, 
AB
   x[[A]] # returns NULL

However, if you have
   y - list(AB=1, AC=2, AD=3)
then y$A will return NULL because there is not a unique partial
match to A among the names of y.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Michael
 Sent: Monday, February 13, 2012 11:00 AM
 To: r-help
 Subject: [R] Puzzling... puzzling... puzzling...
 
  Hi all,
 
 I made sure that it's env$sRes1$nPositionsOptimizedM that's correct...
 
 not the env$sRes1$nPositionsOptimized...
 
 But it seems both point to the same memory area...
 
 This is very dangerous because I have used naming conventions such as:
 
 MyLongVariableNameForA
  MyLongVariableNameForB
  MyLongVariableNameForC
 ...
 ...
 
 Then if internally they are actually the same thing then all my programs
 messed up...
 
 Any thoughts?
 
 env=new.env()
 
 load(MyResults.rData, env)
 
 identical(env$sRes1$nPositionsOptimized, env$sRes1$nPositionsOptimizedM)
 
 [1] TRUE
 
   [[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] R's AIC values differ from published values

2012-02-13 Thread Mark Leeds
hi: the definition of AIC can vary a lot from paper to paper and textbook
to textbook because some people keep the multiplicative constants and
other's don't. all that matters when using AIC is COMPARISON. the value
itself means nothing. So, you'll be fine no matter what
you use as long as you're consistent.




On Mon, Feb 13, 2012 at 1:22 PM, david hamer j.david.ha...@gmail.comwrote:

 Using the Cement hardening data in Anderson (2008) Model Based Inference in
 the Life Sciences. A Primer on Evidence, and working with the best model
 which is
lm  (  y  ~   x1   +   x2,data = cement  )
 the AIC value from R is

model-lm  ( formula   =   y   ~   x1   +  x2  ,   data =
 cement  )
AIC ( model )

 64.312

 which can be converted to AICc by adding the bias correction factor
 2*K*(K+1)/(n-K-1) to give the AICc value of
 69.312
 (addition of 5, where n=13 and K=4).

 This same value, 69.31, can be obtained using R package
 AICcmodavg

   library  (  AICcmodavg  )
   data (cement)
   cement
   Cand.models   -   list( )
   Cand.models[[1]]   -   lm  (  y  ~   x1   +   x2,data = cement  )
   Cand.models[[2]]   -   lm  (  y~   x3   +   x4, data = cement  )
   Cand.models[[3]]   -   lm  (  y   ~   x1 + x2 + x1 * x2,   data =
 cement  )
   Cand.models[[4]]   -   lm  (  y   ~   x3  +  x4  +  x3 * x4,   data =
 cement  )
 ##   vector of model names
   Modnames   -   paste(MODEL, 1:4, sep= )
 ##   AICc
   aictab   (  cand.set   =   Cand.models,   modnames  =  Modnames  )

 However, the AICc value reported by Anderson (2008) is
 32.41.
 The AICc value obtained using RSS value (i.e., calculating AICc manually
 from the output of linear regression) is
 32.41.

 Thanks for any help.
 David
 New R user, minimal familiarity with statistics.

[[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] nice report generator?

2012-02-13 Thread Duncan Murdoch

On 06/02/2012 4:12 PM, Hadley Wickham wrote:

  2. It's more flexible to construct the language object as a language object,
  rather than pasting something together and parsing it.  For one thing, that
  allows non-syntactic variable names; I think it's also easier to read.  So
  your code

  txt- paste(tabular(value*v*, LEFT , ~ ,RIGHT ,, data = m_xx,
  suppressLabels  = 2,...), sep = )
  eval(parse(text = txt ))

  could be rewritten as

  formula- substitute( value*v*LEFT ~ RIGHT, list(LEFT=LEFT, RIGHT=RIGHT))
  tabular(formula, data = m_xx, suppressLabels = 2, ...)

To be strictly correct, shouldn't that be:

formula- eval(substitute( value*v*LEFT ~ RIGHT, list(LEFT=LEFT, RIGHT=RIGHT)))

?

  It might make sense to put something like this into the tables package, but
  I don't want to have a dependency on reshape.

Would you consider making tabular generic?


I have now made tabular() into a generic function, but because of the 
problems at R-forge, can't commit the changes immediately.   The old 
tabular() function is now the tabular.formula() method; the default 
method tries to coerce the object to a formula to call that.  I think 
both my suggestion and yours would likely have problems in the new 
system (as they did in the old one) because the environment associated 
with the formula would be wrong.  It's a little tricky, but now 
tabular() works a lot more like model.frame(), which I think has to be 
considered to be the standard way to do this.


Duncan Murdoch

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


Re: [R] non-isomorphic sequences

2012-02-13 Thread Petr Savicky
On Mon, Feb 13, 2012 at 10:05:02AM -0800, zheng wei wrote:
 Dear All,
 
 Sorry for the typoes earlier, let me repost the question.
 
 Suppose I want to generate sequences of length 3 from two symbols {1,2}, we 
 get the following 8 sequences
 1 1 1
 1 1 2
 1 2 1
 1 2 2
 2 1 1
 2 1 2
 2 2 1
 2 2 2
 
 However, I do not want all these 8 sequences. I call two sequencs to be 
 isomorphic if one sequence could be obtained from the other by relabelling 
 the symbols. For example, 111 is isomorphic to 222, 112 is isomorphic to 
 221.?By eliminating all these isomorphic ones, what I want is the following
 1 1 1
 1 1 2
 1 2 1
 2 1 1

Eliminating isomorphic sequences may be done differently,
if we select different representatives of each equivalence
class. The following also eliminates isomorphic 1,2 sequences

  1 1 1
  1 1 2
  1 2 1
  1 2 2

Is this solution OK?

 In general, I need to generate non-isomorphic sequences of length p from t 
 distinct symbols. For example, when p=3, t=3 we have
 matrix(c(1,2,3,1,1,2,2,1,1,1,2,1,1,1,1),3,5)
 
 [1,]??? 1??? 1??? 2??? 1??? 1
 [2,]??? 2??? 1??? 1??? 2??? 1
 [3,]??? 3??? 2??? 1??? 1??? 1
 
 When p=4, t=4 we have
 matrix(c(1,2,3,4,1,1,2,3,1,2,1,3,1,2,3,1,2,1,1,3,2,3,1,1,2,1,3,1,1,1,2,2,1,2,1,2,1,2,2,1,1,1,1,2,1,1,2,1,1,2,1,1,2,1,1,1,1,1,1,1),4,15)
 
 [1,]??? 1??? 1??? 1??? 1??? 2??? 2??? 2??? 1??? 1 1 1 1 1 
 2 1
 [2,]??? 2??? 1??? 2??? 2??? 1??? 3??? 1??? 1??? 2 2 1 1 2 
 1 1
 [3,]??? 3??? 2??? 1??? 3??? 1??? 1??? 3??? 2??? 1 2 1 2 1 
 1 1
 [4,]??? 4??? 3??? 3??? 1??? 3??? 1??? 1??? 2??? 2 1 2 1 1 
 1 1
 
 
 In general, I need to do this for arbitrary choices of p and t.

If p and t are not too large, try the following

  check.row - function(x)
  {
  y - unique(x)
  all(y == seq.int(along=y))
  }

  p - 4
  tt - 4 # do not rewrite t() for transpose
  elem - lapply(as.list(pmin(1:p, tt)), function(x) seq.int(length=x))
  a - as.matrix(rev(expand.grid(rev(elem
  ok - apply(a, 1, check.row)
  out - a[ok, ]
  out

Var4 Var3 Var2 Var1
   [1,]1111
   [2,]1112
   [3,]1121
   [4,]1122
   [5,]1123
   [6,]1211
   [7,]1212
   [8,]1213
   [9,]1221
  [10,]1222
  [11,]1223
  [12,]1231
  [13,]1232
  [14,]1233
  [15,]1234

This solution differs from yours, for example, in
the row c(1, 2, 3, 3), which is in your solution
represented by c(2, 3, 1, 1). This a different choice
of the representatives. Is the choice important?

A related thread started at

  https://stat.ethz.ch/pipermail/r-help/2012-January/301489.html

There was an additional requirement that each of t symbols
has at least one occurrence.

Hope this helps.

Petr Savicky.

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

2012-02-13 Thread Kurt_Helf
Greetings
 I am attempting to plot observations of a cave aquatic invertebrate
dating from 1901-2004.  I can come up with a nice lattice plot of the eight
sites from which I have data easily enough.  However, I'd like to be able
to highlight the 0 observations on the plots, i.e., attempts to find it at
the site were unsuccessful.  I'd like to be able to highlight these
observations with either a symbol or a color.  Here's a sample of the data
(Reach=site):
 (Embedded image moved to file: pic17437.jpg)

Here's my code for the plot:
xyplot(No.Invert~Year|Reach, data=Invert.Coll.1901.2004,
 layout=c(4,2),
   ylab=No. Invert 'collected',
   scales=list(x=list(rot=45)))

***
Kurt Lewis Helf, Ph.D.
Ecologist
EEO Counselor
National Park Service
Cumberland Piedmont Network
P.O. Box 8
OR
NPS Warehouse
61 Maintenance Rd.
Mammoth Cave, KY 42259
Ph: 270-758-2163
Lab: 270-758-2151
Fax: 270-758-2609
Cumberland Piedmont Network (CUPN) Homepage:
http://tiny.cc/e7cdx
***
Science, in constantly seeking real explanations, reveals the true majesty
of our world in all its complexity.
-Richard Dawkins

[Scientific] theories are passed on not as dogmas but rather with the
challenge to discuss them and improve upon them.
-Karl Popper

...consider yourself a guest in the home of other creatures as significant
as yourself.
-Wayside at Wilderness Threshold in McKittrick Canyon, Guadalupe Mountains
National Park, TX

CUPN Forest Pest Monitoring Website:
http://bit.ly/9rhUZQ

CUPN Cave Cricket Monitoring Website:
http://tiny.cc/ntcql

CUPN Cave Aquatic Biota Monitoring Website:
http://tiny.cc/n2z1o__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] access R basic libraries

2012-02-13 Thread nitin kumar
Hello Everyone,
I am trying to access all R basic C/Fotran libraries to see how some
functions are written in fotran or C so that in case I need to change some
stuff I can do that.

Any help would be great,
nitin

[[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] MCMCglmm with cross-classified random effects

2012-02-13 Thread Ben Bolker
Agostino Moro agostino.moro99 at gmail.com writes:

 I would like to fit  a glmm with cross-classified random effects with
 the function MCMCglmm. Something along the lines:
 
 model1-MCMCglmm(response~pred1, random=~re1+re2, data=data)
 
 where re1 and re2 should be crossed random effects.

 [snip to make gmane happy. Thank you for trying to find the answer
before posting ...]

  It would probably be best to post this one to the r-sig-mixed-models
at r-project.org mailing list instead ...

  Ben Bolker

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

2012-02-13 Thread Berend Hasselman

On 13-02-2012, at 21:47, nitin kumar wrote:

 Hello Everyone,
 I am trying to access all R basic C/Fotran libraries to see how some
 functions are written in fotran or C so that in case I need to change some
 stuff I can do that.
 

BTW; it's fortran.

Well, goto CRAN (http://cran.r-project.org/) and download the sources (link  
R-2.14.1.tar.gz).
Unpack and browse.

Berend

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] entropy package: how to compute mutual information?

2012-02-13 Thread Sam Steingold
suppose I have two factor vectors:
 x - as.factor(c(a,b,a,c,b,c))
 y - as.factor(c(b,a,a,c,c,b))
I can compute their entropies:
 entropy(table(x))
[1] 1.098612
using
 library(entropy)
but it is not clear how to compute their mutual information directly.
I can compute the joint entropy as
  entropy(table(paste(x,y,sep=)))
[1] 1.791759
and then mutual information will be h(x) + h(y) - h(x,y) =
1.098612 + 1.098612 - 1.791759
0.405465

but I was wondering whether there was a better way (without creating a
fresh factor vector and a fresh factor class, both of which are
immediately discarded).


-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://iris.org.il http://ffii.org http://camera.org
http://americancensorship.org http://dhimmi.com http://pmw.org.il
There is Truth, and its value is T.  Or just non-NIL.  So 0 is True!

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


Re: [R] for loop

2012-02-13 Thread eddie smith
Dear Ted,

Thank you very much for your details explanation!

Cheers.

On Mon, Feb 13, 2012 at 7:12 PM, Ted Harding ted.hard...@wlandres.netwrote:

 In addition to Jim's neat solution (see also below),
 some comments on your original code.

 Your for loop executes x=29.5 + i/500 100 times,
 producing a single value each time and replacing the
 previous value which was in x. So, at the end of the loop,
 you have a single value of x. Then you compute y=2x;
 that, as it stands, would prokoke an error:

  Error: unexpected symbol in y=2x

 since variable names cannort start with a digit. You
 need, of course, the mutltiplaction operator * as
 in Jim's y - 2 * x.

 The scope of your for loop (i.e. the set of commands
 that is executed for each round of the loop) is solely
 the command x=29.5 + i/500. The y - 2 * x is not
 part of the scope of the loop, and would only be executed
 once, when the loop was finished. You would need

   for(i in 1:1000) {
 commands
   }

 to cause the execution of several commands in each round
 of the loop.

 Finally, even if you did think that your entire series of
 commands (re-written):

  for(i in 1:1000)
  x=29.5 + i/500
   y=2*x
  plot(y,x)

 would all be executed (down to and including the plot() command)
 in each round of the loop, nevertheless each call to plot()
 creates a new graph, discarding the previous one, so only a single
 point would be plotted each time.

 The solution (as in Jim's suggestion) is to create the full vector
 of x-values and y-values, and then use plot(x,y) where x and y are
 now vectors.

 There are all sorts of little details about how R puts things
 together, which will become familiar as you use R. However,
 you do need to get hold of the basics of how R operates, so
 I would suggest having R for Beginners

  http://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf

 to hand while you learn R. It is very good about how the basics
 work. The next step up would be the more systematic exposition
 of how R works in  An Introduction to R:

  http://cran.r-project.org/doc/manuals/R-intro.html
  http://cran.r-project.org/doc/manuals/R-intro.pdf

 Hoping this helps!
 Ted.

 On 13-Feb-2012 jim holtman wrote:
  x - 29.5 + (1:1000)/500
  y - 2 * x
  plot(y,x)
 
  On Mon, Feb 13, 2012 at 1:34 PM, eddie smith eddie...@gmail.com wrote:
  Hi guys,
 
  This is a very beginner question. Anybody willing to help?
 
  for(i in 1:1000)
  x=29.5 + i/500
  y=2x
  plot(y,x)
 
  The idea is to produce 1000 values of x and y then plot them.
 
  Cheers,
  Eddie
 
  _ _ _ _[[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
  Data Munger Guru
 
  What is the problem that you are trying to solve?
  Tell me what you want to do, not how you want to do it.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.

 -
 E-Mail: (Ted Harding) ted.hard...@wlandres.net
 Date: 13-Feb-2012  Time: 19:12:47
 This message was sent by XFMail
 -


[[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] entropy package: how to compute mutual information?

2012-02-13 Thread Sam Steingold
 * Sam Steingold f...@tah.bet [2012-02-13 16:14:36 -0500]:

 suppose I have two factor vectors:
  x - as.factor(c(a,b,a,c,b,c))
  y - as.factor(c(b,a,a,c,c,b))
 I can compute their entropies:
  entropy(table(x))
 [1] 1.098612
 using
  library(entropy)
 but it is not clear how to compute their mutual information directly.
 I can compute the joint entropy as
   entropy(table(paste(x,y,sep=)))

this can be simplified to entropy(table(x,y))

 [1] 1.791759
 and then mutual information will be h(x) + h(y) - h(x,y) =
 1.098612 + 1.098612 - 1.791759
 0.405465

 but I was wondering whether there was a better way (without creating a
 fresh factor vector and a fresh factor class, both of which are
 immediately discarded).

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://ffii.org http://mideasttruth.com
http://thereligionofpeace.com http://americancensorship.org http://memri.org
If money were measured in piles, I would have had a pit of it.

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

2012-02-13 Thread Cem Girit
Hello,

This is my first attempt to write a script in R. The program below
is intended to do some parametric tests on group data. There are subroutines
for each type of test. The call to the parametric.tests, routine sets the
argument testtype for the test to be used. How can I transfer the
calculated values (in result below) in each routine to the calling
parametric.tests routine?  

Cem




## testtype : 1: Duncan
## 2: Dunnett
## resp:  response variable, must be numeric and vector
## group: group id for resp, numeric or character
## alpha: CL 0.05 or 0.01
## vehicle: Control group name for Dunnett

parametric.tests-function(testtype, resp, group, vehicle, alpha)
{
if (testtype==1){
 
## resp:  response variable, must be numeric and vector
## group: group id for resp, numeric or character
## alpha: CL 0.05 or 0.01

 duncan.test - function (resp, group, alpha) {

.

result - data.frame(label=label, estimate=Estimate, alpha=alpha,
lower=Lower, upper=Upper, p.value=pval, significance=sig)
return(result)
}
}

else if (testtype==2){


dunnett.test - function(resp, group, vehicle, alpha)
{

.
 
 result - data.frame(label=label, estimate=Estimate, alpha=alpha,
lower=Lower, upper=Upper, p.value=pval, significance=sig)
 return(result)
}
}
}

Cem

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

2012-02-13 Thread David Studer
Hello everybody,

I have the following problem and have no idea how to solve it:

In my dataframe I have six columns representing six societal problems (p1,
p2, ..., p6).
The values are ranks between 1 (worst problem) and 6 (best problem)


p1 p2 p3  p4 p5 p6
1   3   2   5   4   6
2   3   1   6   4   5
1   2   3   4   6   5

but I'd like the dataframe the other way round:
123456
p1  p3  p2  p4  p4  p6
p3  p1  p2  p5  p6  p4
p1  p2  p3  p4  p6  p5

Can anyone help?

Thanks!

[[alternative HTML version deleted]]

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


[R] Error Message Comes from the Vuong Function

2012-02-13 Thread mikezhaow
I want to compare the poisson and the zero-inflated poisson distribution on
describing the data.  So, after using the GLM and the ZEROINFL function, I
used the Voung function to compare them.  Here is my code:

library(pscl)
glm1 - glm(nmer9_1[, 1] ~ 1, family = poisson)
zip - zeroinfl(nmer9_1[, 1] ~ 1)
vuong(glm1, zip)

However, R returns the following error message:
Error: cannot allocate vector of size 3.3 Gb.

Would you please tell me what was happening there?  Please note that I am
not trying to do a regression, but only want to compare which of the
distributions explain the data better.

Thank you.

--
View this message in context: 
http://r.789695.n4.nabble.com/Error-Message-Comes-from-the-Vuong-Function-tp4385497p4385497.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] If (x 0)

2012-02-13 Thread Schmidt, Michael
Hi,
I am new to R. I was trying to get a very simple program to run. Take one 
number from the command line. If the number  0 return -1. If number  0 return 
1 and if the number == 0 return 0. The code is in a file called test1.R


The code:

#useage: R --no-save --args 5  test1.R
args = (commandArgs(TRUE))
x = as.numeric(args[1])
print(x)

res - conditional1(x)
cat(result= ,res,\n)

conditional1 - function(x){
result - 0
if (x  0) {
result - 1
} else if (x  0) {
result - -1
}
return(result)
}


The output:
R --no-save --slave --args 1  test1.R
[1] 1
result=  1
R --no-save --slave --args -1  test1.R
[1] -1
result=  -1
] R --no-save --slave --args 0  test1.R
[1] 0
result=  -1


The problem:
For arguments 1 and -1 it works as intended. For 0 (zero) it does not. If the 0 
value is passed into the function named conditional1  I would expect both 
if-statements to evaluate to false and 0 being return. From what I can tell (0 
 0) evaluates to true since -1 is returned. Hm...
What is going on? What am I doing wrong? Why is this happening? I am baffled!
Any help would be appreciated.
Thanks
Mike




[[alternative HTML version deleted]]

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


Re: [R] non-isomorphic sequences

2012-02-13 Thread zheng wei
Dear Petr,
 
This is fantastic!
 
I have one more question, when p=4, tt=4. We have 15 non-isomorphic sequences 
as you have generated. Among these 15, I selected 2 sequences. How do I recover 
all the members of the equivalent classes corresponding to these 2 sequences? 
For example, corresponding to the sequence of , I would like to recover 
,,, from this sequence.
 
Thanks,
Wei



From: Petr Savicky savi...@cs.cas.cz
To: r-help@r-project.org 
Sent: Monday, February 13, 2012 2:53 PM
Subject: Re: [R] non-isomorphic sequences

On Mon, Feb 13, 2012 at 10:05:02AM -0800, zheng wei wrote:
 Dear All,
 
 Sorry for the typoes earlier, let me repost the question.
 
 Suppose I want to generate sequences of length 3 from two symbols {1,2}, we 
 get the following 8 sequences
 1 1 1
 1 1 2
 1 2 1
 1 2 2
 2 1 1
 2 1 2
 2 2 1
 2 2 2
 
 However, I do not want all these 8 sequences. I call two sequencs to be 
 isomorphic if one sequence could be obtained from the other by relabelling 
 the symbols. For example, 111 is isomorphic to 222, 112 is isomorphic to 
 221.?By eliminating all these isomorphic ones, what I want is the following
 1 1 1
 1 1 2
 1 2 1
 2 1 1

Eliminating isomorphic sequences may be done differently,
if we select different representatives of each equivalence
class. The following also eliminates isomorphic 1,2 sequences

  1 1 1
  1 1 2
  1 2 1
  1 2 2

Is this solution OK?

 In general, I need to generate non-isomorphic sequences of length p from t 
 distinct symbols. For example, when p=3, t=3 we have
 matrix(c(1,2,3,1,1,2,2,1,1,1,2,1,1,1,1),3,5)
 
 [1,]??? 1??? 1??? 2??? 1??? 1
 [2,]??? 2??? 1??? 1??? 2??? 1
 [3,]??? 3??? 2??? 1??? 1??? 1
 
 When p=4, t=4 we have
 matrix(c(1,2,3,4,1,1,2,3,1,2,1,3,1,2,3,1,2,1,1,3,2,3,1,1,2,1,3,1,1,1,2,2,1,2,1,2,1,2,2,1,1,1,1,2,1,1,2,1,1,2,1,1,2,1,1,1,1,1,1,1),4,15)
 
 [1,]??? 1??? 1??? 1??? 1??? 2??? 2??? 2??? 1??? 1 1 1 1 1 
 2 1
 [2,]??? 2??? 1??? 2??? 2??? 1??? 3??? 1??? 1??? 2 2 1 1 2 
 1 1
 [3,]??? 3??? 2??? 1??? 3??? 1??? 1??? 3??? 2??? 1 2 1 2 1 
 1 1
 [4,]??? 4??? 3??? 3??? 1??? 3??? 1??? 1??? 2??? 2 1 2 1 1 
 1 1
 
 
 In general, I need to do this for arbitrary choices of p and t.

If p and t are not too large, try the following

  check.row - function(x)
  {
      y - unique(x)
      all(y == seq.int(along=y))
  }

  p - 4
  tt - 4 # do not rewrite t() for transpose
  elem - lapply(as.list(pmin(1:p, tt)), function(x) seq.int(length=x))
  a - as.matrix(rev(expand.grid(rev(elem
  ok - apply(a, 1, check.row)
  out - a[ok, ]
  out

        Var4 Var3 Var2 Var1
  [1,]    1    1    1    1
  [2,]    1    1    1    2
  [3,]    1    1    2    1
  [4,]    1    1    2    2
  [5,]    1    1    2    3
  [6,]    1    2    1    1
  [7,]    1    2    1    2
  [8,]    1    2    1    3
  [9,]    1    2    2    1
  [10,]    1    2    2    2
  [11,]    1    2    2    3
  [12,]    1    2    3    1
  [13,]    1    2    3    2
  [14,]    1    2    3    3
  [15,]    1    2    3    4

This solution differs from yours, for example, in
the row c(1, 2, 3, 3), which is in your solution
represented by c(2, 3, 1, 1). This a different choice
of the representatives. Is the choice important?

A related thread started at

  https://stat.ethz.ch/pipermail/r-help/2012-January/301489.html

There was an additional requirement that each of t symbols
has at least one occurrence.

Hope this helps.

Petr Savicky.

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

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


Re: [R] non-isomorphic sequences

2012-02-13 Thread Petr Savicky
On Mon, Feb 13, 2012 at 02:04:51PM -0800, zheng wei wrote:
 Dear Petr,
  
 This is fantastic!
  
 I have one more question, when p=4, tt=4. We have 15 non-isomorphic sequences 
 as you have generated. Among these 15, I selected 2 sequences. How do I 
 recover all the members of the equivalent classes corresponding to these 2 
 sequences? For example, corresponding to the sequence of , I would like 
 to recover ,,, from this sequence.

Dear Wei:

Try the following.

  getEquivalent - function(a, tt)
  {
  b - as.matrix(rev(expand.grid(rep(list(1:tt), times=max(a)
  ok - apply(b, 1, function(x) length(unique(x))) == ncol(b)
  b - b[ok, , drop=FALSE]
  dimnames(b) - NULL
  t(apply(b, 1, function(x) x[a]))
  }

  getEquivalent(c(1, 1, 1, 1), 4)

   [,1] [,2] [,3] [,4]
  [1,]1111
  [2,]2222
  [3,]3333
  [4,]4444

  getEquivalent(c(1, 1, 1, 2), 4)

[,1] [,2] [,3] [,4]
   [1,]1112
   [2,]1113
   [3,]1114
   [4,]2221
   [5,]2223
   [6,]2224
   [7,]3331
   [8,]3332
   [9,]3334
  [10,]4441
  [11,]4442
  [12,]4443

Hope this helps.

Petr.

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

2012-02-13 Thread Sam Steingold
if I have a vector, I can find the indexes which satisfy a condition:
x - rnorm(10)
 [1]  0.4751132 -0.5442322 -0.1979854 -0.2455521  0.8349336 -0.4283345
 [7]  0.6108130  2.0576160  1.1251716 -1.3933637
x[x0]
[1] 0.4751132 0.8349336 0.6108130 2.0576160 1.1251716
(1:10)[x0]
[1] 1 5 7 8 9

how about a matrix?

   0G  0Q  2O   35   37   3A
0G NA 0.008226002 0.005631718 0.0002625585 0.0010673235 0.0045310915
0Q NA  NA 0.003714951 0.0002007877 0.0016983426 0.0011083925
2O NA  NA  NA 0.0024233691 0.0069849678 0.0024510792
35 NA  NA  NA   NA 0.0006499707 0.0008420414
37 NA  NA  NA   NA   NA 0.0005448872
3A NA  NA  NA   NA   NA   NA
3B NA  NA  NA   NA   NA   NA
3G NA  NA  NA   NA   NA   NA
3H NA  NA  NA   NA   NA   NA
3I NA  NA  NA   NA   NA   NA
 3B   3G   3H  3I
0G 0.0007254316 0.0093954826 3.420231e-04 0.003974556
0Q 0.0013883606 0.0019778247 3.609791e-05 0.001552725
2O 0.0027340806 0.0082790646 2.561862e-03 0.012297821
35 0.0006025767 0.0004534397 1.053946e-03 0.001681780
37 0.0005501974 0.0021137871 1.733880e-03 0.003712675
3A 0.0008969849 0.0043855527 2.786194e-06 0.002492954
3B   NA 0.0019791290 8.301787e-04 0.002816774
3G   NA   NA 3.181892e-07 0.010608717
3H   NA   NA   NA 0.001066141
3I   NA   NA   NA  NA

how do I find the cells whose values are, e.g.,  0.01 ??

thanks!

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://pmw.org.il http://americancensorship.org
http://ffii.org http://iris.org.il http://truepeace.org http://dhimmi.com
The difference between genius and stupidity is that genius has its limits.

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

2012-02-13 Thread Gabor Grothendieck
On Mon, Feb 13, 2012 at 5:07 PM, David Studer stude...@gmail.com wrote:
 Hello everybody,

 I have the following problem and have no idea how to solve it:

 In my dataframe I have six columns representing six societal problems (p1,
 p2, ..., p6).
 The values are ranks between 1 (worst problem) and 6 (best problem)


 p1 p2 p3  p4 p5 p6
 1   3   2   5   4   6
 2   3   1   6   4   5
 1   2   3   4   6   5

 but I'd like the dataframe the other way round:
 1    2    3    4    5    6
 p1  p3  p2  p4  p4  p6
 p3  p1  p2  p5  p6  p4
 p1  p2  p3  p4  p6  p5



First we read the data and then rearrange it into long form (DF) and
turn that into a 2d matrix (tapply):

Lines - p1 p2 p3  p4 p5 p6
1   3   2   5   4   6
2   3   1   6   4   5
1   2   3   4   6   5
DF0 - read.table(text = Lines, header = TRUE)

DF -  as.data.frame.table(as.matrix(DF0), stringsAsFactors = FALSE,
responseName = Ranks)
tapply(DF[[Var2]], DF[-2], c)

The result of the last statement is:

Ranks
Var1 123456
   A p1 p3 p2 p5 p4 p6
   B p3 p1 p2 p5 p6 p4
   C p1 p2 p3 p4 p6 p5

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Change dataframe-structure

2012-02-13 Thread Bert Gunter
P - paste(P,1:6,sep=)
t(apply(yourdataframe,1,function(x)P[order(x)]))

## result is a mtrix, though.

-- Bert


On Mon, Feb 13, 2012 at 2:07 PM, David Studer stude...@gmail.com wrote:
 Hello everybody,

 I have the following problem and have no idea how to solve it:

 In my dataframe I have six columns representing six societal problems (p1,
 p2, ..., p6).
 The values are ranks between 1 (worst problem) and 6 (best problem)


 p1 p2 p3  p4 p5 p6
 1   3   2   5   4   6
 2   3   1   6   4   5
 1   2   3   4   6   5

 but I'd like the dataframe the other way round:
 1    2    3    4    5    6
 p1  p3  p2  p4  p4  p6
 p3  p1  p2  p5  p6  p4
 p1  p2  p3  p4  p6  p5

 Can anyone help?

 Thanks!

        [[alternative HTML version deleted]]

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


Re: [R] Change dataframe-structure

2012-02-13 Thread Justin Haynes
There is probably a more ellegant way, but:

 df -
data.frame(p1=c(1,2,1),p2=c(3,3,2),p3=c(2,1,3),p4=c(5,6,4),p5=c(4,4,6),p6=c(6,5,5))
 as.data.frame(t(apply(df,1,function(x) names(x)[match(1:6,x)])))
  V1 V2 V3 V4 V5 V6
1 p1 p3 p2 p5 p4 p6
2 p3 p1 p2 p5 p6 p4
3 p1 p2 p3 p4 p6 p5



On Mon, Feb 13, 2012 at 2:07 PM, David Studer stude...@gmail.com wrote:

 Hello everybody,

 I have the following problem and have no idea how to solve it:

 In my dataframe I have six columns representing six societal problems (p1,
 p2, ..., p6).
 The values are ranks between 1 (worst problem) and 6 (best problem)


 p1 p2 p3  p4 p5 p6
 1   3   2   5   4   6
 2   3   1   6   4   5
 1   2   3   4   6   5

 but I'd like the dataframe the other way round:
 123456
 p1  p3  p2  p4  p4  p6
 p3  p1  p2  p5  p6  p4
 p1  p2  p3  p4  p6  p5

 Can anyone help?

 Thanks!

[[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


[R] survey package svystat objects from predict()

2012-02-13 Thread Kieran Healy
Hello, 

I'm running R 2.14.1 on OS X (x86_64-apple-darwin9.8.0/x86_64 (64-bit)), with 
version 3.28 of Thomas Lumley's survey package. I was using predict() from 
svyglm(). E.g.:

data(api)
dstrat-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
out - svyglm(sch.wide~ell+mobility, design=dstrat,
family=quasibinomial())
pred.df - expand.grid(ell=c(20,50,80), mobility=20)
out.pred - predict(out, pred.df)

From the console out.pred looks like this:

 class(out.pred)
[1] svystat

 print(out.pred) # or just 'out.pred'
link SE
1 1.8504 0.2414
2 1.6814 0.3033
3 1.5124 0.5197

From here I wanted to conveniently access the predicted values and SEs. I 
thought that I might be able to do this using either ftable() or 
as.data.frame(), as methods for these exist for the objects of class 
svystat. But while the predicted values come through fine, the SE only gets 
calculated for the first element and is then repeated: 

 ftable(out.pred)
  A B
1 1.8504120 0.2413889
2 1.6814293 0.2413889
3 1.5124466 0.2413889

 as.data.frame(out.pred)
  linkSE
1 1.850412 0.2413889
2 1.681429 0.2413889
3 1.512447 0.2413889

I think what's happening is that as.data.frame.svystat() method in the survey 
package ends up calling the wrong function to calculate the standard errors.  
From the survey package:

as.data.frame.svystat-function(x,...){
  rval-data.frame(statistic=coef(x),SE=SE(x))
  names(rval)[1]-attr(x,statistic)
  if (!is.null(attr(x,deff)))
rval-cbind(rval,deff=deff(x))
  rval
}

The relevant SE method seems to be: 

SE.svrepstat-function(object,...){
  if (is.list(object)){
object-object[[1]]
  }
  vv-as.matrix(attr(object,var))
  if (!is.null(dim(object))  length(object)==length(vv))
sqrt(vv)
  else
sqrt(diag(vv))
}

Instead of returning sqrt(vv) on each element, it calculates sort(diag(vv)) 
instead. At least I think this is what's happening. 

I apologize in advance if all this is the result of some elementary error on my 
part. 

Thanks,

Kieran
  
-- 
Kieran Healy :: http://kieranhealy.org

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


Re: [R] only 0s may be mixed with negative subscripts

2012-02-13 Thread ilai
The function you posted runs without error (on these 6 lines), but
does not return anything that looks remotely like a sum, or cumsum of
anything. Can you clarify what you are trying to do? I assume by sum
of every other row you don't mean summing Time, X and Y for rows
1,3,5,..., ?

For the sum of sens2[c(1,3,5,...),] for every column (assuming no NA's
in the data) you could

 (1:nrow(sens2) %% 2) %*% as.matrix(sens2)

   Time   Y X rownumber
[1,] 3985695201 0.56826 0.1369527 9

Hope this helps


On Mon, Feb 13, 2012 at 11:56 AM, Hasan Diwan hasan.di...@gmail.com wrote:
 I'd like to get the sum of every other row in a data.frame. When I
 actually set about doing this, I get the error in the subject line of
 this message. A sample of my data is below, followed by the function
 call that should give me the results I want:

 dput(head(sens2))
 structure(list(Time = c(1328565067, 1328565067.05, 1328565067.1,
 1328565067.15, 1328565067.2, 1328565067.25), Y = c(0.0963890795246276,
 0.227296347215609, 0.240972698811569, 0.221208948983498, 0.230898231782485,
 0.203282153087549), X = c(0.0245045248243853, 0.0835679411703579,
 0.0612613120609633, 0.058568910563872, 0.0511868450318788, 0.0557714205674231
 ), rownumber = 1:6), .Names = c(Time, Y, X, rownumber
 ), row.names = c(NA, 6L), class = data.frame)
 speedX - sapply(sens2[sens2$rownumber %% 2 == 0,], function(row) { 
 cumsum(c(sens2[row+1,3], sens2[row,3]))}, simplify=TRUE)
 Error in xj[i] : only 0's may be mixed with negative subscripts
 Help?
 --
 Sent from my mobile device
 Envoyait de mon portable

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

2012-02-13 Thread R. Michael Weylandt michael.weyla...@gmail.com
which(x0)

or 

which(x0, arr.ind=TRUE)

depending on your application. 

Michael

On Feb 13, 2012, at 5:38 PM, Sam Steingold s...@gnu.org wrote:

 if I have a vector, I can find the indexes which satisfy a condition:
 x - rnorm(10)
 [1]  0.4751132 -0.5442322 -0.1979854 -0.2455521  0.8349336 -0.4283345
 [7]  0.6108130  2.0576160  1.1251716 -1.3933637
 x[x0]
 [1] 0.4751132 0.8349336 0.6108130 2.0576160 1.1251716
 (1:10)[x0]
 [1] 1 5 7 8 9
 
 how about a matrix?
 
   0G  0Q  2O   35   37   3A
 0G NA 0.008226002 0.005631718 0.0002625585 0.0010673235 0.0045310915
 0Q NA  NA 0.003714951 0.0002007877 0.0016983426 0.0011083925
 2O NA  NA  NA 0.0024233691 0.0069849678 0.0024510792
 35 NA  NA  NA   NA 0.0006499707 0.0008420414
 37 NA  NA  NA   NA   NA 0.0005448872
 3A NA  NA  NA   NA   NA   NA
 3B NA  NA  NA   NA   NA   NA
 3G NA  NA  NA   NA   NA   NA
 3H NA  NA  NA   NA   NA   NA
 3I NA  NA  NA   NA   NA   NA
 3B   3G   3H  3I
 0G 0.0007254316 0.0093954826 3.420231e-04 0.003974556
 0Q 0.0013883606 0.0019778247 3.609791e-05 0.001552725
 2O 0.0027340806 0.0082790646 2.561862e-03 0.012297821
 35 0.0006025767 0.0004534397 1.053946e-03 0.001681780
 37 0.0005501974 0.0021137871 1.733880e-03 0.003712675
 3A 0.0008969849 0.0043855527 2.786194e-06 0.002492954
 3B   NA 0.0019791290 8.301787e-04 0.002816774
 3G   NA   NA 3.181892e-07 0.010608717
 3H   NA   NA   NA 0.001066141
 3I   NA   NA   NA  NA
 
 how do I find the cells whose values are, e.g.,  0.01 ??
 
 thanks!
 
 -- 
 Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 
 11.0.11004000
 http://www.childpsy.net/ http://pmw.org.il http://americancensorship.org
 http://ffii.org http://iris.org.il http://truepeace.org http://dhimmi.com
 The difference between genius and stupidity is that genius has its limits.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] only 0s may be mixed with negative subscripts

2012-02-13 Thread Hasan Diwan
On 13 February 2012 14:46, ilai ke...@math.montana.edu wrote:
 The function you posted runs without error (on these 6 lines), but
 does not return anything that looks remotely like a sum, or cumsum of
 anything. Can you clarify what you are trying to do? I assume by sum
 of every other row you don't mean summing Time, X and Y for rows
 1,3,5,..., ?

I'm trying to get a piecewise sum of every n rows in a given column in
this data set.
 For the sum of sens2[c(1,3,5,...),] for every column (assuming no NA's
 in the data) you could

I do format checking well before getting to this stage in the analysis.

  (1:nrow(sens2) %% 2) %*% as.matrix(sens2)

That does not do what I want... Again, what it should return is a list
of the sum of the current and preceding row.
-- 
Sent from my mobile device
Envoyait de mon portable

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


  1   2   >