[R] Help on Principal Component Analysis in R

2015-01-13 Thread R Help!
Hello!

I am a beginner to R. I have read several guides, but still am stuck on
this:

I have data in an excel csv file, on which I want to run PCA.
I'm not sure how the prcomp formula works. The help page states:
prcomp(x, retx = TRUE, center = TRUE, scale. = FALSE,
tol = NULL, ...)

what is x referring to? I tried putting the file name for x, but i get the
following error:
Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric

what kind of numeric value do I need to put in for x?

Potentially helpful information: my data sheet has around 48 columns and
over 7000 rows. I have converted the csv file into a matrix in R.

Thanks in advance for all your help.

I'd appreciate step by step instructions on how to go from my csv file to a
PCA biplot in R.

[[alternative HTML version deleted]]

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


Re: [R] changing column labels for data frames inside a list

2015-03-31 Thread r-help
> Date: Mon, 30 Mar 2015 09:54:39 -0400
> From: Vikram Chhatre 
> To: r-help@r-project.org
> Subject: [R] changing column labels for data frames inside a list
> Message-ID:
>  Content-Type: text/plain; charset="UTF-8"
>
> > summary(mygenfreqt)
>   Length Class  Mode
> dat1.str 59220  -none- numeric
> dat2.str 59220  -none- numeric
> dat3.str 59220  -none- numeric
>
> > head(mylist[[1]])
>1 2 3 4 5 6 7 8 910
>  12
> L0001.1 0.60 0.500 0.325 0.675 0.600 0.500 0.500 0.375 0.550 0.475 0.3
> 0.275
> L0001.2 0.40 0.500 0.675 0.325 0.400 0.500 0.500 0.625 0.450 0.525 0.6
> 0.725
>
> I want to change 1:12 to pop1:pop12
>
> mylist<- lapply(mylist, function(e) colnames(e) <- paste0('pop',1:12))
>
> What this is doing is replacing the data frames with just names
> pop1:pop12.  I just want to replace the column labels.
>
> Thanks for any suggestions.

Some readers have already replied, but here is another option that exploits 
lapply()'s "..." parameter.  First, we make a reproducible example.

(lista <- list(mtcars, mtcars))

Now, we get the unique number of columns of the data frames in the variable 
"lista".

(n.cols <- unique(sapply(lista, ncol)))

Finally, we call lapply() and `colnames<-` to change the column names of both 
data frames in "lista".  See lapply()'s "..." parameter (?lapply).

(lista <- lapply(X = lista, FUN = `colnames<-`, paste0("pop", seq_len(n.cols

>     [[alternative HTML version deleted]]

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


Re: [R] If else statements

2010-03-23 Thread R Help
The short answer is yes, you can, but your syntax is wrong.  You need
to make sure you wrap your conditions inside brackets, and use {, not
(, to delineate your if statements.

> for (v in 1:6) {
> for (i in 2:200) {
> if (v==1){
   if (max(x*v-y*v)>1)
 break()
  }
  }
  }
 et cetera

On Tue, Mar 23, 2010 at 3:32 AM, tj  wrote:
>
> Hi everyone!
> May I request again for your help?
> I need to make some codes using if else statements...
> Can I do an "if-else statement" inside an "if-else statement"? Is this the
> correct form of writing it?
> Thank you.=)
>
> Example:
>
> for (v in 1:6) {
> for (i in 2:200) {
> if (v==1)
> (if max(x*v-y*v)>1 break())
>
> if (v==2)
> (if max(x*v-y*v)>1.8 break())
>
> if (v==3)
> (if max(x*v-y*v)>2 break())
> }
> }
> --
> View this message in context: 
> http://n4.nabble.com/If-else-statements-tp1678705p1678705.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] difference of two rows

2009-11-25 Thread R Help
You want to use tapply

?tapply

This is a simple example

dat = data.frame(a=sample(1:10,100,T),b=rnorm(100,0,1))
tapply(dat$b,dat$a,mean)

Hope that helps,
Sam

On Wed, Nov 25, 2009 at 11:55 AM, clion  wrote:
>
> Dear R user,
> I'd like to calculate the difference of two rows, where "ID" is the same.
> eg.: I've got the following dataframe:
> ID YEAR
> 13 2007
> 15 2003
> 15 2006
> 15 2008
> 21 2006
> 21 2007
>
> and I'd like to get the difference, like this:
> ID YEAR     diff
> 13 2007      NA
> 15 2003       3
> 15 2006       2
> 15 2008      NA
> 21 2006       1
> 21 2007      NA
>
> that should be fairly easy...I hope
> Thanks for any helpful comments
> B.
>
>
>
> --
> View this message in context: 
> http://old.nabble.com/difference-of-two-rows-tp26515212p26515212.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] Missing and number of days

2009-11-26 Thread R Help
For your first question, I believe that

dat[dat==-9]=NA

should do the trick

For your second, are you dates in the Date() format?  If not, try ?Date

Once you get them in Date format, then you can simply subtract them
 d1 = as.Date('20090604',format="%Y%m%d")
d2 = as.Date('20080604',format="%Y%m%d")
d1-d2
Time difference of 365 days

On Thu, Nov 26, 2009 at 12:30 PM, Val  wrote:
> Hi all,
>
>
>
> Assume  that I have a  data set (“xcv”) with several  variables  and some of
> the variables have a missing observation  represented by -9 as shown below.
>  I want to exclude these observations from the analysis ( as a NA).  Is
> there a command that I can do it for the entire data set rather than one by
> one for each variable ( tmp <- xcv[xcv$v1 != -9, ])
>
>
>
>      V1 v2 v3 v4
>
> 11    23  14  -9
>
> 12    -9  21   3
>
>     -9   30  41  25
>
>     15   07 -9  10
>
>
>
>  and I want the results as follows
>
>
>
>      V1    v2     v3      v4
>
> 11       23    14     NA
>
>       12   NA    21      3
>
>       NA   30    41     25
>
>        15     07   NA    10
>
>
>
>
>
> The second question is I want to calculate the number of days between two
> dates
>
>    Start           end                 number of days
>
> 20020626    20020805             40
>
> 20030101    20030421             110
>
>
>
> How do I do it in R?
>
>
> Thanks in advance
>
>        [[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] Hazard ratio

2009-12-10 Thread R Help
Yes, in this case it's comparing to the value '1'.  In general with
factors it's comparing to whatever level is missing.

Sam

On Thu, Dec 10, 2009 at 10:40 AM, Ashta  wrote:
> David,
>
> Thank you very much for your response.
>
> I fitted the model as  factor instead of numeric.
>
> coxfit1 <- coxph(Surv(sdat$time, sdat$cens)~factor(y1)+factor(x2)
>                               coef         exp(coef)  se(coef)      z
>       Pr(>|z|)
> factor(y1)2  0.036161  1.036822  0.083921  0.431   0.6665
> factor(y1)3  -0.510124  0.600421  0.088901 -5.738  9.57e-09 ***
> factor(x2)2  -0.510124  0.600421  0.088901 -5.738  9.57e-09 ***
>
>
>
> What are those values?   Is it comparing in reference to the first
> class of each covariate?
>
> Thanks again.
>
>
>
>
>
>
> On Thu, Dec 10, 2009 at 8:33 AM, Ashta  wrote:
>> Hi all,
>>
>> I want to calculate  hazard  ratio within each covariate
>>
>>
>> Example, one covariate has 3 classes (1,2 and 3) and x2 has 2 classes
>>
>> I want to compare the relative risk ratio within each class of the covariate.
>>  How do I get this result ? .
>>
>>
>> The other question is that how do I interpret  the second column in
>> the second panel  (i.e., exp(-coef))
>>
>> I used the model
>> coxfit1 <- coxph(Surv(sdat$time, sdat$cens)~ y1+x2)
>>
>>           coef       exp(coef)  se(coef)       z          Pr(>|z|)
>> y1    -0.024084  0.976204  0.003077 -7.828 5.00e-15 ***
>> x2     0.036161  1.036822  0.083921  0.431   0.6665
>>
>>         exp(coef)  exp(-coef)   lower .95    upper .95
>>  y1      0.9762     1.0244       0.9703         0.9821
>> x2      1.0368      0.9645       0.8796         1.
>>
>>
>> Thanks in advance
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


[R] how to add a derived column to a data frame?

2011-01-16 Thread r-help
I have a data frame with 10 columns: A:J and I want to have the output as a 
data frame with 11 columns, the value of 11th column is£º


for each row, if any column can be divided by 13, then the 11th column has a 
values of 1, otherwise, it has a value of 0. How to do that?


input is

a=matrix(1:1,1000,10)

dimnames(a)=list(NULL,LETTERS[1:10])










[[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 questions on R and cairo/Cairo

2010-08-09 Thread r-help
 On a headless Linux server running R 2.9.2 I would like to enable 
support for cairo, but capabilities("cairo") keeps on giving me FALSE. 
Is it possible what I am trying to do or can this only be achieved at R 
build time? I do not have administrative rights on this server.


After compiling cairo-1.8.10 and its dependencies from source in my home 
directory, I finally managed to install the Cairo package (capital C). 
Although capabilities("cairo") still gives me FALSE, I am now able to 
produce graphics. Apart from convenience, is there any difference 
between using built-in support for cairo or using the Cairo package?


Carsten

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

2010-08-15 Thread R Help
Hello List,

I'm trying to do a paired t-test, and I'm wondering if it's consistent
with equations.  I have a dataset that has a response and two
treatments (here's an example):

   ID trt order  resp
17  1   0 1  0.0037513592
18  2   0 1  0.0118723051
19  4   0 1  0.0002610251
20  5   0 1 -0.0077951450
21  6   0 1  0.0022339952
22  7   0 2  0.0235195453

The subjects were randomized and assigned to receive either the
treatment or the placebo first, then the other.  I know I'll
eventually have to move on to a GLM or something that incorporates the
order, but for now I wanted to start with a simple t.test.  My problem
is that, if I get the responses into two vectors x and y (sorted by
ID) and do a t.test, and then compare that to a formula t.test, they
aren't the same.

> t.test(x,y,paired=TRUE)

Paired t-test

data:  x and y
t = -0.3492, df = 15, p-value = 0.7318
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -0.010446921  0.007505966
sample estimates:
mean of the differences
   -0.001470477

> t.test(resp~trt,data=dat1[[3]],paired=TRUE)

Paired t-test

data:  resp by trt
t = -0.3182, df = 15, p-value = 0.7547
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -0.007096678  0.005253173
sample estimates:
mean of the differences
  -0.0009217521

What I'm assuming is that the equation isn't retaining the inherent
order of the dataset, so the pairing isn't matching up (even though
the dataset is ordered by ID).  Is there a way to make the t.test
retain the correct ordering?

Thanks,
Sam

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] as.logical(factor) behaviour

2010-08-15 Thread R Help
The problem is that, underneath the factors are actually numbers (1
and 2), where as, if you extract the levels and then get the logical,
it converts them to strings and then to logicals.  I run into this
problem ALL THE TIME with numerics in a dataset.  Consider the
following:

> factor(c(3,6,5,2,7,8,4))
[1] 3 6 5 2 7 8 4
Levels: 2 3 4 5 6 7 8
> as.numeric(factor(c(3,6,5,2,7,8,4)))
[1] 2 5 4 1 6 7 3
> as.numeric(as.character(factor(c(3,6,5,2,7,8,4
[1] 2 3 4 5 6 7 8

as.logical converts all non-zeros to TRUE, and 0 to false:
> as.logical(0:10)
 [1] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE

Hope that helps,
Sam

On Sun, Aug 15, 2010 at 5:32 AM, Philippe Grosjean
 wrote:
> Hello,
>
> According to ?as.logical:
>
> "as.logical attempts to coerce its argument to be of logical type. For
> factors, this uses the levels (labels)."
>
> However,
>
>> as.logical(factor(c("FALSE", "TRUE")))
> [1] TRUE TRUE
>
> Shouldn't it be the same as:
>
>> as.logical(levels(factor(c("FALSE", "TRUE"
> [1] FALSE  TRUE
>
> according to the documentation? Did I miss something here?
>
>> sessionInfo()
> R version 2.11.1 RC (2010-05-29 r52140)
> x86_64-apple-darwin9.8.0
>
> locale:
> [1] C/UTF-8/C/C/C/C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> Thanks,
>
> Philippe
> --
> ..<°}))><
>  ) ) ) ) )
> ( ( ( ( (    Prof. Philippe Grosjean
>  ) ) ) ) )
> ( ( ( ( (    Numerical Ecology of Aquatic Systems
>  ) ) ) ) )   Mons University, Belgium
> ( ( ( ( (
> ..
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Can Cairo do better?

2010-09-07 Thread r-help

 |Hi R-users,

I have used the Cairo package to create graphics on a headless system 
running R 2.9.2 without build-in support for cairo. The results are a 
bit disappointing compared to using the GDD package, although the R 
documentation recommends Cairo over GDD, because it has better 
rendering, symbol support, and a more actively maintained back-end. 
Judge for yourself (note that the sides of the rectangular box have 
unequal widths):


http://amc-app1.amc.sara.nl/twikidata/pub/temp/index.html

I was wondering whether there are Cairo-users that get better results. 
Maybe I did not configure things properly? Below are the statements I 
used to produce the graphic (a build-in data set is used):


library(Cairo)

||Cairo(width=900, height=600, file="cairo.png", bg="white", type="png")

||plot(faithful$eruptions, faithful$waiting, col="red", main="Created on 
the grid via Cairo", pch=4)


||abline(lm(faithful$waiting~faithful$eruptions))

||dev.off()|

Thanks in advance,

CBy

______
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Results of CFA with Lavaan

2011-06-08 Thread R Help
I've just found the lavaan package, and I really appreciate it, as it
seems to succeed with models that were failing in sem::sem.  I need
some clarification, however, in the output, and I was hoping the list
could help me.

I'll go with the standard example from the help documentation, as my
problem is much larger but no more complicated than that.

My question is, why is there one latent estimate that is set to 1 with
no SD for each factor?  Is that normal?  When I've managed to get
sem::sem to fit a model this has not been the case.

Thanks,
Sam Stewart

HS.model <- ' visual  =~ x1 + x2 + x3
  textual =~ x4 + x5 + x6
  speed   =~ x7 + x8 + x9 '
fit <- sem(HS.model, data=HolzingerSwineford1939)
summary(fit, fit.measures=TRUE)
Lavaan (0.4-8) converged normally after 35 iterations

  Number of observations   301

  Estimator ML
  Minimum Function Chi-square   85.306
  Degrees of freedom24
  P-value0.000

Chi-square test baseline model:

  Minimum Function Chi-square  918.852
  Degrees of freedom36
  P-value0.000

Full model versus baseline model:

  Comparative Fit Index (CFI)0.931
  Tucker-Lewis Index (TLI)   0.896

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)  -3737.745
  Loglikelihood unrestricted model (H1)  -3695.092

  Number of free parameters 21
  Akaike (AIC)7517.490
  Bayesian (BIC)  7595.339
  Sample-size adjusted Bayesian (BIC) 7528.739

Root Mean Square Error of Approximation:

  RMSEA  0.092
  90 Percent Confidence Interval  0.071  0.114
  P-value RMSEA <= 0.05  0.001

Standardized Root Mean Square Residual:

  SRMR   0.065

Parameter estimates:

  Information Expected
  Standard Errors Standard


   Estimate  Std.err  Z-value  P(>|z|)
Latent variables:
  visual =~
x11.000
x20.5540.1005.5540.000
x30.7290.1096.6850.000
  textual =~
x41.000
x51.1130.065   17.0140.000
x60.9260.055   16.7030.000
  speed =~
x71.000
x81.1800.1657.1520.000
x91.0820.1517.1550.000

Covariances:
  visual ~~
textual   0.4080.0745.5520.000
speed 0.2620.0564.6600.000
  textual ~~
speed 0.1730.0493.5180.000

Variances:
x10.5490.1144.8330.000
x21.1340.102   11.1460.000
x30.8440.0919.3170.000
x40.3710.0487.7780.000
x50.4460.0587.6420.000
x60.3560.0438.2770.000
x70.7990.0819.8230.000
x80.4880.0746.5730.000
x90.5660.0718.0030.000
visual0.8090.1455.5640.000
textual   0.9790.1128.7370.000
speed 0.3840.0864.4510.000

______
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Results of CFA with Lavaan

2011-06-08 Thread R Help
Yes, that is the difference.  For the last SEM I built I fixed the
factor variances to 1, and I think that's what I want to do for the
CFA I'm doing now.  Does that make sense for a CFA?

I'll try figuring out how to do that with lavaan later, but my model
takes so long to fit that I can't try it right now.

Thanks,
Sam

On Wed, Jun 8, 2011 at 5:58 PM, John Fox  wrote:
> Dear Sam,
>
> In each case, the first observed variable is treated as a "reference
> indicator" with its coefficient fixed to 1 to establish the metric of the
> corresponding factor and therefore to identify the model. If you didn't do
> the same thing (or something equivalent, such as fixing the factor variances
> to 1) in specifying the model to sem::sem(), that might account for the
> problems you encountered.
>
> Best,
>  John
>
> 
> John Fox
> Senator William McMaster
>  Professor of Social Statistics
> Department of Sociology
> McMaster University
> Hamilton, Ontario, Canada
> http://socserv.mcmaster.ca/jfox
>
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
>> On Behalf Of R Help
>> Sent: June-08-11 4:15 PM
>> To: r-help
>> Subject: [R] Results of CFA with Lavaan
>>
>> I've just found the lavaan package, and I really appreciate it, as it
>> seems to succeed with models that were failing in sem::sem.  I need some
>> clarification, however, in the output, and I was hoping the list could
>> help me.
>>
>> I'll go with the standard example from the help documentation, as my
>> problem is much larger but no more complicated than that.
>>
>> My question is, why is there one latent estimate that is set to 1 with
>> no SD for each factor?  Is that normal?  When I've managed to get
>> sem::sem to fit a model this has not been the case.
>>
>> Thanks,
>> Sam Stewart
>>
>> HS.model <- ' visual  =~ x1 + x2 + x3
>>               textual =~ x4 + x5 + x6
>>               speed   =~ x7 + x8 + x9 '
>> fit <- sem(HS.model, data=HolzingerSwineford1939) summary(fit,
>> fit.measures=TRUE) Lavaan (0.4-8) converged normally after 35 iterations
>>
>>   Number of observations                           301
>>
>>   Estimator                                         ML
>>   Minimum Function Chi-square                   85.306
>>   Degrees of freedom                                24
>>   P-value                                        0.000
>>
>> Chi-square test baseline model:
>>
>>   Minimum Function Chi-square                  918.852
>>   Degrees of freedom                                36
>>   P-value                                        0.000
>>
>> Full model versus baseline model:
>>
>>   Comparative Fit Index (CFI)                    0.931
>>   Tucker-Lewis Index (TLI)                       0.896
>>
>> Loglikelihood and Information Criteria:
>>
>>   Loglikelihood user model (H0)              -3737.745
>>   Loglikelihood unrestricted model (H1)      -3695.092
>>
>>   Number of free parameters                         21
>>   Akaike (AIC)                                7517.490
>>   Bayesian (BIC)                              7595.339
>>   Sample-size adjusted Bayesian (BIC)         7528.739
>>
>> Root Mean Square Error of Approximation:
>>
>>   RMSEA                                          0.092
>>   90 Percent Confidence Interval          0.071  0.114
>>   P-value RMSEA <= 0.05                          0.001
>>
>> Standardized Root Mean Square Residual:
>>
>>   SRMR                                           0.065
>>
>> Parameter estimates:
>>
>>   Information                                 Expected
>>   Standard Errors                             Standard
>>
>>
>>                    Estimate  Std.err  Z-value  P(>|z|) Latent variables:
>>   visual =~
>>     x1                1.000
>>     x2                0.554    0.100    5.554    0.000
>>     x3                0.729    0.109    6.685    0.000
>>   textual =~
>>     x4                1.000
>>     x5                1.113    0.065   17.014    0.000
>>     x6                0.926    0.055   16.703    0.000
>>   speed =~
>>     x7                1.000
>>     x8                1.180    0.165    7.152    0.000
>>     x9                1.082    0.151    7.155    0.000
>>
>> Covariances:
>>   visual ~~
>>     textual           0.408    0.074    5.55

Re: [R] Histogram

2011-06-08 Thread R Help
I think the command you want is barplot

x  = rbinom(10,15,0.65)
y = rbinom(10,15,0.25)
barplot(rbind(x,y),beside=TRUE)


Sam

On Wed, Jun 8, 2011 at 10:14 AM, nandini_bn  wrote:
>
> Hello ,
> I am trying to create a histogram in order to compare between two groups and
> would like it to be similar to the figure attached. How can I generate this
> using R ?
>
>
> Thank you,
> Nandini http://r.789695.n4.nabble.com/file/n3582448/5634-15977-1-PB.gif
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Histogram-tp3582448p3582448.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] Results of CFA with Lavaan

2011-06-09 Thread R Help
Thanks for the help, the std.lv=TRUE command is exactly what I was
looking for.  As you stated, it doesn't matter in terms of overall
model fit, but my client is more interested in the loadings than the
factor variances.

In terms of speed, it's just a very large model (7 factors, 90
observations, only ~560 subjects) with missing values, so I don't
expect much in terms of speed.  I think the overall conclusion for the
project is that the model is poorly specified, but whether that's the
model itself or the lack of samples is difficult to determine at this
point.

Thanks for your help, and I'll certainly be using lavaan in the future,
Sam

On Thu, Jun 9, 2011 at 6:19 AM, yrosseel  wrote:
> On 06/08/2011 11:56 PM, R Help wrote:
>>
>> Yes, that is the difference.  For the last SEM I built I fixed the
>> factor variances to 1, and I think that's what I want to do for the
>> CFA I'm doing now.  Does that make sense for a CFA?
>
> If you have a latent variable in your model (like a factor in CFA), you need
> to define its metric/scale. There are typically two ways to do this: 1) fix
> the variance of the latent variable to a constant (typically 1.0), or 2) fix
> the factor loading of one of the indicators of the factor (again to 1.0).
> For CFA with a single group, it should not matter which method you choose.
> The fit measures will be identical.
>
> Lavaan by default uses the second option. If you prefer the first (fixing
> the variances), you can simply add the 'std.lv=TRUE' option to the cfa()
> call, and lavaan will take care of the rest.
>
>> I'll try figuring out how to do that with lavaan later, but my model
>> takes so long to fit that I can't try it right now.
>
> You can use the 'verbose=TRUE' argument to monitor progress. You may also
> use the options se="none" (no standard errors) and test="none" (no test
> statistic) to speed things up, if you are still constructing your model. Or
> the model does not convergence, but I should see both the model and the data
> to determine the possible cause.
>
> Hope this helps,
>
> Yves Rosseel
> http://lavaan.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.
>

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

2011-06-09 Thread R Help
It's difficult to understand what exactly you're looking for without
seeing an example, could you post a simple version?  imgur.com is a
website that lets you quickly upload pictures to share with others.

I think your problem can be solved with the type='s' option to the
general plot routine.  Consider the following three plots, I think the
third is the one you're looking for.

x = runif(10,0,1)
x2 = cumsum(x)

plot(x2)
plot(x2,type='l')
plot(x2,type='s')

Hope that helps,
Sam Stewart

On Thu, Jun 9, 2011 at 9:15 AM, Anupam  wrote:
> Nice graphs there. Thanks. I too am looking to make a similar plot, with a
> difference: I need only the top parts of the many 'histograms' (a
> step-function like plot for histogram/bar-plots). I already have values for
> "heights" of bars for x1-x2 intervals computed from a large survey data; I
> want steps to be left-continuous; and step-functions to be plotted with
> different lines and symbols for each of many groups.
>
> I also want to make similar plots for cumulative 'histograms/bar-plots' to
> compare groups. I have "cumulative heights" for x1-x2 intervals,
> left-continuous.
>
> Any idea how to do this?
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf Of Steven Kennedy
> Sent: Thursday, June 09, 2011 3:28 AM
> To: nandini_bn
> Cc: r-help@r-project.org
> Subject: Re: [R] Histogram
>
> Have a look at:
> http://addictedtor.free.fr/graphiques/thumbs.php
>
> One of the graph examples they have is exactly what you are after.
>
>
> On Wed, Jun 8, 2011 at 11:14 PM, nandini_bn  wrote:
>>
>> Hello ,
>> I am trying to create a histogram in order to compare between two
>> groups and would like it to be similar to the figure attached. How can
>> I generate this using R ?
>>
>>
>> Thank you,
>> Nandini
>> http://r.789695.n4.nabble.com/file/n3582448/5634-15977-1-PB.gif
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/Histogram-tp3582448p3582448.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> ______
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting 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] Histogram

2011-06-09 Thread R Help
I'm getting the impression that you're not overly familiar with R?  If
so then you should really try and read some of the manuals from
r-project.org.  R is a very complex language and has a steep learning
curve.

That being said, the command takes a 2xK array, where K is the number
of observations you have, and 2 is the number of categories (in your
case I picked two because your example has intervention and control).
The first two lines in my example were just to create some sample data
to work with.

For the graph example you provided, you would create a 2x13 matrix,
called dat, and then use the command

barplot(dat,beside=TRUE)

In terms of setting the x and y axis labels, and the tick-marks as
they are defined in the figure, see the options provided by ?barplot,
or type help.start() and search for barplot from there.

And to Rolf: I understand the frustration with posts that are simple
like this, but just because your type RTFM instead of the full
sentence doesn't mean you're not swearing at strangers on the
Internet.  Try being a little more constrained in your responses.

Hope that helps,
Sam

On Thu, Jun 9, 2011 at 1:38 AM, Nandini B  wrote:
> Hi Sam,
> This is exactly what I wanted. Could you please explain the code ? what does
> 15, 0.65 and 0.25 stand for ?
>
>
> Nandini
>
>
>
>
>> Date: Wed, 8 Jun 2011 19:16:06 -0300
>> Subject: Re: [R] Histogram
>> From: rhelp.st...@gmail.com
>> To: nandini...@hotmail.com
>> CC: r-help@r-project.org
>>
>> I think the command you want is barplot
>>
>> x = rbinom(10,15,0.65)
>> y = rbinom(10,15,0.25)
>> barplot(rbind(x,y),beside=TRUE)
>>
>>
>> Sam
>>
>> On Wed, Jun 8, 2011 at 10:14 AM, nandini_bn 
>> wrote:
>> >
>> > Hello ,
>> > I am trying to create a histogram in order to compare between two groups
>> > and
>> > would like it to be similar to the figure attached. How can I generate
>> > this
>> > using R ?
>> >
>> >
>> > Thank you,
>> > Nandini http://r.789695.n4.nabble.com/file/n3582448/5634-15977-1-PB.gif
>> >
>> > --
>> > View this message in context:
>> > http://r.789695.n4.nabble.com/Histogram-tp3582448p3582448.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] set.seed and for loop

2011-06-09 Thread R Help
There are certainly people that would know how the random functions
work better than I, but I believe you would need to simulate 22
datasets and then get the 23rd dataset.  So to restore the 23rd:

set.seed(1001)
for(i in 1:22){
  garbage = runif(50)
}
data[[23]] = runif(50)

Hope that helps,
Sam

On Thu, Jun 9, 2011 at 12:14 PM, Soyeon Kim  wrote:
> Dear All,
>
> This is hard to describe so I made a simple example.
> set.seed(1001)
> total <- 0
> data <- vector("list", 30)
> for(i in 1:30) {
>  data[[i]] <- runif(50)
> }
> Let's call a data set runif(50).
> While the for loop is running, 100 data sets  are generated.
> I want to restore 23th data set (the data set generated in 23th for
> loop) without the loop.
> I've tried set.seed(1023) runif(50)
> but this is different data from the data set gotten from 23th for loop.
> How can I get 23th data set without the loop?
>
> Thank you,
> Soyeon
>
> ______
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Results of CFA with Lavaan

2011-06-09 Thread R Help
Ok, I think this is the last question I have.  My model is producing
an estimate of intercepts for my variables along with my loadings.
>From the documentation it appears that this is controlled by the
meanstructure   option in cfa.  It says that setting it to TRUE includes
the intercepts, and setting it to "default" means thatthe value is set
based on the user-specified model, and/or the values of other
arguments.  I've included my model specification below, and I would
prefer not to fit intercepts, but setting it to FALSE does not seem to
achieve this.

Thanks,
Sam

F1 =~ reFDE + ReFUIDGreg + reFDRwithDDRV + reparD + reparDR +
reparRisk + reWDD + reWDH + reWSP + reWDIS + reWCell + reWFAT + reAanx
+ reDanx + reDstress + reAstress
F2 =~ reSI1 + reSI2 + reSI3 + reSI4 + reSimDE + reSimDD + reSimDrug + reSimDRD
F3 =~ RENOINTEND + RETRYNOTD + RENOSTARTD + REUSEDD + REWILLD1 + REDU1
+ REDA1 + RERIDE1 + REAFTER1 + REUSEC1 + REUSESP1 + REUM1 + REABUSE1 +
RESB1 + REMIGHT1
F4 =~ retrydrink + RetryDope + reNoD + reLeaveD + reDeDR + reDopeNo +
reDopeleave + reDopeDD + reP3D
F5 =~ reP3DA + reP3DD + reP3DRD + reP3Equip + reP3UC + reP3SP + reP3UM
+ reP3Abuse + reP3SB + reP3helmet + reP1DADR + reP1DRUG + reP1SP
F6 =~ reinjwhileDU + reinjwhileWDUDRV + reinjwhileDA +
reinjwhileDRafterD + reinjwhileUcrack + reinjwhileUM +
reinjwhileabusePRDG + reinjwhilenoSB + reinjwhilenohelmet
F7 =~ relikeDR + relikeSP + relikeDIS + relikeCELL + relikeDROW +
relikeDRUG + restupid + reimmature + takerisksFthinkcool +
takeriskFthinkIMP + takeriskFthinkbrave + takeriskFthinkexciting +
reSELF + reNORISK + reNOPERSON + reNOCONSE + reWRONG + reGEAR +
reCONSEQ + reSUCES


On Thu, Jun 9, 2011 at 6:19 AM, yrosseel  wrote:
> On 06/08/2011 11:56 PM, R Help wrote:
>>
>> Yes, that is the difference.  For the last SEM I built I fixed the
>> factor variances to 1, and I think that's what I want to do for the
>> CFA I'm doing now.  Does that make sense for a CFA?
>
> If you have a latent variable in your model (like a factor in CFA), you need
> to define its metric/scale. There are typically two ways to do this: 1) fix
> the variance of the latent variable to a constant (typically 1.0), or 2) fix
> the factor loading of one of the indicators of the factor (again to 1.0).
> For CFA with a single group, it should not matter which method you choose.
> The fit measures will be identical.
>
> Lavaan by default uses the second option. If you prefer the first (fixing
> the variances), you can simply add the 'std.lv=TRUE' option to the cfa()
> call, and lavaan will take care of the rest.
>
>> I'll try figuring out how to do that with lavaan later, but my model
>> takes so long to fit that I can't try it right now.
>
> You can use the 'verbose=TRUE' argument to monitor progress. You may also
> use the options se="none" (no standard errors) and test="none" (no test
> statistic) to speed things up, if you are still constructing your model. Or
> the model does not convergence, but I should see both the model and the data
> to determine the possible cause.
>
> Hope this helps,
>
> Yves Rosseel
> http://lavaan.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.
>

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

2011-06-09 Thread R Help
I am using missing = 'fiml', which would require estimating intercepts.

I figured they would effect my overall model fit, but can I still
estimate my loading coefficients the same way?

The warning would be helpful, but if I had looked closer into the
'fiml' option I might have been able to figure it out myself.

Thanks,
Sam

On Thu, Jun 9, 2011 at 1:02 PM, yrosseel  wrote:
> On 06/09/2011 05:21 PM, R Help wrote:
>>
>> Ok, I think this is the last question I have.  My model is producing
>> an estimate of intercepts for my variables along with my loadings.
>>  From the documentation it appears that this is controlled by the
>> meanstructure   option in cfa.  It says that setting it to TRUE includes
>> the intercepts, and setting it to "default" means thatthe value is set
>> based on the user-specified model, and/or the values of other
>> arguments.  I've included my model specification below, and I would
>> prefer not to fit intercepts, but setting it to FALSE does not seem to
>> achieve this.
>
> Several arguments of the cfa() function force meanstructure=TRUE (and
> indeed, silently overriding the meanstructure=FALSE option if specified by
> the user; perhaps, lavaan should spit out a warning if this happens).
>
> The following argument choices force meanstructure to be TRUE (if there is
> only a single group):
>
> - estimator = "mlm" or "mlf" or "mlr"
> - missing = "ml" or "fiml"
>
> Did you use any one of those arguments?
>
> But why would you prefer not to fit the intercepts? If there are no
> restrictions on the intercepts/means, fitting them should have no effect on
> your model fit whatsoever.
>
> Yves Rosseel
> http://lavaan.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] set.seed and for loop

2011-06-09 Thread R Help
That wouldn't work because the seed is for the first iteration.

Random numbers are generated by a seed, after which the seed changes
(I don't know the mechanism for changing the seed in R, but it's
static)

That means that, if you set the seed to 1001, and then run runif
function 50 times, you'll get 50 different sets of random numbers.  If
you reset the seed to 1001 and then run runif again, the result will
be the same as data[[1]], not [[23]].  And you can't just set the seed
to 1023 because that's not how the seed changes.

I think Jim's suggestion was the best.  I was thinking of that but I
couldn't remember how to extract the seed.

Sam

On Thu, Jun 9, 2011 at 12:23 PM, Samuel Le  wrote:
> What about:
> set.seed(1001)
> total <- 0
> data <- vector("list", 30)
> for(i in 1:30) {
>  data[[i]] <- runif(50)
> }
> set.seed(1001)
> data[[23]] <- runif(50)
>
> HTH
> Samuel
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Soyeon Kim
> Sent: 09 June 2011 16:15
> To: r-help
> Subject: [R] set.seed and for loop
>
> Dear All,
>
> This is hard to describe so I made a simple example.
> set.seed(1001)
> total <- 0
> data <- vector("list", 30)
> for(i in 1:30) {
>  data[[i]] <- runif(50)
> }
> Let's call a data set runif(50).
> While the for loop is running, 100 data sets  are generated.
> I want to restore 23th data set (the data set generated in 23th for
> loop) without the loop.
> I've tried set.seed(1023) runif(50)
> but this is different data from the data set gotten from 23th for loop.
> How can I get 23th data set without the loop?
>
> Thank you,
> Soyeon
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
> __ Information from ESET NOD32 Antivirus, version of virus signature 
> database 6193 (20110609) __
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
> __ Information from ESET NOD32 Antivirus, version of virus signature 
> database 6193 (20110609) __
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.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] Plotting NLS profiles

2011-06-10 Thread R Help
Hello list,

I'm trying to plot nls profiles, but the plot.profile.nls function in
R doesn't seem to accept any plot.default variables.  Specifically,
I'd like to be able to change the x-axis title and the colors to black
and white.  Has anyone had any luck with this?

If not, is there a way to override to plotting colors, perhaps in par()?

Thanks,
Sam

fm1 <- nls(demand ~ SSasympOrig(Time, A, lrc), data = BOD)
pr1 <- profile(fm1, alpha = 0.05)
opar <- par(mfrow = c(2,2), oma = c(1.1, 0, 1.1, 0), las = 1)
plot(pr1, conf = c(95, 90, 80, 50)/100) # works fine
plot(pr1, conf = c(95, 90, 80, 50)/100,xlab=expression(theta),col=1) #
doesn't change

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

2010-05-24 Thread R Help
Hello list,

I'm trying to make sure that I'm performing a path analysis correctly
using the sem package.  the figure at
http://flame.cs.dal.ca/~sstewart/regressDiag.png has a detailing of
the model.

The challenge I'm having is that reuse is an indicator (0/1) variable.

Here's the code I'm using:

corr = 
hetcor(dat[,c('intent','exposure','benefit','norms','childBarrier','parentBarrier','knowBenefit','recuse')],use="pairwise.complete.obs")$correlations
modMat = matrix(c(
  'exposure -> intent', 'gam11',NA,
  'benefit -> intent', 'gam12',NA,
  'norms -> intent', 'gam13',NA,
  'childBarrier -> intent', 'gam14',NA,
  'parentBarrier -> intent', 'gam15',NA,
  'knowBenefit -> intent', 'gam16',NA,
  'intent<->intent','psi11',NA,
  'intent->recuse','gam21',NA,
  'recuse<->recuse','psi22',NA),
  ncol=3,byrow=T)
model4 = 
sem(modMat,corr,N=1520,fixed.x=c('exposure','benefit','norms','childBarrier','parentBarrier','knowBenefit'))

Is this correctly modeling my diagram?  I'm not sure if a) I'm dealing
with the categorical variable correctly, or b) whether fixed.x is
accurately modeling the correlations for me.

Any help would be appreciated.  I'm also looking into creating a plot
function within R (similar to the path.diagram function, but using R
plots).  If I get something useful I'll try and post it back

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

2010-05-24 Thread R Help
That's an interesting idea, I got the same impression from your SEM
appendix to "Companion to applied regression" in the paragraph just
before Section 3.

So I could get the same results if I built the following two models:

mod1 = 
lm(intent~exposure+benefit+norms+childBarrier+parentBarrier+knowBenefit,data=dat)
mod2 = 
glm(recuse~intent+norms+exposure+childBarrier+parentBarrier,data=dat,family=binomial(link=logit))

And in the second model only the intent should have a significant coefficient?

When I run those models I get a number of significant findings in the
mod2.  Does that mean that I have mis-specified my model?  If so (and
I think I have), can I postulate that there is a link between each
significant coefficient?

Thanks so much for your input,
Sam Stewart


> summary(mod2)

Call:
glm(formula = recuse ~ intent + norms + exposure + childBarrier +
parentBarrier, family = binomial(link = logit), data = dat)

Deviance Residuals:
Min   1Q   Median   3Q  Max
-2.2784  -0.9018   0.5899   0.7686   1.9314

Coefficients:
  Estimate Std. Error z value Pr(>|z|)
(Intercept)   -2.512690.50359  -4.990 6.05e-07 ***
intent 0.595740.08345   7.139 9.39e-13 ***
norms  0.238220.02991   7.964 1.67e-15 ***
exposure   0.125220.08613   1.454 0.145981
childBarrier  -0.312960.08693  -3.600 0.000318 ***
parentBarrier -0.234000.08676  -2.697 0.006995 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 1803.0  on 1479  degrees of freedom
Residual deviance: 1567.8  on 1474  degrees of freedom
  (40 observations deleted due to missingness)
AIC: 1579.8

Number of Fisher Scoring iterations: 4

On Mon, May 24, 2010 at 1:17 PM, John Fox  wrote:
> Dear sstewart,
>
> The model appears to reflect the path diagram, assuming that you intend to
> allow the exogenous variables to be correlated and want the errors to be
> uncorrelated.
>
> This is one way to model the binary variable reuse. An alternative would be
> to fit the equation for intent by least-squares regression (assuming that
> the relationships are linear, etc.), and the equation of reuse by, e.g.,
> logistic regression (again assuming that the model is correctly specified).
> If you're right that the effects of the exogenous variables are entirely
> mediated by intent, then if you put these variables in the equation for
> reuse, their coefficients should be small.
>
> I hope this helps,
>  John
>
> 
> John Fox
> Senator William McMaster
>  Professor of Social Statistics
> Department of Sociology
> McMaster University
> Hamilton, Ontario, Canada
> web: socserv.mcmaster.ca/jfox
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On
>> Behalf Of R Help
>> Sent: May-24-10 11:18 AM
>> To: r-help
>> Subject: [R] Path Analysis
>>
>> Hello list,
>>
>> I'm trying to make sure that I'm performing a path analysis correctly
>> using the sem package.  the figure at
>> http://flame.cs.dal.ca/~sstewart/regressDiag.png has a detailing of
>> the model.
>>
>> The challenge I'm having is that reuse is an indicator (0/1) variable.
>>
>> Here's the code I'm using:
>>
>> corr =
>>
> hetcor(dat[,c('intent','exposure','benefit','norms','childBarrier','parentBa
> r
>> rier','knowBenefit','recuse')],use="pairwise.complete.obs")$correlations
>> modMat = matrix(c(
>>   'exposure -> intent', 'gam11',NA,
>>   'benefit -> intent', 'gam12',NA,
>>   'norms -> intent', 'gam13',NA,
>>   'childBarrier -> intent', 'gam14',NA,
>>   'parentBarrier -> intent', 'gam15',NA,
>>   'knowBenefit -> intent', 'gam16',NA,
>>   'intent<->intent','psi11',NA,
>>   'intent->recuse','gam21',NA,
>>   'recuse<->recuse','psi22',NA),
>>   ncol=3,byrow=T)
>> model4 =
>>
> sem(modMat,corr,N=1520,fixed.x=c('exposure','benefit','norms','childBarrier'
> ,
>> 'parentBarrier','knowBenefit'))
>>
>> Is this correctly modeling my diagram?  I'm not sure if a) I'm dealing
>> with the categorical variable correctly, or b) whether fixed.x is
>> accurately modeling the correlations for me.
>>
>> Any help would be appreciated.  I'm also looking into creating a plot
>> function within R (similar to the path.diagram function, but using R
>> plots).  If I get something useful I'll try and post it back
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] Writing custom functions for rpart

2008-01-10 Thread R Help
I'm having a similar problem, and after looking through the test
directory I believe I have it down pat, but would someone mind telling
me if I have it correctly, and if not, what I need to fix?

eval: this seems to be the evaluation of a node, used for for labeling
it with whatever decision method is being used.

split: this seems to be the split decision itself.  I have a small
problem here, because I don't understand exactly how this function
will be called.  I assume that, for each covariate in the problem this
will be called ONCE, and then among all the returned "goodness"
values, the largest is chosen and a decision is made.

init: I don't understand the purpose of this function at all, and I
was going to just try and copy the one from anovatest.s, but if
someone can explain it to me it would be appreciated.

I'm also wondering: overall, do my three functions need to accept the
exact same variables that temp1, temp2 and temp3 do?  It seems to me
that they would have to for them to be called by another program, but
if this is the case then I don't know what to do with wt or parms?

Thanks,
Sam Stewart

On May 9, 2007 10:38 AM, hadley wickham <[EMAIL PROTECTED]> wrote:
> On 5/9/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote:
> > On Wed, 9 May 2007, hadley wickham wrote:
> >
> > > Hi everyone,
> > >
> > > Does anyone has experience with (or documentation for) writing custom
> > > methods with rpart? The documentation hints: "Alternatively, 'method'
> > > can be a list of functions 'init', 'split' and 'eval'", but doesn't
> > > provide any details as to what those methods should do or what
> > > arguments they should take etc.
> > >
> > > I've tried looking at the package source (and the source for the S
> > > code it came from) but I can't follow what's going on in C vs R, and
> > > as the default methods are coded in a different way, there are no
> > > examples to follow.
> >
> > But there are, in the tests directory.
>
> Thanks, I had missed those.  Perhaps a pointer from the documentation
> would be appropriate?
>
> Hadley
>
>
> __
> [EMAIL PROTECTED] mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Changing a plot

2008-09-24 Thread R Help
Hello list,

I've been working on this problem for a while and I haven't been able
to come up with a solution.

I have a couple of functions that plot a bunch of data, then a single
point on top of it.  What I want is to be able to change the plot of
the point without replotting all the data.  Consider the following
example:

x = rnorm(100,1,0.5)
y = rnorm(100,1,0.5)
plot(x,y,pch=16)
points(x[35],y[35],pch=19,col=6,cex=3)

What I want to be able to do is to change the purple point to a
different value without replotting everything.

I know this seems like an odd suggestion, but it comes up a lot with
the work I'm doing.  I've prepared a package on CRAN called
ResearchMethods for a course I'm working on, and there are several
functions in there who's GUIs could work better if I could figure this
out.

If anyone has any ideas, or needs some further explanation, feel free
to contact me.

Thanks a lot,
Sam Stewart

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


Re: [R] Changing a plot

2008-09-25 Thread R Help
Thanks, I looked into the grid package.  The grid package does do a
better job of managing the plotting, but it's still re-plotting the
entire canvas whenever a modifcation is made to a plot.

I guess I should have been a little clearer with my question.  Here's
a sample function.

library(tcltk)
x = runif(1)
y = runif(1)
v1 <- viewport()
grid.rect(gp = gpar(lty = "dashed"))
pushViewport(plotViewport(c(5.1, 4.1, 4.1, 2.1)))
pushViewport(dataViewport(x, y))
grid.rect()
grid.xaxis()
grid.yaxis()
grid.points(x, y)
grid.text("1:10", x = unit(-3, "lines"), rot = 90)
v2 <- viewport()
push.viewport()
grid.points(x[1],y[1],pch=16,gp=gpar(col='green'),name='pts')
index = tclVar(1)
grid
refresh <- function(...){
  i <- as.numeric(tclvalue(index))
  grid.edit('pts',x=unit(x[i],'npc'),y=unit(y[i],'npc'))

}
m <- tktoplevel()
pScale <- 
tkscale(m,from=0,to=1,orient='horiz',resolution=1,variable=index,command=refresh)
tkgrid(pScale)

The green point should change as the slider is moved, but there are so
many points in the background that replotting them confuses the
graphic.  What I want to be able to do is replt the green point
without removing the background.

Sam Stewart

On Wed, Sep 24, 2008 at 11:12 AM, Ben Bolker <[EMAIL PROTECTED]> wrote:
> R Help  gmail.com> writes:
>
>>
>> Hello list,
>>
>> I've been working on this problem for a while and I haven't been able
>> to come up with a solution.
>>
>> I have a couple of functions that plot a bunch of data, then a single
>> point on top of it.  What I want is to be able to change the plot of
>> the point without replotting all the data.  Consider the following
>> example:
>>
>> x = rnorm(100,1,0.5)
>> y = rnorm(100,1,0.5)
>> plot(x,y,pch=16)
>> points(x[35],y[35],pch=19,col=6,cex=3)
>>
>> What I want to be able to do is to change the purple point to a
>> different value without replotting everything.
>>
>
>  R's default (base) graphics model is a 'canvas' -- things get
> drawn, but nothing ever gets erased. (The cheap solution is
> to overplot in the background color, but that
> won't work if there's stuff underneath the point
> that you want to preserve.) You probably need to move
> to the grid graphics package (hint: buy or borrow Paul Murrell's
> book) to do something like this.
>
>  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.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] User defined split function in rpart

2008-02-11 Thread R Help
I had a similar problem, trying to use lme within a custom rpart
function.  I got around it by passing the dataframe I needed through
the parms option in rpart, and then using the parms option in
evaluation, init and split as a dataset.  It's not the most elegant
solution, but it will work.

Have you (or anyone else) figured out the details of the summary and
text options in the init function?  I know that they are used to fill
out the summary of the model and the text.rpart plotting, but I can't
seem to use any of the variables being passed to them efficiently (or
at all).

Hope that helps,
Sam Stewart

On Feb 20, 2007 2:47 PM, Tobias Guennel <[EMAIL PROTECTED]> wrote:
> I have made some progress with the user defined splitting function and I got
> a lot of the things I needed to work. However, I am still stuck on accessing
> the node data. It would probably be enough if somebody could tell me, how I
> can access the original data frame of the call to rpart.
> So if the call is: fit0 <- rpart(Sat ~Infl +Cont+ Type,
>  housing, control=rpart.control(minsplit=10, xval=0),
>  method=alist)
> how can I access the housing data frame within the user defined splitting
> function?
>
> Any input would be highly appreciated!
>
> Thank you
> Tobias Guennel
>
>
> -Original Message-
> From: Tobias Guennel [mailto:[EMAIL PROTECTED]
> Sent: Monday, February 19, 2007 3:40 PM
> To: '[EMAIL PROTECTED]'
> Subject: [R] User defined split function in rpart
>
> Maybe I should explain my Problem a little bit more detailed.
> The rpart package allows for user defined split functions. An example is
> given in the source/test directory of the package as usersplits.R.
> The comments say that three functions have to be supplied:
> 1. "The 'evaluation' function.  Called once per node.
>   Produce a label (1 or more elements long) for labeling each node,
>   and a deviance."
> 2. The split function, where most of the work occurs.
>Called once per split variable per node.
> 3. The init function:
>fix up y to deal with offsets
>return a dummy parms list
>numresp is the number of values produced by the eval routine's "label".
>
> I have altered the evaluation function and the split function for my needs.
> Within those functions, I need to fit a proportional odds model to the data
> of the current node. I am using the polr() routine from the MASS package to
> fit the model.
> Now my problem is, how can I call the polr() function only with the data of
> the current node. That's what I tried so far:
>
> evalfunc <- function(y,x,parms,data) {
>
> pomnode<-polr(data$y~data$x,data,weights=data$Freq)
> parprobs<-predict(pomnode,type="probs")
> dev<-0
> K<-dim(parprobs)[2]
> N<-dim(parprobs)[1]/K
> for(i in 1:N){
> tempsum<-0
> Ni<-0
> for(l in 1:K){
> Ni<-Ni+data$Freq[K*(i-1)+l]
> }
> for(j in 1:K){
> tempsum<-tempsum+data$Freq[K*(i-1)+j]/Ni*log(parprobs[i,j]*Ni/data$Freq[K*(i
> -1)+j])
> }
> dev=dev+Ni*tempsum
> }
> dev=-2*dev
> wmean<-1
> list(label= wmean, deviance=dev)
>
> }
>
> I get the error: Error in eval(expr, envir, enclos) : argument "data" is
> missing, with no default
>
> How can I use the data of the current node?
>
> Thank you
> Tobias Guennel
>
> __
> [EMAIL PROTECTED] mailing list
> https://stat.ethz.ch/mailman/listinfo/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] User defined split function in Rpart

2008-02-13 Thread R Help
Direction corresponds to goodness: for the split represented by
goodness[i], direction[i]=-1 means that values less than the split at
goodness[i] will go left, greater than will go right.   If
direction[i] = 1 then they will be sent to opposite sides.

The long-and-short of it is that, for most trees, we want to send
splits smaller than the split value left, and greater than right, so
direction should be -1 for all values, ie, direction =
rep(-1,length(goodness).  The vector is only added if you want to
customize the structure of your tree.

Hope that helps,
Sam

On Jan 3, 2007 12:56 PM, Paolo Radaelli <[EMAIL PROTECTED]> wrote:
> Dear all,
>  I'm trying to manage with user defined split function in rpart
> (file rpart\tests\usersplits.R in
> http://cran.r-project.org/src/contrib/rpart_3.1-34.tar.gz - see bottom of
> the email).
> Suppose to have the following data.frame (note that x's values are already
> sorted)
> > D
> y x
> 1 7 0.428
> 2 3 0.876
> 3 1 1.467
> 4 6 1.492
> 5 3 1.703
> 6 4 2.406
> 7 8 2.628
> 8 6 2.879
> 9 5 3.025
> 10 3 3.494
> 11 2 3.496
> 12 6 4.623
> 13 4 4.824
> 14 6 4.847
> 15 2 6.234
> 16 7 7.041
> 17 2 8.600
> 18 4 9.225
> 19 5 9.381
> 20 8 9.986
>
> Running rpart and setting minbucket=1 and maxdepth=1 we get the following
> tree (which uses, by default, deviance):
> > rpart(D$y~D$x,control=rpart.control(minbucket=1,maxdepth=1))
> n= 20
> node), split, n, deviance, yval * denotes terminal node
> 1) root 20 84.8 4.60
> 2) D$x< 9.6835 19 72.63158 4.421053 *
> 3) D$x>=9.6835 1 0.0 8.00 *
>
> This means that the first 19 observation has been sent to the left side of
> the tree and one observation to the right.
> This is correct when we observe goodness (the maximum is the last element of
> the vector).
>
> The thing i really don't understand is the direction vector.
> # direction= -1 = send "y< cutpoint" to the left side of the tree
> # 1 = send "y< cutpoint" to the right
>
> What does it mean ?
> In the example here considered we have
> > sign(lmean)
> [1] 1 1 -1 -1 -1 -1 -1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1
>
> Which is the criterion used ?
> In my opinion we should have all the values equal to -1 given that they have
> to be sent to left side of the tree.
> Does someone can help me ?
> Thank you
>
> ###
> # The split function, where most of the work occurs.
> # Called once per split variable per node.
> # If continuous=T (the case here considered)
> # The actual x variable is ordered
> # y is supplied in the sort order of x, with no missings,
> # return two vectors of length (n-1):
> # goodness = goodness of the split, larger numbers are better.
> # 0 = couldn't find any worthwhile split
> # the ith value of goodness evaluates splitting obs 1:i vs (i+1):n
> # direction= -1 = send "y< cutpoint" to the left side of the tree
> # 1 = send "y< cutpoint" to the right
> # this is not a big deal, but making larger "mean y's" move towards
> # the right of the tree, as we do here, seems to make it easier to
> # read
> # If continuos=F, x is a set of integers defining the groups for an
> # unordered predictor. In this case:
> # direction = a vector of length m= "# groups". It asserts that the
> # best split can be found by lining the groups up in this order
> # and going from left to right, so that only m-1 splits need to
> # be evaluated rather than 2^(m-1)
> # goodness = m-1 values, as before.
> #
> # The reason for returning a vector of goodness is that the C routine
> # enforces the "minbucket" constraint. It selects the best return value
> # that is not too close to an edge.
> The vector wt of weights in our case is:
> > wt
> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>
> temp2 <- function(y, wt, x, parms, continuous) {
> # Center y
> n <- length(y)
> y <- y- sum(y*wt)/sum(wt)
> if (continuous) {
> # continuous x variable
> temp <- cumsum(y*wt)[-n]
> left.wt <- cumsum(wt)[-n]
> right.wt <- sum(wt) - left.wt
> lmean <- temp/left.wt
> rmean <- -temp/right.wt
> goodness <- (left.wt*lmean^2 + right.wt*rmean^2)/sum(wt*y^2)
> list(goodness= goodness, direction=sign(lmean))
> }
> }
>
> Paolo Radaelli
> Dipartimento di Metodi Quantitativi per le Scienze Economiche ed Aziendali
> Facoltà di Economia
> Università degli Studi di Milano-Bicocca
> P.zza dell'Ateneo Nuovo, 1
> 20126 Milano
> Italy
> e-mail [EMAIL PROTECTED]
>
> __
> [EMAIL PROTECTED] mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Cross Validation in rpart

2008-02-22 Thread R Help
Hello All,
 I'm writing a custom rpart function, and I'm wondering about
cross-validation.  Specifically, why isn't my splitting function being
called more often with the xval increased?  One would expect that,
with xval=10 compared to xval=1, that the prior would call the
splitting function more than the other, but they both produce the
exact same thing.  Is there something I'm missing about the
cross-validation process for rpart?

Thanks,
Sam Stewart

______
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] re place column names

2008-02-22 Thread R Help
names(dat) will return the column names for a dataset called dat, and
they can also be set this way.

names(dat) <- c("firstName","secondName","thirdName",...)

I would suggest reading the column names into a vector, and then
assigning them as demonstrated above.

On Fri, Feb 22, 2008 at 9:42 AM, hochoi <[EMAIL PROTECTED]> wrote:
>
>  Hi,
>
>  When I tried to replace column names in a data set with label names read
>  from a separated file,
>  I got the following message:
>
>  Error in `[.data.frame` (dataset, , classlabel): undefined columns selected
>
>  I am new in R programming languague. Could someone please tell me what do I
>  need to consider in the dataset dataframe.
>  There are no column names in the dataset dataframe,
>  When I entered
>  dimnames(dataset)[[2]]
>  [1] "X1"  "X2"  "X3"  "X4"  "X5"  "X6"  "X7"  "X8"  "X9"  "X10" "X11" "X12"
>
>  [13] "X13" "X14" "X15" "X16" "X17" "X18" "X19" "X20" "X21" "X22" "X23" "X24"
>
>  [25] "X25" "X26" "X27" "X34" "X35" "X36" "X37" "X38" "X28" "X29" "X30" "X31"
>
>  [37] "X32" "X33"
>
>  Thanks
>  --
>  View this message in context: 
> http://www.nabble.com/replace-column-names-tp15633387p15633387.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] lmer and correlation

2008-03-13 Thread R Help
Hello list,
 I've been reading through the archives and it seems as though, as
of right now, there is no way to specify the correlation structure in
lmer.  I was wondering if anyone knows if this is going to be
implemented?  I'm using mixed-effects models within a tree structure,
so I make a lot of calls to lme to get the resulting deviance, and
lmer2 is almost 5 times faster than lme on my test data, so if it may
be implemented later I'd be willing to wait, otherwise I might look
into trying to hack it myself.

Sam Stewart

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

2007-09-19 Thread R Help
I can't read what your error message, but on mine I get the error:
"Error in plot.new(): margins too large", which is happening because
the default margins do not have enough space.  You can reduce the
margins with using par

par(mar=c(0,0,0,0))

Which will let plot.new() work.  I hope this helps.

Sam

On 9/19/07, marcg <[EMAIL PROTECTED]> wrote:
> Dear all
>
> I try to print 9 plots on a page, arranged as the code shows below.
>
> nf <- layout(matrix(c(1,0,2,0,0,3,0,4,0,5,0,6,0,0,0,0,7,0,8,9), 10,2))
> layout.show(nf)
>
> but when I try to plot, an error message
> Fehler in plot.new() : Grafikränder zu groß
> appears
>
> to verify p.e. with
>
> plot(runif(10:1))
>
> i tried with plot(runif(10:1), ann=F) to produce more space, but neither.
>
> The second question: how to place a cross in the middle of the plot to 
> delineate in 4 big fields (containing each 5 plots)
>
> Thanks a lot
>
>
> --
>
> ______
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> --
>
> ______
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] font family 'symbol'

2007-09-26 Thread R Help
Hello List,

I'm building a package for R, and I want to use the font family
'symbol', because it seems to be the most consistent of the four font
families that par guarantees.  The problem is that when I tried to run
it on a different machine, I got an X11 error message saying that that
font family was not available.

What I would like to do, therefore, is do a check at the beginning of
the programs to check if the 'symbol' family will work, and use the
default font family if it will not.  I figured I could do it with
either require() or tryCatch() but I can't seem to get either of them
to do it.  If anyone has any idea how to check for the presence of
font families could they please let me know?

#Sample code
if(HERE IS WHERE THE CHECK FOR 'symbol' WOULD GO){
fam = 'symbol'
}
else{
fam = ''
}
par(family=fam)
#

Thanks,
Sam

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 to mode numeric within a matrix

2007-09-28 Thread R Help
Your problem is that a matrix can't be a mix of data types, but a data
frame can.  Try the following code.

newBest = as.data.frame(best)

Now you can convert the column of numbers in newBest to numbers from
the factors they start as.  Check the help file for data.frame(...)
for more details of how to label correctly.

Sam

On 9/28/07, Sergey Goriatchev <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I create a matrix:
>
> best <- matrix(0, ncol=2, nrow=num.selected,
> dimnames=list(the.best$.Name, c("Probability(%)", "Inside")))
>
> best[,1] <- as.numeric(the.best$Total*100)
>
> best[,2] <- ifelse(the.best$Weight==0, "No", "Yes")
>
> What I want is the second column of mode numeric, but it is of mode
> character, despite the attempt to convert it to numeric with
> as.numeric(). It must have something to do with the second column of
> the matrix, where I write No/Yes.
> What should I do to have the first column of mode numeric?
> Also, how can I output No/Yes in the second column without citation
> marks around them?
>
> Thanks in advance
> Sergey
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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: to view the memory

2007-09-12 Thread R Help
the function ls() will list all the variables currently in the memory.
 To get their values, you'll also need to use the parse and eval
functions.  Try the following:

x = ls()
for(i in 1:length(x)){
print(x[i])
print(eval(parse(text=x[i])))
}

It's a little crude, but it will do the job.

Sam
On 9/11/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am wondering if it is possible to view what variables and vairable
> values are stored in the R memory. This to enable debugging of R-scripts
> I write.
>
> Sumit
>
>
> [[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] super and subscript in tcltk

2007-09-12 Thread R Help
dear list,

I'm trying to set subscripts in a tcltk menu, but I can't get it to
work.  The basic idea is produced by the following code

###
library(tcltk)
m <- tktoplevel()
norm <- tkfont.create(family="times",size=20,weight="bold")
f1 <- tkfont.create(family="symbol",size=10)
f2 <- tkfont.create(family="symbol",size=5)
frame <- tkframe(m)

entry1 <- tkentry(frame,width=5,bg='white')
entry2 <- tkentry(frame,width=5,bg='white')

tkpack(tklabel(frame,text="m",font=f1),side='left')
tkpack(tklabel(frame,text="1",font=f2),side='left')
tkpack(frame,entry1,side="left")
tkpack(tklabel(frame,text="m",font=f1),side='left')
tkpack(tklabel(frame,text="2",font=f2),side='left')
tkpack(frame,entry2,side="top")


But the problem is that the 1 and 2 are not added as subscripts.  I
think I can do it using a text-object and the offset tag, but I cannot
figure out how to do it.  Does anybody know how to use the
tktag.configure(...) function to set the offset tag so that the text
will appear below the baseline?  It should work like this

###
t <- tktext(frame,font=f1)
tktag.configure(t,"offset=-50")
tkinsert(t,"end","m")
tkinsert(t,"end","1")
###

Any help would be very much appreciated.

Thanks
Sam

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 read and write an S4 class

2009-08-12 Thread ml-r-help

see
?dput
?save


e.g.
setClass("track", representation(x="numeric", y="numeric"))
x <- new("track", x=1:4, y=5:8)

# save as binary
fn <- tempfile()
save(x, ascii=FALSE, file=fn)
rm(x)
load(fn)
x

# save as  ASCII
save(x, ascii=TRUE, file=fn)

# ASCII text representation from which to regenerate the data
dput(x, file=fn)
y <- dget(fn)


R_help Help wrote:
> Hi,
> 
> I have an object in S4 class. Is there anyway that I can write to a
> file and read it back to R? Thank you.
> 
> adschai
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-0fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht PhD (CFO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

______
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Bug in package.skeleton, R 2.9.0?

2009-07-15 Thread ml-r-help
Daniel Klevebring wrote:
> Bump
> 
> Anyone?
> 
> Thanks
> Daniel
> 
> On 13 jul 2009, at 10.57, Daniel Klevebring wrote:
> 
>> Dear all,
>>
>> I am using package.skeleton to build a small packages of misc function
>> for personal use. I have recently discovered that the option
>> force=TRUE doesn't seem to do what is meant to do. Here's what I'm
>> doing:
>>
>>> setwd("/Users/danielk/Documents/R/packages/dk")
>>> files <- paste("codebase", dir("codebase", pattern=".R"), sep="/")
>>> package.skeleton(name="dk", force=TRUE, code_files=files)
>> Creating directories ...
>> Creating DESCRIPTION ...
>> Creating Read-and-delete-me ...
>> Copying code files ...
>> Making help files ...
>> Done.
>> Further steps are described in './dk/Read-and-delete-me'.
>> Now, everything seems fine, but changes to files in me codebase
>> folder, doesn't come along if the folder dk/R already contains the
>> files, even though I use force=TRUE. If I remove the dk/R folder or
>> the dk folder altogether, the changes come along so to me it seems
>> that it's the overwrite part that doesn't work as it should - or am I
>> doing something wrong here? To me, it seems that the function
>> safe.dir.create (which is defined in package.skeleton never overwrites
>> folders, yielding force=TRUE useless.

from the help on package.skeleton

force: If 'FALSE' will not overwrite an existing directory.

which could be clearer in that package.skeleton will stop with an error if the 
top level
directory, i.e. 'dk' in your case, exists and you had specified force=FALSE. 
But it will
not overwrite the existing directory 'dk' with force=TRUE as you observed.

Looking at the code it is clear that file.copy is used to copy the code files 
and that has
per default overwrite=FALSE so your existing code files will not be overwritten.
With the current implementation package.skeleton will not do what you intended.

There are many ways to workaround
e.g.
fn <- dir("codebase", pattern=".R", full.names=TRUE)
file.remove( list.files(path=file.path("dk", "R"), pattern="\\.R", 
full.names=TRUE))
package.skeleton(name="dk", force=TRUE, code_files=fn)


Matthias
>>
>> See below for sessionInfo.
>>
>> Thanks a bunch
>> Daniel
>>
>>
>>
>>> sessionInfo()
>> R version 2.9.0 (2009-04-17)
>> i386-apple-darwin8.11.1
>>
>> locale:
>> en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>>
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods   base
>>
>> loaded via a namespace (and not attached):
>> [1] tools_2.9.0
>>
>> --
>>
>> Contact information:
>>
>> Daniel Klevebring
>> M. Sc. Eng., Ph.D. Student
>> Dept of Gene Technology
>> Royal Institute of Technology, KTH
>> SE-106 91 Stockholm, Sweden
>>
>> Visiting address: Roslagstullsbacken 21, B3
>> Delivery address: Roslagsvägen 30B, 104 06, Stockholm
>> Invoice address: KTH Fakturaserice, Ref DAKL KTHBIO, Box 24075,
>> SE-10450 Stockholm
>> E-mail: dan...@biotech.kth.se
>> Phone: +46 8 5537 8337 (Office)
>> Phone: +46 704 71 65 91 (Mobile)
>> Web: http://www.biotech.kth.se/genetech/index.html
>> Fax: +46 8 5537 8481
>>
>> --
>>
>> Contact information:
>>
>> Daniel Klevebring
>> M. Sc. Eng., Ph.D. Student
>> Dept of Gene Technology
>> Royal Institute of Technology, KTH
>> SE-106 91 Stockholm, Sweden
>>
>> Visiting address: Roslagstullsbacken 21, B3
>> Delivery address: Roslagsvägen 30B, 104 06, Stockholm
>> Invoice address: KTH Fakturaserice, Ref DAKL KTHBIO, Box 24075,
>> SE-10450 Stockholm
>> E-mail: dan...@biotech.kth.se
>> Phone: +46 8 5537 8337 (Office)
>> Phone: +46 704 71 65 91 (Mobile)
>> Web: http://www.biotech.kth.se/genetech/index.html
>> Fax: +46 8 5537 8481
>> MSN messenger: klevebr...@msn.com
>>
>>
>>  [[alternative HTML version deleted]]
>>
>> 
> 
> --
> 
> Contact information:
> 
> Daniel Klevebring
> M. Sc. Eng., Ph.D. Student
> Dept of Gene Technology
> Royal Institute of Technology, KTH
> SE-106 91 Stockholm, Sweden
> 
> Visiting address: Roslagstullsbacken 21, B3
> Delivery address: Roslagsvägen 30B, 104 06, Stockholm
> Invoice address: KTH Fakturaserice, Ref DAKL KTHBIO, Box 24075,  
> SE-10450 Stockholm
> E-mail: dan...@biotech.kth.se
> Phon

Re: [R] How to stop function printing unwanted output?

2009-08-06 Thread ml-r-help
?capture.output

so with the given example this line should do what you wanted while avoiding 
the output file

dummy <- capture.output(comparison <- LSD.test(yield,virus,df,MSerror, 
p.adj="bonferroni",
group=FALSE, main="Yield of sweetpotato\ndealt with different virus"))

Matthias

David Winsemius wrote:
> 
> On Aug 6, 2009, at 12:24 PM, Erik Iverson wrote:
> 
>>>> In my example, I don't want LSD.test to print any output, I just want
>>>> to use some of it later... How to stop it printing anything?
>>
>>> ?invisible
>>
>>
>> I'm not sure that works in this situation:
>>
>> test <- function() {
>>  print("output")
>> }
>>
>> test()
>> invisible(test())
>>
>> Both of the above still print out "output", which I think is the
>> original problem. The invisible function will not print the value of a
>> function, but if there is an explicit "print" call within the
>> function, that will of course happen, since the value hasn't been
>> returned at that point.  However, we don't know the original problem
>> since LSD.test is not defined, and therefore the example is not
>> reproducible.  I assume within the function, it is printing out some
>> values using "print" or "cat"?  We just have to guess though.
>>
>> Maybe the answer is in ?sink ??
>>
> 
> Quite right. A search suggests that LSD.test is from package agricolae
> and it does have several points at which cat() and print() would be
> subverting my intent. So the answer would be to sink it "somewhere that
> the sun does not shine" and then "unsink" or would that be "resurface"?
> With the example on the LSD.test help page:
> 
>> sink(file="undesired.txt")
>> comparison <- invisible( LSD.test(yield,virus,df,MSerror,
> p.adj="bonferroni", group=FALSE,
> + main="Yield of sweetpotato\ndealt with different virus") )
>> sink()
>> comparison
>   trtmeans M N  std.err
> 1  cc 24.4   3 2.084067
> 2  fc 12.86667   3 1.246774
> 3  ff 36.3   3 4.233727
> 4  oo 36.9   3 2.482606
> 
>> Erik
> 
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-0fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht PhD (CFO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

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

2010-05-04 Thread it-r-help

assuming all data frames have the same format
do.call("rbind", dataList)

will concatenate all data frames contained in your list object.

Phil Wieland wrote, On 05/04/10 09:51:
> I made a list (dataList) of data frames. The list looks like this (the
> first two elements):
> 
> [[1]]
> est cond   targets
> 1   400 exo_depth_65Hautklinik
> 2   300 exo_depth_65   Ostturm_UKM
> 3   200 exo_depth_65 Kreuzung_Roxeler/Albert_Schweizer
> ...
> 
> 
> [[2]]
> estcond   targets
> 1   400 controlHautklinik
> 2   220 control   Ostturm_UKM
> 3   300 control Kreuzung_Roxeler/Albert_Schweizer
> ...
> 
> Now I would like to merge the data frames with rbind. It works fine this
> way:
> 
> rbind(dataList[[1]], dataList[[2]], ...)
> 
> but I would like to use lapply or a for loop to get rid of specifying
> the subscripts. The output of lapply(dataList, rbind) is always
> 
>  [,1]   [,2]
> [1,] List,3 List,3
> 
> Thanks for 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.
> 


-- 
Matthias Burger   Project Manager/ Biostatistician
Epigenomics AG Kleine Praesidentenstr. 1 10178 Berlin, Germany
phone:+49-30-24345-0  fax:+49-30-24345-555
http://www.epigenomics.com matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin Amtsgericht Charlottenburg HRB 75861
Vorstand: Geert Nygaard (CEO/Vorsitzender)
  Oliver Schacht PhD (CFO)
Aufsichtsrat: Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

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


Re: [R] if condition doesn't evaluate to True/False

2009-04-29 Thread ml-r-help
see
?is.null

e.g.
if( is.null(sub_grp_whr_cls_data[sbgrp_no, 1]) )
{
  your code
}

Moumita Das wrote:
> Hi friends,
> Please help me with this bug.
> 
> *Bug in my code:*
> 
> In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store the where
> clause.every sub group has a where condition linked with it.
> 
> Database1
> 
> 
> Where clause  was  not found for a particular subgroup,
> sub_grp_whr_cls_data[sbgrp_no,1]  value was NULL
> 
> So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||
> sub_grp_whr_cls_data[sbgrp_no,1]==""*) should evaluate to TRUE ,but it
> evaluated to NA
> 
> So the if block where I used the the condition threw error
> 
> If(*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||
> sub_grp_whr_cls_data[sbgrp_no,1]==""*)
> 
> i.e if(NA)
> 
> Error:--
> 
> Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == "NULL" ||
> sub_grp_whr_cls_data[sbgrp_no,  :
> 
>   missing value where TRUE/FALSE needed
> 
> Comments:-- but when there ‘s no where clause value the condition
> (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL"
> ||sub_grp_whr_cls_data[sbgrp_no,1]=="") should automatically evaluate to *
> TRUE*
> 
> 
> 
> Database2
> 
> Where clause  was  found for a particular subgroup
> 
> The condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL"
> ||sub_grp_whr_cls_data[sbgrp_no,1]=="") evaluated to FALSE
> 
> So if (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL"
> ||sub_grp_whr_cls_data[sbgrp_no,1]=="") is
> 
> If (FALSE) ,control goes to the else part.
> 
> This is exactly what is expected of the program.
> 
> *QUERY:-- **If the condition evaluates to FALSE  when a where condition is
> available why doesn’t it evaluate to TRUE when a where condition available
> is NULL or no where condition is available.*
> 
> Here I have taken the example of two databases where I tried to get the
> where clause for subgroup 1.In case of Database1 it was not available in
> case of Databse2 it was available.But the problem may appear for the same
> database also, when where clause is available for say one subgroup and not
> for the other.
> 
> 
> 
> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-0fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht PhD (CFO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

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


Re: [R] if condition doesn't evaluate to True/False

2009-04-29 Thread ml-r-help
Petr PIKAL wrote:
> Hi
> 
> r-help-boun...@r-project.org napsal dne 29.04.2009 17:05:01:
> 
>> see
>> ?is.null
>>
>> e.g.
>> if( is.null(sub_grp_whr_cls_data[sbgrp_no, 1]) )
>> {
>>   your code
>> }
> 
> It probably will not work as 
> 
> sub_grp_whr_cls_data[sbgrp_no,1]=="NULL"
> 
> implicates that there is character value "NULL". I am not sure if you can 
> get NULL as a part of some object. I tried and failed.
> See what you get
> x<- c(1,2,3, NULL)
> 
> Regards
> Petr

thanks for pointing this out clearly, I had thought only about making the 
comparison
return a logical for use in the expression.

On hindsight it seems implausible to ever get NULL in the matrix/data frame.

(DONT USE
playing around I found the following abuse to work
m <- as.data.frame(diag(3))
m[[3]][3] <- list(NULL)
is.null(m[3,3][[1]])
[1] TRUE
)
Regards,
  Matthias

> 
>> Moumita Das wrote:
>>> Hi friends,
>>> Please help me with this bug.
>>>
>>> *Bug in my code:*
>>>
>>> In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store the where
>>> clause.every sub group has a where condition linked with it.
>>>
>>> Database1
>>>
>>>
>>> Where clause  was  not found for a particular subgroup,
>>> sub_grp_whr_cls_data[sbgrp_no,1]  value was NULL
>>>
>>> So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||
>>> sub_grp_whr_cls_data[sbgrp_no,1]==""*) should evaluate to TRUE ,but it
>>> evaluated to NA
>>>
>>> So the if block where I used the the condition threw error
>>>
>>> If(*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||
>>> sub_grp_whr_cls_data[sbgrp_no,1]==""*)
>>>
>>> i.e if(NA)
>>>
>>> Error:--
>>>
>>> Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == "NULL" ||
>>> sub_grp_whr_cls_data[sbgrp_no,  :
>>>
>>>   missing value where TRUE/FALSE needed
>>>
>>> Comments:-- but when there ‘s no where clause value the condition
>>> (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL"
>>> ||sub_grp_whr_cls_data[sbgrp_no,1]=="") should automatically evaluate 
> to *
>>> TRUE*
>>>
>>>
>>>
>>> Database2
>>>
>>> Where clause  was  found for a particular subgroup
>>>
>>> The condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL"
>>> ||sub_grp_whr_cls_data[sbgrp_no,1]=="") evaluated to FALSE
>>>
>>> So if (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL"
>>> ||sub_grp_whr_cls_data[sbgrp_no,1]=="") is
>>>
>>> If (FALSE) ,control goes to the else part.
>>>
>>> This is exactly what is expected of the program.
>>>
>>> *QUERY:-- **If the condition evaluates to FALSE  when a where 
> condition is
>>> available why doesn’t it evaluate to TRUE when a where condition 
> available
>>> is NULL or no where condition is available.*
>>>
>>> Here I have taken the example of two databases where I tried to get 
> the
>>> where clause for subgroup 1.In case of Database1 it was not available 
> in
>>> case of Databse2 it was available.But the problem may appear for the 
> same
>>> database also, when where clause is available for say one subgroup and 
> not
>>> for the other.
>>>
>>>
>>>
>>>
> 
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> -- 
>> Matthias Burger Project Manager/ Biostatistician
>> Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
>> phone:+49-30-24345-0fax:+49-30-24345-555
>> http://www.epigenomics.com   matthias.bur...@epigenomics.com
>> --
>> Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
>> Vorstand:   Geert Nygaard (CEO/Vorsitzender)
>> Oliver Schacht PhD (CFO)
>> Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)
>>
>> __
>> R-help@r-proje

[R] [R-pkgs] Introducing the futile.paradigm, a package for functional dispatching in R

2010-10-26 Thread Nurometic R Help
Hello useRs,

I'm pleased to announce the general availability of the R package
futile.paradigm, which is a language extension that implements
functional dispatching in R. This is an alternative to the current
object-oriented styles, replacing them with a functional programming
style that provides a clean, fine-grained declarative syntax for
function definitions. The core of the package consists of two operators,
%when% and %must% that implement guard statements that define when a
function variant is executed and post assertions that define the
criteria for success on individual functions. The package also
implements custom type constructors, which are declared using the
'create' function, which is predefined in the futile.paradigm.

Here are some examples to give you an idea of the syntax.

# Factorial function in the 'fac' namespace
fac.0 %when% (x == 0)  # guard statement
fac.0 <- function(x) 1 # function variant

fac.n %when% (x > 0)   # guard statement
fac.n %must% (result >= x) # post-assertion
fac.n <- function(x) x * fac(x-1) # function variant

> fac(4)
[1] 24
> fac(-2)
Error in UseFunction("fac", ...) : No valid function for 'fac/1' : -2

# Numerical optimization with custom type constructors
# Define a function and its derivatives
fx <- function(x) x^2 - 4
f1 <- function(x) 2*x
f2 <- function(x) 2

# Define the numerical optimization harness
converged <- function(x1, x0, tolerance=1e-6) abs(x1 - x0) < tolerance
minimize <- function(x0, algo, max.steps=100)
{
  step <- 0
  old.x <- x0
  while (step < max.steps)
  {
# Calls abstract function 'iterate' with definitions below
new.x <- iterate(old.x, algo)
if (converged(new.x, old.x)) break
old.x <- new.x
  }
  new.x
}

# Implement Newton-Raphson
iterate.nr %when% (algo %isa% NewtonRaphson)
iterate.nr <- function(x, algo) x - algo$f1(x) / algo$f2(x)

# Implement Gradient Descent
iterate.gd %when% (algo %isa% GradientDescent)
iterate.gd <- function(x, algo) x - algo$step * algo$f1(x)

# Create a custom type constructor
create.GradientDescent <- function(T, f1, step=0.01) list(f1=f1,step=step)

> algo <- create(GradientDescent, f1)
> minimize(3, algo)
[1] 3.677989e-06

# Execute using a dynamic type constructor
> algo <- create(NewtonRaphson, f1=f1,f2=f2)
> minimize(3, algo)
[1] 0

More documentation is available in the package help files and also at
https://nurometic.com/quantitative-finance/futile/paradigm

The current version is version 1.2.0 and is available on CRAN.

Regards,
Brian Lee Yung Rowe

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

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


Re: [R] R package tests

2009-01-15 Thread ml-r-help
Hi Nathan,

in addition to what others have already mentioned there is some documentation
in the Writing R Extensions Manual:
- on the supported structure of packages, indicating where test code might be 
added
 
http://stat.ethz.ch/R-manual/R-patched/doc/manual/R-exts.html#Package-subdirectories
- and the recommended standard approach to check a package
http://stat.ethz.ch/R-manual/R-patched/doc/manual/R-exts.html#Checking-and-building-packages

and a wiki article on how to combine the standard check (viz R CMD check) with 
any of the
unit testing approaches
http://wiki.r-project.org/rwiki/doku.php?id=developers:runit&s=unit%20test

Examples for the standard approach employed by R can be found
in the R source repository
https://svn.r-project.org/R/trunk/src/library/stats/tests/

and for unit test based checking
e.g. Rmetrics
http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/?root=rmetrics

or BioConductor examples
https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/Biobase/inst/UnitTests/
where you need the access info provided here
http://wiki.fhcrc.org/bioc/DeveloperPage


Regards,

 Matthias

Nathan S. Watson-Haigh wrote:
> I was wondering if anyone could point me in the right direction for reading 
> up on writing tests in
> R. I'm writing some functions for inclusion into a package and would like to 
> test them to ensure
> they're doing what I expect them to do.
> 
> Are these approaches used for testing packages in CRAN?
> 
> Cheers,
> Nathan
> 
> 

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



-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-371  fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht PhD (CFO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

______
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 var(x, na.rm = na.rm) : no complete element pairs

2009-03-05 Thread ml-r-help
Carlos Morales wrote:
> Hello,
> 
> I still have the same error which I have written in the Subject field, I 
> leave here the code and I hope you can help me with this:
> 
[removed]

the lengthy code example does not make it easier to help you, in particular 
without the
data you used. All the commented out code should have been removed before 
posting.
My guess is that you use R < 2.8.0 and generate a vector s which contains only 
NAs.
Try to inspect your function filter.clones by putting a browser()
call somewhere before the sd() call and run it again.
See ?browser and ?trace.

And you could vectorize this (and other parts), e.g.
the last loop would be rewritten as

tripliclones.info$Estandar_desviation <- apply(tripliclones.info[ ,2:4], 1, 
function(x)
sd(as.numeric(x), na.rm=TRUE))

Regards, Matthias


R version 2.7.1 (2008-06-23)
> b <- rep(NA,4)
> sd(b)
Error in var(x, na.rm = na.rm) : missing observations in cov/cor
> sd(b, TRUE)
Error in var(x, na.rm = na.rm) : no complete element pairs


R version 2.8.1 (2008-12-22)
> b<- rep(NA,4)
> sd(b)
[1] NA
> sd(b, TRUE)
[1] NA

-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-0fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht PhD (CFO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

______
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problem when trying to run Java in R:

2017-10-21 Thread Morkus via R-help
Hello All,

Although running Java from R used to work, for some mysterious reason, it's 
stopped.

Today when I tried to load a basic JDBC driver (or the sample .jinit()) code, I 
got:

- JavaVM: requested Java version ((null)) not available. Using Java at "" 
instead.

- JavaVM: Failed to load JVM: /bundle/Libraries/libserver.dylib

- JavaVM FATAL: Failed to load the jvm library.

I saw postings on StackOverflow about this issue, but none of the suggested 
fixes helped.

I'm on Mac OS 10.13.

My JAVA_HOME is: 
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

I'm using R: 3.3.3

Here is sample code that also throws this same error:

library(rJava)
.jinit() # this starts the JVM
s <- .jnew("java/lang/String", "Hello World!")

(this is the "hello world" equivalent from the rJava site)



I also tried to use Java 7 (rev. 51), which used to work, but that still fails.

Also tried a fresh install of R/RStudio on another machine with the same 
results (same Java version, etc., however).

I suspect Java itself is working fine since JDBC code from Java programs has no 
issues.

Not sure why loading Java in R stopped working, but would appreciate any 
suggestions.

Thanks very much,

Sent from [ProtonMail](https://protonmail.com), Swiss-based encrypted email.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] draw a circle with a gradient fill

2017-10-24 Thread Alaios via R-help
Hi all,I would like to draw a simple circle where the color gradient follows 
the rule color = 1/(r^2) where r is the distance from the circle. I would also 
like to add a color bar with values going from -40 to -110 (and associate those 
with the color gradient that fills the circle).
So far I experiemented with draw circle 
install.packages('plotrix')require(plotrix)colors<-c('#fef0d9','#fdcc8a','#fc8d59','#e34a33','#b3')plot(c(-15,15),c(-15,15),type='n')draw.circle(0,
 0, 10, nv = 1000, border = NULL, col = colors[1], lty = 1, lwd = 
1)draw.circle(0, 0, 8, nv = 1000, border = NULL, col = colors[2], lty = 1, lwd 
= 1)draw.circle(0, 0, 6, nv = 1000, border = NULL, col = colors[3], lty = 1, 
lwd = 1)draw.circle(0, 0, 4, nv = 1000, border = NULL, col = colors[4], lty = 
1, lwd = 1)draw.circle(0, 0, 2, nv = 1000, border = NULL, col = colors[5], lty 
= 1, lwd = 1)

but this package does not give easily color gradients and so my solutions 
contains 5 same colors filled rings.
Will there be any suggested improvements on my code above?
Thanks a lotAlex
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Creating a data table (frame?) from a SQL Statement?

2017-10-24 Thread Morkus via R-help
Hello,

I'm new to R so this is probably a simple question for somebody.

I have an RScript that reads a CSV on the disk using read.table(...). It then 
does a boxM test using that data.

However, I'm now trying to load the same data via an SQL command, but I can't 
seem to get the data structure defined so R will like it -- using the included 
"iris" dataset.

I've tried these ways of loading the SQL statement into a compatible R 
Structure:

irisQuery <- data(dbGetQuery(conn, "select * from iris"))

irisQuery <- data.frame(dbGetQuery(conn, "select * from iris"))

irisQuery <- table(dbGetQuery(conn, "select * from iris"))

.
.
.
Followed by:

boxM(irisQuery[,-5], irisQuery[,5])

Nothing works work.

For example, if i use ...

irisQuery <- data.frame(dbGetQuery(conn, "select * from iris"))

I get this error from R on the boxM test:  Error: is.numeric(x) || 
is.logical(x) is not TRUE

The SQL Statement is returning results, but their not CSV. Not sure if that 
matters.
---

So, how do I read a SQL statement into an R structure like I read the CSV using 
"read.table" so the boxM test will work?

Thanks very much in advance.

- M

Sent from [ProtonMail](https://protonmail.com), Swiss-based encrypted email.
    [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Pass Parameters to RScript?

2017-10-30 Thread Morkus via R-help
Is it possible to pass parameters to an R Script, say, from Java or other 
language?

I did some searches, but came up blank.

Thanks very much in advance,

Sent from [ProtonMail](https://protonmail.com), Swiss-based encrypted email.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Pass Parameters to RScript?

2017-10-30 Thread Morkus via R-help
Thanks Eric,

I saw that page, too, but it states:

"This post describes how to pass external arguments to R when calling a Rscript 
with a command line."

Not what I'm trying to do.

Thanks for your reply.

Sent from [ProtonMail](https://protonmail.com), Swiss-based encrypted email.

>  Original Message 
> Subject: Re: [R] Pass Parameters to RScript?
> Local Time: October 30, 2017 9:39 AM
> UTC Time: October 30, 2017 1:39 PM
> From: ericjber...@gmail.com
> To: Morkus 
> r-help@r-project.org 
>
> I did a simple search and got  hits immediately, e.g.
> https://www.r-bloggers.com/passing-arguments-to-an-r-script-from-command-lines/
>
> On Mon, Oct 30, 2017 at 2:30 PM, Morkus via R-help  
> wrote:
>
>> Is it possible to pass parameters to an R Script, say, from Java or other 
>> language?
>>
>> I did some searches, but came up blank.
>>
>> Thanks very much in advance,
>>
>> Sent from [ProtonMail](https://protonmail.com), Swiss-based encrypted email.
>> [[alternative HTML version deleted]]
>>
>> ______
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Where to get support for Rserve?

2017-11-13 Thread Morkus via R-help
Hello,

I'm using Rserve with Java and although it works OK for 50 or 60 requests, 
eventually Rserve simply stops responding and I have to force-quit and restart 
Rserve. During this time the JVM is fine and Tomcat (app server) is fine, too.

The basic Java code does this:

1. Create an R Connection
2. Execute an R Script via Rserve "eval" statements
3. Close the R Connection.

I was going to use a memory profiler to see what was going on but Tomcat is not 
showing any Java-code memory leaks.

Looking at the Rserve page, I see everything about the Rseve author...except 
for a way to contact him (unless I somehow missed that.)

This may not be the correct R forum to ask this question, but I need to start 
somewhere.

*** Note, in the past I've posted messages like this to the R developer forum 
only to be told that that programming forum is not the right forum as it's only 
for "pure" R programming ***

Would appreciate any suggestions.

Thanks,

- M

Sent from [ProtonMail](https://protonmail.com), Swiss-based encrypted email.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Where to get support for Rserve?

2017-11-13 Thread Morkus via R-help
Hey Bert,

That's super helpful (maintainer ("rserve")). I had no idea. :)

So much good stuff right there in R.

I didn't find any relevant hits looking on the web for my particular problem, 
but I'll email the maintainer.

Thanks very much.

- M

Sent from [ProtonMail](https://protonmail.com), Swiss-based encrypted email.

>  Original Message 
> Subject: Re: [R] Where to get support for Rserve?
> Local Time: November 13, 2017 11:34 AM
> UTC Time: November 13, 2017 4:34 PM
> From: bgunter.4...@gmail.com
> To: Morkus 
> r-help@r-project.org 
>
> ?maintainer
> ## i.e.
>
> maintainer("rserve")
>
> Also, please search. A web search on simply "rserve" brought up what appeared 
> to be many relevant hits.
>
> Cheers,
> Bert
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and 
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> On Mon, Nov 13, 2017 at 4:48 AM, Morkus via R-help  
> wrote:
>
>> Hello,
>>
>> I'm using Rserve with Java and although it works OK for 50 or 60 requests, 
>> eventually Rserve simply stops responding and I have to force-quit and 
>> restart Rserve. During this time the JVM is fine and Tomcat (app server) is 
>> fine, too.
>>
>> The basic Java code does this:
>> 
>> 1. Create an R Connection
>> 2. Execute an R Script via Rserve "eval" statements
>> 3. Close the R Connection.
>>
>> I was going to use a memory profiler to see what was going on but Tomcat is 
>> not showing any Java-code memory leaks.
>>
>> Looking at the Rserve page, I see everything about the Rseve author...except 
>> for a way to contact him (unless I somehow missed that.)
>>
>> This may not be the correct R forum to ask this question, but I need to 
>> start somewhere.
>>
>> *** Note, in the past I've posted messages like this to the R developer 
>> forum only to be told that that programming forum is not the right forum as 
>> it's only for "pure" R programming ***
>>
>> Would appreciate any suggestions.
>>
>> Thanks,
>>
>> - M
>>
>> Sent from [ProtonMail](https://protonmail.com), Swiss-based encrypted email.
>> [[alternative HTML version deleted]]
>>
>> ______
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Multivariate mixture distributions

2017-11-17 Thread psoppat via R-help


Hello, I am searching for a way to generate random values from a multivariate 
mixture distribution. For starters, one could create a mixture distribution 
consisting of a gamma or normal distribution and then a tail/spike of values in 
a normal distribution (eg as in Figure 1, A Eyre-Walker, PD Keightley. 2007. 
The distribution of fitness effects of new mutations. Nature Review Genetics 8: 
610-618)
I am not certain how to implement this in the R environment. The implementation 
becomes even more difficult if one wants to generalize this distribution to 
multiple variables that are related to one another via some correlation 
structure. The analogous situation is a multivariate normal distribution with 
the shape given by the covariance matrix. 
What I need for my research program is to generate values for each of 3 random 
variables with ("one-dimensional") distributions as in Figure 1 and yet 
simultaneously choose a value for each variable so that the resolved values are 
correlated in some way (eg if a high value for variable 1 is chosen, it is 
likely that values 2 and 3 are low).
Thanks in advance for the help.
Patrick SoprovichBiology Department, Dalhousie University


[[alternative HTML version deleted]]

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] RStudio blank upon opening

2017-11-17 Thread Beginner via R-help

I'm having a problem: RStudio (on   desktop comp) blank upon opening (after I 
update Win7). I tried different things (reinstalled R and RStudio, backuping  
RStudio settings folder... etc)! C an I launch Rstudio direct from
RGui(32bit)? or some else way to solve this problem? Thanks! P.S. I  launch 
RStudio with Ctrl-RStudio (that is set the path to R)

[[alternative HTML version deleted]]

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Add vectors of unequal length without recycling?

2017-12-12 Thread Maingo via R-help
I'm a newbie for R lang. And I recently came across the "Recycling Rule" when 
adding two vectors of unequal length.

I learned from this tutor [ 
http://www.r-tutor.com/r-introduction/vector/vector-arithmetics ] that:

""""""

If two vectors are of unequal length, the shorter one will be recycled in order 
to match the longer vector. For example, the following vectors u and v have 
different lengths, and their sum is computed by recycling values of the shorter 
vector u.

> u = c(10, 20, 30)

> v = c(1, 2, 3, 4, 5, 6, 7, 8, 9)

> u + v

[1] 11 22 33 14 25 36 17 28 39

""""""

And I wondered, why the shorter vecter u should be recycled? Why not just leave 
the extra values(4,5,6,7,8,9) in the longer vector untouched by default?

Otherwise is it better to have another function that could add vectors without 
recycling? Right now the recycling feature bugs me a lot.

Sent with [ProtonMail](https://protonmail.com) Secure Email.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] chi-square distribution table

2017-12-18 Thread HATMZAHARNA via R-help
Please could you tell me how to make code to outpot chi-square 
distribution table?


Please help

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] chi-square distribution table

2017-12-18 Thread HATMZAHARNA via R-help
Please could you tell me how to make code to outpot chi-square 
distribution table?


Please help

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] chi-square distribution table

2017-12-18 Thread HATMZAHARNA via R-help
Please could you tell me how to make code to make chi-square 
distribution table?


Please help

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] why the length and width of a plot region produced by the dev.new() function cannot be correctly set?

2018-05-03 Thread sunyeping via R-help
When I check the size of the plot region usingdev.size("in")a new plot region 
is produced and in the Rconsole I get[1] 5.33 5.322917If I mean to produce 
a plot region with size setting bydev.new(length=3,width=3)a plot region is 
produced, but the size is [2.281250, 5.322917], as detected by the de.size 
function. If I type:dev.new(length=10,width=10)I get a plot region of with the 
size of [7.614583, 5.322917]. It seems that the width of the new plot region 
cannot be set, and tt is always 5.322917. The length of the new plot region can 
be set, but it is always smaller that the values I set.What do I miss? What is 
the correct way of setting the dimension of the new plot region? I will be 
grateful to any help.Best regards,

[[alternative HTML version deleted]]

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] why the length and width of a plot region produced by the dev.new() function cannot be correctly set?

2018-05-04 Thread sunyeping via R-help

--From:David 
Winsemius Send Time:2018 May 4 (Fri) 13:25To:孙业平 
Cc:R Help Mailing List Subject:Re: 
[R] why the length and width of a plot region produced by the dev.new() 
function cannot be correctly set?

> On May 3, 2018, at 6:28 PM, sunyeping via R-help  wrote:
> 
> When I check the size of the plot region usingdev.size("in")a new plot region 
>is produced and in the Rconsole I get[1] 5.33 5.322917

Your test is all mangleed together. You failed in your duty to read the list 
info and the Posting guide . NO HTML!

> If I mean to produce a plot region with size setting 
>bydev.new(length=3,width=3)a plot region is produced, but the size is 
>[2.281250, 5.322917], as detected by the de.size function. If I 
>type:dev.new(length=10,width=10)I get a plot region of with the size of 
>[7.614583, 5.322917]. It seems that the width of the new plot region cannot be 
>set, and tt is always 5.322917. The length of the new plot region can be set, 
>but it is always smaller that the values I set.What do I miss? What is the 
>correct way of setting the dimension of the new plot region? I will be 
>grateful to any help.Best regards,

The size of the device is not the size of the plot region. You need to take 
into account the margins. See ?par
Thank you, David.I have read the par() document. Clearly the size of the plot 
region is smaller than or equal to the divice size. However, if I produce a 
graphic device with dev.new (length, width) or other functions, I find the 
largest  width of the new device is always 5.3 inches whatever the values I 
set, and the length of it is alway smaller than what I set. Could you tell me 
how to produce a graphic divice with correct size that I set? I need this 
function because the graphic divice cannot accomendate all of the graph I make 
with some of plot tools such as ggtree. In ggtree plot, part of the tree tips 
label are invisible (https://www.dropbox.com/s/87gyusx7ay1xxu8/tree.pdf?dl=0) 
even I set "par(mar=rep(0,4))". So I think I must plot the tree on a larger 
graphic device.  Best regards. 


> 
>  [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law





[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] why the length and width of a plot region produced by the dev.new() function cannot be correctly set?

2018-05-05 Thread sunyeping via R-help

--From:Duncan 
Murdoch Send Time:2018 May 6 (Sun) 04:58To:孙业平 
; David Winsemius Cc:R Help 
Mailing List Subject:Re: [R] why the length and width of 
a plot region produced by the dev.new() function cannot be correctly set?
On 05/05/2018 11:33 AM, 孙业平 wrote:
> 
> --
> From:Duncan Murdoch 
> Send Time:2018 May 4 (Fri) 17:24
> To:孙业平 ; David Winsemius 
> Cc:R Help Mailing List 
> Subject:Re: [R] why the length and width of a plot region produced by 
> the dev.new() function cannot be correctly set?
> 
> On 04/05/2018 3:04 AM, sunyeping via R-help wrote:
>  >
>  > 
>--From:David 
>Winsemius Send Time:2018 May 4 (Fri) 13:25To:孙业平 
>Cc:R Help Mailing List Subject:Re: 
>[R] why the length and width of a plot region produced by the dev.new() 
>function cannot be correctly set?
>  >
>  >>   On May 3, 2018, at 6:28 PM, sunyeping via R-help  
>wrote:
>  >>
>  >>   When I check the size of the plot region usingdev.size("in")a new plot 
>region is produced and in the Rconsole I get[1] 5.33 5.322917
>  >
>  > Your test is all mangleed together. You failed in your duty to read the 
>list info and the Posting guide . NO HTML!
>  >
>  >>   If I mean to produce a plot region with size setting 
>bydev.new(length=3,width=3)a plot region is produced, but the size is 
>[2.281250, 5.322917], as detected by the de.size function. If I 
>type:dev.new(length=10,width=10)I get a plot region of with the size of 
>[7.614583, 5.322917]. It seems that the width of the new plot region cannot be 
>set, and tt is always 5.322917. The length of the new plot region can be set, 
>but it is always smaller that the values I set.What do I miss? What is the 
>correct way of setting the dimension of the new plot region? I will be 
>grateful to any help.Best regards,
>  >
>  > The size of the device is not the size of the plot region. You need to 
>take into account the margins. See ?par
>  > Thank you, David.I have read the par() document. Clearly the size of the 
>plot region is smaller than or equal to the divice size. However, if I produce 
>a graphic device with dev.new (length, width) or other functions, I find the 
>largest  width of the new device is always 5.3 inches whatever the values I 
>set, and the length of it is alway smaller than what I set.
> 
> The length and width aren't the first and second parameters for any
> device, and length isn't a parameter at all.  Try
> 
> dev.new(height = 10, width = 10)
> 
> and you should get a bigger device if it will fit on your screen.  If it
> won't fit, then you might get a smaller one, and you'll need to choose a
> non-screen device such as png() or pdf() instead of the default device.
> 
> Duncan Murdoch
> 
>Could you tell me how to produce a graphic divice with correct size
> that I set? I need this function because the graphic divice cannot
> accomendate all of the graph I make with some of plot tools such as
> ggtree. In ggtree plot, part of the tree tips label are invisible
> (https://www.dropbox.com/s/87gyusx7ay1xxu8/tree.pdf?dl=0) even I set
> "par(mar=rep(0,4))". So I think I must plot the tree on a larger graphic
> device.  Best regards.
>  >
>  >
>  >>
>  >>[[alternative HTML version deleted]]
>  >>
>  >>   __
>  >>   R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>  >> https://stat.ethz.ch/mailman/listinfo/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
>  >
>  > 'Any technology distinguishable from magic is insufficiently advanced.'   
>-Gehm's Corollary to Clarke's Third Law
>  >
>  >
>  >
>  >
>  >
>  >  [[alternative HTML version deleted]]
>  >
>  > __
>  > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>  > https://stat.ethz.ch/mailman/listinfo/r-help
>  > PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
>  > and provide commented, minimal, self-contained, reproducible code.
>  >
> 
> "dev.new(height = 10, width = 10) " doesn't work neither. It produces a 
> device with a size of [ 5.760417, 5.75]. My computer is

[R] mzR fails to install/compile (linuxes)

2018-06-15 Thread lejeczek via R-help
s and so far only "mzR" and "MSnbase" fail if 
I compile with -j>1.


Would anybody be able to confirm this problem exists?
Many thanks, L.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] rgdal in 3.5 fails(?)

2018-06-15 Thread lejeczek via R-help

hi there

installation of the package fails:

...

g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/include/gdal 
-I/tmp/RtmpPEjOIB/R.INSTALL952df53b77184/rgdal/inst/include 
-I/tmp/RtmpPEjOIB/R.INSTALL952df53b77184/rgdal/inst/include 
-I"/usr/lib64/R/library/sp/include" -I/usr/local/include   -fpic -O2 -g 
-pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
-fstack-protector-strong --param=ssp-buffer-size=4 
-grecord-gcc-switches   -m64 -mtune=generic -c OGR_write.cpp -o OGR_write.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/include/gdal 
-I/tmp/RtmpPEjOIB/R.INSTALL952df53b77184/rgdal/inst/include 
-I/tmp/RtmpPEjOIB/R.INSTALL952df53b77184/rgdal/inst/include 
-I"/usr/lib64/R/library/sp/include" -I/usr/local/include   -fpic -O2 -g 
-pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
-fstack-protector-strong --param=ssp-buffer-size=4 
-grecord-gcc-switches   -m64 -mtune=generic -c gdal-bindings.cpp -o 
gdal-bindings.o

gdal-bindings.cpp: In function ‘SEXPREC* RGDAL_GDALwithGEOS()’:
gdal-bindings.cpp:334:81: error: no matching function for call to 
‘OGRGeometryFactory::createFromWkt(const char*, NULL, OGRGeometry**)’
 OGRGeometryFactory::createFromWkt( (const char*) pszWKT, NULL, 
&poGeometry1 );

^
gdal-bindings.cpp:334:81: note: candidate is:
In file included from /usr/include/gdal/ogr_feature.h:34:0,
 from /usr/include/gdal/ogrsf_frmts.h:35,
 from gdal-bindings.cpp:7:
/usr/include/gdal/ogr_geometry.h:663:19: note: static OGRErr 
OGRGeometryFactory::createFromWkt(char**, OGRSpatialReference*, 
OGRGeometry**)

 static OGRErr createFromWkt( char **, OGRSpatialReference *,
   ^
/usr/include/gdal/ogr_geometry.h:663:19: note:   no known conversion for 
argument 1 from ‘const char*’ to ‘char**’
gdal-bindings.cpp:340:81: error: no matching function for call to 
‘OGRGeometryFactory::createFromWkt(const char*, NULL, OGRGeometry**)’
 OGRGeometryFactory::createFromWkt( (const char*) pszWKT, NULL, 
&poGeometry2 );



Would you know is this the package's problem in new 3.5 version?

Many thanks, L.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] mzR fails to install/compile (linuxes)

2018-06-18 Thread lejeczek via R-help

On 16/06/18 13:09, Martin Morgan wrote:
mzR is a Bioconductor package so you might have more luck contacting 
the maintainer on the Bioconductor support site


  https://support.bioconductor.org

or on the 'bioc-devel' mailing list

  https://stat.ethz.ch/mailman/listinfo/bioc-devel

or most directly by opening an issue on the maintainer's github

  https://github.com/sneumann/mzR/issues/

this is linked to from the package 'landing page'

  https://bioconductor.org/packages/mzR

Martin Morgan

On 06/15/2018 10:49 AM, lejeczek via R-help wrote:

hi guys, just an admin here.

I wonder if anybody see what I see, or similar? I'm on Centos 7.x and 
this occurs with R 3.4.x 3.5.x and probably earlier versions too.


Every time I use something like -j>1 to pass to a compiler, eg.echo -ne

$ "Sys.setenv(MAKEFLAGS = \"-j2\")\\n 
source(\"https://bioconductor.org/biocLite.R\";)\\n 
biocLite(c(\"mzR\"), suppressUpdates=FALSE, suppressAutoUpdate=FALSE, 
ask=FALSE)" | /usr/bin/R --vanilla


mzR fails to compile:
...
g++ -m64 -std=gnu++11 -shared -L/usr/lib64/R/lib -Wl,-z,relro -o 
mzR.so cramp.o ramp_base64.o ramp.o RcppRamp.o RcppRampModule.o 
rnetCDF.o RcppPwiz.o RcppPwizModule.o RcppIdent.o RcppIdentModule.o 
./boost/libs/system/src/error_code.o 
./boost/libs/regex/src/posix_api.o ./boost/libs/regex/src/fileiter.o 
./boost/libs/regex/src/regex_raw_buffer.o 
./boost/libs/regex/src/cregex.o ./boost/libs/regex/src/regex_debug.o 
./boost/libs/regex/src/instances.o ./boost/libs/regex/src/icu.o 
./boost/libs/regex/src/usinstances.o ./boost/libs/regex/src/regex.o 
./boost/libs/regex/src/wide_posix_api.o 
./boost/libs/regex/src/regex_traits_defaults.o 
./boost/libs/regex/src/winstances.o 
./boost/libs/regex/src/wc_regex_traits.o 
./boost/libs/regex/src/c_regex_traits.o 
./boost/libs/regex/src/cpp_regex_traits.o 
./boost/libs/regex/src/static_mutex.o 
./boost/libs/regex/src/w32_regex_traits.o 
./boost/libs/iostreams/src/zlib.o 
./boost/libs/iostreams/src/file_descriptor.o 
./boost/libs/filesystem/src/operations.o 
./boost/libs/filesystem/src/path.o 
./boost/libs/filesystem/src/utf8_codecvt_facet.o 
./boost/libs/chrono/src/chrono.o 
./boost/libs/chrono/src/process_cpu_clocks.o 
./boost/libs/chrono/src/thread_clock.o ./pwiz/data/msdata/Version.o 
./pwiz/data/identdata/Version.o ./pwiz/data/common/MemoryIndex.o 
./pwiz/data/common/CVTranslator.o ./pwiz/data/common/cv.o 
./pwiz/data/common/ParamTypes.o 
./pwiz/data/common/BinaryIndexStream.o ./pwiz/data/common/diff_std.o 
./pwiz/data/common/Unimod.o 
./pwiz/data/msdata/mz5/Configuration_mz5.o 
./pwiz/data/msdata/mz5/Connection_mz5.o 
./pwiz/data/msdata/mz5/Datastructures_mz5.o 
./pwiz/data/msdata/mz5/ReferenceRead_mz5.o 
./pwiz/data/msdata/mz5/ReferenceWrite_mz5.o 
./pwiz/data/msdata/mz5/Translator_mz5.o 
./pwiz/data/msdata/SpectrumList_MGF.o 
./pwiz/data/msdata/DefaultReaderList.o 
./pwiz/data/msdata/ChromatogramList_mzML.o 
./pwiz/data/msdata/ChromatogramList_mz5.o 
./pwiz/data/msdata/examples.o ./pwiz/data/msdata/Serializer_mzML.o 
./pwiz/data/msdata/Serializer_MSn.o ./pwiz/data/msdata/Reader.o 
./pwiz/data/msdata/Serializer_mz5.o 
./pwiz/data/msdata/Serializer_MGF.o 
./pwiz/data/msdata/Serializer_mzXML.o 
./pwiz/data/msdata/SpectrumList_mzML.o 
./pwiz/data/msdata/SpectrumList_MSn.o 
./pwiz/data/msdata/SpectrumList_mz5.o 
./pwiz/data/msdata/BinaryDataEncoder.o ./pwiz/data/msdata/Diff.o 
./pwiz/data/msdata/MSData.o ./pwiz/data/msdata/References.o 
./pwiz/data/msdata/SpectrumList_mzXML.o ./pwiz/data/msdata/IO.o 
./pwiz/data/msdata/SpectrumList_BTDX.o 
./pwiz/data/msdata/SpectrumInfo.o ./pwiz/data/msdata/RAMPAdapter.o 
./pwiz/data/msdata/LegacyAdapter.o 
./pwiz/data/msdata/SpectrumIterator.o ./pwiz/data/msdata/MSDataFile.o 
./pwiz/data/msdata/MSNumpress.o 
./pwiz/data/msdata/SpectrumListCache.o 
./pwiz/data/msdata/Index_mzML.o 
./pwiz/data/msdata/SpectrumWorkerThreads.o 
./pwiz/data/identdata/IdentDataFile.o 
./pwiz/data/identdata/IdentData.o 
./pwiz/data/identdata/DefaultReaderList.o 
./pwiz/data/identdata/Reader.o 
./pwiz/data/identdata/Serializer_protXML.o 
./pwiz/data/identdata/Serializer_pepXML.o 
./pwiz/data/identdata/Serializer_mzid.o ./pwiz/data/identdata/IO.o 
./pwiz/data/identdata/References.o 
./pwiz/data/identdata/MascotReader.o 
./pwiz/data/proteome/Modification.o ./pwiz/data/proteome/Digestion.o 
./pwiz/data/proteome/Peptide.o ./pwiz/data/proteome/AminoAcid.o 
./pwiz/utility/minimxml/XMLWriter.o 
./pwiz/utility/minimxml/SAXParser.o 
./pwiz/utility/chemistry/Chemistry.o 
./pwiz/utility/chemistry/ChemistryData.o 
./pwiz/utility/chemistry/MZTolerance.o 
./pwiz/utility/misc/IntegerSet.o ./pwiz/utility/misc/Base64.o 
./pwiz/utility/misc/IterationListener.o 
./pwiz/utility/misc/MSIHandler.o ./pwiz/utility/misc/Filesystem.o 
./pwiz/utility/misc/TabReader.o 
./pwiz/utility/misc/random_access_compressed_ifstream.o 
./pwiz/utility/misc/SHA1.o ./pwiz/utility/misc/SHA1Calculator.o 
./pwiz/utility/misc

Re: [R] R examples in Agronomy

2018-06-28 Thread mikorym via R-help
> Dear all,
> Are there good R stat examples in the field of agronomy (especially field 
> experiments)?
> Thanks
> /-
> Khaled IBRAHIMI, PhD
> Assistant Professor, Soil Science & Environment
> Higher Institute of Agricultural Sciences of Chott-Mariem
> The University of Sousse, Tunisia
> Tel.: 216 97 276 835
> Email: ibrahimi.is...@gmail.com

I apologise preemptively if this reply messes up the formatting.

Hi Khaled

If your data has a lot of (possibly correlated) parameters, then I would
suggest to look at ade4. 

The main tool behind this package is Principal Component Analysis (PCA) and
although aimed at ecological data, there are specific applications to
agronomical contexts, such as: soil and leaf analyses; market price analyses
or yield analyses; dimensionality reduction of the weather component; and
several other types of possible agronomy related data contexts.

There are other packages for PCA as well, but I don't think they were
specifically aimed at a biological context.

If you are looking for specific papers on this, I would recommend as a
starting point any paper by Patrice Cadet. Or, if you have specific
questions, you are welcome to ask me.

Best regards
Phillip

Phillip-Jan van Zyl
MSc (Category Theory)

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 maintains old values

2018-07-02 Thread Morkus via R-help
Hello,

I have a strange side-effect from executing R-scripts using R and RServe.

I am executing an R-Script from a Java file using RServe in R. I also have 
RStudio installed, but it's not running at the time. The R-script reads a CSV 
file and does various statistical things. RServe enables me to run each line of 
the R script using "eval()" line by line.

All this works fine for a correctly-formatted CSV file. It's great.

But, if the CSV file isn't correctly formatted, AND the last CSV file did 
correctly get run, then, with the incorrect CSV as input, the output is what 
ran last time. Somehow, the last correct run is persisted and returned if there 
is some problem with the current CSV input.

This data persistence is maintained across reboots.

I'm thus baffled how R is maintaining these old values, but more to the point, 
I need to know how to clear these old values so if the CSV input is incorrect, 
I get nothing back, not the old CSV values from a correctly formatted file.

Hope this description is clear.

Thanks in advance to all.

- M

Sent from [ProtonMail](https://protonmail.com), Swiss-based encrypted email.
[[alternative HTML version deleted]]

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


[R] how to plot three dimension data to filled contour plot or surface plot in R Ask Question

2017-04-11 Thread dncdd via R-help
ENV 

R 3.3.2

When I have data like:

rdn<-c(0.8,1.8,2.8)
tdn<-c(1,2,3,4,5,6,7,8,9)

idn<-matrix(c(0.3, 0.3, 0.3, 0.2, 0.2, 0.4, 0.1, 0.1, 0.5, 0, 0.2, 0.5, 0, 
0.3, 0.6, 0, 0.4, 0.6, 0, 0.4, 0.6, 0, 0.5, 0.7, 0, 0.5, 0.7), nrow=9, ncol=3, 
byrow=T)

And the matrix looks like(3*9 = 27 data elements):

0.3, 0.3, 0.3, 
0.2, 0.2, 0.4, 
0.1, 0.1, 0.5, 
0, 0.2, 0.5, 
0, 0.3, 0.6, 
0, 0.4, 0.6, 
0, 0.4, 0.6, 
0, 0.5, 0.7, 
0, 0.5, 0.7

Then I can get a filled.contour with parameters x,y,z. x is tdn, y is rdn, z is 
the matrix. I already get this.

 
**My current problem** is:

What If I have three dimension data

r1dn<-c(0.8,1.8,2.8)
r2dn<-c(0.8,1.8,2.8)
tdn<-c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9)

And (3*3*9 = 81 data elements):

 0.8  1.8  2.8
0.8  1.8  2.8   0.8  1.8  2.80.8  1.8  2.8

--- 81  elements --

0.3, 0.3, 0.3,  0.3, 0.3, 0.5,   0.3, 0.3, 0.3, 
0.2, 0.2, 0.4,  0.2, 0.4, 0.4,   0.4, 0.2, 0.5,
0.1, 0.1, 0.5,  0.2, 0.3, 0.5,   0.4, 0.4, 0.5, 
0, 0.2, 0.5,0.2, 0.2, 0.6,   0.4, 0.5, 0.6, 
0, 0.3, 0.6,0.3, 0.3, 0.6,   0.5, 0.5, 0.7, 
0, 0.4, 0.6,0.2, 0.5, 0.7,   0.5, 0.6, 0.7, 
0, 0.4, 0.6,0, 0.5, 0.6, 0.5, 0.6, 0.9,  
0, 0.5, 0.7,0, 0.6, 0.8, 0.5, 0.7, 0.8, 
0, 0.5, 0.7 0, 0.6, 0.8  0.5, 0.8, 0.9   


I googled many surface and contour codes but I still not find some code for 
three dimension data yet. How to do that in R? Say, x is r1dn, y is r2dn, z is 
tdn, what about the three dimension data? Does ggplot can plot three dimension 
filled contour or surface plot? Or another alternative solutions?

All I expected is a 3d plot with color changes smoothly and no grid on it.

Looks like:

 
no grid for next three figures

 
 
 
Those should be 3d filled contour or 3d surface plot.

Thanks for your time.


  [1]: https://i.stack.imgur.com/z6u3p.png
  [2]: https://i.stack.imgur.com/MEnFn.png
  [3]: https://i.stack.imgur.com/Ri29w.png
  [4]: https://i.stack.imgur.com/CdCqL.jpg
  [5]: https://i.stack.imgur.com/Pt1Nw.jpg
[[alternative HTML version deleted]]

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

[R] 回复: how to plot three dimension data to filled contour plot or surface plot in R Ask Question

2017-04-11 Thread dncdd via R-help
Thank you Ismail SEZEN.The link you give is filled.contour code which only 
works with my first mini data .
The code in the link for R 3.3.2 is :** code * in  link  for R 
3.3.2 panel.filledcontour <- function(x, y, z, subscripts, at, col.regions 
= 
cm.colors, 
col = col.regions(length(at) - 1), ...) 
{ 
  stopifnot(require("gridBase")) 
  z <- matrix(z[subscripts], 
  nrow = length(unique(x[subscripts])), 
  ncol = length(unique(y[subscripts]))) 
  if (!is.double(z)) storage.mode(z) <- "double" 
  opar <- par(no.readonly = TRUE) 
  on.exit(par(opar)) 
  if (panel.number() > 1) par(new = TRUE) 
  par(fig = gridFIG(), omi = c(0, 0, 0, 0), mai = c(0, 0, 0, 0)) 
  cpl <- current.panel.limits() 
  plot.window(xlim = cpl$xlim, ylim = cpl$ylim, 
  log = "", xaxs = "i", yaxs = "i") 
  # paint the color contour regions 
  .filled.contour(as.double(do.breaks(cpl$xlim, nrow(z) - 1)), 
  as.double(do.breaks(cpl$ylim, ncol(z) - 1)), 
  z, levels = as.double(at), col = col)
  # add contour lines 
  contour(as.double(do.breaks(cpl$xlim, nrow(z) - 1)), 
  as.double(do.breaks(cpl$ylim, ncol(z) - 1)), 
  z, levels = as.double(at), add=T, 
  col = "gray", # color of the lines 
  drawlabels=F  # add labels or not 
 ) 
} 
plot.new() 

print(levelplot(volcano, panel = panel.filledcontour, 
  col.regions = terrain.colors, 
  cuts = 10, 
  plot.args = list(newpage = FALSE)))*** END *** code *** in *** link 
*** for R 3.3.2 *** 
first mini datawhich should be a three dimensinal data either and the data in 
matrix is not a function of rdn and tdnwhich means z matrix is not function of 
x,y. 
    rdn<-c(0.8,1.8,2.8)
tdn<-c(1,2,3,4,5,6,7,8,9)

idn<-matrix(c(0.3, 0.3, 0.3, 0.2, 0.2, 0.4, 0.1, 0.1, 0.5, 0, 0.2, 0.5, 0, 
0.3, 0.6, 0, 0.4, 0.6, 0, 0.4, 0.6, 0, 0.5, 0.7, 0, 0.5, 0.7), nrow=9, ncol=3, 
byrow=T)

And the matrix looks like(3*9 = 27 data elements):

0.3, 0.3, 0.3, 
0.2, 0.2, 0.4, 
0.1, 0.1, 0.5, 
0, 0.2, 0.5, 
0, 0.3, 0.6, 
0, 0.4, 0.6, 
0, 0.4, 0.6, 
0, 0.5, 0.7, 
0, 0.5, 0.7

Well, now I realized that the second data might (my current problem) be afour 
dimensional data:
r1dn<-c(0.8,1.8,2.8)
r2dn<-c(0.8,1.8,2.8)
tdn<-c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9)

And (3*3*9 = 81 data elements):

     0.8  1.8  2.8
    0.8  1.8  2.8   0.8  1.8  2.80.8  1.8  2.8

    --- 81  elements --three matrix

    0.3, 0.3, 0.3,  0.3, 0.3, 0.5,   0.3, 0.3, 0.3, 
    0.2, 0.2, 0.4,  0.2, 0.4, 0.4,   0.4, 0.2, 0.5,
    0.1, 0.1, 0.5,  0.2, 0.3, 0.5,   0.4, 0.4, 0.5, 
    0, 0.2, 0.5,0.2, 0.2, 0.6,   0.4, 0.5, 0.6, 
    0, 0.3, 0.6,0.3, 0.3, 0.6,   0.5, 0.5, 0.7, 
    0, 0.4, 0.6,0.2, 0.5, 0.7,   0.5, 0.6, 0.7, 
    0, 0.4, 0.6,0, 0.5, 0.6, 0.5, 0.6, 0.9,  
    0, 0.5, 0.7,0, 0.6, 0.8, 0.5, 0.7, 0.8, 
    0, 0.5, 0.7 0, 0.6, 0.8  0.5, 0.8, 0.9  
The three matrix is not the function of r1dn, r2dn, tdn.  r1dn, r2dn, tdn can 
be labels. So there are four dimensional data. x is r1dn, y is r2dn, z is tdn 
and the three matrix is, let's say, vdn.Four dimension: r1dn r2dn tdn fdn as 
x,y,z,v.  And v is not the function of x,y,z. So there are might need a 3d 
filled.contour. But I did not find it. All the code I found is that x,y,z and z 
is a function of x,y. Another situation I found is that x,y,z,v and v is 
function of x,y,z. But in my data, v is not a function of x,y,z.
--发件人:Ismail 
SEZEN 发送时间:2017年4月12日(星期三) 00:48收件人:dncdd 
抄 送:r-help 主 题:Re: [R] how to plot 
three dimension data to filled contour plot or surface plot in R  Ask Question
After lon long search, my best shot was to use filled.contour + 
lattice::levelplot together [a] to represent 3 dimensional data on a flat 
surface. 
a) 
http://r.789695.n4.nabble.com/Creating-smooth-color-regions-with-panel-contourplot-td866253.html
Some Details:
On 11 Apr 2017, at 09:16, dncdd via R-help  wrote:
ENV 

R 3.3.2

When I have data like:

rdn<-c(0.8,1.8,2.8)
tdn<-c(1,2,3,4,5,6,7,8,9)

idn<-matrix(c(0.3, 0.3, 0.3, 0.2, 0.2, 0.4, 0.1, 0.1, 0.5, 0, 0.2, 0.5, 0, 
0.3, 0.6, 0, 0.4, 0.6, 0, 0.4, 0.6, 0, 0.5, 0.7, 0, 0.5, 0.7), nrow=9, ncol=3, 
byrow=T)

And the matrix looks like(3*9 = 27 data elements):

0.3, 0.3, 0.3, 
0.2, 0.2, 0.4, 
0.1, 0.1, 0.5, 
0, 0.2, 0.5, 
0, 0.3, 0.6, 
0, 0.4, 0.6, 
0, 0.4, 0.6, 
0, 0.5, 0.7, 
0, 0.5, 0.7

Then I can get a filled.contour with parameters x,y,z. x is tdn, y is rdn, z is 
the matrix. I already get this.

If you ha

[R] 回复: how to plot three dimension data to filled contour plot or surface plot in R Ask Question

2017-04-13 Thread dncdd via R-help
This can be a solution. Thank you. Thanks for your time.
--发件人:Ismail 
SEZEN 发送时间:2017年4月13日(星期四) 10:05收件人:dncdd 
抄 送:r-help 主 题:Re: [R] how to plot 
three dimension data to filled contour plot or surface plot in R  Ask Question

On 12 Apr 2017, at 09:08, dncdd  wrote:
Sorry, I might make the question complicated. 
I can use filled.contour() to plot mini data 1(three dimension on flat 
surface). Now my problem is on mini data 2. Let's unfold the mini data 2.

  r1dn   r2dn   tdnfdn
 x, y, z,     v
0.80.80.10.3
0.80.80.20.2
0.80.80.30.1
0.80.80.40
0.80.80.50
0.80.80.60
0.80.80.70
0.80.80.80
0.80.80.90
0.81.80.10.3
0.81.80.20.2
0.81.80.30.1
0.81.80.40.2
0.81.80.50.3
0.81.80.60.4
0.81.80.70.4
0.81.80.80.5
0.81.80.90.5
0.82.80.10.3
0.82.80.20.4
0.82.80.30.5
0.82.80.40.5
0.82.80.50.6
0.82.80.60.6
0.82.80.70.6
0.82.80.80.7
0.82.80.90.7
1.80.80.10.3
1.80.80.20.2
1.80.80.30.2
1.80.80.40.2
1.80.80.50.3
1.80.80.60.2
1.80.80.70
1.80.80.80
1.80.80.90
1.81.80.10.3
1.81.80.20.4
1.81.80.30.3
1.81.80.40.2
1.81.80.50.3
1.81.80.60.5
1.81.80.70.5
1.81.80.80.6
1.81.80.90.6
1.82.80.10.5
1.82.80.20.4
1.82.80.30.5
1.82.80.40.6
1.82.80.50.6
1.82.80.60.7
1.82.80.70.6
1.82.80.80.8
1.82.80.90.8
2.80.80.10.3
2.80.80.20.4
2.80.80.30.4
2.80.80.40.4
2.80.80.50.5
2.80.80.60.5
2.80.80.70.5
2.80.80.80.5
2.80.80.90.5
2.81.80.10.3
2.81.80.20.2
2.81.80.30.4
2.81.80.40.5
2.81.80.50.5
2.81.80.60.6
2.81.80.70.6
2.81.80.80.7
2.81.80.90.8
2.82.80.10.3
2.82.80.20.5
2.82.80.30.5
2.82.80.40.6
2.82.80.50.7
2.82.80.60.7
2.82.80.70.9
2.82.80.80.8
2.82.80.90.9

When x is 0.8, y is 0.8, z is 0.1, then v is 0.3.  So v is not limited by a 
function like v ~ f(x,y,z). I mean x,y,z is just like labels on the 3d 
space.You have give me many suggestions. I think that maybe scatterplot with 
colors on v on 3d space is a solution. I will try it later. At the beginning, I 
was wondering a 3d surface plot or 3d filled.contour on 3d space. I am not sure 
whether it is possble.

First of all, v is function of x,y,z according to sample above wheter you 
accept or not.  Because x,y,z represents coordinates of v in the 3D space and 
if someone wants to plot contours between those points, he/she needs a v(x,y,z) 
function that can calculate values (v) between x,y,z coordinates. Let’s get 
back to main question.
I think you want something like as [1] and [2]. Your best shot is misc3d 
package. I created a simple example how to plot isosurfaces and you can find 
different strategies to plot 4D data in 3D space at [3].
#——library(misc3d)# let's create a function to create a sample data to 
visualizef <- function(x, y, z) sin(x) * sin(y) * sin(z)x <- z <- seq(0, pi, 
length.out = 15)y <- seq(-pi, pi, length.out = 15)d <- expand.grid(x, y, 
z)colnames(d) <- c("x", "y", "z")d$v <- with(d, f(x, y, z))
# this is your initial datahead(d)
k <- 16 # number of contoursalpha_min_max <- c(0.2, 0.6)colf <- 
colorRampPalette(rev(RColorBrewer::brewer.pal(11, "RdBu")))
# isosurfaces are at herelev <- seq(min(d$v), max(d$v), length.out = k)# inner 
isosurfaces are more solid, outer ones are more transparent.# So, we can see 
inner isosurfaces by x-ray vision.alpha <- seq(alpha_min_max[1], 
alpha_min_max[2], length.out = k)
rgl::plot3d(x, y, z, type = "n", aspect = TRUE) # create 
scenemisc3d::contour3d(f, lev, x, y, z, color = colf(k), alpha = alpha,         
 smooth = 3, engine = "rgl", add = TRUE)rgl::aspect3d(1, 2, 1) # set aspect, y 
is different from x and z.#——

1- http://stackoverflow.com/a/1131917

[R] 回复: 回复: how to plot three dimension data to filled contour plot or surface plot in R Ask Question

2017-04-13 Thread dncdd via R-help


x<-c(0.8,1.8,2.8) 
y<-c(0.8,1.8,2.8) 
z<-c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9) 
nx<-sprintf("x%s",x)
ny<-sprintf("y%s",y)
nz<-sprintf("z%s",z)

v<-c(
 0.3, 0.2, 0.1, 0, 0, 0, 0, 0, 0,
 0.3, 0.2, 0.1, 0.2, 0.3, 0.4, 0.4, 0.5, 0.5,
 0.3, 0.4, 0.5, 0.5, 0.6, 0.6, 0.6, 0.7, 0.7,
 0.3, 0.2, 0.2, 0.2, 0.3, 0.2, 0, 0, 0,
 0.3, 0.4, 0.3, 0.2, 0.3, 0.5, 0.5, 0.6, 0.6,
 0.5, 0.4, 0.5, 0.6, 0.6, 0.7, 0.6, 0.8, 0.8,
 0.3, 0.4, 0.4, 0.4, 0.5, 0.5, 0.5, 0.5, 0.5,
 0.3, 0.2, 0.4, 0.5, 0.5, 0.6, 0.6, 0.7, 0.8,
 0.3, 0.5, 0.5, 0.6, 0.7, 0.7, 0.9, 0.8, 0.9)
myarray<-array(v, c(length(z), length(y), length(x)), dimnames=list(z,y,x))
odftarget<-as.data.frame.table(myarray)
names(odftarget) <- c('z', 'y', 'x', 'v')
dftarget <- data.frame(
z=as.numeric(as.character(odftarget$z)),
y=as.numeric(as.character(odftarget$y)), 
x=as.numeric(as.character(odftarget$x)), 
v=odftarget$v
)
head(dftarget)

k <- 16 # number of contours
alpha_min_max <- c(0.2, 0.6)
colf <- colorRampPalette(rev(RColorBrewer::brewer.pal(11, "RdBu")))
colf <- colorRampPalette(colpal)

# isosurfaces are at here
lev <- seq(min(dftarget$v), max(dftarget$v), length.out = k)
# inner isosurfaces are more solid, outer ones are more transparent.
# So, we can see inner isosurfaces by x-ray vision.
alpha <- seq(alpha_min_max[1], alpha_min_max[2], length.out = k)

rgl::plot3d(z, y, x, type = "n", aspect = TRUE) # create scene# I am using the 
array here.
misc3d::contour3d(myarray, lev, z, y, x, color = colf(k), alpha = alpha, smooth 
= 3, engine = "rgl", add = TRUE) 
rgl::aspect3d(2, 1, 1) 



It works.Thank you.


--发件人:dncdd via 
R-help 发送时间:2017年4月13日(星期四) 18:07收件人:Ismail SEZEN 
抄 送:r-help 主 题:[R] 回复: how to plot 
three dimension data to filled contour plot or surface plot in R  Ask Question
This can be a solution. Thank you. Thanks for your time.
--发件人:Ismail 
SEZEN 发送时间:2017年4月13日(星期四) 10:05收件人:dncdd 
抄 送:r-help 主 题:Re: [R] how to plot 
three dimension data to filled contour plot or surface plot in R  Ask Question

On 12 Apr 2017, at 09:08, dncdd  wrote:
Sorry, I might make the question complicated. 
I can use filled.contour() to plot mini data 1(three dimension on flat 
surface). Now my problem is on mini data 2. Let's unfold the mini data 2.

  r1dn   r2dn   tdnfdn
 x, y, z, v
0.80.80.10.3
0.80.80.20.2
0.80.80.30.1
0.80.80.40
0.80.80.50
0.80.80.60
0.80.80.70
0.80.80.80
0.80.80.90
0.81.80.10.3
0.81.80.20.2
0.81.80.30.1
0.81.80.40.2
0.81.80.50.3
0.81.80.60.4
0.81.80.70.4
0.81.80.80.5
0.81.80.90.5
0.82.80.10.3
0.82.80.20.4
0.82.80.30.5
0.82.80.40.5
0.82.80.50.6
0.82.80.60.6
0.82.80.70.6
0.82.80.80.7
0.82.80.90.7
1.80.80.10.3
1.80.80.20.2
1.80.80.30.2
1.80.80.40.2
1.80.80.50.3
1.80.80.60.2
1.80.80.70
1.80.80.80
1.80.80.90
1.81.80.10.3
1.81.80.20.4
1.81.80.30.3
1.81.80.40.2
1.81.80.50.3
1.81.80.60.5
1.81.80.70.5
1.81.80.80.6
1.81.80.90.6
1.82.80.10.5
1.82.80.20.4
1.82.80.30.5
1.82.80.40.6
1.82.80.50.6
1.82.80.60.7
1.82.80.70.6
1.82.80.80.8
1.82.80.90.8
2.80.80.10.3
2.80.80.20.4
2.80.80.30.4
2.80.80.40.4
2.80.80.50.5
2.80.80.60.5
2.80.80.70.5
2.80.80.80.5
2.80.80.90.5
2.81.80.10.3
2.81.80.20.2
2.81.80.30.4
2.81.80.40.5
2.81.80.50.5
2.81.80.60.6
2.81.80.70.6
2.81.80.80.7
2.81.80.90.8
2.82.80.10.3
2.82.80.20.5
2.82.80.30.5
2.82.80.40.6
2.82.80.50.7
2.82.80.60.7
2.82.80.70.9
2.82.80.80.8
2.82.80.90.9

When x is 0.8, y is 0.8, z is 0.1, then v is 0

[R] rollapply() produces NAs

2017-05-27 Thread Sepp via R-help
Hello,
I am fairly new to R and trying to calculate value at risk with exponentially 
decreasing weights.My function works for a single vector of returns but does 
not work with rollapply(), which is what I want to use. The function I am 
working on should assig exponentially decreasing weights to the K most recent 
returns and then order the returns in an ascending order. Subsequently it 
should pick the last return for which the cumulative sum of the weights is 
smaller or equal to a significance level. Thus, I am trying to construct a 
cumulative distribution function and find a quantile.
This is the function I wrote:
VaRfun <- function(x, lambda = 0.94) {
#create data.frame and order returns such that the lates return is the first  
df <- data.frame(weight = c(1:length(x)), return = rev(x))  K <- nrow(df)  
constant <- (1-lambda)/(1-lambda^(K))#assign weights to the returns    for(i in 
1:nrow(df)) {    df$weight[i] <- lambda^(i-1) * constant    }#order returns in 
an ascending order  df <- df[order(df$return),]
#add the cumulative sum of the weights  df$cum.weight <- cumsum(df$weight)
#calculate value at risk  VaR <- -tail((df$return[df$cum.weight <= .05]), 1)  
signif(VaR, digits = 3)}
It works for a single vector of returns but if I try to use it with 
rollapply(), such as
rollapply(r, width = list(-500, -1), FUN = VaRfun),
it outputs a vector of NAs and I don't know why.
Thank you for your help!
[[alternative HTML version deleted]]

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] rollapply() produces NAs

2017-05-28 Thread Sepp via R-help
This is exactly what I want. However, with my function it produces a vector of 
NAs ...


Gabor Grothendieck  schrieb am 16:23 Sonntag, 28.Mai 
2017:



Maybe you want this.It computes VaRfun(r[c(i-500, i-1)] for each i for
which the argument to r makes sense.

rollapply(r, width = list(c(-500, -1)), FUN = VaRfun),


On Sat, May 27, 2017 at 5:29 PM, Sepp via R-help  wrote:
> Hello,
> I am fairly new to R and trying to calculate value at risk with exponentially 
> decreasing weights.My function works for a single vector of returns but does 
> not work with rollapply(), which is what I want to use. The function I am 
> working on should assig exponentially decreasing weights to the K most recent 
> returns and then order the returns in an ascending order. Subsequently it 
> should pick the last return for which the cumulative sum of the weights is 
> smaller or equal to a significance level. Thus, I am trying to construct a 
> cumulative distribution function and find a quantile.
> This is the function I wrote:
> VaRfun <- function(x, lambda = 0.94) {
> #create data.frame and order returns such that the lates return is the first  
> df <- data.frame(weight = c(1:length(x)), return = rev(x))  K <- nrow(df)  
> constant <- (1-lambda)/(1-lambda^(K))#assign weights to the returnsfor(i 
> in 1:nrow(df)) {df$weight[i] <- lambda^(i-1) * constant}#order 
> returns in an ascending order  df <- df[order(df$return),]
> #add the cumulative sum of the weights  df$cum.weight <- cumsum(df$weight)
> #calculate value at risk  VaR <- -tail((df$return[df$cum.weight <= .05]), 1)  
> signif(VaR, digits = 3)}
> It works for a single vector of returns but if I try to use it with 
> rollapply(), such as
> rollapply(r, width = list(-500, -1), FUN = VaRfun),
> it outputs a vector of NAs and I don't know why.
> Thank you for your help!
> [[alternative HTML version deleted]]
>
> ______
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] rollapply() produces NAs

2017-05-28 Thread Sepp via R-help
This is the function in plain text because it looked messy before:

VaRfun <- function(x, lambda = 0.94) {

#create data.frame and order returns such that the lates return is the first
  df <- data.frame(weight = c(1:length(x)), return = rev(x))
  K <- nrow(df)
  constant <- (1-lambda)/(1-lambda^(K))
#assign weights to the returns  
  for(i in 1:nrow(df)) {
df$weight[i] <- lambda^(i-1) * constant
}
#order returns in an ascending order
  df <- df[order(df$return),]

#add the cumulative sum of the weights
  df$cum.weight <- cumsum(df$weight)

#calculate value at risk
  VaR <- -tail((df$return[df$cum.weight <= .05]), 1)
  signif(VaR, digits = 3)
}

It works for a single vector of returns but if I try to use it with 
rollapply(), such as

rollapply(r, width = list(-500, -1), FUN = VaRfun),

it outputs a vector of NAs and I don't know why.


______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] 3D plot with coordinates

2017-06-20 Thread Alaios via R-help
HelloI have three x,y,z vectors (lets say each is set as  rnorm(360)). So each 
one is having 360 elements each one correpsonding to angular coordinates (1 
degree, 2 degrees, 3 degrees, 360 degrees) and I want to plot those on the 
xyz axes that have degress.
Is there a function or library to look at R cran? The ideal will be that after 
plotting I will be able to rotate the shape.
I would like to thank you in advance for your helpRegardsAlex
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] 3D plot with coordinates

2017-06-21 Thread Alaios via R-help
Thanks a lot for the reply.After  looking at different parts of the code today 
I was able to start with simple 2D polar plots as the attached pdf file.  In 
case the attachment is not visible I used the plot.polar function to create 
something like 
that.https://vijaybarve.files.wordpress.com/2013/04/polarplot-05.png
Now the idea now will be to put three of those (for X,Y,Z) in a 3d rotatable 
plane. I tried the rgl function but is not clear how I can use directly polar 
coordinates to draw the points at the three different planes. 
Any ideas on that?
Thanks a lot.RegardsAlex

On Tuesday, June 20, 2017 9:49 PM, Uwe Ligges 
 wrote:
 

 package rgl.

Best,
Uwe Ligges


On 20.06.2017 21:29, Alaios via R-help wrote:
> HelloI have three x,y,z vectors (lets say each is set as  rnorm(360)). So 
> each one is having 360 elements each one correpsonding to angular coordinates 
> (1 degree, 2 degrees, 3 degrees, 360 degrees) and I want to plot those on 
> the xyz axes that have degress.
> Is there a function or library to look at R cran? The ideal will be that 
> after plotting I will be able to rotate the shape.
> I would like to thank you in advance for your helpRegardsAlex
>     [[alternative HTML version deleted]]
> 
> ______
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


   

XNoSink.pdf
Description: Adobe PDF document
______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] 3D plot with coordinates

2017-06-21 Thread Alaios via R-help
Thanks Duncan for the replyI can not suppress anything these are radiation 
pattern measurements that are typically are taken at X,Y and Z planes. See an 
example here, where I want to plot the measurements for the red, green and blue 
planes (so the image below withouth the 3d green structure 
inside)https://www.researchgate.net/publication/258391165/figure/fig7/AS:322947316240401@1454008048835/Radiation-pattern-of-Archimedean-spiral-antenna-a-3D-and-b-elevation-cuts-at-phi.png
 

I am quite confident that there is a tool in R to help me do this 3D plot, and 
even better rotatable.
Thanks for the reply to allAlex 

On Wednesday, June 21, 2017 1:07 PM, Duncan Murdoch 
 wrote:
 

 On 21/06/2017 5:23 AM, Alaios via R-help wrote:
> Thanks a lot for the reply.After  looking at different parts of the code 
> today I was able to start with simple 2D polar plots as the attached pdf 
> file.  In case the attachment is not visible I used the plot.polar function 
> to create something like 
> that.https://vijaybarve.files.wordpress.com/2013/04/polarplot-05.png
> Now the idea now will be to put three of those (for X,Y,Z) in a 3d rotatable 
> plane. I tried the rgl function but is not clear how I can use directly polar 
> coordinates to draw the points at the three different planes.
> Any ideas on that?

You can't easily do what you're trying to do.  You have 6 coordinates to 
display:  the 3 angles and values corresponding to each of them.  You 
need to suppress something.

If the values for matching angles correspond to each other (e.g. x=23 
degrees and y=23 degrees and z=23 degrees all correspond to the same 
observation), then I'd suggest suppressing the angles.  Just do a 
scatterplot of the 3 corresponding values.  It might make sense to join 
them (to make a path as the angles change), and perhaps to colour the 
path to indicate the angle (or plot text along the path to show it).

Duncan Murdoch

> Thanks a lot.RegardsAlex
>
>    On Tuesday, June 20, 2017 9:49 PM, Uwe Ligges 
> wrote:
>
>
>  package rgl.
>
> Best,
> Uwe Ligges
>
>
> On 20.06.2017 21:29, Alaios via R-help wrote:
>> HelloI have three x,y,z vectors (lets say each is set as  rnorm(360)). So 
>> each one is having 360 elements each one correpsonding to angular 
>> coordinates (1 degree, 2 degrees, 3 degrees, 360 degrees) and I want to 
>> plot those on the xyz axes that have degress.
>> Is there a function or library to look at R cran? The ideal will be that 
>> after plotting I will be able to rotate the shape.
>> I would like to thank you in advance for your helpRegardsAlex
>>    [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] 3D plot with coordinates

2017-06-22 Thread Alaios via R-help
Thanks. So after searching 4 hours last night it looks like that there is no R 
package that can do this right now. Any other ideas or suggestions might be 
helpful.RegardsAlex 

On Wednesday, June 21, 2017 3:21 PM, Alaios via R-help 
 wrote:
 

 Thanks Duncan for the replyI can not suppress anything these are radiation 
pattern measurements that are typically are taken at X,Y and Z planes. See an 
example here, where I want to plot the measurements for the red, green and blue 
planes (so the image below withouth the 3d green structure 
inside)https://www.researchgate.net/publication/258391165/figure/fig7/AS:322947316240401@1454008048835/Radiation-pattern-of-Archimedean-spiral-antenna-a-3D-and-b-elevation-cuts-at-phi.png
 

I am quite confident that there is a tool in R to help me do this 3D plot, and 
even better rotatable.
Thanks for the reply to allAlex 

    On Wednesday, June 21, 2017 1:07 PM, Duncan Murdoch 
 wrote:
 

 On 21/06/2017 5:23 AM, Alaios via R-help wrote:
> Thanks a lot for the reply.After  looking at different parts of the code 
> today I was able to start with simple 2D polar plots as the attached pdf 
> file.  In case the attachment is not visible I used the plot.polar function 
> to create something like 
> that.https://vijaybarve.files.wordpress.com/2013/04/polarplot-05.png
> Now the idea now will be to put three of those (for X,Y,Z) in a 3d rotatable 
> plane. I tried the rgl function but is not clear how I can use directly polar 
> coordinates to draw the points at the three different planes.
> Any ideas on that?

You can't easily do what you're trying to do.  You have 6 coordinates to 
display:  the 3 angles and values corresponding to each of them.  You 
need to suppress something.

If the values for matching angles correspond to each other (e.g. x=23 
degrees and y=23 degrees and z=23 degrees all correspond to the same 
observation), then I'd suggest suppressing the angles.  Just do a 
scatterplot of the 3 corresponding values.  It might make sense to join 
them (to make a path as the angles change), and perhaps to colour the 
path to indicate the angle (or plot text along the path to show it).

Duncan Murdoch

> Thanks a lot.RegardsAlex
>
>    On Tuesday, June 20, 2017 9:49 PM, Uwe Ligges 
> wrote:
>
>
>  package rgl.
>
> Best,
> Uwe Ligges
>
>
> On 20.06.2017 21:29, Alaios via R-help wrote:
>> HelloI have three x,y,z vectors (lets say each is set as  rnorm(360)). So 
>> each one is having 360 elements each one correpsonding to angular 
>> coordinates (1 degree, 2 degrees, 3 degrees, 360 degrees) and I want to 
>> plot those on the xyz axes that have degress.
>> Is there a function or library to look at R cran? The ideal will be that 
>> after plotting I will be able to rotate the shape.
>> I would like to thank you in advance for your helpRegardsAlex
>>    [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 my 3D plot function

2017-06-25 Thread Alaios via R-help
Hi all,I had a question last week on asking for a function that will help me 
draw three different circles on x,y,z axis based on polar coordinates (Each 
X,Y,Z circle are coming from three independent measurements of 1-360 polar 
coordinates). It turned out that there  is no such function in R and thus I am 
trying to write my own piece of code that hopefully I will be able to share. I 
have spent some time to write some code based on the rgl library (Still not 
100% sure that this was the best option).
My input are three polar circles X,Y,Z with a good example being the image 
belowhttps://www.mathworks.com/help/examples/antenna/win64/xxpolarpattern_helix.png

So for X axis my input is a 2D matrix [360,2] including a single measurement 
per each polar coordinate. The first thing I tried was to turn my polar 
coordinates to cartesian ones by writing two simple functions. This works so 
far and I was able to print three simple circles on 3d spaceb but the problem 
now are the legends I need to put that remain on cartesian coordinates. As you 
can see from the code below all circles should have radius 1 (in terms of 
simplicity) but unfortunately I have the cartesian coordinates legends that do 
not help on reading my Figure. You can help me by executing the code below 

require("rgls")
degreeToRadian<-function(degree){  return   (0.01745329252*degree)}
turnPolarToX<-function(Amplitude,Coordinate){  return 
(Amplitude*cos(degreeToRadian(Coordinate)))}
turnPolarToY<-function(Amplitude,Coordinate){  return 
(Amplitude*sin(degreeToRadian(Coordinate)))}
# Putting the first circle on 3d space. Circle of radius 
1X1<-turnPolarToX(1,1:360)Y1<-turnPolarToY(1,1:360)Z1<-rep(0,360)
# Putting the second circle on 3d space. Circle of radius 
1X2<-turnPolarToX(1,1:360)Y2<-rep(0,360)Z2<-turnPolarToY(1,1:360)
# Putting the third circle on 3d space. Circle of radius 
1X3<-rep(0,360)Y3<-turnPolarToX(1,1:360)Z3<-turnPolarToY(1,1:360)
Min<-min(X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3)Max<-max(X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3)plot3d(X1,Y1,Z1,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=FALSE,add=TRUE,col="red",type="l")plot3d(X2,Y2,Z2,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=FALSE,add=TRUE,col="green",type="l")plot3d(X3,Y3,Z3,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=TRUE,add=FALSE,col="blue",type="l")
Would it be also possible to include an jpeg image file on a rgls plot?
Thanks a lotRegardsAlex
[[alternative HTML version deleted]]

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 my 3D plot function

2017-06-26 Thread Alaios via R-help
Thanks a lot for this. I never realized that my yahoo mail does not send plain 
text. So this is the code I have 

require("rgls") 

degreeToRadian<-function(degree){ 
return   (0.01745329252*degree) 
} 

turnPolarToX<-function(Amplitude,Coordinate){ 
return (Amplitude*cos(degreeToRadian(Coordinate))) 
} 

turnPolarToY<-function(Amplitude,Coordinate){ 
return (Amplitude*sin(degreeToRadian(Coordinate))) 
} 

X1<-turnPolarToX(1,1:360) 
Y1<-turnPolarToY(1,1:360) 
Z1<-rep(0,360) 


X2<-turnPolarToX(1,1:360) 
Y2<-rep(0,360) 
Z2<-turnPolarToY(1,1:360) 

test3<-runif(360) 
X3<-rep(0,360) 
Y3<-turnPolarToX(1,1:360) 
Z3<-turnPolarToY(1,1:360) 

Min<-min(X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3) 
Max<-max(X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3) 
plot3d(X1,Y1,Z1,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=FALSE,add=TRUE,col="red",type="l")
 
plot3d(X2,Y2,Z2,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=FALSE,add=TRUE,col="green",type="l")
 
plot3d(X3,Y3,Z3,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=TRUE,add=FALSE,col="blue",type="l")



I hope this helps
Regards
Alex
On Monday, June 26, 2017 1:46 AM, Jeff Newmiller  
wrote:



Please look at what I see in your code below (run-on code mush) to understand 
part of why it is important for you to send your email as plain text as the 
Posting Guide indicates.  You might find [1] helpful. 

[1] https://wiki.openstack.org/wiki/MailingListEtiquette
-- 
Sent from my phone. Please excuse my brevity.


On June 25, 2017 2:42:26 PM EDT, Alaios via R-help  wrote:
>Hi all,I had a question last week on asking for a function that will
>help me draw three different circles on x,y,z axis based on polar
>coordinates (Each X,Y,Z circle are coming from three independent
>measurements of 1-360 polar coordinates). It turned out that there  is
>no such function in R and thus I am trying to write my own piece of
>code that hopefully I will be able to share. I have spent some time to
>write some code based on the rgl library (Still not 100% sure that this
>was the best option).
>My input are three polar circles X,Y,Z with a good example being the
>image
>belowhttps://www.mathworks.com/help/examples/antenna/win64/xxpolarpattern_helix.png
>
>So for X axis my input is a 2D matrix [360,2] including a single
>measurement per each polar coordinate. The first thing I tried was to
>turn my polar coordinates to cartesian ones by writing two simple
>functions. This works so far and I was able to print three simple
>circles on 3d spaceb but the problem now are the legends I need to put
>that remain on cartesian coordinates. As you can see from the code
>below all circles should have radius 1 (in terms of simplicity) but
>unfortunately I have the cartesian coordinates legends that do not help
>on reading my Figure. You can help me by executing the code below 
>
>require("rgls")
>degreeToRadian<-function(degree){  return   (0.01745329252*degree)}
>turnPolarToX<-function(Amplitude,Coordinate){  return
>(Amplitude*cos(degreeToRadian(Coordinate)))}
>turnPolarToY<-function(Amplitude,Coordinate){  return
>(Amplitude*sin(degreeToRadian(Coordinate)))}
># Putting the first circle on 3d space. Circle of radius
>1X1<-turnPolarToX(1,1:360)Y1<-turnPolarToY(1,1:360)Z1<-rep(0,360)
># Putting the second circle on 3d space. Circle of radius
>1X2<-turnPolarToX(1,1:360)Y2<-rep(0,360)Z2<-turnPolarToY(1,1:360)
># Putting the third circle on 3d space. Circle of radius
>1X3<-rep(0,360)Y3<-turnPolarToX(1,1:360)Z3<-turnPolarToY(1,1:360)
>Min<-min(X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3)Max<-max(X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3)plot3d(X1,Y1,Z1,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=FALSE,add=TRUE,col="red",type="l")plot3d(X2,Y2,Z2,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=FALSE,add=TRUE,col="green",type="l")plot3d(X3,Y3,Z3,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=TRUE,add=FALSE,col="blue",type="l")
>Would it be also possible to include an jpeg image file on a rgls plot?
>Thanks a lotRegardsAlex
>[[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] scalable and dynamic color bar

2017-07-08 Thread Alaios via R-help
Hi,I am using rgl to plot 3d graphics. You can find below some executable code.
I would like to add a color bar that scales as the window size scale. The 
solution I currently have gives a color bar that gets pixelated once you 
maximize the window.
Can you suggest of alternatives?
ThanksAlex
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] add a color bar

2017-07-10 Thread Alaios via R-help
Hi all,the code you will find at the bottom of the screen creates a 3d diagram 
of antenna measurements. I am adding also to this Figure a color bar,and I 
wanted to ask you if I can add a color bar (which package?) that will scale as 
the windows is maximized. My current color bar is a bit too rought and gets 
pixelized each time I maximize the window.
Any suggestions?I would like to thank you for your replyRegardsAlex
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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: How to multiplying y-axis ticks value by 100?

2017-07-22 Thread iPad via R-help
R: how multiplying y-axis ticks value by 100 (without put the % symbol next to 
the number) here: 
plot (CI.overall, curvlab=c("Discharge", "Death"), xlab="Days", las=1) 
P.S. So instead 0.00, 0.20 etc. the 0, 20 etc.
Thank you in advance, Nic

[[alternative HTML version deleted]]

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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: How to multiplying y-axis ticks value by 100?

2017-07-24 Thread Ted via R-help

Many thanks, Jim!!!

>Jim Lemon < drjimle...@gmail.com >:
>Have a look at axis.mult in the plotrix package.
>Jim
----
>>iPad via R-help <  r-help@r-project.org > wrote:
>> How to multiplying y-axis ticks value by 100 (without put the % symbol next 
>> to the number) here:
>> plot (CI.overall, curvlab=c("Discharge", "Death"), xlab="Days", las=1)
>> P.S. So instead 0.00, 0.20 etc. the 0, 20 etc.
 __
>>  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>  https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] How export data set (available in the package) from R?

2017-07-29 Thread Ted via R-help
"Data set flchain available in the survival  package".  How can I get it (from 
R)  as Excel file? Thanks!

[[alternative HTML version deleted]]

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] switch of cex adjustment with mfrow?

2017-08-02 Thread Jannis via R-help
Dear list members, 


i am trying to create multiple figures with identical layout (i.e. font sizes 
etc.) for a publication created with Latex. To do so (i.e. to get identical 
font sizes) I save all plots as a pdf with widths and heights as they would 
later appear in the paper (to prevent scaling etc.). My problem now is that I 
create several multipanel plots with par(mfrow=c(...)) which sometimes changes 
the cex value. Is there any way (other than using layout() etc which would mean 
a lot of recoding) to prevent this and have identical point and font sizes and 
line widths etc throughout all plots? I tried to increase the cex value so that 
after the reduction by mfrow it is again 1 but I am not sure whether this 
prevents all resizing and was hoping for an easier way to achive this?
Any ideas?
CheersJannis

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] switch of cex adjustment with mfrow?

2017-08-04 Thread Jannis via R-help
Thanks guys for your help. Your suggestions will work in my case, the behaviour 
beeing dependent on the order of arguments (which Steve mentions) is however, 
not the way I would expect R to work. In addition, the way I interpret the 
documentation:
"A numerical value giving the amount by which plotting text and symbols should 
be magnified relative to the default. This starts as 1 when a device is opened, 
and is reset when the layout is changed, e.g. by setting mfrow."
is also different from the behaviour you describe. Before posting, I read this 
in a way that setting mfrow always changes the cex value (either the default 
value or the one you supply) later, so that setting:
par(mfrow=c(2,2), cex = 1)
would still produce a cex <1 later so that you have to run:
par(mfrow=c(2,2), cex = 1/0.66)
to get a effetive cex of one (after the mentioned reset). Maybe it would be 
good to make the documentation a bit more specific here?

Best 
Jannis 

S Ellison  schrieb am 12:31 Donnerstag, 3.August 
2017:
 

 > use
> 
> par(mfrow=c(2,2), cex = 1)

This does work as written. But when I first checked single-call setting, an  
mfrow change to cex in the same call superseded cex=1; hence my suggestion to 
use separate calls to par().
Further checking confirms that the result of a call to par is dependent on 
argument specification order in the call:

par(mfrow=c(2,2), cex = 1)
par("cex")
    # 1

par(cex=1, mfrow=c(2,2))
par("cex")
    # 0.83

This obviously isn't a problem, though as an aside I didn't immediately find 
any comment on the effect of argument order in ?par. It just means you have to 
be careful exactly what you specify.
It may also mean that for future-proofing against possible changes in par 
execution order, you might want to use separate calls anyway.

Steve Ellison


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

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Dispersion Index in POT

2017-08-11 Thread FMH via R-help
Dear All,
I would like to plot the dispersion index against lambda and dispersion index 
against threshold.

Appreciate if someone could help me to extract dispersion index in POT package. 
Pls also let me know the way to calculate it manually for a skewed distribution.
Thank you

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Choosing subset of data

2016-05-20 Thread oslo via R-help
Hi all;
I have a big data set (a small part is given below) and V1 column has repeated 
info in it. That is rs941873, rs12307687... are repeating many times. I need 
choose only one SNP (in first column named rs) which has the smallest  Pvalue 
withing V1 column. That is I need choose only one SNP for repeated names in V1 
which has the smallest Pvalue.
Your helps are truly appreciated,




 rs                   Chr V6            A1  A2   Freq   Effect  StdErr         
Pvalue  V1          Gene rs941873 chr10 81139462 a g 0.4117 -0.0541 0.0103 
1.52E-07 rs941873        no_value rs634552 chr11 75282052 t g 0.3735 0.0159 
0.0099 1.08E-01 rs941873 SERPINH1 rs11107175 chr12 94161719 t c 0.0896 -0.0386 
0.0176 2.85E-02 rs941873  CRADD rs12307687 chr12 47175866 a t 0.7379 -0.0208 
0.0135 1.23E-01 rs12307687 SLC38A4 rs3917155 chr14 76444685 c g 0.0495 0.0153 
0.0371 6.80E-01 rs941873  TGFB3 rs1600640 chr15 84603034 t g 0.1791 -0.0448 
0.0123 2.75E-04 rs12307687 ADAMTSL3 rs2871865 chr15 99194896 c g 0.5515 0.0191 
0.0106 7.09E-02 rs12307687 IGF1R rs2955250 chr17 61959740 t c 0.6945 0.0277 
0.0129 3.17E-02 rs12307687 GH2 rs228758 chr17 42148205 t c 0.1222 -0.0265 0.015 
7.72E-02 rs12307687 G6PC3 rs224333 chr20 34023962 a g 0.8606 0.0568 0.0246 
2.10E-02 rs10071837 GDF5 rs4681725 chr3 56692321 t g 0.2362 0.0386 0.011 
4.45E-04 rs10071837 C3orf63 rs7652177 chr3   171969077 c g 0.1478 -0.0458 
0.0134 6.34E-04 rs10071837 FNDC3B rs925098 chr4   17919811 a g 0.6529 -0.0563 
0.0097 5.55E-09 rs925098 LCORL rs1662837 chr4  82168889 t c 0.2728 -0.0411 
0.0105 8.66E-05 rs925098  no_value rs10071837 chr5  33381581 t c 0.424 -0.0324 
0.0094 5.74E-04 rs925098  no_value

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Inverse normal transformation of ranked data

2016-05-20 Thread data_analyst20bhrl--- via R-help
I am using ddply on a data set that contains 2+ million rows; trying to rank 
the values of a variable within groups, and then transform the ranks to 
(approximate) z-scores --- i.e generate quantiles on the normal scale.
Here is some sample data for one group:x <- NA 0.3640951 0.1175880 0.3453916 
0.4214050 0.7469022 0.1091423 0.6099482        NA        NA 0.6786140 0.1785854 
0.9750262        NA

I have tried the following two alternatives: 
(1) Using the qnorm function from the stats package in conjunction with the 
percent_rank function from the dplyr  package:For example:
y <- qnorm(percent_rank(x))
This produces -Inf and Inf for the extreme values in the sample data. This 
issue is resolved if I use the rank function from the stats package instead, 
for example:y <- qnorm(rank(x, na.last = "keep", ties.method = 
"average")/length(x))
but if there are no NAs in a certain group, the upper extreme data point is 
still evaluated to Inf.
(2) Using the ztransform function from the GenABEL package:
For example: 
y <- ztransform(percent_rank(x))
This preserves the extreme values but produces one of the following types of 
errors when used on my full data set.

Error in ztransform(x) : trait is binary
ORError in ztransform(x) : trait is monomorphic
I suspect these errors may be due to the fact that there are very few 
observations and/or several missing values (NAs) within certain groups, but I 
am not sure since there are several hundred groups.  
Is there a better way?
Sent from Yahoo Mail. Get the app
[[alternative HTML version deleted]]

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] An averaged model based on Quartile and Mean of Quartiles

2016-05-21 Thread ch.elahe via R-help
Hi all,

Here is my df and I want to make an averaged model of my variables based on 
Time like the following:


   $ Protocol   : Factor w/ 48 levels "DP FS QTSE SAG",..: 2 3 43 42 
   $ Time   : num  182 185 189 234 186 ... 

   $ Systemtype   : Factor w/ 2 levels "Aera XJ","AERA XQ": 1 1 1 
   $ ADJ: Factor w/ 2 levels "auto","manu": 1 1 
   $ BR : int  384 384 384 384 512 384
   $ TF : int  10 10 13 7 7 5 5 
I split my df into quartiles for time,

   
   df$quant=findInterval(df$Time, quantile(df$Time), rightmost.closed=TRUE)
by the column df$quant I see quartiles 1 to 4 for time, next I want to create a 
new column for example for BR and if df$quant==1 then put mean of first 
quartile of BR in that,if df$quant==2 put mean of second quartile of BR in that 
and so on. I do the same for every numeric variable. Does anyone know how to 
that?


Thanks for any help!
Elahe

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Choosing rows

2016-05-21 Thread oslo via R-help
Hi all;
I have a big data set (a small part is given below) and V1 column has repeated 
info in it. That is rs941873, rs12307687... are repeating many times. I need 
choose only one SNP (in first column named rs) which has the smallest  Pvalue 
withing V1 column. That is I need choose only one SNP for repeated names in V1 
which has the smallest Pvalue.
Your helps are truly appreciated,Oslo

|  rs  | n0 | Pvalue | V1 |
|   rs941873  | 81139462 | 1.52E-07 | rs941873 |
|   rs634552  | 75282052 | 1.08E-01 | rs941873 |
|   rs11107175  | 94161719 | 2.85E-02 | rs941873  |
|   rs12307687  | 47175866 | 1.23E-01 | rs12307687 |
|   rs3917155  | 76444685 | 6.80E-01 | rs941873  |
|   rs1600640  | 84603034 | 2.75E-04 | rs12307687 |
|   rs2871865  | 99194896 | 7.09E-02 | rs12307687 |
|   rs2955250  | 61959740 | 3.17E-02 | rs12307687 |
|   rs228758  | 42148205 | 7.72E-02 | rs12307687 |
|   rs224333  | 34023962 | 2.10E-02 | rs10071837 |
|   rs4681725  | 56692321 | 4.45E-04 | rs10071837 |
|   rs7652177  | 171969077 | 6.34E-04 | rs10071837 |
|   rs925098  | 17919811 | 5.55E-09 | rs925098 |
|   rs1662837  | 82168889 | 8.66E-05 | rs925098  |
|   rs10071837  | 33381581 | 5.74E-04 | rs925098  |


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Choosing rows

2016-05-23 Thread oslo via R-help
Hi Rui;
Thanks so much for this. It works perfectly.
Regards,Oslo 

On Sunday, May 22, 2016 7:35 AM, "ruipbarra...@sapo.pt" 
 wrote:
 

 Hello,

First of all, it's better to post data using ?dput. Below, I give an example of 
that  in the lines structure(...).
dat <-
structure(list(rs = c("   rs941873  ", "   rs634552  ", "   rs11107175  ",
"   rs12307687  ", "   rs3917155  ", "   rs1600640  ", "   rs2871865  ",
"   rs2955250  ", "   rs228758  ", "   rs224333  ", "   rs4681725  ",
"   rs7652177  ", "   rs925098  ", "   rs1662837  ", "   rs10071837  "
), n0 = c(81139462, 75282052, 94161719, 47175866, 76444685, 84603034,
99194896, 61959740, 42148205, 34023962, 56692321, 171969077,
17919811, 82168889, 33381581), Pvalue = c(1.52e-07, 0.108, 0.0285,
0.123, 0.68, 0.000275, 0.0709, 0.0317, 0.0772, 0.021, 0.000445,
0.000634, 5.55e-09, 8.66e-05, 0.000574), V1 = c("rs941873", "rs941873",
"rs941873", "rs12307687", "rs941873", "rs12307687", "rs12307687",
"rs12307687", "rs12307687", "rs10071837", "rs10071837", "rs10071837",
"rs925098", "rs925098", "rs925098")), .Names = c("rs", "n0",
"Pvalue", "V1"), row.names = c(NA, -15L), class = "data.frame")

Now, if I understand correctly, the following might do what you want.


tmp <- split(dat[, "Pvalue"], dat[, "V1"])
idx <- unlist(lapply(tmp, function(x) x == min(x)))[order(order(dat[, "V1"]))]
rm(tmp)
result <- dat[idx, ]
result

Hope this helps,

Rui Barradas
 Citando oslo via R-help :
Hi all;
I have a big data set (a small part is given below) and V1 column has repeated 
info in it. That is rs941873, rs12307687... are repeating many times. I need 
choose only one SNP (in first column named rs) which has the smallest  Pvalue 
withing V1 column. That is I need choose only one SNP for repeated names in V1 
which has the smallest Pvalue.
Your helps are truly appreciated,Oslo

|  rs  | n0 | Pvalue | V1 |
|   rs941873  | 81139462 | 1.52E-07 | rs941873 |
|   rs634552  | 75282052 | 1.08E-01 | rs941873 |
|   rs11107175  | 94161719 | 2.85E-02 | rs941873  |
|   rs12307687  | 47175866 | 1.23E-01 | rs12307687 |
|   rs3917155  | 76444685 | 6.80E-01 | rs941873  |
|   rs1600640  | 84603034 | 2.75E-04 | rs12307687 |
|   rs2871865  | 99194896 | 7.09E-02 | rs12307687 |
|   rs2955250  | 61959740 | 3.17E-02 | rs12307687 |
|   rs228758  | 42148205 | 7.72E-02 | rs12307687 |
|   rs224333  | 34023962 | 2.10E-02 | rs10071837 |
|   rs4681725  | 56692321 | 4.45E-04 | rs10071837 |
|   rs7652177  | 171969077 | 6.34E-04 | rs10071837 |
|   rs925098  | 17919811 | 5.55E-09 | rs925098 |
|   rs1662837  | 82168889 | 8.66E-05 | rs925098  |
|   rs10071837  | 33381581 | 5.74E-04 | rs925098  |


        [[alternative HTML version deleted]]

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

 

  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Factor Variable frequency

2016-05-24 Thread ch.elahe via R-help
Hi all,
I have the following df:


$ Protocol   : Factor w/ 48 levels "DP FS QTSE SAG",..: 2 3 43 42 31 36 
37 30 28 5 ...

$ Speed : chr  "SLOW" "SLOW" "SLOW" "VerySLOW" ...
How can I get the most frequent Protocol when Speed is "SLOW"?
Thanks for any help!
Elahe

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] subset data right

2016-05-26 Thread ch.elahe via R-help
Hi all,
I have the following df and I want to know which Protocols are VeryFast, which 
are FAST, which are SLOW and also which ones are VerySLOW :


  $ Protocol   : Factor w/ 48 levels "DP FS QTSE SAG",..: 5 5 28 5 5 5 7 7 
47 5 ...

  $ quant  : Factor w/ 4 levels "FAST","SLOW",..: 2 2 2 4 2 1 1 2 4 

I do the following subset but nothing is changed in my df:


  subdf=subset(df,quant%in%c("VeryFast"))
  subdf$quant=factor(subdf$quant)
and when I get the str(df) again Protocol has 48 levels. Does anyone know how 
can I get these subsets right?
Thanks for any help!
Elahe

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] add value to Bar chart ggplot2

2016-05-27 Thread ch.elahe via R-help

Hi all ,
I have the following bar chart and I want to add SLC variable values to the 
charts but I don't know how to use geom_text:
 
 
ggplot(df,(Protocol,fill=quant))+geom_bar()+coord_flip()
 
Thanks for any help!
Elahe

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


Re: [R] add value to Bar chart ggplot2

2016-05-27 Thread ch.elahe via R-help
Thanks Ulrik,
But in these examples they want to mark the percentage or frequency of plot 
variables, in my case I want to mark the bars with a different variable of my 
df. DO you have any idea?



On Friday, May 27, 2016 3:22 PM, Ulrik Stervbo  wrote:



Hi Elahe,

maybe this will help: 
http://stackoverflow.com/questions/6455088/how-to-put-labels-over-geom-bar-in-r-with-ggplot2
 or this: 
http://stackoverflow.com/questions/12018499/how-to-put-labels-over-geom-bar-for-each-bar-in-r-with-ggplot2

Best,
Ulrik


On Fri, 27 May 2016 at 15:12 ch.elahe via R-help  wrote:


>Hi all ,
>I have the following bar chart and I want to add SLC variable values to the 
>charts but I don't know how to use geom_text:
>
>
>ggplot(df,(Protocol,fill=quant))+geom_bar()+coord_flip()
>
>Thanks for any help!
>Elahe
>
>______
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Creating R file

2016-05-28 Thread jay28 via R-help
 Hi. I am new to R and confused by some conflicting and contradictory 
information about it. Where and how do I create a numeric data file with .csv 
extension for use in R? So numbers meaning numeric data will be separated by 
commas and will consist of one line of numbers randomly chosen from 1 to 40. 
Thanks to all who reply. jay28.
Sent from Yahoo Mail. Get the app
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Training set in Self organizing Map

2016-06-01 Thread ch.elahe via R-help
Hi all,
I want to use Self Organizing Map in R for my data. I want my training set to 
be the following subset of my data:
 

subdf=subset(df,Country%in%c("US","FR"))
next I should change this subset to a matrix but I get the following error:
 
data_train_matrix=as.matrix(scale(subdf))
error in colMeans(x,na.rm=TRUE):'x' must be numeric
 
Can anyone help me to solve that?
Thanks for any help
Elahe

______
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Training set in Self organizing Map

2016-06-05 Thread ch.elahe via R-help
Hi Jeff,
Thanks for your reply. My df contains Protocols and their Parameters and I want 
to use SOM to see if I can find some clusters in customor's using protocols. 
Some of these Parameters are factors and some are numeric. I want to make a 
subset of some protocols and give them to SOM as training set and keep some for 
test set. is it possible to have also those factors in training set of SOM?



$ Protocol  : Factor w/ 132 levels "_unknown","A5. SAG TSE T2 
FS",..: 5
$ BR: int  320 320 384 384 384 320 256 320 384 38
$ BW: int  150 150 191 191 98 150 150 150 
$ COUNTRY   : Factor w/ 35 levels "AE","AT","AU",..: 10 10 
$ FSM   : Factor w/ 2 levels "strong","weak": 2 2 


On Wednesday, June 1, 2016 7:59 AM, Jeff Newmiller  
wrote:



You did not send  sample of your data, using dput. Before doing that,  I 
suggest peeling apart your troublesome line of code yourself:

str( as.matrix( scale( subdf ) ) )
str( scale( subdf ) )
str( subdf )

And then think about what the scale function does. Does it make sense to ask it 
to scale character or factor data? Could you perhaps exclude some of the 
columns that don't belong in the scaled data? 
-- 
Sent from my phone. Please excuse my brevity.


On June 1, 2016 7:39:30 AM PDT, "ch.elahe via R-help"  
wrote:
Hi all,
>I want to use Self Organizing Map in R for my data. I want my training set to 
>be the following subset of my data:
>
>
>subdf=subset(df,Country%in%c("US","FR"))
>next I should change this subset to a matrix but I get the following error:
>
>data_train_matrix=as.matrix(scale(subdf))
>error in colMeans(x,na.rm=TRUE):'x' must be numeric
>
>Can anyone help me to solve that?
>Thanks for any help
>Elahe
>
>
>
>
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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   3   4   5   6   7   8   9   10   >