{"id":20099187,"url":"https://github.com/angelobattaglia/r_statistical_inference","last_synced_at":"2026-05-05T16:42:28.373Z","repository":{"id":262622635,"uuid":"775439357","full_name":"angelobattaglia/r_statistical_inference","owner":"angelobattaglia","description":"Statistical Inference implemented in R","archived":false,"fork":false,"pushed_at":"2024-11-13T12:26:24.000Z","size":113,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-13T04:08:47.513Z","etag":null,"topics":["r","statistical-analysis","statistical-inference","statistics"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/angelobattaglia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-21T11:49:52.000Z","updated_at":"2024-11-13T12:26:28.000Z","dependencies_parsed_at":"2024-11-13T12:30:47.854Z","dependency_job_id":"ecbacb3b-9590-4d81-b69c-08011e0abcaf","html_url":"https://github.com/angelobattaglia/r_statistical_inference","commit_stats":null,"previous_names":["angelobattaglia/r_statistical_inference"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angelobattaglia%2Fr_statistical_inference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angelobattaglia%2Fr_statistical_inference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angelobattaglia%2Fr_statistical_inference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angelobattaglia%2Fr_statistical_inference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/angelobattaglia","download_url":"https://codeload.github.com/angelobattaglia/r_statistical_inference/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241541360,"owners_count":19979117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["r","statistical-analysis","statistical-inference","statistics"],"created_at":"2024-11-13T17:08:41.598Z","updated_at":"2026-05-05T16:42:28.367Z","avatar_url":"https://github.com/angelobattaglia.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Statistical Inference implementation in R\n\nAn implementation of some statistical inference topics in R.\n\n## Setting up a Jupyter Notebook environment with R\n\nThe idea is to have three terminal instances: one running Rterm, one jupyter and the other to run git.\nThe R packages will be installed globally. The Rterm will be the one instance through which we will be installing the packages.\nTo install and start a Jupyter Notebook session with the R programming language\nyou'll need to follow these steps (NOTE: highly recommended to use the latest R distribution):\n\n1. **Install R:**\n\nIf you haven't already, you need to install R on your system. You can download R from the official CRAN (Comprehensive R Archive Network) website: https://cran.r-project.org/\n\n2. **Install R Kernel for Jupyter:**\n\nTo use R in Jupyter Notebooks, you need to install the IRkernel. Open an R console and run the following commands:\n\n```R\ninstall.packages('IRkernel')\n# To install it for all users on the local machine\nIRkernel::installspec(user = FALSE)\n# If it is for one user, then:\nIRkernel::installspec(user = TRUE)\n```\n\nThe first command installs the IRkernel package, and the second command registers the kernel with Jupyter.\n\nIf you want to install some other library that you'll be using in your notebook sessions, like ggplot2,\nyou can keep the Rterm opened on the terminal and run the following command:\n\n```R\ninstall.packages('ggplot2')\n```\n\nit will install the packages globally and usually these are located somewhere in the file system, the R Shell\nshould be prompting the path, afterwards.\n\n3. **Install Jupyter Notebook:**\n\nIf you don't have Jupyter Notebook installed, you can install it using Python's package manager, pip. Open a terminal or command prompt and run:\n\n```bash\npip install notebook\n```\n\n4. **Start Jupyter Notebook:**\n\nIn the same terminal or command prompt, navigate to the directory where you want to create or open your notebook and run:\n\n```bash\njupyter notebook\n```\n\nThis command will start the Jupyter Notebook server, and your default web browser will open with the Jupyter dashboard.\n\n5. **Create a New R Notebook:**\n\nOnce the Jupyter Notebook dashboard is open, click on the \"New\" button and select \"R\" from the drop-down menu. This will create a new notebook with R as the kernel.\n\nAlternatively, you can open an existing notebook or create a new one and change the kernel to R using the \"Kernel\" menu.\n\nNow you should have a Jupyter Notebook session running with the R kernel, and you can start coding in R within the notebook.\n\nRemember to periodically update your R ages, including IRkernel, to ensure you have the latest versions. You can do this using the `install.packages` function in R.\n\n## Alternative (not yet tested)\nIn R, there is a similar mechanism for creating isolated environments, akin to Python's `virtualenv` or `venv`. \nThe R equivalent is typically managed through the **`renv`** package, which allows you to create project-specific environments and manage dependencies.\n\nHere’s how to create a virtual environment in R using `renv`:\n\n1. Install the `renv` package (if you don't have it already):\n\n   ```r\n   install.packages(\"renv\")\n   ```\n\n2. Initialize a new environment in your project:\n\n   ```r\n   renv::init()\n   ```\n\n   This will set up an isolated environment for the project, where packages are managed separately from your global R environment.\n\n3. From then on, when you install new packages in the project, they will be installed inside the `renv` environment rather than the global library:\n\n   ```r\n   install.packages(\"ggplot2\")  # Example\n   ```\n\n4. To save your environment state, you can use:\n\n   ```r\n   renv::snapshot()\n   ```\n\n   This will record the current state of the environment into a `renv.lock` file.\n\n5. To restore the environment on a different machine or later, you can run:\n\n   ```r\n   renv::restore()\n   ```\n\nThis allows you to maintain reproducibility and isolate package versions for your R projects, much like Python's `venv`.`\n\n# In the R shell, how to \"pwd\" or just run a script, whilst in the same folder ? \n\nIn the R shell, there are commands and functions you can use to manage the working directory and execute scripts:\n\n### 1. **Check the Current Working Directory (`pwd`)**\n   To check the current working directory in R, use:\n   ```R\n   getwd()\n   ```\n   This is equivalent to the `pwd` command in the terminal.\n\n---\n\n### 2. **Set the Working Directory**\n   If you need to change the working directory to the folder where your script is located:\n   ```R\n   setwd(\"path/to/your/folder\")\n   ```\n   Replace `\"path/to/your/folder\"` with the actual directory path.\n\n---\n\n### 3. **Run a Script in the Same Folder**\n   To run an R script in the current working directory, use:\n   ```R\n   source(\"script_name.R\")\n   ```\n   Replace `\"script_name.R\"` with the name of your script file.\n\n   **Tip:** If the script is in the current working directory, you don't need to specify the full path. If it's in another directory, provide the relative or absolute path.\n\n---\n\n### Automating the Process\nIf you want the script to automatically set its directory to the folder where it's located, add the following at the beginning of the script:\n\n```R\nsetwd(dirname(rstudioapi::getActiveDocumentContext()$path))\n```\n\nThis requires the `rstudioapi` package, which you can install using:\n```R\ninstall.packages(\"rstudioapi\")\n```\n\nThis ensures the script runs from its own folder regardless of where the R shell was started.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangelobattaglia%2Fr_statistical_inference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fangelobattaglia%2Fr_statistical_inference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangelobattaglia%2Fr_statistical_inference/lists"}