Re: [R] nth root of matrix

2013-07-03 Thread Spencer Graves



On 7/2/2013 9:24 PM, David Winsemius wrote:

On Jul 2, 2013, at 8:11 PM, Sachinthaka Abeywardana wrote:


Hi all,

I want to do the following:

a=matrix(c(-1,-2,-3))
a^(1/3) #get 3rd root of numbers[,1]

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


All I get is NaNs, what is the proper way of doing this? Would like to
retain the fact that it is a matrix if possible (not a requirement
though).

?complex

  a=matrix(c(-1+0i,-2+0i,-3+0i))



  I tried that.  The problem is that there are 3 different cube 
roots in the complex plane, and a^(1/3) only gives one of them.  See 
Wikipedia, roots of unity or the examples in the help file for 
newton_raphson {elliptic}.



  I assume that Sachinthaka wants the real roots.  Try the following:


n - 3 # n must be an odd integer for this to work
a=matrix(c(-1,-2,-3))
as - sign(a)
ab - abs(a)
cr - as*(ab^(1/n))
 cr
  [,1]
[1,] -1.00
[2,] -1.259921
[3,] -1.442250
cr^n


  Hope this helps.  Spencer Graves


David Winsemius
Alameda, CA, USA

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


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


Re: [R] Recoding variables based on reference values in data frame

2013-07-03 Thread arun
Hi,
May be this helps:
Kgeno- read.table(text=
SNP_ID SNP1 SNP2 SNP3 SNP4
Maj_Allele C G  C  A
Min_Allele T A T G  
ID1 CC    GG    CT    AA
ID2 CC    GG    CC AA
ID3 CC    GG nc  AA
ID4  _  _  _  _ 
ID5 CC    GG    CC    AA
ID6 CC    GG    CC  AA
ID7 CC    GG    CT    AA
ID8 _ _ _ _  
ID9 CT    GG  CC AG
ID10 CC    GG    CC    AA
ID11 CC    GG    CT    AA
ID12 _ _ _ _  
ID13 CC    GG    CC    AA
,sep=,header=TRUE,stringsAsFactors=FALSE)

library(stringr)
library(car)

fun1- function(x){
 MajMin- paste0(x[1],x[2])
 MajMaj-str_dup(x[1],2)
 MinMin-str_dup(x[2],2)
 recode(x,'nc'=NA;'_'=NA;MajMaj=0;MajMin=1;MinMin=2)}
sapply(Kgeno[,-1],fun1)

#or

 mat1-sapply(Kgeno[1:2,-1],function(x) 
{c(str_dup(x,2),paste(x,collapse=))})[c(1,3,2),]
sapply(seq_len(ncol(Kgeno[,-1])),function(i) 
{x-Kgeno[-c(1:2),-1][,i];as.numeric(factor(x,levels=mat1[,i]))-1})


#Speed comparison
KgenoNew- rbind(Kgeno[c(1:2),-1],sapply(Kgeno[-c(1:2),-1],rep,1e4))
 system.time(res1- sapply(KgenoNew,fun1))
#   user  system elapsed 
 #0.672   0.000   0.674 


system.time({
mat1-sapply(Kgeno[1:2,-1],function(x) 
{c(str_dup(x,2),paste(x,collapse=))})[c(1,3,2),]
res2- sapply(seq_len(ncol(KgenoNew)),function(i){ x- 
KgenoNew[-c(1:2),][,i];as.numeric(factor(x,levels=mat1[,i]))-1})
})
#user  system elapsed 
#  0.212   0.000   0.214 
res1New- res1[-c(1:2),]
res1New1- as.numeric(res1New)
 dim(res1New1)- dim(res1New)
identical(res1New1,res2)
#[1] TRUE
A.K.







- Original Message -
From: kathleen askland k.askl...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Tuesday, July 2, 2013 4:46 PM
Subject: [R] Recoding variables based on reference values in data frame

I'm new to R (previously used SAS primarily) and I have a genetics data
frame consisting of genotypes for each of 300+ subjects (ID1, ID2, ID3,
...) at 3000+ genetic locations (SNP1, SNP2, SNP3...). A small subset of
the data is shown below:
  SNP_ID SNP1 SNP2 SNP3 SNP4  Maj_Allele C G  C  A  Min_Allele T A T G  ID1
CC     GG     CT     AA      ID2 CC     GG     CC AA      ID3 CC     GG
nc
AA      ID4 _ _ _ _  ID5 CC     GG     CC     AA      ID6 CC     GG     CC
     AA      ID7 CC     GG     CT     AA      ID8 _ _ _ _  ID9 CT     GG
CC AG      ID10 CC     GG     CC     AA      ID11 CC     GG     CT     AA
      ID12 _ _ _ _  ID13 CC     GG     CC     AA
The name of the data file is Kgeno.
What I would like to do is recode all of the genotype values to standard
integer notation, based on their values relative to the reference rows
(Maj_Allele and Min_Allele). Standard notation sums the total of minor
alleles in the genotype, so values can be 0, 1 or 2.

Here are the changes I want to make:
1. If the genotype= nc or '_ then set equal to NA.
2. If genotype value = a character string comprised of two consecutive
major allele values -- c(Maj_Allele, Maj_Allele) -- then set equal to 0.
3. If genotype  value= c(Maj_Allele, Min_Allele) then set equal to 1.
4. If genotype  value = c(Min_Allele, Min_Allele) then set equal to 2.

I've tried the following ifelse processing but get error (Warning: Executed
script did not end with R session at the top-level prompt.  Top-level state
will be restored) and can't seem to fix the code properly. I've counted the
parentheses. Also, not sure if it would execute properly if I could fix it.

# change 'nc' and '_' to NA, else leave as is:
Kgeno[,2] - ifelse(Kgeno[,2] == nc, NA, Kgeno[,2])
Kgeno[,2] - ifelse(Kgeno[,2] == _, NA, Kgeno[,2])

#convert genotype strings in the first data column to numeric values #(two
major alleles=0, 1 minor and 1 major=1, 2 minor alleles=2), else #leave as
is (to preserve NA values).

Kgeno[,2] -

ifelse(Kgeno[,2] == noquote(paste(as.character(Kgeno[1,2]), as.character(
Kgeno[1,2]), sep=), 0,

ifelse(Kgeno[,2] == noquote(paste(as.character(Kgeno[1,2]), as.character(
Kgeno[2,2]), sep=), 1,

ifelse(Kgeno[,2] == noquote(paste(as.character(Kgeno[2,2]), as.character(
Kgeno[2,2]), sep=), 2,
            Kgeno[,2])))


Finally, if above code were corrected, this would only change the first
column of data, but I would like to change all 3000+ columns in the same
way.

I would greatly appreciate some suggestions on how to proceed.

Thank you,

Kathleen

---
Kathleen Askland, MD
Assistant Professor
Department of Psychiatry  Human Behavior
The Warren Alpert School of Medicine
Brown University/Butler Hospital

    [[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] matching similar character strings

2013-07-03 Thread arun
Dear Mario,
Not sure if this is what you wanted:
F1_ex- read.table(text=
   Nome.azienda;Indirizzo
17;Alterego;Via Edmondo De Amicis, 18
18;Alterego;Via Edmondo De Amicis, 65
,sep=;,header=TRUE,stringsAsFactors=FALSE)

F2_ex- read.table(text=
   CODICE;STRADA;AREADICIRCOLAZIONE;NUMBER1;BARRATO1;NUMBER2;BARRATO2;SECTION
1;15620;VIA;DE AMICIS EDMONDO;1;;5;;1288 
2;15620;VIA;DE AMICIS EDMONDO;2;;34;;1261
3;15620;VIA;DE AMICIS EDMONDO;7;;17;;1287
4;15620;VIA;DE AMICIS EDMONDO;36;;62;;1264
5;15620;VIA;DE AMICIS EDMONDO;37;;37;;1287
6;15620;VIA;DE AMICIS EDMONDO;64;;84;;1262
,sep=;,header=TRUE,stringsAsFactors=FALSE)
library(stringr)
 
vec1-sapply(lapply(toupper(str_trim(gsub([0-9,],,F1_ex[,2]))),word,c(1,3,4,2)),paste,collapse=
 )
 vec2- as.numeric(gsub(\\D+,,F1_ex[,2]))
 F1_ex[,1]-F2_ex[sapply(vec2,function(x) which((xF2_ex[,4]  x F2_ex[,6])  
paste(F2_ex[,2],F2_ex[,3])%in%vec1)),SECTION]
 F1_ex
#   Nome.azienda Indirizzo
#17 1261 Via Edmondo De Amicis, 18
#18 1262 Via Edmondo De Amicis, 65
A.K.





- Original Message -
From: A M Lavezzi mario.lave...@unipa.it
To: r-help r-help@r-project.org
Cc: 
Sent: Tuesday, July 2, 2013 10:22 AM
Subject: Re: [R] matching similar character strings

Dear Arun,
please excuse me for this late reply, we had to stop working on this
temporaririly.

Let me reproduce here two examples of rows from F1 and F2 (sorry, but
with dput() I am not able to produce a clear example)

 F1_ex
        Nome.azienda                   Indirizzo
17     Alterego             Via Edmondo De Amicis, 18

On row 17 of F1 we have a firm named (Nome.azienda) 'Alterego' whose
address (indirizzo) is  'Via Edmondo de Amicis, 18'

Below I reproduce the portion of F2 with information on the street
mentioned in F1_ex$Indirizzo.

 F2_ex

  CODICE    STRADA       AREADICIRCOLAZIONE          NUMBER1 BARRATO1
NUMBER2 BARRATO2 SECTION
1  15620        VIA            DE AMICIS EDMONDO                     1
                          5                                 1288
2  15620        VIA            DE AMICIS EDMONDO                     2
                         34                                 1261
3  15620        VIA            DE AMICIS EDMONDO                     7
                         17                                 1287
4  15620        VIA            DE AMICIS EDMONDO                    36
                         62                                1264
5  15620        VIA            DE AMICIS EDMONDO                    37
                         37                                1287
6  15620        VIA            DE AMICIS EDMONDO                    64
                         84                                1262


Line 1 says that the portion of VIA DE AMICIS EDMONDO
(STRADA+AREADICIRCOLAZIONE), with street numbers between 1 and 5
belongs to SECTION 1288 (these are census sections). (BARRATO1 and
BARRATO2 refer to the letter in street numbers such as 12/A, 28/D,
etc. In the present example they are empty)

Line 2 says that the portion of VIA DE AMICIS EDMONDO, with street
numbers between 2 and 34 belongs to SECTION 1261,

etc.

Our problem is to assign SECTION 1261 to 'Alterego', exploting the
information on its address. The problem is that the syntax of the
street address in F1 is different from the syntax in F2.

Hope I have clarified the issue

thanks a lot
Mario








On Fri, Jun 21, 2013 at 5:25 PM, arun smartpink...@yahoo.com wrote:
 Dear Mario,
 I didn't find any difference between 1st and 2nd row of F2, except for the 
 last three columns.  Question is that why should F1 1st row should be merged 
 to 2nd row of F2 instead of 1st row of F2. In your previous example, you 
 mentioned about A1, A2, ... and B1, B2, etc.  Here, it is not provided.  As I 
 mentioned before, it is better to provide the output of ?dput() from a subset 
 of dataset.
 dput(head(F1,20))

 dput(head(F2,20))

 #so that there would be atleast some matching pairs within the example 
 dataset.  Also, please post it to r-help as I will be able to check only 
 after a couple of hours
 Tx.
 Arun



 - Original Message -
 From: Mario Lavezzi mario.lave...@unipa.it
 To: arun smartpink...@yahoo.com
 Cc:
 Sent: Friday, June 21, 2013 11:08 AM
 Subject: Re: [R] matching similar character strings

 dear Arun
 thank you very much. Let me explain the problem:

 Imagine that a portion of the row in F1 is:

 
 F1

 1) Street | J.F. Kennedy | 30
 

 it means that our unit of interest (a firm) has address: J.F. Kennedy Street, 
 30


 The F2 database contains the list of all the streets of the city, with 
 additional variables characterizing that street (Census data). The database
 contains sometimes street divided in some parts, according to the street 
 number. For example:


 Example of three rows of F2 concerning Kennedy street and Kennedy Road:

 F2

 1) Street | Kennedy John Fitzgerald  | 1  | 20 | A12
 2) Street | Kennedy John 

Re: [R] nth root of matrix

2013-07-03 Thread arun
 sign(a)*abs(a)^(1/3)
#  [,1]
#[1,] -1.00
#[2,] -1.259921
#[3,] -1.442250
A.K. 




- Original Message -
From: Sachinthaka Abeywardana sachin.abeyward...@gmail.com
To: r-help@r-project.org r-help@r-project.org
Cc: 
Sent: Tuesday, July 2, 2013 11:11 PM
Subject: [R] nth root of matrix

Hi all,

I want to do the following:

a=matrix(c(-1,-2,-3))
a^(1/3) #get 3rd root of numbers[,1]

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


All I get is NaNs, what is the proper way of doing this? Would like to
retain the fact that it is a matrix if possible (not a requirement
though).


Thanks,

Sachin

    [[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] Multinomial model and p-values

2013-07-03 Thread peter dalgaard

On Jul 2, 2013, at 21:21 , Luciano La Sala wrote:

 Hello everyone, 
 
 I have a dataset which consists of Pathology scores (Absent, Mild, Severe)
 as outcome variable, and two main effects: Age (two factors: twenty / thirty
 days old) and Treatment Group (four factors: infected without ATB; infected
 + ATB1; infected + ATB2; infected + ATB3).
 
 First I tried to fit an ordinal regression model, which seems more
 appropriate given the characteristics of my dependent variable (ordinal).
 However, the assumption of odds proportionality was severely violated
 (graphically), which prompted me to use a multinomial model instead, using
 the nnet package.  
 
 
 First I chose the outcome level that I need to use as baseline category: 
 
 Data$Path - relevel(Data$Path, ref = Absent)
 
 Then, I needed to set baseline categories for the independent variables:
 
 Data$Age - relevel(Data$Age, ref = Twenty) 
 Data$Treat - relevel(Data$Treat, ref = infected without ATB) 
 
 The model:
 
 test - multinom(Path ~ Treat + Age, data = Data)
 # weights:  18 (10 variable)
 initial  value 128.537638 
 iter  10 value 80.623608
 final  value 80.619911 
 converged
 
 summary1 - summary(test1)
 summary1
 
 Call:
 multinom(formula = Jej_fact ~ Treat + Age, data = Data)
 
 Coefficients:
 (Intercept)   infected+ATB1   infected+ATB2   infected+ATB3
 AgeThirty
 Moderate   -2.238106   -1.1738540  -1.709608   -1.599301
 2.684677
 Severe -1.544361   -0.8696531  -2.991307   -1.506709
 1.810771
 
 Std. Errors:
 (Intercept)infected+ATB1   infected+ATB2   infected+ATB3
 AgeThirty
 Moderate   0.78800460.8430368   0.7731359   0.7718480
 0.8150993
 Severe 0.61109030.7574311   1.1486203   0.7504781
 0.6607360
 
 Residual Deviance: 161.2398 
 AIC: 181.2398
 
 For a while, I could not find a way to get the p-values for the model and
 estimates when using nnet:multinom. Yesterday I came across a post where the
 author put forward a similar issue regarding estimation of p-values for
 coefficients
 (http://stats.stackexchange.com/questions/9715/how-to-set-up-and-estimate-a-
 multinomial-logit-model-in-r).
 
 There, one blogger suggested that getting p-values from the summary() result
 of multinom() is pretty easy, by first getting the t values as follows: 
 
 pt(abs(summary1$coefficients / summary1$standard.errors), df=nrow(Data)-10,
 lower=FALSE) 
 
 (Intercept)   infected+ATB1   infected+ATB2   infected+ATB3
 AgeThirty
 Moderate 0.002670340   0.08325396  0.014506395 0.02025858
 0.0006587898
 Severe   0.006433581   0.12665278  0.005216581 0.02352202
 0.0035612114
 
 I AM NOT a statistician, so don't be baffled by a silly question! I this
 procedure correct?

There's at least a factor of 2 missing for a two-tailed p value. It is usually 
a mistake to use the t-distribution for what is really a z-statistic; for 
aggregated data, it can be a very bad mistake. However, it's not really an R 
question, and you obviously know where to find stackexchange... (local, 
professional advice would be even better, though.) 


-- 
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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] MuMIn package: plotting averaged model estimates with CI

2013-07-03 Thread Katarzyna Kulma
Hiya,

I'm fairly new to MuMIn (and plotting predicted values in R, for that
matter) and I have quite a basic question:

I want to plot model-averaged estimates with their 95% CI's for the
supported interaction (Infection x ecs). I used the following data:


 head(summ12b)
  ld sum12  Infection   ecs
1 13  78.0   Infected Enlarged
2 15 134.5 Uninfected Enlarged
3 14  91.5   Infected   Control
4 16  62.0   Infected  Reduced
5 17  93.6   Infected   Control
6 15 104.6 Uninfected   Control



s12b-lm(sum12~(Infection+ecs)^2+ld,data=summ12b)
ss12b-dredge(s12b,trace = TRUE, rank = AICc)
top.ss12b- get.models(ss12b, subset = delta2)
ad-summary(model.avg(top.ss12b))



and here's what I've got:

ad

Call:
model.avg.default(object = top.ss12b)

Component models:
 df  logLik   AICc Delta Weight
1234  8 -112.95 249.10  0.00   0.47
124   7 -115.31 249.95  0.86   0.31
1 4 -120.44 250.55  1.45   0.23

Term codes:
  ecs Infectionld ecs:Infection
1 2 3 4

Model-averaged coefficients:
 Estimate Std. Error Adjusted SE z value
Pr(|z|)
(Intercept)   112.737 30.847  31.505   3.578
0.000346 ***
ecsEnlarged23.817 13.376  13.798   1.726
0.084324 .
ecsReduced-10.597  8.352   8.740   1.212
0.225364
InfectionUninfected 7.493  9.381   9.893   0.757
0.448793
ld -3.477  1.763   1.865   1.864
0.062252 .
ecsEnlarged :InfectionUninfected   23.308 14.740  15.510   1.503
0.132892
ecsReduced :InfectionUninfected   -22.112 12.589  13.307   1.662
0.096572 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Full model-averaged coefficients (with shrinkage):
 (Intercept) ecsEnlarged  ecsReduced  InfectionUninfected   ld
ecsEnlarged :InfectionUninfected
112.7373  23.8169-10.5966  5.7952
-1.6285  18.0261
 ecsReduced :InfectionUninfected
-17.1008

Relative variable importance:
  ecs Infection ecs:Infectionld
 1.00  0.77  0.77  0.47


I know that I can obtain 95% Ci's by using ad$avg.model, however, how to
derive the estimates and CI's for ALL the groups and their factor levels
included in the interaction?
Thanks for your help!

cheers,
Kasia

[[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] Package PLM

2013-07-03 Thread Eliano Marques
Hi Giovanni and Yves,

My is Eliano Marques, i'm a master degree econometrician from ISEG in
Portugal.

I was trying to use your R package with a specific output i cannot get the
same results that i'm getting in Stata.

Could you please let me know if the below is correct or if i'm missing
anything?

On the below model I want to run a model for 62 companies for a 5 year
period:

log(revenue+2)it = log(revenue+2)(-1)it*b1 + log(Cost+2)(-1)it*b2 +
log(Cost+2)it*b3 + vit
modeloutput- pgmm(log(Revenue+2) ~ lag(log(Revenue+2), 1)+
lag(log(Cost+2), 0:1)
 | lag(log(Cost+2), 2:99) +
lag(log(Cost+2), 2:99) ,
data = BD, effect = twoways, model = onestep,
transformation = ld)
summary(modeloutput, robust = TRUE)

I want to include time.dummies in both equation in level and differences.

I get this output:

Coefficients
Estimate Std. Error z-value  Pr(|z|)
lag(log(Revenue + 2), 1)0.486593   0.146151  3.3294 0.0008703 ***
lag(log(Cost+ 2), 0:1)0  1.165293   0.069329 16.8081  2.2e-16 ***
lag(log(Cost + 2), 0:1)1 -0.565378   0.199199 -2.8383 0.0045360 **

From Stata, running the following code I get this:

xtabond2 lnrevenue l.lnrevenue lncost l.lncost  i.year , iv(i.year  )
 gmm(l.lnrevenue lncost ) robust small

  lnrevenue |  Coef.   Std. Err.  tP|t| [95% Conf.
Interval]
-+
   lnrevenue |
 L1. |.358987   .1176716 3.05   0.003  .123688
.594286
 |
lncost |
 --. |   1.185943   .036389132.59   0.000 1.113179
 1.258708
 L1. |  -.4332851   .1551862-2.79   0.007-.7435992
-.1229711
 |
year |
   2009  |  -.2100918   .0466175-4.51   0.000-.3033094
-.1168743
   2010  |  -.0936157   .0365742-2.56   0.013-.1667503
 -.020481
   2011  |  -.0351653.036502-0.96   0.339-.1081556
.037825
 |
   _cons |   .3372286.194194 1.74   0.088-.0510863
 .7255435
--
Instruments for first differences equation
  Standard
D.(2008b.year 2009.year 2010.year 2011.year 2012.year)
  GMM-type (missing=0, separate instruments for each period unless
collapsed)
L(1/4).(L.lnrevenue lncost)
Instruments for levels equation
  Standard
2008b.year 2009.year 2010.year 2011.year 2012.year
_cons
  GMM-type (missing=0, separate instruments for each period unless
collapsed)
D.(L.lnrevenue lncost)

Do you what I be doing wrong to correct this values?

Many thanks in advance,
Eliano

[[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] spped up a function

2013-07-03 Thread Jim Holtman
first thing to do when trying to speed up a function is to see where it is 
spending its time.  take a subset of the data and use Rprof to profile the 
code.  my guess is that a lot of time is taken up in the use of dataframes.  
see if you can use matrices instead.

Sent from my iPad

On Jul 2, 2013, at 13:47, Santiago Guallar sgual...@yahoo.com wrote:

 Hi,
 
 I have written a function to assign the values of a certain variable 'wd' 
 from a dataset to another dataset. Both contain data from the same time 
 period but differ in the length of their time intervals: 'GPS' has regular 
 10-minute intervals whereas 'xact' has irregular intervals. I attached 
 simplified text versions from write.table. You can also get a dput of 'xact' 
 in this address: http://www.megafileupload.com/en/file/431569/xact-dput.html).
 The original objects are large and the function takes almost one hour to 
 finish.
 Here's the function:
 
 fxG= function(xact, GPS){
 l - rep( 'A', nrow(GPS) )
 v - unique(GPS$Ring) # the process is carried out for several individuals 
 identified by 'Ring'
 for(k in 1:length(v) ){
 I = v[k]
 df - xact[xact$Ring == I,]
 for(i in 1:nrow(GPS)){
 if(GPS[i,]$Ring== I){# the code runs along the whole data.frame for each i; 
 it'd save time to make it stop with the last record of each i instead
 u - df$timepos = GPS[i,]$timepos
 # fill vector l for each interval t from xact = each interval from GPS (take 
 the max if there's  1 interval)
 l[i] - df[max( which(u == TRUE) ),]$wd
 }
 }
 }
 return(l)}
 
 vwd - fxG(xact, GPS)
 
 
 My question is: how can I speed up (optimize) this function?
 
 Thank you for your help
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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

2013-07-03 Thread tong
Dear all,

I want to run a nomal copula based quantile regression with XLS data.

I've worked out how to load xls data in r. 

the regression fumula is simply: y= a+bx+e  and the quantile curve is 

http://r.789695.n4.nabble.com/file/n4670779/%E6%97%A0%E6%A0%87%E9%A2%98.png 
 

I use:

 excel.file-file.path(D:/dailyvix.xls)
 dailyvix-readWorksheetFromFile(excel.file, sheet=1)
 names(dailyvix)
[1] y x
 fit1-nlrq(y~qnorm(pnorm(mu*qnorm(pnorm(x))+sqrt(1-mu*mu)*qnorm(tau))),
 tau=0.5, data=dailyvix)

However, I get
Error in getInitial.default(func, data, mCall = as.list(match.call(func,  : 
  no 'getInitial' method found for function objects


I am a greenhand. I don't know how to deal with such error.

I really need help

Looking forward to any reply

Yours,

Tong



--
View this message in context: 
http://r.789695.n4.nabble.com/nlrq-with-normal-copula-tp4670779.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] merge dataframes

2013-07-03 Thread André de Boer
Hello,

I have two dataframes:
dat1-data.frame(x=c(1.0,1.2,3.2,4.0,5.1),y=c(23,17,12,27,8))
dat2-data.frame(x=seq(0,6,by=0.1),y=rep(0,60)))

I want to replace the corresponding rows of dat2 with the ones of dat1.
I tried:

for(i in 1:nrow(dat1))
{
  dat2[dat2$x==dat1[i,1],2]-dat1[i,2]
}

But I discovered that not every 5.1 is equal:

 dat2[52,1][1] 5.1 dat1[5,1][1] 5.1 dat2[52,1]==dat1[5,1][1] FALSE



How to solve this?



Regards,

André

[[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] merge dataframes

2013-07-03 Thread jim holtman
FAQ 7.31


On Wed, Jul 3, 2013 at 7:55 AM, André de Boer rnie...@gmail.com wrote:

 Hello,

 I have two dataframes:
 dat1-data.frame(x=c(1.0,1.2,3.2,4.0,5.1),y=c(23,17,12,27,8))
 dat2-data.frame(x=seq(0,6,by=0.1),y=rep(0,60)))

 I want to replace the corresponding rows of dat2 with the ones of dat1.
 I tried:

 for(i in 1:nrow(dat1))
 {
   dat2[dat2$x==dat1[i,1],2]-dat1[i,2]
 }

 But I discovered that not every 5.1 is equal:

  dat2[52,1][1] 5.1 dat1[5,1][1] 5.1 dat2[52,1]==dat1[5,1][1] FALSE



 How to solve this?



 Regards,

 André

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

[[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-linear modelling with several variables including a categorical variable

2013-07-03 Thread Prof J C Nash (U30A)
If preytype is an independent variable, then models based on it should 
be OK. If preytype comes into the parameters you are trying to estimate, 
then the easiest way is often to generate all the possible combinations 
(integers -- fairly modest number of these) and run all the least 
squares minimizations. Crude but effective. nlxb from nlmrt or nlsLM 
from minpack.lm may be more robust in doing this, but less efficient if 
nls works OK.


JN

On 13-07-03 06:00 AM, r-help-requ...@r-project.org wrote:

Message: 10
Date: Tue, 2 Jul 2013 19:01:55 +0700
From: Robbie Weteringsrobbie.weteri...@gmail.com
To:r-help@r-project.org
Subject: [R] Non-linear modelling with several variables including a
categorical variable
Message-ID:
cafe5dhzrm+bpg1v77ezhun+tacv64j_9pnsfgh_xne5csz9...@mail.gmail.com
Content-Type: text/plain

Hello everyone,

I am trying to model some data regarding a predator prey interaction
experiment (n=26). Predation rate is my response variable and I have 4
explanatory variables: predator density (1,2,3,4 5), predator size, prey
density (5,10,15,20,25,30) and prey type (3 categories). I started with
several linear models (glm) and found (as expected) that prey and predator
density were non-linear related to predation rates. If I use a log
transformation on these variables I get really nice curves and an adjusted
R2 of 0.82, but it is not really the right approach for modelling
non-linear relationships. Therefore I switched to non-linear least square
regression (nls). I have several predator-prey models based on existing
ecological literature e.g.:

model1 - nls(rates ~ (a * prey)/(1 + b * prey), start = list(a = 0.27,b =
0.13), trace = TRUE) ### Holling's type II functional response

model2 - nls(rates ~ (a*prey)/(1+ (b * prey) + c * (pred -1 )), start =
list(a=0.22451, b=-0.18938, c=1.06941), trace=TRUE, subset=I1) ###
Beddington-**DeAngelis functional response

These models work perfectly, but now I want to add prey type as well. In
the linear models prey type was the most important variable so I don't want
to leave it out. I understand that you can't add categorical variables in
nls, so I thought I try a generalized additive model (gam).

The problem with the gam models is that the smoothers (both spline and
loess) don't work on both variables because there are only a very
restricted number of values for prey density and predator density. I can
manage to get a model with a single variable smoothed using loess. But for
two variables it is simply not working. The spline function does not work
at all because I have so few values (5) for my variables (see model 4).

model3 - gam(rates~ lo(pred, span=0.9)+prey) ## this one is actually
working but does not include a smoother for prey.

model4 - gam(rates~ s(pred)+prey) ## this one gives problems:
*A term has fewer unique covariate combinations than specified maximum
degrees of freedom*

My question is: are there any other possibilities to model data with 2
non-linear related variables in which I can also include a categorical
variable. I would prefer to use nls (model2) with for example different
intercepts for each category but I'm not sure how to get this sorted, if it
is possible at all. The dataset is too small to split it up into the three
categories, moreover, one of the categories only contains 5 data points.

Any help would be really appreciated.

With kind regards,
-- Robbie Weterings *Project Manager Cat Drop Thailand ** Tel:
+66(0)890176087 * 65/13 Mooban Chakangrao, Naimuang Muang Kamphaeng Phet
62000, Thailand àÅ¢·Õè 65/13 Á.ªÒ¡Ñ§ÃÒÇ ¶¹¹ ÃÒª´íÒà¹Ô¹2 ã¹àÁ×ͧ ÍíÒàÀÍ/
ࢵ àÁ×ͧ¡íÒàྦྷྪà ¨Ñ§ËÇÑ´ ¡íÒàྦྷྪà 62000
http://www.catdropfoundation.org
http://www.catdropfoundation.org/facebook/Facebook.html
*www.catdropfoundation.org* http://www.catdropfoundation.org/
*www.facebook.com/catdropfoundation*http://www.facebook.com/catdropfoundation
*Boorn 45, 9204 AZ, Drachten, The Netherlands* [[alternative HTML
version deleted]]


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


[R] One-parameter fitting

2013-07-03 Thread Birdada Simret
Greetings to every body.

we know that for linear regression: two-parameter fitting in R: (for a and
b as slope and intercept)

[a] for y=ax+b type models we use: lm(y~x)
[b] for y=axtype models we use:  lm(y~0+x)  = forced to pass through
origin

Now I have question:   what about y=b  fitting?  is there any model to
force or  impose the ax to be zero

Let say

x - c(1,2,3,4,5,6,7,8,9)
y - c( 0.853,0.852, 0.854, 0.858, 0.862, 0.856, 0.858, 0.857, 0.863)
plot(y~x, xlim=c(0,10), ylim=c(0,1))
abline(lm(y~x),col=blue)  # this doesn't give exact horizontal  but
slightly inclined.

or is it as simple as, just find the intercept using the lm(y~x) , then
abline(h=intercept,col=red) ?

any comment or advice is greatly appreciated ;)

[[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] One-parameter fitting

2013-07-03 Thread Rui Barradas

Hello,

Try ?mean

abline(h = mean(y), col = blue)

Hope this helps,

Rui Barradas



Em 03-07-2013 15:07, Birdada Simret escreveu:

Greetings to every body.

we know that for linear regression: two-parameter fitting in R: (for a and
b as slope and intercept)

[a] for y=ax+b type models we use: lm(y~x)
[b] for y=axtype models we use:  lm(y~0+x)  = forced to pass through
origin

Now I have question:   what about y=b  fitting?  is there any model to
force or  impose the ax to be zero

Let say

x - c(1,2,3,4,5,6,7,8,9)
y - c( 0.853,0.852, 0.854, 0.858, 0.862, 0.856, 0.858, 0.857, 0.863)
plot(y~x, xlim=c(0,10), ylim=c(0,1))
abline(lm(y~x),col=blue)  # this doesn't give exact horizontal  but
slightly inclined.

or is it as simple as, just find the intercept using the lm(y~x) , then
abline(h=intercept,col=red) ?

any comment or advice is greatly appreciated ;)

[[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] merge dataframes

2013-07-03 Thread David Carlson
In addition to reading Frequently Asked Questions Section 7.31, you
should always run your own code before posting. Yours does not work.
Spend some time reading one or more of the R tutorials and learn
about vectorization. It will save you time and typing. There are
many to choose from at

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

Do not try to match decimal values. Instead create an index value
that is a character string. Then you can match the character
strings:

 dat1-data.frame(x=c(1.0,1.2,3.2,4.0,5.1),y=c(23,17,12,27,8))
 dat2 - data.frame(x=seq(0.1,6,by=0.1),y=rep(0,60)) # Errors in
your code corrected here
 dat1$xc - sprintf(%1.1f, dat1$x, 1) # Create dat1 index value
as character
 dat2$xc - sprintf(%1.1f, dat2$x, 1) # Create dat2 index value
as character
 dat2[match(dat1$xc, dat2$xc),] - dat1 # update dat2 with dat1
 dat2[dat2$y0,] # Check the results
 x  y  xc
10 1.0 23 1.0
12 1.2 17 1.2
32 3.2 12 3.2
40 4.0 27 4.0
51 5.1  8 5.1
 dat1
x  y  xc
1 1.0 23 1.0
2 1.2 17 1.2
3 3.2 12 3.2
4 4.0 27 4.0
5 5.1  8 5.1

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


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of jim holtman
Sent: Wednesday, July 3, 2013 7:22 AM
To: André de Boer
Cc: R mailing list
Subject: Re: [R] merge dataframes

FAQ 7.31


On Wed, Jul 3, 2013 at 7:55 AM, Andri de Boer rnie...@gmail.com
wrote:

 Hello,

 I have two dataframes:
 dat1-data.frame(x=c(1.0,1.2,3.2,4.0,5.1),y=c(23,17,12,27,8))
 dat2-data.frame(x=seq(0,6,by=0.1),y=rep(0,60)))

 I want to replace the corresponding rows of dat2 with the ones of
dat1.
 I tried:

 for(i in 1:nrow(dat1))
 {
   dat2[dat2$x==dat1[i,1],2]-dat1[i,2]
 }

 But I discovered that not every 5.1 is equal:

  dat2[52,1][1] 5.1 dat1[5,1][1] 5.1 dat2[52,1]==dat1[5,1][1]
FALSE



 How to solve this?



 Regards,

 Andri

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

[[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] merge dataframes

2013-07-03 Thread Rui Barradas

Hello,

Or use ?all.equal.

all.equal(dat2[52, 1], dat1[5, 1])  # TRUE


Hope this helps,

Rui Barradas

Em 03-07-2013 15:18, David Carlson escreveu:

In addition to reading Frequently Asked Questions Section 7.31, you
should always run your own code before posting. Yours does not work.
Spend some time reading one or more of the R tutorials and learn
about vectorization. It will save you time and typing. There are
many to choose from at

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

Do not try to match decimal values. Instead create an index value
that is a character string. Then you can match the character
strings:


dat1-data.frame(x=c(1.0,1.2,3.2,4.0,5.1),y=c(23,17,12,27,8))
dat2 - data.frame(x=seq(0.1,6,by=0.1),y=rep(0,60)) # Errors in

your code corrected here

dat1$xc - sprintf(%1.1f, dat1$x, 1) # Create dat1 index value

as character

dat2$xc - sprintf(%1.1f, dat2$x, 1) # Create dat2 index value

as character

dat2[match(dat1$xc, dat2$xc),] - dat1 # update dat2 with dat1
dat2[dat2$y0,] # Check the results

  x  y  xc
10 1.0 23 1.0
12 1.2 17 1.2
32 3.2 12 3.2
40 4.0 27 4.0
51 5.1  8 5.1

dat1

 x  y  xc
1 1.0 23 1.0
2 1.2 17 1.2
3 3.2 12 3.2
4 4.0 27 4.0
5 5.1  8 5.1

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


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of jim holtman
Sent: Wednesday, July 3, 2013 7:22 AM
To: André de Boer
Cc: R mailing list
Subject: Re: [R] merge dataframes

FAQ 7.31


On Wed, Jul 3, 2013 at 7:55 AM, Andri de Boer rnie...@gmail.com
wrote:


Hello,

I have two dataframes:
dat1-data.frame(x=c(1.0,1.2,3.2,4.0,5.1),y=c(23,17,12,27,8))
dat2-data.frame(x=seq(0,6,by=0.1),y=rep(0,60)))

I want to replace the corresponding rows of dat2 with the ones of

dat1.

I tried:

for(i in 1:nrow(dat1))
{
   dat2[dat2$x==dat1[i,1],2]-dat1[i,2]
}

But I discovered that not every 5.1 is equal:


dat2[52,1][1] 5.1 dat1[5,1][1] 5.1 dat2[52,1]==dat1[5,1][1]

FALSE




How to solve this?



Regards,

Andri

 [[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] One-parameter fitting

2013-07-03 Thread S Ellison
 Now I have question:   what about y=b  fitting?  is there any model to
 force or  impose the ax to be zero

Rui Barradas has answered correctly for a simple lm case.

You can also do 
lm(y~1) to obtain an estimated mean.
 
That formulation happens to be quite useful if you are interested in a purely 
random-effects model* fitted using, say, lme, though you won't generally get a 
simple mean for unbalanced data in such a case.

S Ellison



***
This email and any attachments are confidential. Any use...{{dropped:8}}

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


Re: [R] One-parameter fitting

2013-07-03 Thread Birdada Simret
Thank you all ;)


On Wed, Jul 3, 2013 at 4:28 PM, S Ellison s.elli...@lgcgroup.com wrote:

  Now I have question:   what about y=b  fitting?  is there any model to
  force or  impose the ax to be zero

 Rui Barradas has answered correctly for a simple lm case.

 You can also do
 lm(y~1) to obtain an estimated mean.

 That formulation happens to be quite useful if you are interested in a
 purely random-effects model* fitted using, say, lme, though you won't
 generally get a simple mean for unbalanced data in such a case.

 S Ellison



 ***
 This email and any attachments are confidential. Any u...{{dropped:13}}

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


[R] promise already under evaluation

2013-07-03 Thread Sam Steingold
Hi, I asked this question on SO but got no answers:
http://stackoverflow.com/questions/17310825/r-promise-already-under-evaluation

I understand that you are probably sick and tired of answering the same 
question again, 
but I am still getting the error discussed in several other questions:

 promise already under evaluation: recursive default argument reference or 
 earlier problems?

even though I did follow the cumbersome advice of prepending .:

--8---cut here---start-8---
show.large.objects.threshold - 10
show.large.objects.exclude - c(closure)
show.large.objects - function (.envir = sys.frame(),
threshold = show.large.objects.threshold,
exclude = show.large.objects.exclude) {
  for (n in print(ls(.envir, all.names = TRUE))) tryCatch({
o - get(n,envir = .envir)
s - object.size(o)
if (s  threshold  !(typeof(o) %in% exclude)) {
  cat(n,: )
  print(s,units=auto)
}
  }, error = function(e) { cat(n=,n,\n); print(e) })
}
show.large.objects.stack - function (threshold = show.large.objects.threshold,
  skip.levels = 1,# do not examine the last 
level - this function
  exclude = show.large.objects.exclude) {
  for (level in 1:(sys.nframe()-skip.levels)) {
cat(*** show.large.objects.stack(,level,) )
print(sys.call(level))
show.large.objects(.envir = sys.frame(level))
  }
}
--8---cut here---end---8---

but I still get errors:

--8---cut here---start-8---
 f - function () { c - 1:1e7; d - 1:1e6; 
 print(system.time(show.large.objects.stack())) }
 f()
*** show.large.objects.stack( 1 ) f()
[1] c d
c : 38.1 Mb
d : 3.8 Mb
*** show.large.objects.stack( 2 ) print(system.time(show.large.objects.stack()))
[1] ... x  
n= ... 
simpleError in get(n, envir = .envir): argument ... is missing, with no 
default
n= x 
simpleError in get(n, envir = .envir): promise already under evaluation: 
recursive default argument reference or earlier problems?
*** show.large.objects.stack( 3 ) system.time(show.large.objects.stack())
[1] exprgcFirst ppt time   
n= expr 
simpleError in get(n, envir = .envir): promise already under evaluation: 
recursive default argument reference or earlier problems?
  user systemelapsed 
0 (0.00ms) 0 (0.00ms) 0.002 (2.00ms) 
--8---cut here---end---8---

So, what am I still doing wrong?
Do I really need the . in .envir?
Why do I get the [[argument ... is missing, with no default]] error?
Why do I get the [[promise already under evaluation]] error?
What is the right way to pass threshold and exclude from
show.large.objects.stack to show.large.objects?

Thanks!

PS. I would prefer an answer on SO, but please feel free to reply using any
venue you like and I will copy your explanation to the other venues.

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 13.04 (raring) X 11.0.11303000
http://www.childpsy.net/ http://iris.org.il http://mideasttruth.com
http://honestreporting.com http://openvotingconsortium.org
Linux - find out what you've been missing while you've been rebooting Windows.

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


Re: [R] promise already under evaluation

2013-07-03 Thread Sam Steingold
 * Sam Steingold f...@tah.bet [2013-07-03 11:33:47 -0400]:

 Hi, I asked this question on SO but got no answers:
 http://stackoverflow.com/questions/17310825/r-promise-already-under-evaluation

Backlin explained on SO that the errors are to be expected: ... is a
formal argument which was not supplied and expr and x were actually
being evaluated at the time of get() call.

The bottom line is that I must catch and ignore errors.

The remaining problem is: how do I pass the same arguments down?

e.g.,

--8---cut here---start-8---
f - function (... verbose=FALSE ...) { ... }
g - function (... verbose=FALSE ...) { ... f(... verbose=verbose ...) ... }
--8---cut here---end---8---

results in promise already under evaluation (and, yes, I do understand
why).

is there anything better than

--8---cut here---start-8---
f - function ( ... f.verbose=FALSE ... ) { ... }
g - function ( ... g.verbose=FALSE ... ) { ... f(... f.verbose=g.verbose ...) 
... }
--8---cut here---end---8---


-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 13.04 (raring) X 11.0.11303000
http://www.childpsy.net/ http://www.memritv.org http://mideasttruth.com
http://honestreporting.com http://think-israel.org http://jihadwatch.org
Incorrect time synchronization.

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

2013-07-03 Thread Dan Murphy
I have a vector of strings that contain mathematical expressions. E.g.,
x - c(5 = 7, z = 1+2)
and I would like to decompose each expression into its left- and
right-hand-side components etc., output something like

5 = 7
z = 1 + 2

Is there something built into the R language to accomplish this?
Thanks for 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.


Re: [R] Splitting a string expression into components

2013-07-03 Thread William Dunlap
If your syntax is like R's syntax then parse() can help.
  R p - parse(text=z = 1 + 2)
  R p[[1]] # the first ( only) expression in z = 1 + 2
  z = 1 + 2
  R as.list(p[[1]]) # the 'function' called (`=`) and its 'arguments'
  [[1]]
  `=`
  
  [[2]]
  z
  
  [[3]]
  1 + 2
  
  R as.list(p[[1]][[3]]) # ditto for the 2nd argument above
  [[1]]
  `+`

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

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 Dan Murphy
 Sent: Wednesday, July 03, 2013 10:38 AM
 To: R-help@r-project.org
 Subject: [R] Splitting a string expression into components
 
 I have a vector of strings that contain mathematical expressions. E.g.,
 x - c(5 = 7, z = 1+2)
 and I would like to decompose each expression into its left- and
 right-hand-side components etc., output something like
 
 5 = 7
 z = 1 + 2
 
 Is there something built into the R language to accomplish this?
 Thanks for 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.


Re: [R] Splitting a string expression into components

2013-07-03 Thread Bert Gunter
Alternatively, perhaps strsplit() with an appropriate regex argument.

See ?strsplit ?regexp

e.g.

strsplit (z=5,split = [=]+)
[[1]]
[1] z 5

This of course will only work if you know what the characters are that
define left and right, how complex the expressions might be, etc.
-- i.e. the simple case.

-- Bert

On Wed, Jul 3, 2013 at 10:55 AM, William Dunlap wdun...@tibco.com wrote:
 If your syntax is like R's syntax then parse() can help.
   R p - parse(text=z = 1 + 2)
   R p[[1]] # the first ( only) expression in z = 1 + 2
   z = 1 + 2
   R as.list(p[[1]]) # the 'function' called (`=`) and its 'arguments'
   [[1]]
   `=`

   [[2]]
   z

   [[3]]
   1 + 2

   R as.list(p[[1]][[3]]) # ditto for the 2nd argument above
   [[1]]
   `+`

   [[2]]
   [1] 1

   [[3]]
   [1] 2

 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 Dan Murphy
 Sent: Wednesday, July 03, 2013 10:38 AM
 To: R-help@r-project.org
 Subject: [R] Splitting a string expression into components

 I have a vector of strings that contain mathematical expressions. E.g.,
 x - c(5 = 7, z = 1+2)
 and I would like to decompose each expression into its left- and
 right-hand-side components etc., output something like

 5 = 7
 z = 1 + 2

 Is there something built into the R language to accomplish this?
 Thanks for 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.



-- 

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.


[R] Academic study of R users and developers

2013-07-03 Thread aserebrenik
Dear all,

A group of researchers from Eindhoven Univ of Technology (The Netherlands)
and UC Davis (USA) is conducting a study of support activities in R. In this
study, our goal is to understand how R user support activities have been
evolving over time, in the presence of different information exchange media,
such as mailing lists, forums, blogs or questionanswer websites. 

Your participation is voluntary and confidential. If you agree to
participate, you will be asked to complete self-report measures that tell us
a bit about your information seeking and information providing experiences
related to R. Participation in this study is expected to take about 10
minutes of your time.

We thank you in advance for your participation in this study. We plan to
include the results of this survey in a scientific publication. Individual
responses cannot be traced back to an individual respondent.

https://docs.google.com/forms/d/14dXaSdy2NJ94Fq50fAbmEr3_GK8XfbRdys9qPLMMZ-c/viewform
https://docs.google.com/forms/d/14dXaSdy2NJ94Fq50fAbmEr3_GK8XfbRdys9qPLMMZ-c/viewform
  

Best regards,
Alexander Serebrenik
Eindhoven Univ Technology
The Netherlands



--
View this message in context: 
http://r.789695.n4.nabble.com/Academic-study-of-R-users-and-developers-tp4670797.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] The R Journal, Volume 5, Issue 1

2013-07-03 Thread Hadley Wickham
Dear all,

The latest issue of The R Journal is now available at
http://journal.r-project.org/archive/2013-1/

Many thanks to all contributors.

Hadley

--
Editor-in-chief, The R Journal

___
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] String based chemical name identification

2013-07-03 Thread Zsurzsa Laszlo
The problem is the following:

I have two big databases one look like this:

  2-Methyl-4-trimethylsilyloxyoct-5-yne   Benzoic acid, methyl ester   Benzoic
acid, 2-methyl-, methyl ester   Acetic acid, phenylmethyl ester
 2,7-Dimethyl-4-trimethylsilyloxyoct-7-en-5-yne   etc.

The second one looks like this:

 Name: D-Tagatose 1,6-bisphosphate  Name: 1-Phosphatidyl-D-myo-inositol;:
1-Phosphatidyl-1D-myo-inositol;: 1-Phosphatidyl-myo-inositol;:
Phosphatidyl-1D-myo-inositol;: (3-Phosphatidyl)-1-D-inositol;:
1,2-Diacyl-sn-glycero-3-phosphoinositol;: Phosphatidylinositol  Name:
Androstenedione;: Androst-4-ene-3,17-dione;: 4-Androstene-3,17-dione  Name:
Spermine;: N,N'-Bis(3-aminopropyl)-1,4-butanediamine  Name: H+;: Hydron  Name:
3-Iodo-L-tyrosine  etc.

Both of them have more then 3000 lines. Matching their name by hand is not
an option because I don't know chemistry.

*Possible solution I came up with*:

Go through all the names of the first database and then try to match with
the other one. I'm using *regexec *and *strsplit *functions for the
matching. Basically I split the name into small chunks and try to get some
hit in the other database.

I can supply code If needed but I did not want to spam in the first mail.


Any solution is welcome! It can be in pseudo-cod also or in any type of
logical arguing. It does not matter.


Laszlo-Andras Zsurzsa

Msc. Informatics, Technical University Munchen

[[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] Subsetting multiple rows of a data frame at once

2013-07-03 Thread arun

Hi,
Try this:

set.seed(24)
df- data.frame(x=sample(seq(0.25,4.25,by=.05),1e5,replace=TRUE),y= 
sample(seq(0.10,1.05,by=.05),1e5,replace=TRUE),z=rnorm(1e5))

#Used a shorter vector 
x1- c(1.05,2.85,3.40,4.25,0.25)
y1- c(0.25,0.10,0.90,0.25,1.05)

res-do.call(rbind,lapply(seq_along(x1),function(i) 
subset(df,x==x1[i]y==y1[i])))
head(res,2)
#    x    y  z
#466  1.05 0.25  0.7865224
#4119 1.05 0.25 -1.5679096
 tail(res,2)
# x    y  z
#98120 0.25 1.05 -2.1239596
#98178 0.25 1.05  0.3321464


A.K.

Hi Everyone, 

First time poster so any posting rules i should know about feel free to 
advise... 

I've got a data frame of 250 000 rows in columns of x y and z. 

i need to extract 20-30 rows from the data frame with specific x
 and y values, such that i can find the z value that corresponds. There 
is no repeated data. (its actually 250 000 squares in a 5x5m grid) 

to find them individually i can use subset successfully 

result-subset(df,x==1.05  y==c0.25) 

gives me the row in the dataframe with that x and y value. 

so if i have 

x = 1.05 2.85 3.40 4.25 0.25 3.05 3.70 0.20 0.30 0.70 1.05 1.20 
1.40 1.90 2.70 3.25 3.55 4.60 2.05 2.15 3.70 4.85 4.90 1.60 2.45 3.20 
3.90 4.45 

and 

y= 0.25 0.10 0.90 0.25 1.05 1.70 2.05 2.90 2.35 2.60 2.55 2.15 
2.75 2.05 2.70 2.25 2.55 2.05 3.65 3.05 3.00 3.50 3.75 4.85 4.50 4.50 
3.35 4.90 

then how can i retrieve the rows for all those values at once. 

if i name x=xt and y=yt and then 

result-subset(df,x==xt  y==yt) 

then i get 

result 
[1] x      y      Height 
0 rows (or 0-length row.names) 

i dont understand why zero rows are selected. obviously im 
applying the vectors inappropriately, but i cant seem to find anything 
on this method of subsetting online. 

Thanks for any replies!   


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Meta-analysis on a repeated measures design with multiple trials per subject using metafor

2013-07-03 Thread Marc Heerdink

Hi all,

I am currently attempting to compile a summary of a series of five 
psychological experiments, and I am trying to do this using the metafor 
package. However, I am quite unsure which of the scenarios described in 
the metafor help pages applies to these data, because it is a repeated 
measures design, with multiple trials in each condition.


Assume that for every participant, I have a basic contingency table such 
as this one:


treatment
1   2
response
1   10  20
2   20  10

(if this ASCII version does not work, I have 30 trials in each 
treatment, and participants give either response 1 or 2; the exact 
numbers don't matter)


The problem that I am trying to solve is how to convert these numbers to 
an effect size estimate that I can use with metafor.


As far as I understand it, I can only use it to get an effect size for 
outcomes that are dichotomous; i.e., either 1 or 0 for any subject. 
However, I have proportion data for every participant.


I have considered and tried these strategies:

1. Base the effect size on within-participant proportion differences. 
That is, in the table above, the treatment effect would be 
(20/30)-(10/30) = 1/3; and I would take the M and SD of these values to 
estimate a study-level effect (MN measure in metafor).


2. Use the overall treatment * response contingency table, ignoring the 
fact that these counts come from different participants (PHI or OR 
measures in metafor). In a study with 10 participants, I would get cell 
counts around 150.


However, from the research I've done into this topic, I know that 1) is 
not applicable to (as far as I understand) an odds ratio, and I suspect 
2) overestimates the effect.


A third method would be to use the regression coefficients, that I can 
easily obtain since I have all the raw data that I need. However, it is 
unclear to me whether and if yes, how I can use these in the metafor 
package.


From my understanding of another message about this topic I found on 
this list (1), I understand that having access to the raw data is an 
advantage, but I am not sure whether the scenario mentioned applies to 
my situation.


1: 
http://r.789695.n4.nabble.com/meta-analysis-with-repeated-measure-designs-td2252644.html


I would very much appreciate any suggestions or hints on this topic.

Regards,
Marc

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


[R] nls.profile

2013-07-03 Thread Thomas de Marchin

Hello Daniel,

I have the same problem than you : i use nls.profile to compute 
confidence intervals of estimated parameters but it fails and stop...
I tried to increase alphamax value as Douglas suggested that it should 
work but it's not...


Did you find a method to tell nls.profile to ignore errors and proceed 
to the next parameter value ?


Thank you very much!


--
Thomas de Marchin
PhD Student
Laboratory of Bioenergetics
University of Liège, Institute of Botany (B.22-P.70)
Bld du Rectorat, 27
Sart Tilman, 4000 Liège, Belgium
Tel: +32 (0)4 366 38 08
http://www.biophoto.ulg.ac.be

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] qtlnet mcmc.qtlnet sample genetic architeture and QTL network

2013-07-03 Thread schaefe9
Im working with the qtlnet package and want to sample the genetic
architecture and QTL network. I aiming to do this with the function
qtlnet:::mcmc.qtlnet. So far so good. However I cant do it with my own
cross dataset. data(Pscdbp) works fine, but not my own. I mean it is from
class cross. However, I receive the error:

Error in dimnames(geno.dat)[[2]] - tmp : 'dimnames' must be a list

Can anybody help me out? I uploaded my crossdata here:

http://www.risclab.com/cross_gpsm.RData

Would be awesome if somebody could help me out

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

2013-07-03 Thread JiangZhengyu



Dear R experts,

I have two  matrices (mat1  mat2) with the same dimension  the cells (row and 
column) are corresponding to each other.
 
I want to change cell values to NA given values of the corresponding cells in 
mat1 and mat2 are both 1.
 
E.g. both mat1[2,3] and mat2[2,3] are 1, I will put mat1[2,3]=NA, and 
mat2[2,3]=NA; if either mat1[2,3]=1 or  mat2[2,3]=1, I will save both cells.
 
I tried the code, but not working. Could anyone can help fix the problem?
 
mat1[mat11mat21]=NA
mat2[mat11mat21]=NA
 
 
 mat1=matrix(rnorm(12),3)
 mat2=matrix(rnorm(12),3)
 mat1
   [,1]   [,2]   [,3]   [,4]
[1,] -1.3387075 -0.7142333 -0.5614211  0.1846955
[2,] -0.7936087 -0.2215797 -0.3686067  0.7328731
[3,]  0.6505082  0.1826019  1.5577883 -1.5580384
 mat2
   [,1]   [,2]   [,3]   [,4]
[1,]  0.4331573 -1.8086826 -1.7688123 -1.4278934
[2,] -0.1841451  0.1738648 -1.1086942  1.3065109
[3,] -1.0827245 -0.4143808 -0.6889405  0.4046203

  
[[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] change cell values

2013-07-03 Thread Rui Barradas

Hello,

It's not working because you are changing mat1 before the second 
condition is evaluated, and so mat1 is full of NA values. Try the following.




tmp - mat1  # Make a copy
tmp[mat1  1  mat2  1] - NA  # And change that copy
mat2[mat1  1  mat2  1] - NA
mat1 - tmp
rm(tmp)


Hope this helps,

Rui Barradas

Em 03-07-2013 22:27, JiangZhengyu escreveu:




Dear R experts,

I have two  matrices (mat1  mat2) with the same dimension  the cells (row and 
column) are corresponding to each other.

I want to change cell values to NA given values of the corresponding cells in mat1 
and mat2 are both 1.

E.g. both mat1[2,3] and mat2[2,3] are 1, I will put mat1[2,3]=NA, and mat2[2,3]=NA; 
if either mat1[2,3]=1 or  mat2[2,3]=1, I will save both cells.

I tried the code, but not working. Could anyone can help fix the problem?

mat1[mat11mat21]=NA
mat2[mat11mat21]=NA



mat1=matrix(rnorm(12),3)
mat2=matrix(rnorm(12),3)
mat1

[,1]   [,2]   [,3]   [,4]
[1,] -1.3387075 -0.7142333 -0.5614211  0.1846955
[2,] -0.7936087 -0.2215797 -0.3686067  0.7328731
[3,]  0.6505082  0.1826019  1.5577883 -1.5580384

mat2

[,1]   [,2]   [,3]   [,4]
[1,]  0.4331573 -1.8086826 -1.7688123 -1.4278934
[2,] -0.1841451  0.1738648 -1.1086942  1.3065109
[3,] -1.0827245 -0.4143808 -0.6889405  0.4046203


[[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] change cell values

2013-07-03 Thread JiangZhengyu
Hi Rui,
 
Yes, I see.  You are right. Thanks for your help.
 
Zhengyu
 
 Date: Wed, 3 Jul 2013 22:38:37 +0100
 From: ruipbarra...@sapo.pt
 To: zhyjiang2...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] change cell values
 
 Hello,
 
 It's not working because you are changing mat1 before the second 
 condition is evaluated, and so mat1 is full of NA values. Try the following.
 
 
 
 tmp - mat1  # Make a copy
 tmp[mat1  1  mat2  1] - NA  # And change that copy
 mat2[mat1  1  mat2  1] - NA
 mat1 - tmp
 rm(tmp)
 
 
 Hope this helps,
 
 Rui Barradas
 
 Em 03-07-2013 22:27, JiangZhengyu escreveu:
 
 
 
  Dear R experts,
 
  I have two  matrices (mat1  mat2) with the same dimension  the cells (row 
  and column) are corresponding to each other.
 
  I want to change cell values to NA given values of the corresponding cells 
  in mat1 and mat2 are both 1.
 
  E.g. both mat1[2,3] and mat2[2,3] are 1, I will put mat1[2,3]=NA, and 
  mat2[2,3]=NA; if either mat1[2,3]=1 or  mat2[2,3]=1, I will save both 
  cells.
 
  I tried the code, but not working. Could anyone can help fix the problem?
 
  mat1[mat11mat21]=NA
  mat2[mat11mat21]=NA
 
 
  mat1=matrix(rnorm(12),3)
  mat2=matrix(rnorm(12),3)
  mat1
  [,1]   [,2]   [,3]   [,4]
  [1,] -1.3387075 -0.7142333 -0.5614211  0.1846955
  [2,] -0.7936087 -0.2215797 -0.3686067  0.7328731
  [3,]  0.6505082  0.1826019  1.5577883 -1.5580384
  mat2
  [,1]   [,2]   [,3]   [,4]
  [1,]  0.4331573 -1.8086826 -1.7688123 -1.4278934
  [2,] -0.1841451  0.1738648 -1.1086942  1.3065109
  [3,] -1.0827245 -0.4143808 -0.6889405  0.4046203
 
  
  [[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] modify timestemp

2013-07-03 Thread Ye Lin
Hey All,

I want to standardize my timestamp which is formatted as hh:mm:ss

 My data looks like this:

 Date Time
01/01/2013 00:09:01
01/02/2013 00:10:14
01/03/2013 00:11:27
01/04/2013 00:12:40
01/05/2013 00:13:53
01/06/2013 00:15:06
01/07/2013 00:16:19
01/08/2013 00:17:32
01/09/2013 00:18:45
01/10/2013 00:19:58

Dataset - structure(list(Date = c(01/01/2013, 01/02/2013,
01/03/2013,
01/04/2013, 01/05/2013, 01/06/2013, 01/07/2013, 01/08/2013,
01/09/2013, 01/10/2013), Time = c(00:09:01, 00:10:14,
00:11:27, 00:12:40, 00:13:53, 00:15:06, 00:16:19, 00:17:32,
00:18:45, 00:19:58)), .Names = c(Date, Time), class = data.frame,
row.names = c(NA,
-10L))

I would like to change all the records in Time column uniformed as
hh:mm:00, then the output would be this:

Date Time
01/01/2013 00:09:00
01/02/2013 00:10:00
01/03/2013 00:11:00
01/04/2013 00:12:00
01/05/2013 00:13:00
01/06/2013 00:15:00
01/07/2013 00:16:00
01/08/2013 00:17:00
01/09/2013 00:18:00
01/10/2013 00:19:00

Thanks for your help!

[[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] change cell values

2013-07-03 Thread David Winsemius

On Jul 3, 2013, at 2:27 PM, JiangZhengyu wrote:

 
 
 
 Dear R experts,
 
 I have two  matrices (mat1  mat2) with the same dimension  the cells (row 
 and column) are corresponding to each other.
 
 I want to change cell values to NA given values of the corresponding cells in 
 mat1 and mat2 are both 1.
 
 E.g. both mat1[2,3] and mat2[2,3] are 1, I will put mat1[2,3]=NA, and 
 mat2[2,3]=NA; if either mat1[2,3]=1 or  mat2[2,3]=1, I will save both cells.
 
 I tried the code, but not working. Could anyone can help fix the problem?
 
 mat1[mat11mat21]=NA
 mat2[mat11mat21]=NA

I beleive the problem is that after the first NA assignment that mat1 will have 
changed. You need to record the status of both mat1 and mat2 before the change:

 both - mat11mat21  
  both
  [,1]  [,2]  [,3] [,4]
[1,] FALSE FALSE  TRUE TRUE
[2,]  TRUE FALSE  TRUE TRUE
[3,] FALSE  TRUE FALSE TRUE
 
 mat1[both] - NA
 mat2[both] - NA
 mat1
   [,1]  [,2] [,3] [,4]
[1,]  1.5599872  2.209537   NA   NA
[2,] NA -1.144140   NA   NA
[3,] -0.8516326NA 1.000368   NA
 mat2
  [,1]   [,2] [,3] [,4]
[1,] 0.8863107 -0.3863741   NA   NA
[2,]NA  1.3185811   NA   NA
[3,] 1.4487338 NA 1.051689   NA

There is also formalism:

is.na(object) - logical.vector so it could have been:

is.na(mat1) - both
is.na(mat2) - both


 
 
 mat1=matrix(rnorm(12),3)
 mat2=matrix(rnorm(12),3)
 mat1
   [,1]   [,2]   [,3]   [,4]
 [1,] -1.3387075 -0.7142333 -0.5614211  0.1846955
 [2,] -0.7936087 -0.2215797 -0.3686067  0.7328731
 [3,]  0.6505082  0.1826019  1.5577883 -1.5580384
 mat2
   [,1]   [,2]   [,3]   [,4]
 [1,]  0.4331573 -1.8086826 -1.7688123 -1.4278934
 [2,] -0.1841451  0.1738648 -1.1086942  1.3065109
 [3,] -1.0827245 -0.4143808 -0.6889405  0.4046203
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

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


[R] converting a list of loglin terms to a model formula

2013-07-03 Thread Michael Friendly
I'm developing some functions to create symbolic specifications for 
loglinear models of different types.
I don't really know how to 'compute' with model formulas, so I've done 
this in the notation

for stats::loglin(), which is a list of high-order terms in the model.

What I'd like is a function to turn the results of these into a model 
formula, suitable for

MASS::loglm.  That's the reverse of what loglm does.

For example, the simplest versions of models for 3-way tables for joint,
 conditional, and marginal independence can be computed as follows. 
After each, I indicated

the WANTED model formula I'd like from the result

 joint(3)
$term1
[1] 1 2

$term2
[1] 3

WANTED:  ~ 1:2 + 3

 condit(3)
$term1
[1] 1 3

$term2
[1] 2 3

WANTED: ~ 1:2 + 2:3

 mutual(3)
$term1
[1] 1

$term2
[1] 2

$term3
[1] 3

WANTED: ~ 1 + 2 + 3

In case anyone want to play with the code, here are the current, not too 
elegant definitions

of the functions, and some further test cases,

# models of joint independence
  joint - function(nf, factors=1:nf, with=nf) {
if (nf == 1) return (list(term1=factors[1]))
if (nf == 2) return (list(term1=factors[1], term2=factors[2]))
others - setdiff(1:nf, with)
result - list(term1=factors[others], term2=factors[with])
result
  }
# conditional independence
  condit - function(nf, factors=1:nf, with=nf) {
if (nf == 1) return (list(term1=factors[1]))
if (nf == 2) return (list(term1=factors[1], term2=factors[2]))
main - setdiff(1:nf, with)
others - matrix(factors[with], length(with), length(main))
result - rbind(factors[main], others)
result - as.list(as.data.frame(result, stringsAsFactors=FALSE))
names(result) - paste('term', 1:length(result), sep='')
result
  }
# mutual independence
  mutual - function(nf, factors=1:nf) {
result - sapply(factors[1:nf], list)
names(result) - paste('term', 1:length(result), sep='')
result
  }

### some comparisons

loglin(HairEyeColor, list(c(1, 2), c(1, 3), c(2, 3)))$lrt
loglm(~1:2 + 1:3 +2:3, HairEyeColor)

# use factor names
joint(3, factors=names(dimnames(HairEyeColor)))
condit(3, factors=names(dimnames(HairEyeColor)))

loglin(HairEyeColor, joint(3))$lrt
loglm(~1:2 + 3, HairEyeColor)

loglin(HairEyeColor, condit(3))$lrt
loglm(~1:3 + 2:3, HairEyeColor)



--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.  Chair, Quantitative Methods
York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

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


Re: [R] String based chemical name identification

2013-07-03 Thread Law, Jason
Might be better off using a web service like ChemSpider to do the matching for 
you http://www.chemspider.com/AboutServices.aspx?.  The idea that you can 
identify the synonyms by name is probably optimistic unless they are exact 
matches.

Here's some python code that seems to make it pretty easy: 
https://github.com/mcs07/ChemSpiPy.  Search the names, extract the InChI for 
the best match and then you can match them in R via the InChI.  Might require 
some fixing by hand afterwards.

HTH,

Jason Law

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Zsurzsa Laszlo
Sent: Wednesday, July 03, 2013 7:28 AM
To: r-help@r-project.org
Subject: [R] String based chemical name identification

The problem is the following:

I have two big databases one look like this:

  2-Methyl-4-trimethylsilyloxyoct-5-yne   Benzoic acid, methyl ester   Benzoic
acid, 2-methyl-, methyl ester   Acetic acid, phenylmethyl ester
 2,7-Dimethyl-4-trimethylsilyloxyoct-7-en-5-yne   etc.

The second one looks like this:

 Name: D-Tagatose 1,6-bisphosphate  Name: 1-Phosphatidyl-D-myo-inositol;:
1-Phosphatidyl-1D-myo-inositol;: 1-Phosphatidyl-myo-inositol;:
Phosphatidyl-1D-myo-inositol;: (3-Phosphatidyl)-1-D-inositol;:
1,2-Diacyl-sn-glycero-3-phosphoinositol;: Phosphatidylinositol  Name:
Androstenedione;: Androst-4-ene-3,17-dione;: 4-Androstene-3,17-dione  Name:
Spermine;: N,N'-Bis(3-aminopropyl)-1,4-butanediamine  Name: H+;: Hydron  Name:
3-Iodo-L-tyrosine  etc.

Both of them have more then 3000 lines. Matching their name by hand is not an 
option because I don't know chemistry.

*Possible solution I came up with*:

Go through all the names of the first database and then try to match with the 
other one. I'm using *regexec *and *strsplit *functions for the matching. 
Basically I split the name into small chunks and try to get some hit in the 
other database.

I can supply code If needed but I did not want to spam in the first mail.


Any solution is welcome! It can be in pseudo-cod also or in any type of logical 
arguing. It does not matter.


Laszlo-Andras Zsurzsa

Msc. Informatics, Technical University Munchen

[[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] change cell values

2013-07-03 Thread arun
Hi,

set.seed(24) 
mat1=matrix(rnorm(12),3)
set.seed(28)
mat2=matrix(rnorm(12),3)
 indx- mat11  mat21
mat1[indx]-NA
 mat2[indx]-NA
 mat1
# [,1] [,2] [,3]    [,4]
#[1,]   NA   NA   NA 0.002311942
#[2,]   NA   NA   NA  NA
#[3,]   NA   NA   NA 0.598269113
 mat2
# [,1] [,2] [,3] [,4]
#[1,]   NA   NA   NA 1.841481
#[2,]   NA   NA   NA   NA
#[3,]   NA   NA   NA 1.520367
A.K.

- Original Message -
From: JiangZhengyu zhyjiang2...@hotmail.com
To: r-help@r-project.org r-help@r-project.org
Cc: 
Sent: Wednesday, July 3, 2013 5:27 PM
Subject: [R] change cell values




Dear R experts,

I have two  matrices (mat1  mat2) with the same dimension  the cells (row and 
column) are corresponding to each other.

I want to change cell values to NA given values of the corresponding cells in 
mat1 and mat2 are both 1.

E.g. both mat1[2,3] and mat2[2,3] are 1, I will put mat1[2,3]=NA, and 
mat2[2,3]=NA; if either mat1[2,3]=1 or  mat2[2,3]=1, I will save both cells.

I tried the code, but not working. Could anyone can help fix the problem?

mat1[mat11mat21]=NA
mat2[mat11mat21]=NA


 mat1=matrix(rnorm(12),3)
 mat2=matrix(rnorm(12),3)
 mat1
           [,1]       [,2]       [,3]       [,4]
[1,] -1.3387075 -0.7142333 -0.5614211  0.1846955
[2,] -0.7936087 -0.2215797 -0.3686067  0.7328731
[3,]  0.6505082  0.1826019  1.5577883 -1.5580384
 mat2
           [,1]       [,2]       [,3]       [,4]
[1,]  0.4331573 -1.8086826 -1.7688123 -1.4278934
[2,] -0.1841451  0.1738648 -1.1086942  1.3065109
[3,] -1.0827245 -0.4143808 -0.6889405  0.4046203

                          
    [[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] modify timestemp

2013-07-03 Thread arun
Hi,
May be this helps:

dat1# dataset
dat1[,2]-gsub(\\d+$,00,dat1[,2])
 dat1
# Date Time
#1  01/01/2013 00:09:00
#2  01/02/2013 00:10:00
#3  01/03/2013 00:11:00
#4  01/04/2013 00:12:00
#5  01/05/2013 00:13:00
#6  01/06/2013 00:15:00
#7  01/07/2013 00:16:00
#8  01/08/2013 00:17:00
#9  01/09/2013 00:18:00
#10 01/10/2013 00:19:00
A.K.


Hey All, 

I want to standardize my timestamp which is formatted as hh:mm:ss 

 My data looks like this: 

     Date     Time 
01/01/2013 00:09:01 
01/02/2013 00:10:14 
01/03/2013 00:11:27 
01/04/2013 00:12:40 
01/05/2013 00:13:53 
01/06/2013 00:15:06 
01/07/2013 00:16:19 
01/08/2013 00:17:32 
01/09/2013 00:18:45 
01/10/2013 00:19:58 

Dataset - structure(list(Date = c(01/01/2013, 01/02/2013, 
01/03/2013, 
01/04/2013, 01/05/2013, 01/06/2013, 01/07/2013, 01/08/2013, 
01/09/2013, 01/10/2013), Time = c(00:09:01, 00:10:14, 
00:11:27, 00:12:40, 00:13:53, 00:15:06, 00:16:19, 00:17:32, 
00:18:45, 00:19:58)), .Names = c(Date, Time), class = data.frame, 
row.names = c(NA, 
-10L)) 

I would like to change all the records in Time column uniformed as 
hh:mm:00, then the output would be this: 

Date     Time 
01/01/2013 00:09:00 
01/02/2013 00:10:00 
01/03/2013 00:11:00 
01/04/2013 00:12:00 
01/05/2013 00:13:00 
01/06/2013 00:15:00 
01/07/2013 00:16:00 
01/08/2013 00:17:00 
01/09/2013 00:18:00 
01/10/2013 00:19:00 

Thanks for your help!

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


Re: [R] converting a list of loglin terms to a model formula

2013-07-03 Thread Henrique Dallazuanna
Try this:

 as.formula(sprintf( ~ %s, do.call(paste, c(lapply(mutual(3), paste,
collapse = :), sep = +



On Wed, Jul 3, 2013 at 6:55 PM, Michael Friendly frien...@yorku.ca wrote:

 I'm developing some functions to create symbolic specifications for
 loglinear models of different types.
 I don't really know how to 'compute' with model formulas, so I've done
 this in the notation
 for stats::loglin(), which is a list of high-order terms in the model.

 What I'd like is a function to turn the results of these into a model
 formula, suitable for
 MASS::loglm.  That's the reverse of what loglm does.

 For example, the simplest versions of models for 3-way tables for joint,
  conditional, and marginal independence can be computed as follows. After
 each, I indicated
 the WANTED model formula I'd like from the result

  joint(3)
 $term1
 [1] 1 2

 $term2
 [1] 3

 WANTED:  ~ 1:2 + 3

  condit(3)
 $term1
 [1] 1 3

 $term2
 [1] 2 3

 WANTED: ~ 1:2 + 2:3

  mutual(3)
 $term1
 [1] 1

 $term2
 [1] 2

 $term3
 [1] 3

 WANTED: ~ 1 + 2 + 3

 In case anyone want to play with the code, here are the current, not too
 elegant definitions
 of the functions, and some further test cases,

 # models of joint independence
   joint - function(nf, factors=1:nf, with=nf) {
 if (nf == 1) return (list(term1=factors[1]))
 if (nf == 2) return (list(term1=factors[1], term2=factors[2]))
 others - setdiff(1:nf, with)
 result - list(term1=factors[others], term2=factors[with])
 result
   }
 # conditional independence
   condit - function(nf, factors=1:nf, with=nf) {
 if (nf == 1) return (list(term1=factors[1]))
 if (nf == 2) return (list(term1=factors[1], term2=factors[2]))
 main - setdiff(1:nf, with)
 others - matrix(factors[with], length(with), length(main))
 result - rbind(factors[main], others)
 result - as.list(as.data.frame(result, stringsAsFactors=FALSE))
 names(result) - paste('term', 1:length(result), sep='')
 result
   }
 # mutual independence
   mutual - function(nf, factors=1:nf) {
 result - sapply(factors[1:nf], list)
 names(result) - paste('term', 1:length(result), sep='')
 result
   }

 ### some comparisons

 loglin(HairEyeColor, list(c(1, 2), c(1, 3), c(2, 3)))$lrt
 loglm(~1:2 + 1:3 +2:3, HairEyeColor)

 # use factor names
 joint(3, factors=names(dimnames(**HairEyeColor)))
 condit(3, factors=names(dimnames(**HairEyeColor)))

 loglin(HairEyeColor, joint(3))$lrt
 loglm(~1:2 + 3, HairEyeColor)

 loglin(HairEyeColor, condit(3))$lrt
 loglm(~1:3 + 2:3, HairEyeColor)



 --
 Michael Friendly Email: friendly AT yorku DOT ca
 Professor, Psychology Dept.  Chair, Quantitative Methods
 York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
 4700 Keele StreetWeb:   http://www.datavis.ca
 Toronto, ONT  M3J 1P3 CANADA

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




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[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] setClass confusion

2013-07-03 Thread Erin Hodgess
Dear R People:


I am experimenting with S4 classes and methods but am having trouble with
setting up a class.

Here is an example:

 buzz - setClass(buzz,slots=c(x=matrix),
+ validity - function(object) {
+ if(is.matrix(object)==FALSE)stop(Input must be a matrix)
+ TRUE
+ })
Error in setClass(buzz, slots = c(x = matrix), validity -
function(object) { :
  Argument representation cannot be used if argument slots is supplied


I know that there is something simple that I'm just not seeing.

This is R-3.0.1 for Windows.
Thanks for any help.

Sincerely,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] setClass confusion

2013-07-03 Thread Duncan Murdoch

On 13-07-03 7:54 PM, Erin Hodgess wrote:

Dear R People:


I am experimenting with S4 classes and methods but am having trouble with
setting up a class.

Here is an example:


buzz - setClass(buzz,slots=c(x=matrix),

+ validity - function(object) {
+ if(is.matrix(object)==FALSE)stop(Input must be a matrix)
+ TRUE
+ })
Error in setClass(buzz, slots = c(x = matrix), validity -
function(object) { :
   Argument representation cannot be used if argument slots is supplied




I know that there is something simple that I'm just not seeing.


Since you used -, your third argument uses the positional name 
representation, not validity, which is presumably what you intended.


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.