Re: [R] Clustering algorithms don't find obvious clusters

2010-06-11 Thread Cuvelier Etienne



Le 11/06/2010 12:45, Henrik Aldberg a écrit :

I have a directed graph which is represented as a matrix on the form


0 4 0 1

6 0 0 0

0 1 0 5

0 0 4 0


Each row correspond to an author (A, B, C, D) and the values says how many
times this author have cited the other authors. Hence the first row says
that author A have cited author B four times and author D one time. Thus the
matrix represents two groups of authors: (A,B) and (C,D) who cites each
other. But there is also a weak link between the groups. In reality this
matrix is much bigger and very sparce but it still consists of distinct
groups of authors.


My problem is that when I cluster the matrix using pam, clara or agnes the
algorithms does not find the obvious clusters. I have tried to turn it into
a dissimilarity matrix before clustering but that did not help either.


The layout of the clustering is not that important to me, my primary
interest is the to get the right nodes into the right clusters.



   

Hello Henrik,
You can use a graph clustering using the igraph package.
Example:

library(igraph)
simM-NULL
simM-rbind(simM,c(0, 4, 0, 1))
simM-rbind(simM,c(6, 0, 0, 0))
simM-rbind(simM,c(0, 1, 0, 5))
simM-rbind(simM,c(0, 0, 4, 0))
G - graph.adjacency( simM,weighted=TRUE,mode=directed)
plot(G,layout=layout.kamada.kawai)

### walktrap.community
wt - walktrap.community(G, modularity=TRUE)
wmemb - community.to.membership(G, wt$merges,
steps=which.max(wt$modularity)-1)

V(G)$color - rainbow(3)[wmemb$membership+1]
plot(G)

I hope  it helps

Etienne


Sincerely


Henrik

[[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] colored PCA biplot

2009-04-29 Thread Cuvelier Etienne

Hillary Cooper a écrit :

Hi-
I'm trying to make my PCA (princomp) colored. In my csv excel sheet, I have
the first column numbered according to the groupings I want to assign to the
PCA. I've played around with trying to set this first column as the color
vector, but haven't had any luck.
Any suggestions? Thanks,

Hillary


Hellor Hillary,
Here is some modifications of my own DIY code,
the thing to do is to test it and compare with the original biplot and 
with what you want.


I hope it helps

Etienne

#my.data is your/my data
# I create some groups just for the  test
groups = sample(1:3,N,replace=TRUE)
N = nrow(my.data)
acp=princomp(my.data,cor=TRUE)
# The original biplot for comparison
biplot(acp)
# Compute de min/max of new coordinates
xmin = min(acp$scores[,1])
xmax = max(acp$scores[,1])
ymin = min(acp$scores[,2])
ymax = max(acp$scores[,2])
plot(c(xmin,xmax),c(ymin,ymax),col=white, xlab=Comp 1, ylab=Comp 2)
# Plot the points with colors
text(acp$scores[,1],acp$scores[,2],1:N,col= groups)
title(PCA with colors)
abline(v=0,lty=2)
abline(h=0, lty=2)
# Compute and apply a re-scaling for the arrows of old components
# xl.min for min of xloadings,...
xl.min = min(0,min(acp$loadings[,1]))
xl.max = max(0,max(acp$loadings[,1]))
yl.min = min(0,min(acp$loadings[,2]))
yl.max = max(0,max(acp$loadings[,2]))
xl.scale = max(abs(xmax),abs(xmin))/max(abs(xl.max),abs(xl.min))*0.75
# 0.75 factor is just for leave some place for the text
yl.scale = max(abs(ymax),abs(ymin))/max(abs(yl.max),abs(yl.min))*0.75
#Draw old components
arrows(rep(0,100),rep(0,100),acp$loadings[,1]*xl.scale, 
acp$loadings[,2]*yl.scale)

# Names of old components
text(acp$loadings[,1]*xl.scale*1.25, acp$loadings[,2]*yl.scale*1.25 
,colnames(my.data))




[[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] legend with small colored boxes

2009-04-29 Thread Cuvelier Etienne



Christophe Dutang a écrit :

Hi all,

I tried to a nice legend with small boxes filled with the colors used  
for the plots. But it does nor work, boxes are always filled with black.


An example is here

plot(1:4,1:4)
lines(1:4,4:1, col=blue)

#try something like this
legend(top,leg=c(a,b),fill=1:2)
Etienne

legend(top,leg=c(a,b),col=c(black,blue), fill=TRUE)

How could I specify the colors? the argument col.box is the color of  
the whole legend box...


Thanks in advance

Christophe

PS : I work with R 2.9.0.

--
Christophe Dutang
Ph. D. student at ISFA, Lyon, France
website: http://dutangc.free.fr





[[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] truehist and density plots

2009-04-28 Thread Cuvelier Etienne

Perhaps like this :

temp =density(b[20:50])
truehist(b, ymax=max(temp$y))
lines(temp)

Etienne

carol white a écrit :
Consider a vector of 100 elements (attached files). then, 


truehist(b)
lines(density(b[20:50]))

How is it possible to have density plots of all subsets like b[20:50] within 
histogram (without exceeding the max of historgram on y axis)?

Is it more clear?

Best,

--- On Tue, 4/28/09, Uwe Ligges lig...@statistik.tu-dortmund.de wrote:
From: Uwe Ligges lig...@statistik.tu-dortmund.de
Subject: Re: [R] truehist and density plots
To: carol white wht_...@yahoo.com
Cc: r-h...@stat.math.ethz.ch
Date: Tuesday, April 28, 2009, 5:42 AM


carol white wrote:

Hi,
I wanted to plot the histogram of a vector and then, plot the density

function of subsets of the vector on the histogram. So I use truehist in MASS
package and lines(density) as follows:

length(b) = 1000
truehist(b)
lines(density(b[1:100]))



I do not undertsand what you mean. Can you please provide a *reproducible*
example?

Uwe Ligges



however the density plot of the first 100 points exceeds the max of y axis

(see attached). how is it possible to make a graphics so that the density plot
of the subsets doesn't go beyond the maximum of all points in the complete
set?

Cheers,

Carol






  




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] How to create a graph layout?

2009-04-27 Thread Cuvelier Etienne
At 02:32 27/04/2009, Christian Bustamante wrote:
I all,
I want to create a graph layout in a 3x3 matrix like this:

ylab  |__|  |__|   |__|
   ___  ___   ___
ylab  |__|  |__|   |__|
   ___  ___   ___
ylab  |__|  |__|   |__|
xl xl xl

With this layout, then I'll insert the 9 plots. How ca I create it?

see ?layout
# Example
layout(matrix(1:9,ncol=3, byrow=TRUE))
for(i in 1:9) plot(density(rnorm(1000)), main=paste(Graph N°,i))

Hope it helps.

Etienne



-- 
CdeB

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


+ 
+ Cuvelier Etienne
+ Assistant 
+ FUNDP - Faculté d'Informatique  
+ rue Grandgagnage, 21   B-5000 Namur (Belgique)
+ tel: 32.81.72.49.75fax: 32.81.72.49.67
+ skype: cuvelier.etienne

THE TOP TEN REASONS TO BECOME A STATISTICIAN
 1. Deviation is considered normal.
 2. We feel complete and sufficient.
 3. We are mean lovers.
 4. Statisticians do it discretely and continuously.
 5. We are right 95% of the time.
 6. We can legally comment on someone's posterior distribution.
 7. We may not be normal but we are transformable.
 8. We never have to say we are certain.
 9. We are honestly significantly different.
10 No one wants our jobs.

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

2009-04-27 Thread Cuvelier Etienne
See http://finzi.psych.upenn.edu/R/Rhelp02/archive/113531.html

Etienne

At 12:43 27/04/2009, Thomas Loridan wrote:
Hi all

I can t seem to find a way to send an email using R

would anyone have a suggestion?

much appreciated

Thomas

-- 
Thomas Loridan
King's College email: thomas.lori...@kcl.ac.uk
webpage:http://geography.kcl.ac.uk/micromet/tloridan/index.htm

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


+ 
+ Cuvelier Etienne
+ Assistant 
+ FUNDP - Faculté d'Informatique  
+ rue Grandgagnage, 21   B-5000 Namur (Belgique)
+ tel: 32.81.72.49.75fax: 32.81.72.49.67
+ skype: cuvelier.etienne

THE TOP TEN REASONS TO BECOME A STATISTICIAN
 1. Deviation is considered normal.
 2. We feel complete and sufficient.
 3. We are mean lovers.
 4. Statisticians do it discretely and continuously.
 5. We are right 95% of the time.
 6. We can legally comment on someone's posterior distribution.
 7. We may not be normal but we are transformable.
 8. We never have to say we are certain.
 9. We are honestly significantly different.
10 No one wants our jobs.

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

2009-04-26 Thread Cuvelier Etienne


hesicaia a écrit :
Hello, 


I have a specific question regarding figure layout. I am tryng to make a 2
by 1 figure but I would like to make the bottom figure slightly larger than
the top figure. I have read through the help posts and have tried to use
fig=c(),new=T and have also tried to use split.screen and although
they both work for most types of plotting(ie. hist, plot, etc...), for some
strange reason, they do not function when I try to use them with the
metaplot function in package rmeta. The plot come out ok, but they are
on two separate pages instead of the same one. I realize this is a very
specific question, but was hoping someone might be able to suggest how I
could achieve this. Below is my code for both fig and split.screen,
minus the axis labels which take up a lot of space in the code.
Thanks very much, Daniel.


You can try to use the layout function:

?layout
#Example 1
# First plot take 3/5 of the screen
# Second plot 5/5of the screen
layout(matrix(c(0,1,1,1,0,2,2,2,2,2),nrow = 2, byrow=TRUE))
plot(density(rnorm(1000)))
plot(density(rnorm(1000)))

#Example 2
# First plot take 4/6 of the screen
# Second plot 6/6of the screen
layout(matrix(c(0,1,1,1,0,2,2,2,2,2),nrow = 2, byrow=TRUE))
plot(density(rnorm(1000)))
plot(density(rnorm(1000)))
...

I hope it helps.

Etienne



***
library(rmeta)
meta.n-meta.summaries(ttable.n$lin.yeff,ttable.n$lin.se,method=random)
conf.n-1/(meta.n$se.summary^2)
meta.c-meta.summaries(ttable.c$lin.yeff,ttable.c$lin.se,method=random)
conf.c-1/(meta.c$se.summary^2)

bitmap(/scratch/dboyce/nmfs/figs/yeareffs.all.metaplot.dev.pdf,type=pdfwrite,res=800,height=6,width=6,pointsize=12)
par(mfrow=c(2,1),mar=c(1,2,1,1),oma=c(4,6,.5,.5),cex.axis=.8,fig=c(0,1,.6,1))
metaplot(mn=ttable.n$lin.yeff,se=ttable.n$lin.se,nn=(ttable.n$dev)-.05,labels=NULL,conf.level=0.95,summn=meta.n$summary,sumse=meta.n$se.summary,sumnn=conf.n/700,logeffect=F,colors=meta.colors(box=firebrick3,lines=gray38,zero=black,summary=blue,text=black),xlim=c(-.06,.16),cex=1.2,ylab=,summlabel=,xaxt=n)
axis(side=1,at=seq(-.06,.16,by=.03),labels=T)
text(-.06,0.5,A,cex=1.4)
box()
 
par(fig=c(0,1,0,.6),new=T)

metaplot(ttable.c$lin.yeff,ttable.c$lin.se,nn=ttable.c$dev,labels=NULL,conf.level=0.95,summn=meta.c$summary,sumse=meta.c$se.summary,sumnn=conf.c/7000,logeffect=F,colors=meta.colors(box=firebrick3,lines=gray38,zero=black,summary=blue,text=black),xlim=c(-.02,.06),cex=1.2,summlabel=,ylab=,xaxt=n)
text(-.02,0.5,B,cex=1.4)
axis(side=1,at=seq(-.02,.06,by=.01),labels=T)
mtext(Instantaneous rate of change,side=1,line=3,cex=1.5)
box()
dev.off()


split.screen(figs=c(2,1),erase=F)
screen(1)
metaplot(mn=ttable.n$lin.yeff,se=ttable.n$lin.se,nn=(ttable.n$dev)-.05,labels=NULL,conf.level=0.95,summn=meta.n$summary,sumse=meta.n$se.summary,sumnn=conf.n/700,logeffect=F,colors=meta.colors(box=firebrick3,lines=gray38,zero=black,summary=blue,text=black),xlim=c(-.06,.16),cex=1.2,ylab=,summlabel=,xaxt=n)
screen(2)
par(new=T)
metaplot(ttable.c$lin.yeff,ttable.c$lin.se,nn=ttable.c$dev,labels=NULL,conf.level=0.95,summn=meta.c$summary,sumse=meta.c$se.summary,sumnn=conf.c/7000,logeffect=F,colors=meta.colors(box=firebrick3,lines=gray38,zero=black,summary=blue,text=black),xlim=c(-.02,.06),cex=1.2,summlabel=,ylab=,xaxt=n)
close.screen(all=T)



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

2009-04-16 Thread Cuvelier Etienne

Hello,
I use the map package in conjunction with the mapdata package,
and I want to draw the map of China without  interior regions.
After reading the doc and searched in this mailing list I've tried
map(china,interior=FALSE)
and
map(china,fill=TRUE)

but I allways see the interior regions...

If someone can help me...
Thanks
Etienne

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

2009-04-13 Thread Cuvelier Etienne

Hello,
In the past I have used intensively the mtrace function from the debug 
package, but now with my actual version of R(2.8.1) , it is impossible 
to use it anymore.
I've updated all my packages, and I don't understand  how solve this 
problem...


Here is an example code :

 foo-function(){cat(Test Function)}
 mtrace(foo)
 foo() # A tcl/tk windows open and close immediately
Erreur dans FUN(l[[1L]], ...) :
 l'argument l est manquant, avec aucune valeur par défaut
 #argument l is missing without default value...


I've tried to look in with traceback(), but it does not help me.

 traceback()
21: FUN(l[[1L]], ...)
20: lapply(savers, get, envir = nlocal.env)
19: mlocal(index(nchar(names(line.list))  0)[l] - 1)
18: screen.line(lno)
17: assign(answer, {


Here is some technical informations :

 Sys.info()
sysname   release versionnodename
Windows Vista build  6001, Service Pack 1  XXX-HOME-VISTA
machinelogin  user
x86  xxx  xxx

 R.Version()
$platform
[1] i386-pc-mingw32
$arch
[1] i386
$os
[1] mingw32
$system
[1] i386, mingw32
$status
[1] 
$major
[1] 2
$minor
[1] 8.1
$year
[1] 2008
$month
[1] 12
$day
[1] 22
$`svn rev`
[1] 47281
$language
[1] R
$version.string
[1] R version 2.8.1 (2008-12-22)


Sincerely

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