[R] Importing, viewing and screening imported data

Install and load the package psych and forcats

install.packages(“psych”)

library(“psych”)

Load data

#Load the UCBAdmissions data
data("UCBAdmissions")
head(UCBAdmissions)

Explore the data set

#Explore the dataset using the commands mentionned in the word file
summary(UCBAdmissions)
describe(UCBAdmissions)
table(UCBAdmissions)
str(UCBAdmissions)

summary(UCBAdmissions):

  • Function: Provides a summary of the main statistical measures for each variable in the dataset
Number of cases in table: 4526 
Number of factors: 3 
Test for independence of all factors:
	Chisq = 2000.3, df = 16, p-value = 0

describe(UCBAdmissions):

  • Function: Generates a comprehensive summary of the dataset, including measures of central tendency, spread, and other statistics
Error in describe(UCBAdmissions) : 没有"describe"这个函数

why error? 

The describe() function from the "Hmisc" package is generally used for data frames, not for tables. If you have a data frame, you can use describe() to get a comprehensive summary of the variables. However, if you have a table, you might use other functions like summary(), str(), or specific functions designed for tables.

table(UCBAdmissions):

  • Function: Creates a contingency table, showing the frequency of occurrences of each combination of variable values.
    UCBAdmissions
      8  17  19  22  24  53  89  94 120 131 138 202 205 207 244 279 299 313 317 351 353 
      1   1   1   1   1   1   1   1   1   1   2   1   1   1   1   1   1   1   1   1   1 
    391 512 
      1   1 

str(UCBAdmissions):

Function: Provides the structure of the dataset, displaying the data type and the first few values of each variable.

 'table' num [1:2, 1:2, 1:6] 512 313 89 19 353 207 17 8 120 205 ...
 - attr(*, "dimnames")=List of 3
  ..$ Admit : chr [1:2] "Admitted" "Rejected"
  ..$ Gender: chr [1:2] "Male" "Female"
  ..$ Dept  : chr [1:6] "A" "B" "C" "D" ...

After explore the structure

The structure may not be well organized for R and statistic analysis. 

str()

library(forcats)
#load the gss_cat data (remember you need to load forcats first)
data("gss_cat")
head(gss_cat)
#Use the string command to know the number of levels in the variable rincome
str(gss_cat$rincome)

You may see info like

"No answer","Don't know",
Factor w/ 16 levels "No answer","Don't know",..: 8 8 16 16 16 5 4 9 4 4 ...

after the str() function, these info should be merged into "NA" for analysis.

the levles command

#Use the levles command to know what is the ninth level of the variable rincome
levels(gss_cat$rincome)
 [1] "No answer"      "Don't know"     "Refused"       
 [4] "$25000 or more" "$20000 - 24999" "$15000 - 19999"
 [7] "$10000 - 14999" "$8000 to 9999"  "$7000 to 7999" 
[10] "$6000 to 6999"  "$5000 to 5999"  "$4000 to 4999" 
[13] "$3000 to 3999"  "$1000 to 2999"  "Lt $1000"      
[16] "Not applicable"

rincome is a not well ordered variable
#(the first three should be in NA ), and be put after all the ranges. (which will be taught in the next article)

to get the info and calculate

# What is the proportion of buddhist believers
table(gss_cat$marital)
table(gss_cat$relig)
147/21483*100
#What is the 9th label in the variable relig
levels(gss_cat$relig)

shapiro.test()

shapiro.test is a statistical test in R used to assess the normality of a univariate data sample. The test is based on the Shapiro-Wilk W statistic, which tests the null hypothesis that a given sample comes from a normally distributed population. Here is an overview of the functionality of shapiro.test:

# Perform the Shapiro-Wilk test
shapiro.test(data)
Shapiro-Wilk normality test

data:  USArrests$Murder
W = 0.95703, p-value = 0.06674

Interpretation:

  • If the p-value is less than the significance level (commonly 0.05), you would reject the null hypothesis, suggesting that the data does not follow a normal distribution.
  • If the p-value is greater than the significance level, you would fail to reject the null hypothesis, indicating that there is not enough evidence to conclude that the data deviates significantly from a normal distribution.

So it is useful to detect whether the dataset is worth using. Remember, the choice of the 0.05 significance level is somewhat arbitrary, and it's a common convention. The interpretation of p-values is always relative to the chosen significance level. A p-value close to 0.05 may indicate that there is some evidence against the null hypothesis, but the decision to reject or not depends on the specific threshold set by the researcher.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/333399.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

杂记 | 在Linux上使用Docker-compose安装单机版Milvus向量数据库并配置访问控制和可视化面板(Attu)

文章目录 01 Milvus向量数据库简介02 安装前的准备03 安装3.1 创建milvus工作目录3.2 下载并编辑docker-compose.yml3.3 下载milvus.yml文件3.4 启动milvus 04 访问可视化面板并修改密码 01 Milvus向量数据库简介 Milvus是一款开源的向量数据库,它专为AI应用设计&a…

移动端 h5-table react版本支持虚拟列表

介绍 适用于 react ts 的 h5 移动端项目 table 组件 github 链接 :https://github.com/duKD/react-h5-table 有帮助的话 给个小星星 有两种表格组件 常规的: 支持 左侧固定 滑动 每行点击回调 支持 指定列排序 支持滚动加载更多 效果和之前写的vue…

聚类模型评估指标

聚类模型评估指标-轮廓系数 计算样本i到同簇其它样本到平均距离ai,ai越小,说明样本i越应该被聚类到该簇(将ai称为样本i到簇内不相似度);计算样本i到其它某簇Cj的所有样本的平均距离bij,称为样本i与簇Cj的…

鉴源实验室|自动驾驶仿真测试技术分析

01 引言 随着科技的不断发展,自动驾驶技术逐渐成为汽车行业的热门话题。然而,要将自动驾驶车辆投放到真实道路上之前,必须进行广泛的测试,以确保其在各种情况下都能安全可靠地运行。自动驾驶车辆的测试是一个复杂而昂贵的过程。…

AQY212S光耦合器:特性和应用揭秘

在不断发展的电子元件领域,AQY212S光耦合器作为适合众多应用的多功能且可靠的解决方案脱颖而出。作为光耦合器技术专家,让我们深入研究AQY212S的功能和应用,揭开这款令人印象深刻的器件的神秘面纱。 AQY212S是一款固态继电器(SSR)光耦合器&a…

【docker-compose】【nginx】内网环境https配置

目录 1、openssl生成自签名证书和私钥2、nginx.conf配置ssl3、docker-compose挂载 1、openssl生成自签名证书和私钥 在部署服务器上,新建cert目录,执行以下指令,然后生成.crt和.key文件 openssl req -newkey rsa:2048 -nodes -keyout rsa_pri…

2023年全球软件架构师峰会(ArchSummit深圳站):核心内容与学习收获(附大会核心PPT下载)

本次峰会是一次重要的技术盛会,旨在为全球软件架构师提供一个交流和学习的平台。本次峰会聚焦于软件架构的最新趋势、最佳实践和技术创新,吸引了来自世界各地的软件架构师、技术专家和企业领袖。 在峰会中,与会者可以了解到数字化、AIGC、To…

指针定义与使用

系列文章目录 指针定义与使用 指针定义与使用 系列文章目录一、指针的定义与使用二、相关案例 一、指针的定义与使用 指针 指针的定义和使用: 1、指针:是一种数据类型 指针变量也是一种变量 int* p int*是数据类型 p是指针变量 2、指针格式:…

webpack面试题学习

说说你对webpack的理解?解决了什么问题? 说说webpack的构建流程? 说说webpack中常见的Loader?解决了什么问题? 说说webpack中常见的Plugin?解决了什么问题? 说说Loader和Plugin的区别?编写Load…

代码随想录 Leetcode459. 重复的子字符串(KMP算法)

题目&#xff1a; 代码&#xff08;首刷看解析 KMP算法 2024年1月18日&#xff09;&#xff1a; class Solution { public:void getNext(string& s,vector<int>& next) {int j 0;next[0] j;for (int i 1; i < s.size(); i) {while (j > 0 && s…

x-www-form-urlencoded接收方式代码示例

数据回推方式是 “x-www-form-urlencoded”&#xff0c;可以选择使用 GET 或 POST 方法来接收数据回推。 使用 GET 方法接收数据回推时&#xff0c;您可以将数据作为查询参数附加在请求的 URL 中。例如&#xff1a; http://example.com/callback?param1value1&param2val…

Redis高级系列-缓存双写一致性

Redis高级系列-缓存双写一致性 文章目录 Redis高级系列-缓存双写一致性1. 什么叫做缓存双写一致性&#xff1f;2. 缓存双写一致性有那些解决方案&#xff1f;2.1 Cache Aside Pattern(旁路缓存模式)延迟双删重试删除binlog订阅异步删除 2.2 Read Through/Write Through(读写穿透…

LightGlue: Local Feature Matching at Light Speed

一、论文概述 发表于&#xff1a; 2023 ICCV 作者信息&#xff1a;Philipp Lindenberger Paul-Edouard Sarlin Marc Pollefeys 对比算法&#xff1a;SuperGlue 代码&#xff1a;github.com/cvg/LightGlue 效果: 现有问题&#xff1a; 1&#xff09; SuperGlue 与其他基于 …

“尔滨”宠粉再升级!百亿像素VR冰雪盛宴

1月10日&#xff0c;由哈尔滨市委网信办、哈尔滨日报社主办&#xff0c;冰城客户端、哈尔滨新闻网承办的“激情迎亚冬&#xff0c;冰雪暖世界——2024年哈尔滨冰雪乐园”VR沉浸式体验产品正式上线。 如果你还没去过最近爆火出圈的“尔滨” ❄️这份哈尔滨冰雪景点VR❄️ 为你…

初识 Elasticsearch 应用知识,一文读懂 Elasticsearch 知识文集(4)

&#x1f3c6;作者简介&#xff0c;普修罗双战士&#xff0c;一直追求不断学习和成长&#xff0c;在技术的道路上持续探索和实践。 &#x1f3c6;多年互联网行业从业经验&#xff0c;历任核心研发工程师&#xff0c;项目技术负责人。 &#x1f389;欢迎 &#x1f44d;点赞✍评论…

HDClone X.5 新版功能亮点

在 HDClone X.4 版本的基础上,HDClone X.5 新版本推出了对网盘、映射磁盘等的镜像功能,让磁盘镜像更加如虎添翼。 创建卷的镜像:可将非物理介质作为卷,对其制作镜像,从而保护其中数据。挂载这些镜像后,即可直接访问其中的文件,设置的保护层可以确保文件不被更改。 用于存…

小程序系列--8.页面事件

一、下拉刷新事件 1. 什么是下拉刷新&#xff1f; 下拉刷新是移动端的专有名词&#xff0c;指的是通过手指在屏幕上的下拉滑动操作&#xff0c;从而重新加载页面数据的行为。 2. 启用下拉刷新 3. 配置下拉刷新窗口的样式 4. 监听页面的下拉刷新事件 在页面的 .js 文件中&am…

FastAPI 并发请求详解:提升性能的关键特性

在当今的数字化世界中&#xff0c;网络用户对于高速响应和持续连接的诉求日益显著。这促使了基于 Python 构建的 FastAPI 框架受到广泛关注&#xff0c;它不仅现代化且效率极高&#xff0c;而且简化了并行请求的处理。本篇文章旨在探讨 FastAPI 如何处理这类请求&#xff0c;并…

【遥感专题系列】影像信息提取之——面向对象的影像分类技术

“同物异谱&#xff0c;同谱异物”会对影像分类产生的影响&#xff0c;加上高分辨率影像的光谱信息不是很丰富&#xff0c;还有经常伴有光谱相互影响的现象&#xff0c;这对基于像素的分类方法提出了一种挑战&#xff0c;面向对象的影像分类技术可以一定程度减少上述影响。 本…
最新文章