Principal Component analysis (PCA) in R

Поделиться
HTML-код
  • Опубликовано: 21 авг 2024
  • library("ggplot2")
    library("gridExtra")
    library(ggbiplot)
    library("corrplot")
    library(factoextra)
    #conversion of row number
    data=rownames(GGE)=c("Me","E6","E2","E4","KB","HUl","kat","Dan","EA2","Ts",
    "E0","E5","DI","E8","E39","ET1","BO","Ab","Si")
    pca =prcomp(GGE[,c(2:11)], center = TRUE,scale. = TRUE)
    print(pca)
    to get eigen value
    eig.val = get_eigenvalue(pca)
    eig.val
    #to get scree plot
    fviz_eig(pca, addlabels = TRUE, ylim = c(0, 50))
    PCA results for variables
    var=get_pca_var(pca)
    to see the most contributing variables for each dimension
    corrplot(var$cos2, is.corr=FALSE)
    #to see the most contributing variables for both dimension
    fviz_cos2(pca, choice = "var", axes = 1:2)
    to draw a bar plot of variable contributions
    Contributions of variables to PC1
    a=fviz_contrib(pca, choice = "var", axes = 1)# top= 5 to limit to five var.
    Contributions of variables to PC2
    b=fviz_contrib(pca, choice = "var", axes = 2)
    grid.arrange(a,b, ncol=2, top='Contribution of the variables to the first two PCs')
    Total contribution on PC1 and PC2
    fviz_contrib(pca, choice = "ind", axes = 1:2)
    #Graph of variables
    fviz_pca_var(pca,
    col.var = "cos2",
    gradient.cols = c("red", "blue", "green"),
    repel = TRUE)
    #Biplot of individuals and variables
    fviz_pca_biplot(pca, repel = TRUE,
    col.var = "blue",
    col.ind = "red")
    #########################################################################
    #Plotting PCA
    ggbiplot(pca)
    #This will name each point with the name of the genotypes
    ggbiplot(pca,labels=rownames(GGE))
    plot using PC1 and PC2
    ggbiplot(pca,ellipse=TRUE,choices=c(1,2),labels=rownames(GGE), groups=GGE$ENV)
    scale the samples
    ggbiplot(pca,ellipse=TRUE,obs.scale = 2, var.scale = 4.5,
    labels=rownames(GGE), groups=GGE$ENV)
    #remove the arrows altogether
    ggbiplot(pca,ellipse=TRUE,obs.scale = 1, var.scale = 1,var.axes=FALSE,
    labels=rownames(GGE), groups=GGE$ENV)
    final biplot by Customize ggbiplot
    aa=ggbiplot(pca,ellipse=TRUE,obs.scale = 1, var.scale = 1, labels=rownames(GGE), groups=GGE$ENV) +
    scale_colour_manual(name="Location", values= c("blue", "red", "green","pink"))+
    ggtitle("PCA of wakjira")+
    theme_minimal()+
    theme(legend.position = "bottom")
    aa
    ggsave(filename = "Waq.png", plot = aa,width = 22, height = 15, dpi = 2500, units = "cm")

Комментарии • 119

  • @oromokomacharles1751
    @oromokomacharles1751 Год назад +3

    This is by far the best tutorial on doing PCA using R statistics. Thank you so much

  • @MengistuGelasso
    @MengistuGelasso 2 месяца назад

    The best tutorial on how to compute PCA using R. Thank you!

  • @fredericadedopartey3521
    @fredericadedopartey3521 Год назад +2

    this is by far the best explanatory video on PCA. strangely I can't install corrplot and ggbilot packages

    • @wakjiratesfahun3682
      @wakjiratesfahun3682  Год назад

      Use this codes
      library(devtools)
      install_github("vqv/ggbiplot")
      ########################
      devtools::install_github('taiyun/corrplot', build_vignettes = TRUE)
      Thanks

    • @kantidewi6031
      @kantidewi6031 11 месяцев назад

      same here, but it still can't install ggbiplot
      @@wakjiratesfahun3682

  • @user-qy5uy9fl1p
    @user-qy5uy9fl1p 8 месяцев назад

    thank you so much. This is the best tutorial on running PCA using Rstudio. more grace

  • @amadovelasquez6780
    @amadovelasquez6780 4 месяца назад

    The best explanation that I have found; thank you very much.

  • @johneagle4384
    @johneagle4384 Год назад +1

    Thank you. This is a very good explanation of PCA. Very useful, I am using what I learned from it in my research work.

  • @birtukantolera4448
    @birtukantolera4448 Год назад +3

    Thank you so much very helpful Waki, Please keep up the good work!.

  • @simonnjaukariukico-bi2116
    @simonnjaukariukico-bi2116 Год назад +2

    Was very helpful. Thank you Sir.

  • @sefawdinberta4515
    @sefawdinberta4515 Год назад +1

    Excellent presentation

  • @nasrmhm
    @nasrmhm Год назад +1

    Thank you for explanations and sharing the helpful and nice work

  • @JuHP-hy1jo
    @JuHP-hy1jo Год назад +1

    Best tutor ever!

  • @ManzoorRaieesKhan
    @ManzoorRaieesKhan 2 года назад +2

    Thanks for uploading this video

  • @mohamedlagzouli6679
    @mohamedlagzouli6679 2 года назад +2

    well explained
    well illustrated

  • @mailabib3900
    @mailabib3900 9 месяцев назад +1

    Wonderful video, Thank you very much

  • @jimmycliffordoppong7988
    @jimmycliffordoppong7988 Год назад +1

    This is really helpful. Thank you. However, do you have transcribed commentaries on what you were saying whilst you were running the codes? it will be helpful since I did not catch some of the things you said.

  • @abinashdas3604
    @abinashdas3604 Год назад +1

    Wonderful video...thank you so much for this 😊

  • @basilotieno2677
    @basilotieno2677 11 месяцев назад +2

    Thank you!!

  • @abhilashwodeyar
    @abhilashwodeyar Год назад

    Wonderful explanation...Thank you so much

  • @asradesofi7048
    @asradesofi7048 11 месяцев назад +1

    Thanks for a nice explanation

  • @nezifabamecha8037
    @nezifabamecha8037 2 года назад +1

    Well explained

  • @afeezoluniyishittuirri7645
    @afeezoluniyishittuirri7645 8 месяцев назад +1

    Thanks Prof for this wonderful lecture. Am having problems installing ggbiplot, any hint you can help me with? thanks

    • @wakjiratesfahun3682
      @wakjiratesfahun3682  8 месяцев назад

      Run this code
      library(devtools)
      install_github("vqv/ggbiplot")

    • @afeezoluniyishittuirri7645
      @afeezoluniyishittuirri7645 8 месяцев назад

      library(devtools)
      Error: package ‘usethis’ 2.1.5 was found, but >= 2.1.6 is required by ‘devtools’
      In addition: Warning message:
      package ‘devtools’ was built under R version 4.1.3
      > install_github("vqv/ggbiplot")
      Error in install_github("vqv/ggbiplot") :
      could not find function "install_github"= this is the errors I have been having since before I contacted you
      @@wakjiratesfahun3682

  • @hope2024-g
    @hope2024-g 2 года назад +2

    Thank you Sir 🙏❤

  • @saro4761
    @saro4761 10 месяцев назад +1

    Perfect Video thanks

  • @WorkuKebedeTekle
    @WorkuKebedeTekle Год назад +1

    really I like it. Thank you!

  • @martinazoric4098
    @martinazoric4098 Год назад

    Thank you so much!!! Thank you for sharing knowledge!

  • @techalebirhan1399
    @techalebirhan1399 Год назад +1

    The Greatest one !!!!

  • @jebelhaji6666
    @jebelhaji6666 2 месяца назад

    it is good english
    thank you

  • @selamawitkebebew3373
    @selamawitkebebew3373 Год назад +2

    Thanks!

  • @saptarshimondal8666
    @saptarshimondal8666 Год назад

    Awesome tutorial

  • @NebiyouMaseboMalore
    @NebiyouMaseboMalore 2 года назад +2

    Dear, i have tried to search the normality checking youtube that was done by you but I couldn't find it, please would you help me?

    • @wakjiratesfahun3682
      @wakjiratesfahun3682  2 года назад

      I did a tutorial on normality test. Please check my channel.

  • @seenaamulatu3825
    @seenaamulatu3825 2 года назад +2

    Thank you🙏 for your important tutorial. but how do I arrange my data from a simple lattice design? can I use the mean for the parameters??

  • @NebiyouMaseboMalore
    @NebiyouMaseboMalore 2 года назад +2

    Too impressive, moreover is there this tube in Amharic language?

    • @wakjiratesfahun3682
      @wakjiratesfahun3682  2 года назад +1

      Initially planned to give a tutorial in Amharic but due to bunch request , I changed the medium to English.

  • @sakisuf3237
    @sakisuf3237 Год назад +1

    Thanks sir for this video
    Sir I want to analyse the effect of physicochemical parameters of waterbody on the distribution of single species of fish.can you please suggest me the appropriate stastical tool .so that I can get results

  • @gizawwegayehu6103
    @gizawwegayehu6103 Год назад +1

    Realy nice,

  • @afeezoluniyishittuirri7645
    @afeezoluniyishittuirri7645 4 месяца назад +1

    Hi Prof please how to fix this error when running this script
    fviz_eig(pca, addlabels = TRUE, ylim = c(0, 50))
    Error in loadNamespace(j = 3.4.0 is required. I tried to install Cli but still not working. thanks

  • @AlemayehuLema
    @AlemayehuLema Год назад +1

    Thank you

  • @cengizturkay9230
    @cengizturkay9230 Год назад +1

    I came across this code in PCA analysis.
    Error in names(df.v)

  • @bayisakabe
    @bayisakabe Месяц назад

    If the number of row is large, for example my data has 140 row so what I shall do?

  • @pitopizoide
    @pitopizoide Год назад +1

    Thank you for the video! I have a question, for the ggbiplot, how can I select just some variables/axes to represent ?

  • @subhankarsanyal8138
    @subhankarsanyal8138 Год назад +1

    superlike

  • @Aesthetics10000
    @Aesthetics10000 10 месяцев назад +1

    how to label each PC in final chart with traits

    • @wakjiratesfahun3682
      @wakjiratesfahun3682  10 месяцев назад

      Give me the title and I will provide the code for you.

  • @cengizturkay9230
    @cengizturkay9230 Год назад +1

    Thanks for video.
    I have a question Sir
    I can't run the ggbiplot command. I'm trying to download it still doesn't work. How we can solve this problem?
    Can you help me

  • @kantidewi6031
    @kantidewi6031 11 месяцев назад

    thank you for the explanation, but why i couldn't find this command
    (library("ggplot2")
    library("gridExtra")
    library(ggbiplot)
    library("corrplot")
    library(factoextra)
    it always said error

  • @GEORONAKUSMAALBARKI
    @GEORONAKUSMAALBARKI Год назад +1

    Sir the ggbiplot is not functin in New Update R ???

    • @wakjiratesfahun3682
      @wakjiratesfahun3682  Год назад

      what happened?

    • @GEORONAKUSMAALBARKI
      @GEORONAKUSMAALBARKI Год назад

      @@wakjiratesfahun3682 Have done sir, ggbiplot I get from git hub recently.. and I want ask you about how we can add the colour of contribution line in pca ggbiplot version, like graph Fvis or add some ellipse lshape in graph Fvis.. Thanks

  • @nduwayezugilbert7912
    @nduwayezugilbert7912 Год назад +1

    Hi thank you for your video. However, I tried to use your codes with my data but I cannot get the Eigenvalue. I hit this error 'Error in get_eigenvalue(pca) : could not find function "get_eigenvalue".

    • @wakjiratesfahun3682
      @wakjiratesfahun3682  Год назад

      You forget to run factoextra package .

    • @nduwayezugilbert7912
      @nduwayezugilbert7912 Год назад +1

      @@wakjiratesfahun3682 Thank you so much for your assistance. I ran, but I tried to install the "ggbiplot" package in vain; I could not. Any other way to install it?

    • @wakjiratesfahun3682
      @wakjiratesfahun3682  Год назад

      @@nduwayezugilbert7912 I made a tutorial on some packages that found in other repositories.Please use this code to install ggbiplot.
      library(devtools) install_github("vqv/ggbiplot")

    • @nduwayezugilbert7912
      @nduwayezugilbert7912 Год назад +1

      @@wakjiratesfahun3682 Thank you so much

    • @wakjiratesfahun3682
      @wakjiratesfahun3682  Год назад

      @@nduwayezugilbert7912 it's okay.

  • @shahadathossen3377
    @shahadathossen3377 3 месяца назад

    can I get the data file for practice

  • @jebelhaji6666
    @jebelhaji6666 2 месяца назад

    Does R software free access?

  • @bezawitmekonnen9218
    @bezawitmekonnen9218 Год назад +1

    Well explained

  • @user-xu1kv3vq7k
    @user-xu1kv3vq7k Год назад

    Sir i changed the rownames but in pca plot it shows same (1,2 ,3....),can you slove this problem pls