The unnest_tokens () function is a function included in the tidytext package of the R programming language, and separates text data into tokens. This function processes text appropriately for the ‘tidy data’ format, making it useful for text mining and natural language processing. This function creates a new row for each token, leaving columns other than those containing the text intact.
The unnest_tokens function is a key tool in R text mining to divide sentences or documents into words. To analyze text data, you must first break sentences into tokens and connect them to the next step, such as word frequency or sentiment analysis. This article summarizes the tidytext-based tokenization flow and usage of the unnest_tokens function.
1. unnest_tokens() concept
The unnest_tokens() function is included in R's tidytext package and is used to tokenize text data. Tokenization is the process of breaking down long text strings into smaller units, such as words or sentences.
This function is useful for converting text data into a form that is easy to process and analyze. For example, you can separate words that make up a single document or sentence.
output_column: The name of the new column in which to store the token.
input_column: Name of the column containing the text to tokenize.
token: Type of token (default is “words”).
example
library(dplyr)
library(tibble)
# example example
data <- tibble(id = c(1, 2), text = c("I love R", "Data science is awesome"))
# example example
tokenized_data <- data %>%
unnest_tokens(word, text)
# example example
print(tokenized_data)
In this example, we used a tibble dataframe with an id column and a text column. We applied the unnest_tokens() function to tokenize the text in the text column into words, and stored the results in a new word column.
Additional options
drop : If set to FALSE, include the input column in the results.
This function is very flexible and can be applied to a variety of text data. It can be used with several tokenization options and other tidytext functions to perform more complex text analysis tasks.
Token: This is the basic unit when analyzing text, and can usually be a word, phrase, or sentence.
Tidy Text: This refers to a text data format in which each word (token) forms one line and is stored together with a document or other identifier.
2. unnest_tokens parameter
The unnest_tokens() function has several options that allow you to fine-tune the process of tokenizing text. I'll explain some of the main options below.
1) Basic parameters:
data: The data frame to tokenize.
output_column: The name of the new column in which to store the token.
input_column: Name of the column containing the text to tokenize.
token: Type of token (e.g. “words”, “characters”, etc.)
2) Additional options:
drop: logical type. Whether to remove the input column from the results. The default is TRUE.
to_lower: logical type. Whether to convert all characters to lowercase. The default is TRUE.
strip_numeric: logical type. Whether to remove numbers. The default is FALSE.
strip_punct: logical type. Whether to remove punctuation. The default is FALSE.
collapse: string. Whether to concatenate tokens with this string. The default is NULL.
library(dplyr)
library(tidytext)
# example example
data <- tibble(id = c(1, 2), text = c("I love R", "Data science is awesome"))
# example example, example example example, example example
tokenized_data <- data %>%
unnest_tokens(word, text, drop = FALSE, to_lower = FALSE)
# example example
print(tokenized_data)
3) Remarks
If you set drop = FALSE, the original input_column will be retained in the result even after tokenization.
If you set to_lower = FALSE, case will be preserved.
If you set strip_numeric = TRUE, numbers will be removed.
If you set strip_punct = TRUE, punctuation will be removed.
By combining these options, you can increase the precision of tokenization or simplify the preprocessing process.
input: The name of the column containing the text to tokenize.
output: The name of the new column in which to store the tokenized results.
token: This is an option that determines what unit to tokenize in. These include ‘words’, ‘characters’, ‘ngrams’, ‘sentences’, ‘lines’, ‘paragraphs’, and ‘regex’.
4) Omitted
You can omit the input and output parameters in the unnest_tokens() function, but in that case the function will use the default settings of the first column of the data frame as input and word as the output column name. So you can also use it in the following form:
text %>%
unnest_tokens(token = "sentences")
However, if you do this, it can be difficult to clearly understand from code alone which columns are being tokenized and in which columns the tokens are stored. For code readability and maintainability, it is recommended to specify input and output explicitly.
Explicitly specifying column names is recommended because it makes it easier for readers of your code or when modifying your code later to know what the column means.
To download the R program, you can click the download link on the R program's official website (https://www.r-project.org/).
Good article to read together
Text replacement str_replace, str_replace_all functions
str_squish function to remove unnecessary spaces
Understanding Tibble and the as_tibble() function
Execute PHP and R code in conjunction
Importance and usage of pipe operator %>%
Key Checklist
Is the text column to be analyzed clear?
Have you decided which unit to divide into: sentences, words, or n-grams?
Is there a plan to remove stop words and analyze frequencies after tokenization?
Have you confirmed whether morpheme analysis is necessary in processing Korean text?
Good R statistics articles to read together
How to use the R pipe operator %>%: An easy way to read data analysis flows
Research Method Introduction to R Statistics: Understanding research design and analysis methods at a glance
Variables and Measurement R Statistics: Understanding independent variables, dependent variables and measurement levels
What is research: Summary of research concepts for introduction to R statistics
Related Reading
Continue with these related Thinknote English articles in the Data Analysis cluster.
This article is part of Thinknote’s English R statistics and data-analysis archive. It explains research, measurement, text processing, or tidyverse-style workflow concepts in practical language.
How should I use this guide?
Use it as a learning note and starter reference. When applying code, adjust package versions, object names, and dataset structure to your own R environment.
Linking PHP and R code: Running PHP and R code in conjunction combines the advantages of both programming languages to handle complex web applications and data analysis together. However, since there are many pros and cons, you must consider your development goals and scenarios to decide whether to link PHP and R code.
Leverage language expertise: PHP is strong in web development, and R is strong in data analysis. You can take advantage of the strengths of both languages.
Code reuse: Data analysis code or models already written in R can be easily reused in web applications.
Create dynamic web content: By running R code in PHP, you can dynamically display real-time data analysis results on your website.
Capable of complex analysis: R provides a wide variety of data analysis functions, including statistical analysis, machine learning, and graph creation.
System resource efficiency: Make efficient use of system resources by executing R code only when needed.
2) Disadvantages of linking PHP and R code
Performance Issues: Running R code in PHP can be slow in general, and performance can be especially problematic when dealing with large amounts of data or complex analysis.
Security Vulnerability: Using functions like exec or shell_exec puts your server at risk of vulnerability. Be careful when using these functions.
Environment setup and management: Running R and PHP together requires both environments to be well set up and maintained, which can increase complexity.
Error handling: Error handling can become complicated when linking two languages. Any errors that may occur in both PHP and R must be caught and managed.
Memory usage: R is a fairly memory-intensive language. If PHP and R processes run simultaneously, memory usage can increase significantly.
Version compatibility: Over time, R libraries or PHP packages are updated, which can cause compatibility issues.
2. Execute R code in PHP using the exec function
Executing R code using PHP's exec() function is a simple way to run external programs in PHP. This method generally requires R to be installed on the server running PHP, and make sure the exec() function is not disabled in the server settings.
1) Concept
The exec() function is used to run external programs in PHP. To run an R script using this function, simply pass as an argument the command to run the R script on the command line. Typically this command is Rscript.
exec("Rscript [R example example]", $output);
2) Example 1
Example 1 is a very simple example of executing the R script simple_example.R using PHP's exec() function.
Example 2 shows the process of running an R script in PHP to fit a linear model, summarizing the results, and saving them to a text file. The PHP code then reads this text file and outputs it.
R script ( linear_model.R ):
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 1, 8, 7)
fit <- lm(y ~ x)
summary_str <- capture.output(summary(fit))
write(summary_str, "summary.txt")
PHP code:
<?php
exec("Rscript linear_model.R");
// Rexample example summary.txt example example
$summary = file_get_contents("summary.txt");
echo "R Summary:\n$summary";
?>
3) Example 3
Example 3 demonstrates how an R script and PHP interact by reading and writing a CSV file. This example specifically demonstrates how an R script can take command line arguments and process them dynamically.
<?php
$input_file = "input.csv";
$output_file = "output.csv";
exec("Rscript data_processing.R $input_file $output_file");
// Rexample example output.csv example example
$output_data = file_get_contents("output.csv");
echo "R Output Data:\n$output_data";
?>
caution
Make sure the exec() function is not disabled on the server.
Security issue: Be careful with the exec() function as it can cause server security issues if used incorrectly.
Error handling: The exec() function does not output a PHP warning on failure by default, so you may need to implement separate error handling logic.
3. Run R code in PHP using the Rserve package
1) Rserve concept
Rserve is one of the packages provided by R that allows R to operate as a server. Typically R is used as a tool for interactive statistical calculations, but Rserve allows you to operate R as a server and run R code from other applications (e.g. PHP, Java, Python, etc.). This is accomplished using the TCP/IP protocol.
TCP/IP protocol support: Easy to communicate with other languages or frameworks.
Multi-session support: Multiple users can use R’s services at the same time.
Platform independence: Can be used on a variety of operating systems and languages.
Low barrier to entry: Users familiar with R can use Rserve with relative ease.
2) Rhythm
Integration between languages: R's special data analysis libraries and functions can be easily used in other languages.
Performance optimization: R tasks are processed on a separate server, reducing the load on the web server.
Code reusability: The same R code can be reused in multiple applications.
Concurrency: Multiple users can perform R analysis simultaneously.
3) Disadvantages
Setup complexity: There can be complexity in setting up interfaces between R, Rserve, and other programming languages.
Debugging Difficulty: Interoperability between R and other languages can complicate debugging.
Security vulnerabilities: Because they communicate over TCP/IP, misconfiguration can lead to security vulnerabilities.
4) Basic use
Install Rserve in R: install.packages("Rserve")
Start Rserve in R: library(Rserve) Rserve()
Install the PHP Rserve client. Create a composer.json file and add the content below. { "require": { "cturbelin/rserve-php": "^2.1" } }
When you run composer instll in the terminal, a vendor folder will be created and contain related files.
Call an R function from your PHP code: <?php require './vendor/autoload.php'; define('RSERVE_HOST', 'localhost'); use Sentiweb\Rserve\Connection; use Sentiweb\Rserve\Parser\NativeArray; $cnx = new Connection(RSERVE_HOST); $r = $cnx->evalString('2+2' ); echo $r; ?>
If an error occurs when running, check whether php-mbstring is installed correctly.
5) Use multiple lines
You can run multiple lines of R code inside $r->evalString(). You can write your R code as a string over multiple lines.
<?php
require './vendor/autoload.php';
define('RSERVE_HOST', 'localhost');
use Sentiweb\Rserve\Connection;
use Sentiweb\Rserve\Parser\NativeArray;
$cnx = new Connection(RSERVE_HOST);
// example example R example
$script = <<<RSCRIPT
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 1, 8, 7)
fit <- lm(y ~ x)
summary_fit <- summary(fit)
RSCRIPT;
$r->evalString($script);
$summary = $cnx->evalString('capture.output(summary_fit)');
foreach($summary as $line) {
echo $line . "\n";
}
?>
In this example, we included multiple lines of R code by writing it in the format HereDoc ( <<<RSCRIPT … RSCRIPT; ). After that, I am executing these multiple lines of code at once by calling the evalString() method.
This allows even complex R scripts to run in PHP.
3. Run R code in PHP using the Rserve package
Rserve can be useful when web servers or other applications require complex statistical analysis or data processing. However, you should carefully consider the pros and cons mentioned above before using it.
To download the R program, you can click the download link on the R program's official website (https://www.r-project.org/).
Good article to read together
Install PHP 8 (ubuntu)
Setting up Nginx + Php8
Install memory caching APCu, Redis, Memcached
Install Centos 8
Linux user management useradd usermod userdel
Related Reading
Continue with these related Thinknote English articles in the Data Analysis cluster.
This article is part of Thinknote’s English R statistics and data-analysis archive. It explains research, measurement, text processing, or tidyverse-style workflow concepts in practical language.
How should I use this guide?
Use it as a learning note and starter reference. When applying code, adjust package versions, object names, and dataset structure to your own R environment.
1. Database package that can be installed on Ubuntu
MySQL: A popular open source relational database management system (RDBMS).
PostgreSQL: A powerful open source RDBMS that offers many features and extensibility.
MongoDB: A document-oriented NoSQL database.
SQLite: A lightweight, open source relational database engine suitable for embedded systems and small-scale applications.
Redis: A high-performance key-value store and memory-based data structure server.
MariaDB: A fork of MySQL that offers improved performance and stability while maintaining compatibility.
2. Understanding MariaDB
MariaDB is an open source relational database management system (RDBMS) that began as a fork of MySQL. It is fully compatible with MySQL, and users can easily migrate from their existing MySQL environment to MariaDB. MariaDB is used as the basic RDBMS in many Linux distributions.
Performance: MariaDB provides excellent performance for processing large amounts of data. Performance improvements have been achieved through optimizations such as query optimization, indexing functions, and parallel processing.
Scalability: MariaDB can scale your database servers horizontally and vertically. Scalability can be achieved in a variety of ways, such as master-slave replication and clustering.
Security: MariaDB places a strong emphasis on database security. It provides features such as SSL/TLS encryption, access control, and data masking to ensure the safety of your data.
Openness: MariaDB was developed as open source, allowing users to access the source code to modify and improve it. It also offers a variety of plugins and extensions to customize it to suit your needs.
2) MariaDB Advantages
MariaDB is fully compatible with MySQL, so existing MySQL users can easily migrate.
MariaDB delivers fast performance with optimized query processing and indexing features.
MariaDB allows you to flexibly scale your database servers.
MariaDB is stable in many Linux distributions and provides features for error recovery and fault tolerance.
3) Disadvantages of MariaDB
Because it has a relatively small community compared to MySQL, troubleshooting and support can be difficult to find.
MariaDB is compatible with MySQL, but differences may occur in some specific features, which may cause some applications to not work properly.
3. Install MariaDB
1) Preparing MariaDB in advance
Update and upgrade Ubuntu packages.
sudo apt update
sudo apt upgrade
Article image 1
2) Install MariaDB
sudo apt install mariadb-server
Article image 2
2) Check MariaDB service
Once installation is complete, the MariaDB service will start automatically. To check the service status, run the following command:
sudo systemctl status mariadb
Article image 3
3) Run MariaDB security script
To configure MariaDB more easily, run the security script by running the following command:
Enter current password for root: During initial installation, there is no password, so press enter.
Change the root password: Enter Y and set the password.
Remove anonymou user: Type Y to remove an anonymous user.
Disallow root login remotely: Enter Y to enable remote login or N to disable it.
Remove test database and access to it: Type Y to delete the test database.
Reload privilege tables now: Type Y to save changes.
sudo mysql_secure_installation
Article image 4
The security settings for your MySQL server are now complete.
Thinknote
Good article to read together
Install OpenSSL
Activate Centos 8 RHEL & REMI Repository
Linux administrator tool – enable cockpit
Install Ubuntu 22.04.1 (VirtualBox)
VirtualBox Virtual Box virtual machine download and installation
Related Reading
Continue with these related Thinknote English articles in the Server & Infrastructure cluster.
This article is part of Thinknote’s English server and infrastructure archive. It focuses on practical Linux, Ubuntu, web-server, database, SSH, firewall, or hosting operations that readers can adapt to their own environment.
How should I use this guide?
Use it as a practical checklist and concept guide. Before applying commands on a live server, verify package names, OS versions, ports, and backup requirements for your own setup.
OpenSSL is a collection of libraries and tools that implement encryption and security protocols. It is primarily used on Linux operating systems, but can be used on other operating systems as well. OpenSSL included with Ubuntu Server has the following functions and features:
Encryption and hash functions: OpenSSL supports a variety of encryption algorithms (AES, DES, RSA, etc.) and hash functions (MD5, SHA-1, SHA-256, etc.). This allows users to store or transmit data securely to ensure data security.
SSL/TLS Protocol: OpenSSL is used to implement the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols. It encrypts communications between servers and clients, ensuring the confidentiality and integrity of data and protecting against man-in-the-middle attacks.
Certificate Management: OpenSSL supports the X.509 certificate format, allowing you to create, manage, and verify public key certificates. It establishes a trust relationship between a server and a client and is used in e-commerce and authentication systems.
Encryption key and CSR generation: OpenSSL can generate symmetric and asymmetric encryption keys. Additionally, you can generate a certificate signing request (CSR) and send it to the certification authority. CSR is used to request issuance of a server certificate.
Command-line tools: OpenSSL includes command-line tools, allowing developers and system administrators to perform tasks such as encryption, hashing, certificate management, and more.
Open Source: OpenSSL is an open source project, with many developers contributing to it. This helps verify source code and strengthen security, and has the advantage of receiving community support and updates.
2. Install OpenSSL
1) Install OpenSSL
OpenSSL on Ubuntu Server is used to implement secure network communication by providing the above functions and features.
sudo apt install openssl
Article image 1
Install OpenSSL by running the following command:
1) Check OpenSSL version
openssl version
3. Create param key
1) param necessity
The reason for using Openssl to generate param keys is mainly to generate parameters needed for security algorithms such as:
Diffie-Hellman (DH) Key Exchange: DH is a type of public key cryptosystem that allows secure communication without sharing two different private keys. DH requires shared parameters p and g, which can be generated using OpenSSL.
RSA encryption: RSA is a public key encryption method that uses prime numbers p and q to generate private and public keys. You can generate these prime numbers using OpenSSL.
You can change the size and file name according to your needs. There is also a way to use OpenSSL to generate the parameters needed for other encryption algorithms. The param key is used to generate parameters required for the Diffie-Hellman (DH) key exchange protocol used by OpenSSL. The DH protocol is a type of public key cryptosystem, used to generate a secret shared key between two entities. These secret keys can be used for secure communications.
4. Additional study material
If you would like to learn more about OpenSSL, you can refer to the following resources:
OpenSSL official documentation
OpenSSL page on Ubuntu Wiki
Thinknote
Good article to read together
Installing and managing MariaDB (MySQL)
Activate Centos 8 RHEL & REMI Repository
Linux administrator tool – enable cockpit
Install Ubuntu 22.04.1 (VirtualBox)
VirtualBox Virtual Box virtual machine download and installation
Related Reading
Continue with these related Thinknote English articles in the Server & Infrastructure cluster.
This article is an English translation and global-reader adaptation of the original Thinknote article “Install OpenSSL.” It preserves the original article’s main explanation, examples, and practical context.
Why is it translated into English?
The English version helps global readers access Thinknote articles through English search keywords while keeping the Korean source available as the original reference.
Let’s Encrypt is a certification authority that issues SSL/TLS certificates for free. Let’s Encrypt on Ubuntu systems allows you to provide secure HTTPS connections to your web servers.
Free: Let’s Encrypt is a public project that is free to use. So, you can get an SSL/TLS certificate without any cost issues.
Automation: Let’s Encrypt automates the certificate issuance and renewal process to make it easier to use. This generally means that you can issue and renew certificates by simply typing a single command line.
Security: Let’s Encrypt enhances security by providing encrypted HTTPS connections for all connections. This helps keep your data and personal information safe.
2) Cloudflare.com
Cloudflare is a company that provides web security and performance optimization services. The company routes traffic through a global network to improve the speed, security and availability of websites, and protect against malicious activity. It has features to compress and optimize web content.
Cloudflare’s main features can be seen like this:
CDN (Content Delivery Network): Helps users access your website faster through Cloudflare’s global network.
Web Firewall: Provides a firewall to protect against malicious activities such as DDoS attacks, SQL injections, etc.
SSL/TLS Encryption: Securely transmit your website using SSL/TLS certificates.
Performance optimization: We use techniques such as caching, image optimization, and JavaScript minimization to improve your website’s loading speed.
Advantages of Cloudflare
High Availability: Cloudflare distributes traffic across a global network, increasing the availability of your website.
Enhanced security: Provides a powerful web firewall to protect against DDoS attacks and other malicious activities.
Improve performance: We use caching and optimization techniques to improve the loading speed of your website.
2. Install and configure Let’s Encrypy package
1) Install Let’s Encrypt
Install Certbot: Certbot is the official client for Let’s Encrypt and is a tool for issuing and managing certificates.
Install Certbot with the following command:
sudo apt update
sudo apt install certbot
The python3-certbot-dns-cloudflare package provides the ability to automatically add and manage domain records to Cloudflare’s (DNS provider) DNS servers using Certbot’s DNS-01 domain validation method and operates in the following order:
Certbot asks you to add a specific TXT record to Cloudflare DNS servers to verify that you own the domain.
The python3-certbot-dns-cloudflare package uses the Cloudflare API to log in with an authenticated user account.
The package adds a TXT record to the Cloudflare DNS server based on the authentication request information received from Certbot.
Certbot verifies that the record is reflected in Cloudflare DNS servers.
When authentication is successfully completed, Certbot issues an SSL/TLS certificate and saves it to the path specified by the user.
Run the following code to install python3-certbot-dns-cloudflare.
sudo apt install python3-certbot-dns-cloudflare
2) Generate Cloudflare API key
Log in to your Cloudflare account and go to “My Profile”.
Go to the “API Tokens” section and click the “Create Token” button.
In the “Use Template” section, select the “Edit Zone DNS” template.
After selecting access to the Zone, click the “Continue to Summary” button.
Name the token and store the generated token value in a safe place.
Article image 1
3) Save API Token
Create the /root/.secrets/certbot directory.
Create the /root/.secrets/certbot/cloudflare.ini file.
Enter email address (used for urgent renewal and security notices) (Enter ‘c’ to cancel): Enter your email address (c to cancel)
2) Code description
The above code is a command that uses Certbot to generate a certificate for the example.com domain.
certbot : Runs the Certbot tool.
certonly: Only generates a certificate and does not connect to the web server. (Only performs certificate issuance)
–dns-cloudflare : Issue a certificate via domain verification against Cloudflare DNS.
–preferred-challenges dns-01: Uses dns-01, one of the DNS-based domain resolution methods.
–dns-cloudflare-propagation-seconds 20 : Number of seconds to wait for Cloudflare DNS updates to complete. Here it is set to 20 seconds.
–dns-cloudflare-credentials /root/.secrets/certbot/certbot-cloudflare.ini : Path to the file containing credentials to access the Cloudflare API. Here we use the /root/.secrets/certbot/cloudflare.ini file.
-d example.com : The domain name to issue the certificate to, here example.com is used.
2) Confirmation of issuance
The issued certificate is created in the domain folder under /etc/letsencrypt/live.
A total of 4 files (cert.pem, chain.pem, fullchain.pem, privkey.pem) are created.
4. Additional study material
Here are links to official documentation and references from Let’s Encrypt and Certbot.
Let’s Encrypt official documentation: https://letsencrypt.org/docs/
Certbot official documentation: https://certbot.eff.org/docs/
This article is part of Thinknote’s English server and infrastructure archive. It focuses on practical Linux, Ubuntu, web-server, database, SSH, firewall, or hosting operations that readers can adapt to their own environment.
How should I use this guide?
Use it as a practical checklist and concept guide. Before applying commands on a live server, verify package names, OS versions, ports, and backup requirements for your own setup.
Memory caching methods available in Ubuntu include APCu, Redis, and Memcached. Each caching tool must be selected for different purposes and requirements.
For example, APCu can improve the performance of PHP code, but it can only be used on a single server, making it unsuitable for distributed environments.
Redis provides a variety of data structures and clustering capabilities, making it suitable for complex applications.
Memcached is designed to support large-scale throughput in a distributed environment.
1) APCu (Alternative PHP Cache user caching)
APCu is a PHP extension used to cache data within a local server and is suitable for use in a single server environment. APCu does not allow sharing of data between processes, and data is kept only in that process.
A memory caching system for PHP.
You can cache data by accessing PHP code directly.
It can only be used on a single server and is not suitable for distributed environments.
APCu stores data natively in memory, providing fast read/write speeds.
However, APCu does not support data retention and replication, so data may be lost in the event of a server failure.
2) Redis
Redis is an open source in-memory data structure store that can scale out in multi-server environments and store data both in memory and persistently on disk. It supports a variety of data structures (strings, hashes, lists, sets, etc.) and can also be used as a message broker through the Pub/Sub mechanism.
It operates as a single thread and uses an event-driven architecture to solve concurrency problems.
It supports a variety of data structures, including strings, hashes, lists, sets, and sorted sets.
You can build a message-based architecture by supporting the Publish/Subscribe (Pub/Sub) mechanism.
Supports distributed systems such as master-slave replication and Redis clusters.
We provide a variety of performance monitoring and management tools to help you monitor the health of your database instances and optimize performance.
3) Memcached
Memcached is a distributed memory object cache system that can scale out in a multi-server environment and stores data in memory. Data is stored in key-value format and does not support complex data structures.
It is a distributed object caching system.
It is used to store and retrieve data in key-value form.
It is suitable for use in a distributed environment and allows data to be shared between multiple servers.
Memcached is a simple key-value store and does not support complex data structures.
Memory usage is large and data is not stored on disk, so data may be lost in the event of a server failure.
Typically, APCu, Redis, and Memcached can all be installed and operated.
Server resources (memory and CPU) must be considered when operating all systems simultaneously, and the setup and operation of each cache system must be understood and optimized. You should also consider data consistency and synchronization issues.
2. APCu caching
1) Install APCu
To install APCu, run the following command:
sudo apt install php8.2-apcu
2) Activate APCu (acpu.ini)
Run the following command to open the PHP configuration file. For PHP version, enter the PHP version installed on the server.
If you use Apache web server, you need to edit /etc/php/8.2/apache2/php.ini.
sudo nano /etc/php/8.2/apache2/php.ini
If you use PHP in PHP-FPM (PHP FastCGI Process Manager), edit sudo nano /etc/php/8.2/fpm/php.ini or edit the acpu.ini file. If there is no acpu.ini file, create the /etc/php/8.2/mods-available/apcu.ini file and paste the following content into it.
sudo nano
/etc/php/8.2/mods-available/apcu.ini
extension = apcu.so
apc.enabled = 1
Article image 1
Activate the apcu module with the following command.
sudo phpenmod -v 8.2 apcu
Restart the nginx server for the changes to take effect.
sudo systemctl restart nginx
3) Check APCu execution (acpu.ini)
You can run the command below to print the results of the phpinfo() function and check APCu-related settings, version information, directory path, etc.
php -i | grep apcu
1. Redis caching
1) Install Redis
To install Redis, run the following command: Once installation is complete, the Redis server will start automatically
sudo apt install redis-server
2) Check Redis status
Run the following command to check the service status. After verifying that your Redis server is running normally, you can modify the Redis configuration file as needed. The configuration file is located in the path /etc/redis/redis.conf
sudo systemctl status redis-server
sudo usermod -a -G redis www-data
Article image 2
3) Firewall settings (iptables)
Open port 6379 used by redis-server and save and reload iptable.
sudo iptables -A INPUT -p tcp --dport 6379 -j ACCEPT
sudo netfilter-persistent save
sudo netfilter-persistent reload
4) Linking Redis and PHP
Install the Redis PHP extension module.
sudo apt install php8.2-redis
Restart the nginx server for the changes to take effect.
sudo systemctl restart nginx
5) Activate Redis (redis.ini)
Add the code below in sudo nano /etc/php/8.2/mods-available/redis.ini.
You can check the connection and operation with Redis by creating a new PHP file and writing the following code (value output):
<?php
$redis = new Redis();
$redis->connect('localhost', 6379);
// example example example example example
$redis->set("key", "value");
echo $redis->get("key");
// example example example example example
$redis->hSet("hash", "field", "value");
echo $redis->hGet("hash", "field");
// example example
$redis->close();
?>
2. Memcached caching
1) Install Memcached
Run the following command to install Memcache.
sudo apt install memcached
2) Start Memcached service
Run the following command to start the Memcached service.
sudo systemctl start memcached
sudo systemctl status memcached
Run the code below to automatically start the Memcached service on boot.
sudo systemctl enable memcached
3) Firewall settings (iptables)
Memcached runs on port 11211 on localhost (127.0.0.1). Open iptables port 11211 for Memcached to run.
sudo iptables -A INPUT -p tcp --dport 11211 -j ACCEPT
sudo netfilter-persistent save
sudo netfilter-persistent reload
Additionally, you can edit the following settings files to configure your application to use Memcached:
Modifying memory quotas: You can adjust quotas by modifying the value of the -m option in the /etc/memcached.conf file.
Modify binding address: You can bind to a different IP address by changing the -l option value in the /etc/memcached.conf file.
Modifying the port: You can set it to a different port number by changing the value of the -p option in the /etc/memcached.conf file.
4) PHP integration (php.ini)
Run the command below to install the package.
sudo apt install php8.2-memcached
In the /etc/php/8.2/fpm/php.ini file or /etc/php/8.2/mods-avaiable/memcached.ini, find the extension=memcached.so line, uncomment it and save it.
You can use the following code to connect to a Memcached server and store, retrieve and test values. (value output is normal)
<?php
$memcached = new Memcached();
$memcached->addServer('localhost', 11211);
$memcached->set('key', 'value', 60); // 60example example example example
$value = $memcached->get('key');
echo $value; // example example example
?>
4. Additional study material
Links to official documentation and references related to APCu, Redis, and Memcached.
1) APCu
APCu official documentation: https://www.php.net/manual/en/book.apcu.php
“APCu: User Caching and Optimization” (with information and examples): https://www.sitepoint.com/caching-with-apcu/
“APCu vs Redis vs Memcached” (comparison and performance testing): https://haydenjames.io/apcu-vs-redis-vs-memcached/
2) Redis
Redis official documentation: https://redis.io/documentation
“Redis Basics for Beginners” (an introduction to basic concepts): https://www.digitalocean.com/community/tutorials/redis-basics-for-beginners
“Redis Tutorial” (Learn Redis with examples): https://www.tutorialspoint.com/redis/index.htm
3) Memcached
Memcached official documentation: https://memcached.org/documentation
“Memcached Tutorial” (including basic concepts and examples): https://www.tutorialspoint.com/memcached/index.htm
“Introduction to Memcached” (Memcached introduction and use cases): https://phoenixnap.com/kb/memcached-tutorial
Thinknote
Good article to read together
Install PHP 8 (ubuntu)
Setting up Nginx + Php8
Install Nginx web server (ubuntu)
Free HTTPS setup (Let’s Encrypt, Cloudflare)
Install Nginx web server (Centos 8)
Related Reading
Continue with these related Thinknote English articles in the Server & Infrastructure cluster.
This article is part of Thinknote’s English server and infrastructure archive. It focuses on practical Linux, Ubuntu, web-server, database, SSH, firewall, or hosting operations that readers can adapt to their own environment.
How should I use this guide?
Use it as a practical checklist and concept guide. Before applying commands on a live server, verify package names, OS versions, ports, and backup requirements for your own setup.
Nextcloud is a cloud storage and collaboration platform for personal and enterprise use. Nextcloud is open source software developed by Frank Karlitschek after leaving the ownCloud project in 2016. members of the ownCloud community gathered together to create Nextcloud and began development.
1) Nextcloud Features
Nextcloud is widely used by individuals and businesses as a secure and efficient cloud storage and collaboration tool.
File Sync and Share: Nextcloud allows you to sync and share files across multiple devices.
Security: Nextcloud provides a variety of security features, including data encryption and two-factor authentication, to enhance user data protection.
Collaboration tools: Include collaboration tools like document editing, calendar, address book, and more to help you accomplish a variety of tasks with your team.
App Ecosystem: We offer a variety of apps and extensions to extend Nextcloud to fit your needs.
Self-hosted: Nextcloud is available on-premise or in the cloud, allowing users to run their own servers to manage their data.
2) Advantages
Privacy Protection: Nextcloud is easy to protect personal information because users can directly manage their data.
Extensibility: A variety of apps and extensions allow you to extend Nextcloud to fit your needs.
Collaboration features: It provides various collaboration tools such as document editing and calendar, making it easy to work with team members.
3) Disadvantages
Technical Knowledge Required: Must have a technical understanding of server setup and maintenance.
Initial setup complexity: Initially setting up Nextcloud can be a bit complicated.
4) System Requirements
Platform Options Operating System (64-bit) Ubuntu 22.04 LTS (recommended) Ubuntu 20.04 LTS Red Hat Enterprise Linux 8 (recommended) Debian 12 Linux Enterprise Server 15 openSUSE Leap 15.4 CentOS Stream Database MySQL 8.0+ or MariaDB 10.3/10.4/10.5/ 10.6 (recommended) Oracle Database 11g (enterprise) (only as part of subscription) ) PostgreSQL 10/11/12/13/14/15 SQLite (recommended for testing and minimum instances only) ) Web server Apache 2.4 and or (recommended) mod_phpphp-fpm nginx php-fpm PHP runtime 8.0 (deprecated)) 8.1 8.2 (recommended)
3) Hardware Requirements
Processor: 1 GHz or faster dual core processor
Memory: At least 512MB RAM (recommended: 2GB or more)
Storage space: At least 10GB of free space
Network: Network interface for Internet connection
2. Install Nextcloud
Nextcloud installation includes all-in-one VM, all-in-one Docker, and web installer installation methods. Here, we will proceed with the installation using the web installer.
1) Create folder and download installation file
Create a folder to install nextcloud. Create a logs folder to store web logs and a public folder to install nextcloud.
Paste the code below and change the domain part to your own domain.
upstream php-handler {
server unix:/var/run/php/php8.2-fpm.sock;
}
# Set the `immutable` cache control options only for assets with a cache busting `v` argument
map $arg_v $asset_immutable {
"" "";
default "immutable";
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256;
ssl_ecdh_curve secp384r1;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 1.0.0.1 valid=300s;
resolver_timeout 5s;
access_log /var/www/nc.skdream.com/logs/access.log;
error_log /var/www/nc.skdream.com/logs/error.log;
root /var/www/nc.skdream.com/public/;
#index index.php index.html;
#Nextcloud
# Prevent nginx HTTP Server Detection
server_tokens off;
# HSTS settings
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always;
# set max upload size and increase upload timeout:
client_max_body_size 512M;
client_body_timeout 300s;
fastcgi_buffers 64 4K;
# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml text/javascript application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
# Pagespeed is not supported by Nextcloud, so if your server is built
# with the `ngx_pagespeed` module, uncomment this line to disable it.
#pagespeed off;
# The settings allows you to optimize the HTTP2 bandwitdth.
# See https://blog.cloudflare.com/delivering-http-2-upload-speed-improvements/
# for tunning hints
client_body_buffer_size 512k;
# HTTP response headers borrowed from Nextcloud `.htaccess`
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
#add_header X-Download-Options "noopen" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "noindex, nofollow" always;
add_header X-XSS-Protection "1; mode=block" always;
# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;
# Add .mjs as a file extension for javascript
# Either include it in the default mime.types list
# or include you can include that list explicitly and add the file extension
# only for Nextcloud like below:
include mime.types;
# Specify how to handle directories -- specifying `/index.php$request_uri`
# here as the fallback means that Nginx always exhibits the desired behaviour
# when a client requests a path that corresponds to a directory that exists
# on the server. In particular, if that directory contains an index.php file,
# that file is correctly served; if it doesn't, then the request is passed to
# the front-end controller. This consistent behaviour means that we don't need
# to specify custom rules for certain paths (e.g. images and other assets,
# `/updater`, `/ocs-provider`), and thus
# `try_files $uri $uri/ /index.php$request_uri`
# always provides the desired behaviour.
index index.php index.html /index.php$request_uri;
#types {
# text/javascript js mjs;
#}
# Rule borrowed from `.htaccess` to handle Microsoft DAV clients
location = / {
if ( $http_user_agent ~ ^DavClnt ) {
return 302 /remote.php/webdav/$is_args$args;
}
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Make a regex exception for `/.well-known` so that clients can still
# access it despite the existence of the regex rule
# `location ~ /(\.|autotest|...)` which would otherwise handle requests
# for `/.well-known`.
location ^~ /.well-known {
# The rules in this block are an adaptation of the rules
# in `.htaccess` that concern `/.well-known`.
location = /.well-known/carddav { return 301 /remote.php/dav/; }
location = /.well-known/caldav { return 301 /remote.php/dav/; }
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
location /.well-known/pki-validation { try_files $uri $uri/ =404; }
# Let Nextcloud's API for `/.well-known` URIs handle all other
# requests by passing them to the front-end controller.
return 301 /index.php$request_uri;
}
# Rules borrowed from `.htaccess` to hide certain paths from clients
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
# Ensure this block, which passes PHP files to the PHP process, is above the blocks
# which handle static assets (as seen below). If this block is not declared first,
# then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
# to the URI, resulting in a HTTP 500 error response.
# to the URI, resulting in a HTTP 500 error response.
location ~ \.php(?:$|/) {
# Required for legacy support
rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param HTTPS on;
fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
fastcgi_param front_controller_active true; # Enable pretty urls
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
fastcgi_max_temp_file_size 0;
}
# Javascript mimetype fixes for nginx
# Note: The block below should be removed, and the js|mjs section should be
# added to the block below this one. This is a temporary fix until Nginx
# upstream fixes the js mime-type
location ~* \.(?:js|mjs)$ {
types {
text/javascript js mjs;
}
default_type "text/javascript";
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463, $asset_immutable";
access_log off;
}
# Serve static files
location ~ \.(?:css|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463, $asset_immutable";
access_log off; # Optional: Don't log access to assets
location ~ \.wasm$ {
default_type application/wasm;
}
}
location ~ \.woff2?$ {
try_files $uri /index.php$request_uri;
expires 7d; # Cache-Control policy borrowed from `.htaccess`
access_log off; # Optional: Don't log access to assets
}
# Rule borrowed from `.htaccess`
location /remote {
return 301 /remote.php$request_uri;
}
location / {
try_files $uri $uri/ /index.php$request_uri;
}
}
server {
listen 80;
listen [::]:80;
server_name example.com;
# Prevent nginx HTTP Server Detection
server_tokens off;
return 301 https://example.com$request_uri;
}
If you have not installed MariaDB, please refer to the following article: Installing and Managing MariaDB (MySQL) – Thinknote
Create a database to use with Nextcloud.
CREATE DATABASE nextcloud;
Create a new user. If you want to connect an existing user, you can omit it.
CREATE USER '[example example]'@'localhost' IDENTIFIED BY '[example]';
Grant permissions for the new database to the created user.
GRANT ALL PRIVILEGES ON [example example].* TO '[example example]'@'localhost';
Apply the changed permission settings.
FLUSH PRIVILEGES;
exit;
4) php requirements
To use Nextcloud, an additional PHP module is required. Below are the requirements presented in the Nextcloud manual.
PHP (see System requirements for a list of supported versions)
PHP module ctype
PHP module curl
PHP module dom
PHP module fileinfo (included with PHP)
PHP module filter (only on Mageia and FreeBSD)
PHP module GD
PHP module hash (only on FreeBSD)
PHP module JSON (included with PHP >= 8.0)
PHP module libxml (Linux package libxml2 must be >=2.7.0)
PHP module mbstring
PHP module openssl (included with PHP >= 8.0)
PHP module posix
PHP module session
PHP module SimpleXML
PHP module XMLReader
PHP module XMLWriter
PHP module zip
PHP module zlib
Enter the code below to install uninstalled modules. If PHP8 is not installed, please refer to the following article. Install PHP 8 (ubuntu) – Thinknote
Access the web installer on your domain and proceed with the installation.
https://example.com/setup-nextcloud.php
Article image 1
If the error Fatal error: Uncaught ValueError: Invalid or uninitialized Zip object in occurs, it is because the decompression path is /var/www/html. In this case, you must unzip and install it yourself. If it is unzipped, you can access it using the domain URL.
Article image 2
Installation is complete.
4. Check security and alerts
Log in as administrator and go to administrator settings. If a security and installation warning message appears at this time, please refer to the solutions for each item.
1) Errors related to file integrity
Uncomment clear_env = no in /etc/php/8.2/fpm/pool.d/www.conf
sudo nano /etc/php/8.2/fpm/pool.d/www.conf
clear_env = no #example
2) Error in system environment variable getenv(‘path’)
Check the list of files related to the integrity of the administrator settings and delete problematic files. Then run the code below to check if the integrity issue is resolved.
sudo -u www-data php occ integrity:check-core
3) PHP memory limitations
In php.ini, set the memory_limit value and upload_max_filesize to 512M or more.
Memory_limit = 1G
upload_max_filesize = 1G
4) Set country phone number
Add the following to the nextcloud config.php file:
This article is part of Thinknote’s English server and infrastructure archive. It focuses on practical Linux, Ubuntu, web-server, database, SSH, firewall, or hosting operations that readers can adapt to their own environment.
How should I use this guide?
Use it as a practical checklist and concept guide. Before applying commands on a live server, verify package names, OS versions, ports, and backup requirements for your own setup.
We ask the question, “Why?” This is because we are curious. Because we are curious. And various studies are conducted to obtain answers to interesting questions. To conduct research, you need data to create and test theories. There are quantitative and qualitative methods for verification. To use quantitative research methods, you must know numbers.
If you first understand what research is, the direction of R statistical learning becomes much clearer. Before you memorize statistical functions or analysis procedures, you need to know the overall flow of developing a research question, collecting data, and interpreting the results. This article summarizes the meaning and basic structure of research that beginners in R statistics must know.
Research Methods
I. Research methods
To answer an interesting question, you need to take the following steps:
Observation: The first step begins with observation. Observations can be stories that can be captured between actual events or people in everyday life.
Theory: Initially create a theory that explains the observations.
Hypothesis: Create a hypothesis to make a guess or inference from a theory. At this time, variables are defined and relationships between variables are established.
Data collection: Collect relevant data to logically verify the theory. The form of data may vary depending on the type of information that matches the variable.
Data analysis: Analyze collected data to verify or revise the theory.
Article image 2
Ⅱ. What is a meaningful hypothesis?
A good theory should be able to make statements (propositions) about the state of the world. In this case, the statement means something good. We make sense of the world through statements and make decisions that affect our future. Some statements can be verified through scientific activities, while others cannot be scientifically verified. Scientific statements can be confirmed or disproved by experiments. ‘IU is a popular singer’ – unscientific statement ‘IU is the singer with the highest album sales in Korea. ‘ – Scientific statement So, a meaningful hypothesis is one that creates a hypothesis that corresponds to a scientific statement with a good theory.
Ⅲ. Verification and disproof
In scientific research, verification and falsification play a key role in the process of evaluating the validity of scientific theories and accumulating scientific knowledge. Both verification and falsification are important in scientific research, but their roles are different.
Verification: The process of finding data that supports a hypothesis or theory and thereby increasing reliability.
Counterevidence: The process of proving a hypothesis or theory wrong due to a single counterexample.
Ⅱ – 1. Verification
Verification is the process of confirming whether a particular theory or hypothesis is actually correct. If the data obtained through verification supports a hypothesis or theory, the reliability of that theory is strengthened. However, verification alone cannot prove that the theory is absolutely true, because other possible explanations may exist.
[Example] Law of universal gravitation: Isaac Newton’s law of universal gravitation explains the magnitude of gravitational force acting between two objects. To verify this, various experiments and observations were conducted. For example, by observing the orbital motion of planets or experimenting with objects falling on Earth, the results predicted by Newton’s laws were compared with the actual results. Through these numerous successful verification cases, it is accepted that the law of universal gravitation exists.
Ⅲ – 2. Falsification
Falsification is the process of proving that a specific theory or hypothesis is wrong. Philosopher Karl Popper argued that falsifiability is important in scientific methodology. This is because no hypothesis can be proven completely true by an infinite number of test cases, but it can be proven wrong by a single counterexample.
[Example] Ether theory: Until the end of the 19th century, it was believed that light propagated through a medium called ‘ether.’ However, the Michelson-Morley experiment proved that light can propagate in a vacuum without ether. Ultimately, the ether theory was disproved. Accordingly, a new understanding of light became necessary, which led to Einstein’s theory of relativity.
Good article to read together
str_squish function to remove unnecessary spaces
Creative thinking has become more important in the AI era, and the power of questions and perspectives spoken of by Dr. Jeongwoon Kim
Human Values in the AI Era: What should people who cannot be replaced prepare?
Key Checklist
Is the research question clear?
Are the research object and scope determined?
Does the data collection method connect to the research question?
Have you decided on what criteria to interpret the analysis results?
Good R statistics articles to read together
Research Method Introduction to R Statistics: Understanding research design and analysis methods at a glance
Variables and Measurement R Statistics: Understanding independent variables, dependent variables and measurement levels
Measurement Error R Statistics: Easily Understand Random Error and Systematic Error
Validity/Reliability R Statistics: Criteria for judging a good measurement tool
Related Reading
Continue with these related Thinknote English articles in the Data Analysis cluster.
This article is part of Thinknote’s English R statistics and data-analysis archive. It explains research, measurement, text processing, or tidyverse-style workflow concepts in practical language.
How should I use this guide?
Use it as a learning note and starter reference. When applying code, adjust package versions, object names, and dataset structure to your own R environment.
In order to collect data to test a theory, you must be able to answer two questions: 1) What to measure? and 2) How to measure it? In other words, to clarify the purpose and method of data collection, you must understand variables and measurements. In research, variables refer to elements that researchers observe or measure, and variables allow researchers to explain or predict specific phenomena. When designing a study, clearly defining various types of variables and controlling and analyzing them appropriately can lead to more reliable and valid research results.
Variables and measurements are the starting point of R statistical analysis. Failure to distinguish between independent and dependent variables or misunderstanding the level of measurement can affect both the choice of analysis method and the interpretation of results. This article easily summarizes the role of variables and nominal, ordinal, interval, and ratio scales, and explains why they are important in R statistics.
Ⅰ. Types of Variables [Variables and Measurements]
Ⅰ-1. Independent Variable
Independent variable: A variable manipulated by the researcher that serves to provide a cause. An independent variable is a variable that a researcher manipulates or changes to observe its effects. It is considered a cause in an experiment and acts as a factor that affects the dependent variable.
Example: Let’s say your experiment examines the effect of light on plant growth. In this case, the amount of light (e.g. 4, 8, or 12 hours per day) is the independent variable. Researchers adjust the amount of light to see how it affects plant growth.
Ⅰ-2. Dependent Variable
Dependent variable: An outcome variable that changes depending on changes in the independent variable. The dependent variable is the outcome or response variable that the researcher wishes to measure. In other words, it is a variable that changes depending on changes in the independent variable, and the impact of the independent variable can be evaluated by looking at how the dependent variable changes.
Example: In the plant growth experiment mentioned earlier, the degree of plant growth (e.g. height, number of leaves) is the dependent variable. Here, we measure how the degree of plant growth (dependent variable) changes as the amount of light (independent variable) changes.
Ⅰ-3. Parameter (Mediator Variable)
Mediating variable: A variable that mediates or explains the relationship between an independent variable and a dependent variable. Mediating variables help us understand how an independent variable conveys its influence on a dependent variable. It plays an important role when researchers explore the mechanism between independent and dependent variables.
Example: In a plant growth experiment, the amount of light (independent variable) can affect the degree of plant growth (dependent variable) through the plant’s photosynthetic rate (parameter). Here, the rate of photosynthesis changes as the amount of light increases, which in turn affects the degree of plant growth.
Ⅰ-4. Control Variable
Control variable: A variable that is kept constant in a study so as not to affect the results of the experiment. By holding the control variables constant, we can measure the net effect of the independent variable on the dependent variable. Control variables are important to increase the reliability of research results.
Example: In a plant growth experiment, temperature, amount of water, soil type, etc. are control variables. By keeping these variables constant, we can clearly see how the amount of light affects plant growth.
Ⅰ-5. Predictor Variable
Predictor variable: A variable that is expected to affect changes in the dependent variable. Predictor variables are variables that researchers manipulate or observe and are used when making predictions about the dependent variable. This plays an important role in explaining or predicting changes in dependent variables.
Example: In a weight loss study, predictors could include exercise amount, diet, and sleep time. Here we will analyze how these predictors affect weight loss (dependent variable).
Ⅰ-6. Outcome Variable
Outcome variable: This is the main variable that the researcher wants to measure as a result of changes in the predictor variable. Outcome variables describe responses or changes that occur under specific situations or conditions, and through them, the impact of predictor variables can be evaluated.
Example: In a study of academic achievement, a student’s test score is the outcome variable. In this case, we evaluate how study time or study method (predictor variable) affects test scores (outcome variable).
Ⅱ. Level of measurement [variables and measurements]
The measurement level refers to the relationship between the measurement object and the value it represents. Variables can be divided into categorical variables and continuous variables.
Ⅱ-1. Categorical Variable
Categorical variables are when data is divided into several fixed categories or groups. Each value represents a specific category, and there is no concept of order or size among these values.
example:
Gender: Male, Female
Blood type: Type A, B, AB, O
Housing type: Apartment, single-family home, villa Categorical variables can be further divided into nominal and ordinal.
Ordinal variables: ordered categories (e.g. level of education – elementary school, middle school, high school)
Ⅱ-2. Continuous Variable
A continuous variable is a variable that can have any real number within a specific range. These values are measurable and the concepts of order and size exist among numbers. When dealing with continuous variables, various statistical techniques can be used, and data are analyzed using measures such as mean, standard deviation, and variance.
example:
Height (cm): 170.5 cm
Weight (kg): 65.3 kg
Temperature (°C): 22.4°C
Categorical variables can be divided into interval, ratio, and discrete types.
Interval variable: A variable that has continuous values with constant differences between values but no absolute zero (e.g. temperature (Celsius or Fahrenheit), IQ score, date)
Ratio variable: A variable that has continuous values, the difference between the values is constant, and has an absolute zero point (e.g. weight, height, age, income)
Discrete variable: A variable expressed as a non-continuous integer (e.g. number of students, number of cars, number of people in the household)
Variables and Measurements
Good article to read together
1. What is research? [R Statistics]
3. Measurement error [R statistics]
4. Validity, reliability [R statistics]
5. Research method [R statistics]
Importance and usage of pipe operator %>%
Key Checklist
Have you distinguished between independent and dependent variables?
Are control variables or parameters needed?
Have you checked the measurement level of each variable?
Have you chosen an analysis method appropriate for the level of measurement?
Good R statistics articles to read together
What is research: Summary of research concepts for introduction to R statistics
Research Method Introduction to R Statistics: Understanding research design and analysis methods at a glance
Measurement Error R Statistics: Easily Understand Random Error and Systematic Error
Validity/Reliability R Statistics: Criteria for judging a good measurement tool
Related Reading
Continue with these related Thinknote English articles in the Data Analysis cluster.
This article is part of Thinknote’s English R statistics and data-analysis archive. It explains research, measurement, text processing, or tidyverse-style workflow concepts in practical language.
How should I use this guide?
Use it as a learning note and starter reference. When applying code, adjust package versions, object names, and dataset structure to your own R environment.
To test a hypothesis, it is important to accurately measure and analyze data. However, measurement errors often occur during the measurement process. Measurement error refers to the difference between the value we actually intend to measure and the actually measured value.
The concept of measurement error R statistics is essential when judging the reliability of research results. Even if the same object is measured, values may vary depending on the tool, environment, and respondent status, and these differences affect the analysis results. This article summarizes the difference between random error and systematic error, and basic methods for reducing error.
These errors can affect the interpretation of results and drawing conclusions, so they are a very important factor in hypothesis testing. To minimize and control measurement errors, experimental design must be carefully designed, instruments must be regularly calibrated, random errors must be averaged through repeated measurements, and systematic causes must be identified and corrected. Measurement error is generally divided into systematic error and random error.
systematic error
Ⅰ. Systematic Error
Systematic error is an error that consistently occurs in a specific direction and shows the same pattern even in repeated measurements. Since this affects repeated measurements in the same way, it does not disappear when averaging. These errors are mainly caused by defects in measuring equipment, changes in environmental conditions, or problems with the experimental method itself.
Predictability: Systematic errors have a certain pattern and are therefore predictable.
Modifiable: Once the cause is identified, it can be modified.
Ⅰ – 1. Types of systematic errors
Instrumental Error: This is an error that occurs due to defects or imperfections in the measurement equipment itself. For example, a scale may always read higher by a certain amount, or a thermometer may consistently read lower than the actual temperature.
Environmental Factors: Occur when environmental conditions change or specific environmental conditions continue to have an impact. For example, changes in temperature or humidity may affect measuring devices, or there may be electromagnetic interference.
Procedural or Methodological Errors: Errors that occur due to problems with the experiment or measurement method itself. This can occur, for example, if the method of collecting samples is inconsistent or if a particular experimental procedure is set up incorrectly.
Human Error: This is when the person performing the measurement consistently operates or records incorrectly in the same way. This can mainly be caused by lack of training or carelessness.
Confounding Variables: In experimental design, uncontrolled variables affect the results. This can occur especially frequently in social science research or life science research.
Ⅰ – 2. Systematic error minimization strategy
Systematic errors are, by their very nature, difficult to detect and correct. Therefore, several strategies are needed to minimize this:
Calibration of Instruments: Calibrate equipment periodically to maintain accuracy.
Standardization: Standardize experiments and measurement procedures so that they can be performed under the same conditions.
Control of Environmental Conditions: Maintain or control environmental factors as constant as possible.
Training and Education: Reduce human error by providing sufficient training and education to those performing measurements.
Blind Testing: Blind testing techniques can be used to prevent researchers from having preconceptions about the results.
Reducing systematic errors is very important to increase the reliability of research and experimental results. To this end, it is important to use various methods to obtain as accurate and consistent data as possible.
Ⅱ. Random Error
Random errors are unpredictable errors that inevitably occur during the measurement process and appear in different sizes and directions for each measurement. These errors can disappear or be minimized when averaged over repeated measurements. It mainly occurs due to small changes in the environment, small changes in experimental conditions, or natural factors.
Predictability: Random errors are unpredictable and do not show a consistent pattern.
Correctability: Taking averages over repeated measurements can reduce the impact of random error.
Ⅱ – 1. Types of random errors
Environmental Factors: Occurs when environmental conditions fluctuate slightly. For example, small changes in wind strength or temperature can affect measurement results.
Limitations of Measuring Instruments: Occur when the resolution or precision of the instrument is limited. For example, a digital scale may have a limited number of decimal places.
Sample Variability: Occurs when the sample itself is inconsistent. For example, even the same chemical substance shows slightly different properties.
Human Minor Errors: These are small errors that occur when humans perform measurements. For example, this includes slight errors in reading scales or hand tremors.
Ⅱ – 2. Random error minimization strategy
Random error is difficult to completely eliminate due to its nature, but several strategies can be used to minimize it:
Repeated Measurements: Reduce random errors by measuring multiple times under the same conditions and calculating the average value.
Use of High-Quality Instruments: Overcome the limitations of measuring instruments by using high-precision equipment.
Control Environmental Conditions: Minimize the influence of external factors by keeping environmental conditions as constant as possible.
Adherence to Standard Procedures: Obtain consistent results by strictly following standardized procedures.
Data Processing Techniques: Analyze and remove randomness in data using statistical methods.
Understanding the characteristics and causes of both random and systematic errors and responding appropriately is a key factor in increasing the accuracy and reliability of research and experiment results.
Good article to read together
1. What is research? [R Statistics]
2. Variables and Measurements [R Statistics]
4. Validity, reliability [R statistics]
5. Research method [R statistics]
Importance and usage of pipe operator %>%
Key Checklist
Are measurement tools used consistently?
Is there any possibility of errors occurring in the respondents, survey environment, and recording process?
Have you distinguished between random and systematic errors?
Are there preliminary inspection procedures to reduce errors?
Good R statistics articles to read together
What is research: Summary of research concepts for introduction to R statistics
Variables and Measurement R Statistics: Understanding independent variables, dependent variables and measurement levels
Validity/Reliability R Statistics: Criteria for judging a good measurement tool
Research Method Introduction to R Statistics: Understanding research design and analysis methods at a glance
Related Reading
Continue with these related Thinknote English articles in the Data Analysis cluster.
This article is part of Thinknote’s English R statistics and data-analysis archive. It explains research, measurement, text processing, or tidyverse-style workflow concepts in practical language.
How should I use this guide?
Use it as a learning note and starter reference. When applying code, adjust package versions, object names, and dataset structure to your own R environment.
A study with high validity actually measures exactly what it was intended to do, but high reliability is necessary to maintain high validity and provide stable results even in repeated situations.
The concepts of validity and reliability R statistics are key criteria for judging a good measurement tool. High reliability does not always mean high validity, and it must be checked whether the measurement is appropriate for the purpose of the study and whether repeated measurements produce consistent results. This article explains the differences between the two concepts and the criteria to check in actual research.
Ⅰ. feasibility
Validity refers to how accurately a measurement tool or method in research actually measures what it is intended to measure.
Content Validity: Concept: Content validity evaluates whether a measurement tool contains all important content for the research topic or purpose. Example: For example, if there is a test that evaluates students’ math skills, the process of evaluating content validity is to check whether the test includes only addition and subtraction problems or whether it includes all various mathematical concepts such as multiplication, division, and geometry.
Criterion-related Validity: Concept: Criterion-related validity evaluates the validity of a measurement tool through correlation with a specific criterion (or external measure). Types and examples: Concurrent Validity: Evaluation compared to standards at the current time. For example, if a new depression test shows a high correlation with an existing, validated depression test, it can be said to have high concurrent validity. Predictive Validity: Evaluation compared to future standards. For example, if college entrance exam scores are a good predictor of job achievement after graduation, the test has high predictive validity.
Construct Validity: Concept: Construct validity evaluates whether a measurement tool actually reflects the theoretical construct well. Example: The process of reviewing structural validity is to check whether the questionnaire intended to measure ‘self-esteem’ is composed of questions that actually reflect self-esteem. For this purpose, various statistical analysis techniques (e.g. factor analysis) can be used.
Ecological Validity: Concept: Ecological validity means whether research results can be equally applied in the real world. Example: If the results of a memory test performed in a laboratory environment show the same memory pattern in everyday life, it can be said to have high ecological validity.
Concept: Content validity evaluates whether a measurement tool contains all important content for the research topic or purpose.
Example: For example, if there is a test that evaluates students’ math skills, the process of evaluating content validity is to check whether the test includes only addition and subtraction problems or whether it includes all various mathematical concepts such as multiplication, division, and geometry.
Concept: Criterion-related validity evaluates the validity of a measurement tool through its correlation with a specific criterion (or external measure).
Types and examples: Concurrent Validity: Evaluation compared to standards at the current time. For example, if a new depression test shows a high correlation with an existing, validated depression test, it can be said to have high concurrent validity. Predictive Validity: Evaluation compared to future standards. For example, if college entrance exam scores are a good predictor of job achievement after graduation, the test has high predictive validity.
Concurrent Validity: Evaluation compared to standards at the current time. For example, if a new depression test shows a high correlation with an existing, validated depression test, it can be said to have high concurrent validity.
Predictive Validity: Evaluation compared to future standards. For example, if college entrance exam scores are a good predictor of job achievement after graduation, the test has high predictive validity.
Concept: Structural validity evaluates whether a measurement tool actually reflects the theoretical construct.
Example: The process of reviewing structural validity is to check whether the questionnaire intended to measure ‘self-esteem’ is composed of questions that actually reflect self-esteem. For this purpose, various statistical analysis techniques (e.g. factor analysis) can be used.
Concept: Ecological validity refers to whether research results can be equally applied in the real world.
Example: If the results of a memory test performed in a laboratory environment show the same memory pattern in everyday life, it can be said to have high ecological validity.
feasibility
Ⅱ. reliability
Reliability refers to whether a measurement tool or method in research consistently produces results. In other words, the degree to which similar results are obtained when measured repeatedly under the same conditions is evaluated.
Internal Consistency: Concept: Internal consistency evaluates how well the items in a measurement tool reflect the same concept. Example: If a questionnaire consists of 10 questions, and all of these questions measure ‘self-esteem,’ internal consistency can be said to be high only when the correlation between each question is high. To evaluate this, Cronbach’s α coefficient is often used.
Test-Retest Reliability: Concept: Retest reliability evaluates how consistent the results are when the same measurement tool is repeatedly applied to the same subject at regular time intervals. Example: When a psychological test is administered to the same person twice, two months apart, if the scores on both tests are similar, the test’s test-retest reliability can be said to be high.
Parallel-Forms Reliability: Concept: Parallel-Forms Reliability evaluates the consistency between two different forms of measurement tools designed to measure the same concept. Example: When there is a type A test paper and a type B test paper that evaluates mathematical ability, if the scores obtained when evaluating the same students with the two test papers are similar, the reliability of the alternative form can be said to be high.
Inter-Rater Reliability: Concept: Inter-rater reliability refers to how consistent the results are when different evaluators independently evaluate the same object. Example: When several psychologists watch a recording of a counseling session for the same patient and each rate the level of depression, if their ratings are similar, inter-rater reliability can be said to be high.
Split-Half Reliability: Concept: Split-Half Reliability is a method of evaluating the consistency of the entire test by dividing the data obtained from one test into half and finding a correlation between the scores of each half. Example: In a cognitive ability test consisting of 20 questions, if there is a high correlation between the scores of each part of the first 10 questions and the last 10 questions, the reliability of the split response can be said to be high.
Concept: Internal consistency evaluates how well the items in a measurement tool reflect the same concept.
Example: If a questionnaire consists of 10 questions, and all of these questions measure ‘self-esteem,’ internal consistency can be said to be high only when the correlation between each question is high. To evaluate this, Cronbach’s α coefficient is often used.
Concept: Test-retest reliability evaluates how consistent the results are when the same measurement tool is repeatedly applied to the same subject at certain time intervals.
Example: When a psychological test is administered to the same person twice, two months apart, if the scores on both tests are similar, the test’s test-retest reliability can be said to be high.
Concept: Alternative reliability assesses the consistency between two different types of measurement instruments designed to measure the same concept.
Example: When there is a type A test paper and a type B test paper that evaluates mathematical ability, if the scores obtained when evaluating the same students with the two test papers are similar, the reliability of the alternative form can be said to be high.
Concept: Inter-rater reliability refers to how consistent the results are when different evaluators independently evaluate the same object.
Example: When several psychologists watch a recording of a counseling session for the same patient and each rate the level of depression, if their ratings are similar, inter-rater reliability can be said to be high.
Concept: Split response reliability is a method of evaluating the consistency of the entire test by dividing the data obtained from one test into half and finding a correlation between the scores of each half.
Example: In a cognitive ability test consisting of 20 questions, if there is a high correlation between the scores of each part of the first 10 questions and the last 10 questions, the reliability of the split response can be said to be high.
Good article to read together
1. What is research? [R Statistics]
2. Variables and Measurements [R Statistics]
3. Measurement error [R statistics]
5. Research method [R statistics]
Importance and usage of pipe operator %>%
Key Checklist
Is the measurement tool appropriate for the research purpose?
Do repeated measurements produce similar results?
Isn’t this a situation where reliability is high but validity is low?
Has the validity been confirmed through existing research or expert review?
Good R statistics articles to read together
What is research: Summary of research concepts for introduction to R statistics
Variables and Measurement R Statistics: Understanding independent variables, dependent variables and measurement levels
Measurement Error R Statistics: Easily Understand Random Error and Systematic Error
Research Method Introduction to R Statistics: Understanding research design and analysis methods at a glance
Related Reading
Continue with these related Thinknote English articles in the Data Analysis cluster.
This article is part of Thinknote’s English R statistics and data-analysis archive. It explains research, measurement, text processing, or tidyverse-style workflow concepts in practical language.
How should I use this guide?
Use it as a learning note and starter reference. When applying code, adjust package versions, object names, and dataset structure to your own R environment.
Research method refers to a systematic and organized procedure in which a researcher explores a specific research topic or problem, collects and analyzes data, and draws conclusions. Research methods can be divided into quantitative research and qualitative research. Research methods vary by academic field, and in each field, various methodologies and tools tailored to its characteristics are developed and used.
Research Method R Statistics learning begins with understanding the research design before the analysis technique. The statistical method you use will depend on what questions you ask, what data you collect, and how you interpret the results. This article explains the differences between quantitative and qualitative research, cross-sectional and longitudinal research, and correlational and experimental research by linking them to the R statistical learning flow.
Ⅰ. Quantitative Research
Ⅰ – 1. Types and Features:
Quantitative research is a research method that analyzes and interprets phenomena through numerical data.
Purpose: The purpose is to verify hypotheses, clearly identify relationships between variables, and build a prediction model through generalization.
Data collection method: Data is collected from a large sample through methods such as surveys, experiments, and observations.
Analysis method: Data analysis is performed using statistical techniques and mathematical models.
Ⅰ – 2. Example of use:
A study that analyzes the results of standardized tests administered nationally to assess the academic performance of students.
Marketing research that examines the relationship between changes in market share of a specific product and consumer satisfaction.
In the medical field, research that analyzes clinical trial data to verify the effectiveness of a specific drug.
Ⅱ. Qualitative Research
Ⅱ – 1. Types and characteristics:
Qualitative research is a research method that seeks to deeply understand human behavior, experience, and social phenomena through non-numerical data.
Purpose: Focus on deep understanding of complex phenomena or contexts and creation of new theories.
Data collection method: Data are collected from a small sample through interviews, participant observation, and document analysis.
Analysis method: Classify and interpret by topic, and derive results through narrative or case study methods.
Ⅱ – 2. Example of use:
Medical sociology research that explores patients’ treatment experiences and emotions through in-depth interviews.
Anthropological research that investigates through participant observation how culture and traditions are maintained and changed within a specific community.
Focus group interview study to explore organizational culture and job satisfaction of employees within a company.
Research method
Ⅲ. Longitudinal Study
Ⅲ – 1. Types and Features:
Longitudinal research is a research method that tracks changes over time by repeatedly examining the same group over a long period of time.
Purpose: To identify patterns of change or development over time and to clearly identify the relationship between cause and effect.
Data collection point: Collect data repeatedly at multiple points in time to track trends and changes.
Advantages and limitations: It is possible to understand the individual change process in detail, but it is time consuming and expensive.
Ⅲ – 2. Example of use:
Growth and development research that periodically examines the growth and development process of children from infancy to adolescence.
Human resource management research that tracks and analyzes career development and job satisfaction changes in specific occupational groups over a long period of time.
Medical research that evaluates long-term health outcomes in patients with chronic diseases by tracking treatment effectiveness and lifestyle changes.
Ⅳ. Correlation Study
Ⅳ – 1. Types and characteristics:
Correlational research is a research method that determines the relationship between two variables.
Purpose: To determine the relationship between variables and how changes in one variable affect other variables.
Interpretation of results: Measure the strength and direction of the relationship between two variables through the correlation coefficient. The correlation coefficient has values from -1 to +1, with +1 meaning a completely positive correlation and -1 meaning a completely negative correlation.
Causality: Correlational studies do not prove causality; they simply show whether variables change together.
Ⅳ – 2. Example of use:
A study examining the relationship between students’ study time and grades.
A study analyzing the relationship between smoking amount and lung cancer incidence.
A study exploring the relationship between income level and happiness index.
Ⅴ. Cross-sectional Study
Ⅴ – 1. Types and Features:
Cross-sectional research is a research method that collects data by investigating a group with one or more characteristics at a specific point in time.
Purpose: To determine the status or distribution among various variables at a specific point in time.
Data collection point: Since data is collected at a single point in time, temporal changes or trends are not reflected.
Ease of comparison: Easy to compare various groups (e.g. age group, gender, etc.).
V – 2. Example of use:
A study that examines the health status and lifestyle habits of a population of a specific age.
A study that analyzes the differences between the education and income levels of residents of various regions within a country.
A study that simultaneously surveys multiple populations to determine the prevalence of a specific disease.
Ⅵ. Behavioral Experimentation
Ⅵ – 1. Types and Features:
Behavioral experimentation is a research method that attempts to understand psychology or human behavior patterns by inducing and observing the behavioral responses of subjects in an experimental environment.
Purpose: To measure the behavioral responses of humans or animals under specific stimuli or conditions and to verify theories or make new discoveries based on this.
Data collection method: Depending on the experimental design, various stimuli or tasks are provided to experimental participants in a controlled environment and their responses are recorded.
Analysis method: Experiment results are statistically analyzed and used to verify hypotheses or derive theories.
Ⅵ – 2. Example of use:
A marketing experiment to determine the impact of a specific advertising message on consumers’ purchase intentions.
A psychological experiment to assess the effects of stress on work performance.
In the field of neuroscience, experiments are conducted to measure brain activity and record behavioral responses using various technologies such as electromagnetic waves to understand the relationship between brain activity and behavior.
Good article to read together
1. What is research? [R Statistics]
2. Variables and Measurements [R Statistics]
3. Measurement error [R statistics]
4. Validity, reliability [R statistics]
Importance and usage of pipe operator %>%
Key Checklist
Is the research purpose closer to exploration, explanation, or verification?
Do you need quantitative or qualitative data?
Which design is better: cross-sectional data or longitudinal data?
Are you distinguishing between correlation and causation?
Good R statistics articles to read together
What is research: Summary of research concepts for introduction to R statistics
Variables and Measurement R Statistics: Understanding independent variables, dependent variables and measurement levels
Measurement Error R Statistics: Easily Understand Random Error and Systematic Error
Validity/Reliability R Statistics: Criteria for judging a good measurement tool
Related Reading
Continue with these related Thinknote English articles in the Data Analysis cluster.
This article is part of Thinknote’s English R statistics and data-analysis archive. It explains research, measurement, text processing, or tidyverse-style workflow concepts in practical language.
How should I use this guide?
Use it as a learning note and starter reference. When applying code, adjust package versions, object names, and dataset structure to your own R environment.