Re: [R] IF LOOOP

2017-06-13 Thread Jim Lemon
Hi Matthias.
The first thing I notice is that the vector r:

r<-c(1.1717118,1.1605215,1.1522907,1.1422830,1.1065277,1.1165451,
 1.1163768,1.1048872,1.0848836,1.0627211,1.0300964,1.0296879,
 1.0308194,1.0518188,1.0657229,1.0685514,1.0914881,1.1042577,
 1.1039351,1.0880163)

doesn't contain the value 0.990956. If it ain't there, you can't
remove it. It has already been suggested that the failure of any
explicit value like 0.990956 to equal its displayed representation is
due to machine precision. I'll guess that you really want to remove a
range of values, something like those less than 1.00. If so, try
this:

r[r>=1]

Jim

On Wed, Jun 14, 2017 at 6:46 AM, matthias worni  wrote:
> Hey
>
> This should be a rather simple quesiton for some of you. I want to make
> some progress in looping...
> I have the vector r, which contains single values --> see below:
>
> r
>   [1] 1.1717118 1.1605215 1.1522907 1.1422830 1.1065277 1.1165451 1.1163768
> 1.1048872 1.0848836 1.0627211
>  [11] 1.0300964 1.0296879 1.0308194 1.0518188 1.0657229 1.0685514 1.0914881
> 1.1042577 1.1039351 1.0880163
>
>
> I would like to take out simply the value "0.990956" from the vector,
> printing out the rest of it.  The code is from the internet but does not
> seem to work for my vector. Can't figure out why... Thanks for the help
>
> r <- as.vector(lw)
> count=0
> for (i in r)  {
>   if(i == 0.990956) {
> break
>   }
> print(i)
>   }
>
>
> Best
> Matthias
>
> [[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.


Re: [R] reading data

2017-06-13 Thread jim holtman
You need to provide reproducible data.  What does the file contain?  Why
are you using 'sep=' when reading fixed format.  You might be able to
attach the '.txt' to your email to help with the problem.  Also you did not
state what the differences that you are seeing.  So help us out here.


Jim Holtman
Data Munger Guru

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

On Tue, Jun 13, 2017 at 5:09 PM, Ashta  wrote:

> Hi all,
>
> I am using R to extract  data on a regular basis.
> However, sometimes using the same script and the same data I am
> getting different observation.
> The library I am using and how I am reading  it is as follows.
>
> library(stringr)
> namelist <- file("Adress1.txt",encoding="ISO-8859-1")
> Name <- read.fwf(namelist,
> colClasses="character", skip=2,sep="\t",fill=T,
>   width =c(2,8,1,1,1,1,1,1,9,5)+1,col.names=ccol)
>
> Can some one suggest me how track the issue?
> Is it the library issue or Java issue?
> May I read as free format instead of fixed format?
>
> Thank you in advance
>
> __
> 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] [FORGED] IF LOOOP

2017-06-13 Thread David Winsemius

> On Jun 13, 2017, at 4:10 PM, Rolf Turner  wrote:
> 
> On 14/06/17 08:46, matthias worni wrote:
>> Hey
>> This should be a rather simple quesiton for some of you. I want to make
>> some progress in looping...
>> I have the vector r, which contains single values --> see below:
>> r
>>   [1] 1.1717118 1.1605215 1.1522907 1.1422830 1.1065277 1.1165451 1.1163768
>> 1.1048872 1.0848836 1.0627211
>>  [11] 1.0300964 1.0296879 1.0308194 1.0518188 1.0657229 1.0685514 1.0914881
>> 1.1042577 1.1039351 1.0880163
>> I would like to take out simply the value "0.990956" from the vector,
>> printing out the rest of it.  The code is from the internet but does not
>> seem to work for my vector.

I'm not sure that the source of this code should be considered a trusted 
foundation for learning R. You should not be using for-loops to modify vectors 
in this manner.


>> Can't figure out why... Thanks for the help
>> r <- as.vector(lw)

That's probably not needed.

>> count=0
>> for (i in r)  {
>>   if(i == 0.990956) {
>> break

I suspect you meant to use:

?'next'   # since `break` completely terminates a for-loop.


The ?'help' page has all the "control structures": `for`, `repeat`, `while` and 
associated boundaries and terminators

Both `break` and `next` are reserved words (names of functions, control 
tokens), so using the `?` operator requires quoting.

Also that for-next loop would do _nothing_ to the value of r. Printing would 
not modify the value of `r`.

You should read:

?Reserved

?'for'  # since `for` is also reserved

?print



>>   }
>> print(i)
>>   }
> 
> FAQ 7.31

After following Rolf's advice ... Try:

r[ all.equal(r, 0.990956) ]

> 


> cheers,
> 
> Rolf Turner

Further note to matthias:
All caps in Subject is considered poor form, as is posting in HTML.

-- 

David Winsemius
Alameda, CA, USA

__
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] [FORGED] IF LOOOP

2017-06-13 Thread Rolf Turner

On 14/06/17 08:46, matthias worni wrote:

Hey

This should be a rather simple quesiton for some of you. I want to make
some progress in looping...
I have the vector r, which contains single values --> see below:

r
   [1] 1.1717118 1.1605215 1.1522907 1.1422830 1.1065277 1.1165451 1.1163768
1.1048872 1.0848836 1.0627211
  [11] 1.0300964 1.0296879 1.0308194 1.0518188 1.0657229 1.0685514 1.0914881
1.1042577 1.1039351 1.0880163


I would like to take out simply the value "0.990956" from the vector,
printing out the rest of it.  The code is from the internet but does not
seem to work for my vector. Can't figure out why... Thanks for the help

r <- as.vector(lw)
count=0
for (i in r)  {
   if(i == 0.990956) {
 break
   }
 print(i)
   }


FAQ 7.31

cheers,

Rolf Turner


--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] IF LOOOP

2017-06-13 Thread matthias worni
Hey

This should be a rather simple quesiton for some of you. I want to make
some progress in looping...
I have the vector r, which contains single values --> see below:

r
  [1] 1.1717118 1.1605215 1.1522907 1.1422830 1.1065277 1.1165451 1.1163768
1.1048872 1.0848836 1.0627211
 [11] 1.0300964 1.0296879 1.0308194 1.0518188 1.0657229 1.0685514 1.0914881
1.1042577 1.1039351 1.0880163


I would like to take out simply the value "0.990956" from the vector,
printing out the rest of it.  The code is from the internet but does not
seem to work for my vector. Can't figure out why... Thanks for the help

r <- as.vector(lw)
count=0
for (i in r)  {
  if(i == 0.990956) {
break
  }
print(i)
  }


Best
Matthias

[[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] S-mode PCAs

2017-06-13 Thread Daniel Vecellio
Hi all,

I have a file of average SWE observations for 40 years at over 4,000 points
and am attempting to do a spatiotemporal analysis of the data using PCA,
much like this paper did using snow depth:
http://journals.ametsoc.org/doi/pdf/10.1175/1520-0442%281998%29011%3C0856%3ATCIRWS%3E2.0.CO%3B2

I have followed the code in the link below by my loadings are far too small
(For example, the paper listed above had loading above 0.5 and below -0.5
while my loadings for PC1 go between 0.02 and -0.03).

https://stackoverflow.com/questions/41022927/principal-component-analysis-pca-of-time-series-data-spatial-and-temporal-pat

I have standardized the data in the prcomp function so that a correlation
matrix is used in my study, just like the paper above. Does anyone have any
idea why my loadings might be so off and any suggestions regarding the PCA
functions in R to help solve this problem?

Thanks in advance,
Dan

-- 

*Daniel J. Vecellio*

*Ph.D. Student - Climate Science Lab, **Department of Geography, **Texas
A&M 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] reading data

2017-06-13 Thread Ashta
Hi all,

I am using R to extract  data on a regular basis.
However, sometimes using the same script and the same data I am
getting different observation.
The library I am using and how I am reading  it is as follows.

library(stringr)
namelist <- file("Adress1.txt",encoding="ISO-8859-1")
Name <- read.fwf(namelist,
colClasses="character", skip=2,sep="\t",fill=T,
  width =c(2,8,1,1,1,1,1,1,9,5)+1,col.names=ccol)

Can some one suggest me how track the issue?
Is it the library issue or Java issue?
May I read as free format instead of fixed format?

Thank you in advance

__
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] Classification and Regression Tree for Survival Analysis

2017-06-13 Thread Achim Zeileis

On Tue, 13 Jun 2017, Dimitrie Siriopol via R-help wrote:


I am trying to use the CART in a survival analysis. I have three variables of 
interest (all 3 ordinal - x, y and z, each of them with 5 categories) from 
which I want to make smaller groups (just an example 1st category from X 
variable with the 2nd and 3rd categories from the Y category and 2, 3 and 4 
categories from the Z category etc) based on their, let's say, association with 
mortality.
Now I would also want that this analysis to be adjusted for a number of 
variables (that I don't want to incorporate in the decision tree, just to take 
them into consideration in the relationship between the 3 variables and the 
outcome; I would also want to mention that for this confounders I have missing 
values - how should this be deal with?), this survival analysis to be 
stratified and also to use clusters.
I have tried party and rpart packages, but I don't seem to get how to properly 
do what I want.


I don't think that such an analysis is available "out of the box". In 
principle, you can iterate between (a) estimating a survival regression 
with the confounders - given the groups from the tree, and (b) estimating 
the tree - given an offset in the survival regression for the confounders. 
Such a strategy is implemented in the palmtree() function from the 
"partykit" package - however only for lm() and glm() models, not for 
survreg(). But the same idea could be applied in that case as well, e.g., 
using a Weibull distribution.


For incorporating stratification/clustering one could either use clustered 
inference in the variable selection or add some random effect. For lm/glm 
this is provided in the package "glmertree" but I don't think there are 
readily available code blocks to do the same for a survival response.


And as for the missing values in the confounders: I can't think of a good 
strategy for this. One could try generic imputation strategies but it's 
rather unlikely that this does not affect the subsequent regression plus 
tree selection process.


References for palmtree and glmertree:
http://arxiv.org/abs/1612.07498
http://EconPapers.RePEc.org/RePEc:inn:wpaper:2015-10


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-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] fedback from foreach

2017-06-13 Thread Ismail SEZEN
> 
> On 13 Jun 2017, at 23:05, Bond, Stephen  wrote:
> 
> Hi useRs,
> 
> I am running a foreach loop and hoped to get a small message when it hits a 
> multiple of 1000, but it does not work.
> 
>p <- foreach(i=1:1, .combine='c') %dopar% {
>if(i%%1000==0) print(i)
>sqrt(i)
>}
> 
> What is the proper way to do it.
> Thanks everybody.
> 
> Stephen B


https://stackoverflow.com/questions/10903787/how-can-i-print-when-using-dopar 


https://www.r-bloggers.com/monitoring-progress-inside-a-foreach-loop/ 


https://github.com/berkeley-scf/tutorial-parallel-basics/issues/2 


https://sumidiot.wordpress.com/2011/11/05/printing-in-foreachs-dopar/ 



[[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] fedback from foreach

2017-06-13 Thread Bond, Stephen
Hi useRs,

I am running a foreach loop and hoped to get a small message when it hits a 
multiple of 1000, but it does not work.

p <- foreach(i=1:1, .combine='c') %dopar% {
if(i%%1000==0) print(i)
sqrt(i)
}

What is the proper way to do it.
Thanks everybody.

Stephen B


[[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] understanding I() in lmer formula

2017-06-13 Thread Bert Gunter
If you don't get a prompt reply here, you might do better posting this
on the r-sig-mixed-models list (for obvious reasons).

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 Tue, Jun 13, 2017 at 11:25 AM, Don Cohen  wrote:
>  Is there a difference between I(x*y) and I(y*x) ?
> I have a call to lmer that results in this complaint:
>   Error in is.alpha2.subordinate * ~z.min.co.res :
>   non-numeric argument to binary operator
> when I change this line:
>   I(is.alpha2.subordinate*z.min.co.res)+
> to this:
>   I(z.min.co.res*is.alpha2.subordinate)+
> the complaint goes away.
> I'd like to understand 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] understanding I() in lmer formula

2017-06-13 Thread Don Cohen
 Is there a difference between I(x*y) and I(y*x) ?
I have a call to lmer that results in this complaint:
  Error in is.alpha2.subordinate * ~z.min.co.res :  
  non-numeric argument to binary operator
when I change this line:
  I(is.alpha2.subordinate*z.min.co.res)+
to this:
  I(z.min.co.res*is.alpha2.subordinate)+
the complaint goes away.
I'd like to understand 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.


Re: [R] Classification and Regression Tree for Survival Analysis

2017-06-13 Thread Bert Gunter
1. Please read and follow the posting guide below. Your post does not
meet the guidelines.

2. Search before posting!

e.g. on rseek.org: "Regression trees survival analysis"

in which you will find:
 https://cran.r-project.org/web/views/MachineLearning.html


-- 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 Tue, Jun 13, 2017 at 6:02 AM, Dimitrie Siriopol via R-help
 wrote:
> I am trying to use the CART in a survival analysis. I have three variables of 
> interest (all 3 ordinal - x, y and z, each of them with 5 categories) from 
> which I want to make smaller groups (just an example 1st category from X 
> variable with the 2nd and 3rd categories from the Y category and 2, 3 and 4 
> categories from the Z category etc) based on their, let's say, association 
> with mortality.
> Now I would also want that this analysis to be adjusted for a number of 
> variables (that I don't want to incorporate in the decision tree, just to 
> take them into consideration in the relationship between the 3 variables and 
> the outcome; I would also want to mention that for this confounders I have 
> missing values - how should this be deal with?), this survival analysis to be 
> stratified and also to use clusters.
> I have tried party and rpart packages, but I don't seem to get how to 
> properly do what I want.
> 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-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] Classification and Regression Tree for Survival Analysis

2017-06-13 Thread Dimitrie Siriopol via R-help
I am trying to use the CART in a survival analysis. I have three variables of 
interest (all 3 ordinal - x, y and z, each of them with 5 categories) from 
which I want to make smaller groups (just an example 1st category from X 
variable with the 2nd and 3rd categories from the Y category and 2, 3 and 4 
categories from the Z category etc) based on their, let's say, association with 
mortality.
Now I would also want that this analysis to be adjusted for a number of 
variables (that I don't want to incorporate in the decision tree, just to take 
them into consideration in the relationship between the 3 variables and the 
outcome; I would also want to mention that for this confounders I have missing 
values - how should this be deal with?), this survival analysis to be 
stratified and also to use clusters.
I have tried party and rpart packages, but I don't seem to get how to properly 
do what I want.
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] Σχετ: plotting gamm results in lattice

2017-06-13 Thread Maria Lathouri via R-help
Hi Duncan
Thank you very much for your help. 
The function model$gam is correct; it applies to gamm4 as well. 
I believe that it is the smooth term the reason that the plots from lattice are 
not the same as the plots from the plot(model$gam) but at least I can get the 
smooth line and the confidence intervals. 
Kind regards,Maria 

Στις 4:26 μ.μ. Δευτέρα, 12 Ιουνίου 2017, ο/η Duncan Mackay 
 έγραψε:
 

 Hi Maria

If you have problems just start with a small model with predictions and then 
plot with xyplot
the same applies to xyplot
Try 

library(gamm4)

spring <- dget(file = "G:/1/example.txt")
 str(spring)
'data.frame':  11744 obs. of  11 variables:
 $ WATERBODY_ID          : Factor w/ 1994 levels "GB102021072830",..: 1 1 2 2 2 
3 3 3 4 4 ...
 $ SITE_ID              : int  157166 157166 1636 1636 1636 1635 1635 1635 
134261 1631 ...
 $ Year                  : int  2011 2014 2013 2006 2003 2002 2013 2005 2013 
2006 ...
 $ Q95                  : num  100 100 80 80 80 98 98 98 105 105 ...
 $ LIFE.OE_spring        : num  1.02 1.03 1.02 1.06 1.06 1.07 1.12 1.05 1.14 
1.05 ...
 $ super.end.group      : Factor w/ 6 levels "B","C","D","E",..: 1 1 3 3 3 2 2 
2 4 4 ...
 $ X.urban.suburban      : num  0 0 0.07 0.07 0.07 0.53 0.53 0.53 8.07 8.07 ...
 $ X.broadleaved_woodland: num  2.83 2.83 10.39 10.39 10.39 ...
 $ X.CapWks              : num  0 0 0 0 0 0 0 0 0 0 ...
 $ Hms_Poaching          : int  0 0 10 10 10 0 0 0 0 0 ...
 $ Hms_Rsctned          : int  0 0 0 0 0 0 0 0 0 0 ...

model<-
gamm4(LIFE.OE_spring~s(Q95, 
by=super.end.group)+Year+Hms_Rsctned+Hms_Poaching+X.broadleaved_woodland 
+X.urban.suburban+X.CapWks, data=spring,
      random=~(1|WATERBODY_ID/SITE_ID))
Warning message:
Some predictor variables are on very different scales: consider rescaling

# plot(model$gam, page=1, font.lab=2, xlab="Residual Q95")

M <-predict(model$gam,type="response",se.fit=T)

# joining the dataset and the predictions keep it "in house" and on path
springP = cbind(spring, M)
springP$upper = with(springP,fit+1.96*se.fit)
springP$lower = with(springP,fit-1.96*se.fit)
str(springP)
'data.frame':  11744 obs. of  15 variables:
 $ WATERBODY_ID          : Factor w/ 1994 levels "GB102021072830",..: 1 1 2 2 2 
3 3 3 4 4 ...
 $ SITE_ID              : int  157166 157166 1636 1636 1636 1635 1635 1635 
134261 1631 ...
 $ Year                  : int  2011 2014 2013 2006 2003 2002 2013 2005 2013 
2006 ...
 $ Q95                  : num  100 100 80 80 80 98 98 98 105 105 ...
 $ LIFE.OE_spring        : num  1.02 1.03 1.02 1.06 1.06 1.07 1.12 1.05 1.14 
1.05 ...
 $ super.end.group      : Factor w/ 6 levels "B","C","D","E",..: 1 1 3 3 3 2 2 
2 4 4 ...
 $ X.urban.suburban      : num  0 0 0.07 0.07 0.07 0.53 0.53 0.53 8.07 8.07 ...
 $ X.broadleaved_woodland: num  2.83 2.83 10.39 10.39 10.39 ...
 $ X.CapWks              : num  0 0 0 0 0 0 0 0 0 0 ...
 $ Hms_Poaching          : int  0 0 10 10 10 0 0 0 0 0 ...
 $ Hms_Rsctned          : int  0 0 0 0 0 0 0 0 0 0 ...
 $ fit                  : num [1:11744(1d)] 1.03 1.04 1.04 1.02 1.01 ...
  ..- attr(*, "dimnames")=List of 1
  .. ..$ : chr  "1" "2" "3" "4" ...
 $ se.fit                : num [1:11744(1d)] 0.00263 0.00266 0.00408 0.00408 
0.00411 ...
  ..- attr(*, "dimnames")=List of 1
  .. ..$ : chr  "1" "2" "3" "4" ...
 $ upper                : num [1:11744(1d)] 1.03 1.04 1.05 1.03 1.02 ...
  ..- attr(*, "dimnames")=List of 1
  .. ..$ : chr  "1" "2" "3" "4" ...
 $ lower                : num [1:11744(1d)] 1.02 1.03 1.03 1.01 1 ...
  ..- attr(*, "dimnames")=List of 1
  .. ..$ : chr  "1" "2" "3" "4" ...

# this produces a mess of lines for the upper and lower
xyplot(fitted(model$gam) ~ Q95 |super.end.group, data = springP,
      lower = springP$lower,
      upper = springP$upper,
      subscripts = TRUE,
      panel = function(x,y, upper, lower, subscripts, ...){
                  panel.xyplot(x,y, type="smooth")
                  panel.xyplot(x[order(x)], upper[subscripts][order(x)], lty=2, 
col="red")
                  panel.xyplot(x[order(x)], lower[subscripts][order(x)], lty=2, 
col="red")
                  #panel.loess(x,y,...) #  have not tried to fix these lines- 
depends on what you want to do
                  #panel.rug(x = x[is.na(y)], y = y[is.na(x)])
                }
)

# smoothing them produces reasonable lines
xyplot(fitted(model$gam) ~ Q95 |super.end.group, data = springP,
      lower = springP$lower,
      upper = springP$upper,
      subscripts = TRUE,
      panel = function(x,y, upper, lower, subscripts, ...){
                  panel.xyplot(x,y, type="smooth")
                  panel.xyplot(x[order(x)], upper[subscripts][order(x)], type = 
"smooth", lty=2, col="red")
                  panel.xyplot(x[order(x)], lower[subscripts][order(x)], type = 
"smooth", lty=2, col="red")
                  #panel.loess(x,y,...)
                  #panel.rug(x = x[is.na(y)], y = y[is.na(x)])
                }
)

# by newdata = ...
# take a cross-section of data - reduces the amount of data to be plotte

[R] Mean correlation within cluster

2017-06-13 Thread Sergio Ferreira Cardoso


Hello all, 

I'd like to calculate the mean correlation within a cluster and understand if 
it's significantly >0. I'm using packages 'geomorph' and 'paleomorph'. 
#Simulate an array A <- array ( rep ( 1 : 36 , by = 4 ), dim = c ( 12 , 3 , 4 
)) #Load 'geomorph' package and superimpose coordinates test.gpa <- gpagen ( A 
, print.progress = FALSE ) #Load 'paleomorph' and generate covariance and 
correlation matrices cvmatrix <- dotcvm ( test.gpa $ coords ) corrmatrix <- 
dotcorr ( test.gpa $ coords ) 


Then I do a clustering with Ward method and euclidean distance, using the 
cvmatrix and I get a dendrogram. This part is not the problem, so I'll go 
directly to what I want. I would like to calculate the mean correlation between 
the elements of each cluster. Since clustering methods will mandatorily produce 
clusters, I'd like to know if the elements of my clusters are correlated (I 
mean, if the clusters are valid). 

I believe this might not be very complicated, given that I have all the 
elements. I just don't know how to do it on R. I tried to do the clustering 
with p-values for each cluster, with pvclust(), but I'm following a paper in 
which the authors test the significancy of the clusters by assessing the mean 
correlation of the elements within each cluster. I'd like to compare this 
method with the one from pvclust(). 

Thank you in advance. 




Best regards, 

Sérgio. 



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