Re: [R] igraph_vertex

2024-02-25 Thread Kimmo Elo

Hi,

a quick additional note: try

"edge.width= E(.)$weight"

instead of the current "edge.width= network". Seems to work and makes a
visible difference...

HTH,
Kimmo

su, 2024-02-25 kello 19:11 +, Kimmo Elo kirjoitti:
> 
> Hi again,
> 
> your code is still not reproducible without modifications, but I
> succeed in getting the data straight. All read.csv-command are
> missing
> 'sep="\t"', it is need to read you tsv-data.
> 
> And it could be more reproducible if you used e.g.
> 
> --- snip ---
> aes<-read.csv(text="    A.A B.B C.C D.D E.E F.F
> A.A 0   0   5   5   5   5
> B.B 4   0   1   1   1   1
> C.C 5   5   0   5   4   2
> D.D 5   0   5   0   5   3
> E.E 5   1   5   5   0   4
> F.F 1   2   3   4   5   5", 
> sep="\t", row.names = 1)
> --- snip ---
> 
> This would save us from unnecessary copy-pasting :-)
> 
> However, the error is still the same I mentioned in my first reply,
> i.e.:
> 
> network %>% plot(
>     vertex.color=clrs[V(.)$community], 
>     vertex.size=V(.)$hub_score*5, 
>     vertex.frame.color=V(.)$color, 
>     vertex.label.color="white", 
>     vertex.label.cex=0.5, 
>     vertex.label.family="Helvetica",
>     vertex.label.font=1,
>     edge.curved=0.5,
> HERE -->    edge.width= network,  <-- HERE
>     layout=layout_with_mds(.))
> 
> Try to comment out his line and see what happens. What network data
> variable should be mapped to edge width?
> 
> Best,
> Kimmo
> 
> su, 2024-02-25 kello 09:59 +0100, sibylle.stoec...@gmx.ch kirjoitti:
> > Dear coummunity
> > 
> > Thanks a lot to David and Kimmo. Yes I see now that I need to
> > provide
> > the two raw tables. Find here the reproducible example.
> > 
> > Kind regards
> > Sibylle
> > 
> > # R-labraries
> > library(circlize)
> > library(ggplot2)
> > library(igraph)
> > library(tidyverse)
> > library(RColorBrewer)
> > library(stringi)
> > library(scico)
> > library(plotly)
> > library(ggraph)
> > 
> > 
> > # Tables
> > aes<-read.csv("Test_adjac.csv", row.names = 1)
> > details<-read.csv("Test_cat.csv")
> > 
> > # Edge table, reorganisation
> > aes_collapsed<-aes %>%
> >   rownames_to_column(var='Names') %>%
> >   tidyr::gather(target, weight, 1:ncol(aes)+1) %>%
> >   dplyr::filter(weight != 0) %>%
> >   mutate(weight = ifelse(weight == "-1", 0, weight)) # here 0 =
> > negative values
> > 
> > write.csv(aes_collapsed, "edges_table_Test.csv", row.names = F)
> > edge_list<-read.csv("edges_table_Test.csv")
> > 
> > # Network attributes
> > network <- graph_from_data_frame(aes_collapsed, directed= FALSE, 
> >  vertices = details)
> > 
> > 
> > temp<-cluster_optimal(network)
> > temp<-cbind(membership=temp$membership, Names=temp$name)
> > aes_collapsed <- aes_collapsed %>%
> >   merge(temp, by="Names")
> > 
> > 
> > network <- network %>%
> >   set_edge_attr(name = "type", value = factor(aes_collapsed$Names, 
> >  ordered =
> > is.ordered(V(network)$name))) %>%
> >   set_edge_attr(name = "membership", value =
> > aes_collapsed$membership) %>%
> >   set_edge_attr(name = "color", 
> >   value = c(viridis::viridis(5))
> >   [match(E(.)$type, c(factor(V(.)$name)))]) %>%
> >   set_vertex_attr(name = "trans_v_net", value = c(transitivity(.,
> > type = "local"))) %>%
> >   set_vertex_attr(name = "hub_score", value =
> > c(hub_score(.)$vector))
> > %>%
> >   set_vertex_attr(name = "color", 
> >   value = c(viridis::viridis((5)))
> >   [match(V(.)$name, c(factor(V(.)$name)))]) %>%
> >   set_vertex_attr(name= "community",
> > value=cluster_optimal(.)$membership)
> > 
> > clrs<-scico(3, palette = "batlow")
> > 
> > par(bg="black")
> > network %>% plot(
> >  vertex.color=clrs[V(.)$community], 
> >  vertex.size=V(.)$hub_score*5, 
> >  vertex.frame.color=V(.)$color, 
> >  vertex.label.color="white", 
> >  vertex.label.cex=0.5, 
> >  vertex.label.family="Helvetica",
> >  vertex.label.font=1,
> >  edge.curved=0.5,
> >  edge.width= network,
> >  layout=layout_with_mds(.))
> > 
> > #error
> > Error in intI(i, n = x@Dim[1], dn[[1]], give.dn = FALSE) : 
> >   Index größer als maximales 6
> > 
> > # Test_adjac.csv
> > A.A B.B C.C D.D E.E F.F
> > A.A 0   0   5   5   5   5
> > B.B 4   0   1   1   1   1
> > C.C 5   5   0   5   4   2
> > D.D 5   0   5   0   5   3
> > E.E 5   1   5   5   0   4
> > F.F 1   2   3   4   5   5
> > 
> > # Test_cat.csv
> > Names   corresponding-
> > NCP   CategorySubcategory_typesources.cytos
> > ou
> > rce  Factor
> > A.A 7   hydrologic attribute"A" A   1
> > B.B 6, 11   hydrologic att

Re: [R] igraph_vertex

2024-02-25 Thread Kimmo Elo

Hi again,

your code is still not reproducible without modifications, but I
succeed in getting the data straight. All read.csv-command are missing
'sep="\t"', it is need to read you tsv-data.

And it could be more reproducible if you used e.g.

--- snip ---
aes<-read.csv(text="A.A B.B C.C D.D E.E F.F
A.A 0   0   5   5   5   5
B.B 4   0   1   1   1   1
C.C 5   5   0   5   4   2
D.D 5   0   5   0   5   3
E.E 5   1   5   5   0   4
F.F 1   2   3   4   5   5", 
sep="\t", row.names = 1)
--- snip ---

This would save us from unnecessary copy-pasting :-)

However, the error is still the same I mentioned in my first reply,
i.e.:

network %>% plot(
vertex.color=clrs[V(.)$community], 
vertex.size=V(.)$hub_score*5, 
vertex.frame.color=V(.)$color, 
vertex.label.color="white", 
vertex.label.cex=0.5, 
vertex.label.family="Helvetica",
vertex.label.font=1,
edge.curved=0.5,
HERE -->edge.width= network,  <-- HERE
layout=layout_with_mds(.))

Try to comment out his line and see what happens. What network data
variable should be mapped to edge width?

Best,
Kimmo

su, 2024-02-25 kello 09:59 +0100, sibylle.stoec...@gmx.ch kirjoitti:
> Dear coummunity
> 
> Thanks a lot to David and Kimmo. Yes I see now that I need to provide
> the two raw tables. Find here the reproducible example.
> 
> Kind regards
> Sibylle
> 
> # R-labraries
> library(circlize)
> library(ggplot2)
> library(igraph)
> library(tidyverse)
> library(RColorBrewer)
> library(stringi)
> library(scico)
> library(plotly)
> library(ggraph)
> 
> 
> # Tables
> aes<-read.csv("Test_adjac.csv", row.names = 1)
> details<-read.csv("Test_cat.csv")
> 
> # Edge table, reorganisation
> aes_collapsed<-aes %>%
>   rownames_to_column(var='Names') %>%
>   tidyr::gather(target, weight, 1:ncol(aes)+1) %>%
>   dplyr::filter(weight != 0) %>%
>   mutate(weight = ifelse(weight == "-1", 0, weight)) # here 0 =
> negative values
> 
> write.csv(aes_collapsed, "edges_table_Test.csv", row.names = F)
> edge_list<-read.csv("edges_table_Test.csv")
> 
> # Network attributes
> network <- graph_from_data_frame(aes_collapsed, directed= FALSE, 
>  vertices = details)
> 
> 
> temp<-cluster_optimal(network)
> temp<-cbind(membership=temp$membership, Names=temp$name)
> aes_collapsed <- aes_collapsed %>%
>   merge(temp, by="Names")
> 
> 
> network <- network %>%
>   set_edge_attr(name = "type", value = factor(aes_collapsed$Names, 
>  ordered =
> is.ordered(V(network)$name))) %>%
>   set_edge_attr(name = "membership", value =
> aes_collapsed$membership) %>%
>   set_edge_attr(name = "color", 
>   value = c(viridis::viridis(5))
>   [match(E(.)$type, c(factor(V(.)$name)))]) %>%
>   set_vertex_attr(name = "trans_v_net", value = c(transitivity(.,
> type = "local"))) %>%
>   set_vertex_attr(name = "hub_score", value = c(hub_score(.)$vector))
> %>%
>   set_vertex_attr(name = "color", 
>   value = c(viridis::viridis((5)))
>   [match(V(.)$name, c(factor(V(.)$name)))]) %>%
>   set_vertex_attr(name= "community",
> value=cluster_optimal(.)$membership)
> 
> clrs<-scico(3, palette = "batlow")
> 
> par(bg="black")
> network %>% plot(
>  vertex.color=clrs[V(.)$community], 
>  vertex.size=V(.)$hub_score*5, 
>  vertex.frame.color=V(.)$color, 
>  vertex.label.color="white", 
>  vertex.label.cex=0.5, 
>  vertex.label.family="Helvetica",
>  vertex.label.font=1,
>  edge.curved=0.5,
>  edge.width= network,
>  layout=layout_with_mds(.))
> 
> #error
> Error in intI(i, n = x@Dim[1], dn[[1]], give.dn = FALSE) : 
>   Index größer als maximales 6
> 
> # Test_adjac.csv
> A.A B.B C.C D.D E.E F.F
> A.A 0   0   5   5   5   5
> B.B 4   0   1   1   1   1
> C.C 5   5   0   5   4   2
> D.D 5   0   5   0   5   3
> E.E 5   1   5   5   0   4
> F.F 1   2   3   4   5   5
> 
> # Test_cat.csv
> Names   corresponding-
> NCP   CategorySubcategory_typesources.cytosou
> rce  Factor
> A.A 7   hydrologic attribute"A" A   1
> B.B 6, 11   hydrologic attribute"B" B   1
> C.C 1, 14, 15, 16, 17,
> 18   AES intrinsic   "C" C   0
> D.D 1, 14, 15, 16, 17,
> 18   AES intrinsic   "D" D   0
> E.E 1, 14, 15, 16, 17,
> 18   AES intrinsic   "E" E   0
> F.F 7   AES material"F" F   0
> 
> 
> # edges_tables_Test.csv
> Names   target  weight
> B.B A.A 4
> C.C A.A 5
> D.D A.A 5
> E.E A.A 5
> F.F A.A 1
> C.C B.B 5
> E.E B.B 1

Re: [R] Interactions in regression

2024-02-25 Thread Bert Gunter
It is trivial in R to add whatever decorations to a plot that you would
like, but that requires that you go beyond point and click production of
graphics and write actual code. If you are unwilling or unable to do this,
you are stuck with whatever various packaged graphics functionality
provides.So you might want to search on "interaction plots for linear
models in R" or similar at rseek.org or in your favorite web search engine
if you haven't already done so. My minimal efforts brought up lots of hits,
though none may be useful for your concerns, especially, as has already
been pointed out, as your query doesn't seem to make much sense
statistically.

Cheers,
Bert


On Sun, Feb 25, 2024 at 7:46 AM Jacek Kownacki 
wrote:

> Hi All,
> I stumbled upon some topics regarding interactions in anova and regression
> and packages for tabulating and visualizations the results of them.
> Here we are:
>
> https://stackoverflow.com/questions/77933272/how-to-add-a-reference-level-for-interaction-in-gtsummary-and-sjplot/77935742#77935742
> ,
>
> https://stackoverflow.com/questions/78016795/how-to-add-reference-levels-for-interaction-in-r?noredirect=1&lq=1
> .
> I was wondering because I usually use GUI software and these questions did
> not get answers, if from a technical point of view
> how to do it, using these (sjPlot, gtsummary) or other ways to make such
> tables, inserting the reference levels of these mentioned interactions.
> This is not likely to be used in publications (including three base
> levels), but from the point of view of solving the topics this questions
> have interested me.
> I tried myself to make it happen, but so far without success.
> I recall this reprex based on SO:
>
> set.seed(1000)
> my_data <- rbind(
>   data.frame(time = "Pre", treatment = "Control", response =
> rnorm(100, mean=1)),
>   data.frame(time = "Pre", treatment = "Treatment", response =
> rnorm(100, mean=2)),
>   data.frame(time = "Post", treatment = "Control", response =
> rnorm(100, mean=1)),
>   data.frame(time = "Post", treatment = "Treatment", response =
> rnorm(100, mean=2))
> ) %>% mutate(time = factor(time, levels = c("Pre", "Post")))
> %>%mutate(treatment = factor(treatment, levels = c("Control",
> "Treatment")))
> model3 <- lm(response ~ time * treatment, data = my_data)
>
> Thanks,
> Jacek
>
> [[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] Interactions in regression

2024-02-25 Thread Jacek Kownacki
Hi All,
I stumbled upon some topics regarding interactions in anova and regression
and packages for tabulating and visualizations the results of them.
Here we are:
https://stackoverflow.com/questions/77933272/how-to-add-a-reference-level-for-interaction-in-gtsummary-and-sjplot/77935742#77935742
,
https://stackoverflow.com/questions/78016795/how-to-add-reference-levels-for-interaction-in-r?noredirect=1&lq=1
.
I was wondering because I usually use GUI software and these questions did
not get answers, if from a technical point of view
how to do it, using these (sjPlot, gtsummary) or other ways to make such
tables, inserting the reference levels of these mentioned interactions.
This is not likely to be used in publications (including three base
levels), but from the point of view of solving the topics this questions
have interested me.
I tried myself to make it happen, but so far without success.
I recall this reprex based on SO:

set.seed(1000)
my_data <- rbind(
  data.frame(time = "Pre", treatment = "Control", response =
rnorm(100, mean=1)),
  data.frame(time = "Pre", treatment = "Treatment", response =
rnorm(100, mean=2)),
  data.frame(time = "Post", treatment = "Control", response =
rnorm(100, mean=1)),
  data.frame(time = "Post", treatment = "Treatment", response =
rnorm(100, mean=2))
) %>% mutate(time = factor(time, levels = c("Pre", "Post")))
%>%mutate(treatment = factor(treatment, levels = c("Control",
"Treatment")))
model3 <- lm(response ~ time * treatment, data = my_data)

Thanks,
Jacek

[[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] Data consideration in executing pca

2024-02-25 Thread Jiji Sid
Dear R users,

 I have a txt file named 'data_1.txt' whose first column contains the names
of the individuals and the other columns contain the values of four
variables X_1,X_2,X_3 and X_4. I read it with R from its location and
called it data. I'd like to do a normalized principal component analysis. I
started by calculating the correlation matrix:
cor(data)
 I got the following message:
Error in cor(nnotes) : 'x' must be numeric.
I eliminated the first column of names, then read the modified data and
then added the names of individuals with rownames. I was able to run PCA
and obtain graphical representations of the variables, their coordinates,
contributions and cos2. However, when I used fviz_pca_ind to get the
graphical representation of the individuals, I got a graphic that considers
the variables as individuals. Can you please help me? I have attached the
file data_1 .txt file.

Many thanks in advance.
Name X_1  X_2X_3 X_4 
John10.2  10 65
Ricardo 14.75 13.5   10.5 9
Suzane  17.75 16.5  12.5 10
Monica   1514 13  9
Meriam   1619 14  13 
Philipps 17.75 17 12  12
Sonia2017 13  14__
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] igraph_vertex

2024-02-25 Thread SIBYLLE STÖCKLI via R-help
Dear coummunity

Thanks a lot to David and Kimmo. Yes I see now that I need to provide the two 
raw tables. Find here the reproducible example.

Kind regards
Sibylle

# R-labraries
library(circlize)
library(ggplot2)
library(igraph)
library(tidyverse)
library(RColorBrewer)
library(stringi)
library(scico)
library(plotly)
library(ggraph)


# Tables
aes<-read.csv("Test_adjac.csv", row.names = 1)
details<-read.csv("Test_cat.csv")

# Edge table, reorganisation
aes_collapsed<-aes %>%
  rownames_to_column(var='Names') %>%
  tidyr::gather(target, weight, 1:ncol(aes)+1) %>%
  dplyr::filter(weight != 0) %>%
  mutate(weight = ifelse(weight == "-1", 0, weight)) # here 0 = negative values

write.csv(aes_collapsed, "edges_table_Test.csv", row.names = F)
edge_list<-read.csv("edges_table_Test.csv")

# Network attributes
network <- graph_from_data_frame(aes_collapsed, directed= FALSE, 
 vertices = details)


temp<-cluster_optimal(network)
temp<-cbind(membership=temp$membership, Names=temp$name)
aes_collapsed <- aes_collapsed %>%
  merge(temp, by="Names")


network <- network %>%
  set_edge_attr(name = "type", value = factor(aes_collapsed$Names, 
 ordered = 
is.ordered(V(network)$name))) %>%
  set_edge_attr(name = "membership", value = aes_collapsed$membership) %>%
  set_edge_attr(name = "color", 
  value = c(viridis::viridis(5))
  [match(E(.)$type, c(factor(V(.)$name)))]) %>%
  set_vertex_attr(name = "trans_v_net", value = c(transitivity(., type = 
"local"))) %>%
  set_vertex_attr(name = "hub_score", value = c(hub_score(.)$vector)) %>%
  set_vertex_attr(name = "color", 
  value = c(viridis::viridis((5)))
  [match(V(.)$name, c(factor(V(.)$name)))]) %>%
  set_vertex_attr(name= "community", value=cluster_optimal(.)$membership)

clrs<-scico(3, palette = "batlow")

par(bg="black")
network %>% plot(
 vertex.color=clrs[V(.)$community], 
 vertex.size=V(.)$hub_score*5, 
 vertex.frame.color=V(.)$color, 
 vertex.label.color="white", 
 vertex.label.cex=0.5, 
 vertex.label.family="Helvetica",
 vertex.label.font=1,
 edge.curved=0.5,
 edge.width= network,
 layout=layout_with_mds(.))

#error
Error in intI(i, n = x@Dim[1], dn[[1]], give.dn = FALSE) : 
  Index größer als maximales 6

# Test_adjac.csv
A.A B.B C.C D.D E.E F.F
A.A 0   0   5   5   5   5
B.B 4   0   1   1   1   1
C.C 5   5   0   5   4   2
D.D 5   0   5   0   5   3
E.E 5   1   5   5   0   4
F.F 1   2   3   4   5   5

# Test_cat.csv
Names   corresponding-NCP   CategorySubcategory_type
sources.cytosource  Factor
A.A 7   hydrologic attribute"A" A   1
B.B 6, 11   hydrologic attribute"B" B   1
C.C 1, 14, 15, 16, 17, 18   AES intrinsic   "C" C   0
D.D 1, 14, 15, 16, 17, 18   AES intrinsic   "D" D   0
E.E 1, 14, 15, 16, 17, 18   AES intrinsic   "E" E   0
F.F 7   AES material"F" F   0


# edges_tables_Test.csv
Names   target  weight
B.B A.A 4
C.C A.A 5
D.D A.A 5
E.E A.A 5
F.F A.A 1
C.C B.B 5
E.E B.B 1
F.F B.B 2
A.A C.C 5
B.B C.C 1
D.D C.C 5
E.E C.C 5
F.F C.C 3
A.A D.D 5
B.B D.D 1
C.C D.D 5
E.E D.D 5
F.F D.D 4
A.A E.E 5
B.B E.E 1
C.C E.E 4
D.D E.E 5
F.F E.E 5
A.A F.F 5
B.B F.F 1
C.C F.F 2
D.D F.F 3
E.E F.F 4
F.F F.F 5

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