使用R语言的make2x2函数生成列联表

R语言 专栏收录该内容
¥59.90 ¥99.00
110篇文章

使用R语言的make2x2函数生成列联表

在数据分析和统计学中,列联表(contingency table)是一种用于展示两个或多个分类变量之间关系的表格。在R语言中,我们可以使用make2x2函数来生成列联表。本文将详细介绍如何使用make2x2函数生成列联表,并提供相应的源代码示例。

首先,我们需要安装并加载R的epitools包,该包提供了make2x2函数的实现。可以使用以下命令安装epitools包:

install.packages("epitools")

安装完毕后,可以通过以下命令加载epitools包:

library(epitools)

接下来,我们准备数据用于生成列联表。假设我们有一个数据集,包含两个分类变量A和B,每个变量有两个水平(level)。我们可以使用以下代码创建一个示例数据集:

# 创建示例数据集
A <- c(1, 1, 2, 2, 1, 2, 1, 2)
B <- c(1, 2, 1, 2, 1, 2, 2, 1)

# 将A和B合并为一个数据框
data <- data.frame(A, B)

现在,我们可以使用make2x2函数生成列联表。make2x2函数接受两个向量作为输入,分别表示两个分类变量的水平。以下是使用make2x2函数生成列联表的代码:


        
使用R语言生成列联表基于make2x2函数 在上面的示例中,我们创建了两个向量var1和var2,分别表示两个分类变量的观测值。然后,我们使用make2x2函数将这两个变量传递给函数,并将结果存储在cont_table变量中。通过以上步骤,我们可以使用R语言中的make2x2函数生成列联表,并进行相关的统计分析。这些分析可以帮助我们理解和描述两个分类变量之间的关系,以及是否存在显著的相关性。除了交叉频数之外,列联表还可以提供其他有用的统计信息,例如卡方检验的结果。生成的列联表cont_table是一个二维表格,显示了两个分类变量之间的交叉频数。 阅读详情

相关推荐

R语言explore包进行探索性数据分析实战(EDA、exploratory data analysis):基于iris数据集

R语言explore包进行探索性数据分析实战(EDA、exploratory data analysis):基于iris数据集 目录 R语言explore包进行探索性数据分析实战(EDA、exploratory data analysis):基于iris数据集 #包的安装 #包和数据导入 #探索iris数据集的变量 #目标变量解析(构建决策树) #输出数据报告 #explore手动编码EDA分析 #泰坦尼克号数据示例 #包的安装 # install.packages("...

data+scenario+science+insight 803

R CrossTable生成二维列联表

对于二维列联表,table()函数的使用格式为: mytable <- table(A, B) 其中的A是行变量,B是列变量。除此之外,xtabs()函数还可使用公式风格的输入创建列联表, 格式为 使用gmodels包中的CrossTable()函数是创建二维列联表的第三种方法。CrossTable() 函数仿照SAS中PROC FREQ或SPSS中CROSSTABS的形式生成二维列联表。 > library(gmodels) > CrossTable(Arthritis$Trea

Mrrunsen的博客 4273

R语言使用table函数计算单分类变量的频率表(frequency table)、使用prop.table函数将table函数计算获得的频率表转化为比率表、返回单分类变量每一个类别的比率、或者百分比

R语言使用table函数计算单分类变量的频率表(frequency table)、使用prop.table函数将table函数计算获得的频率表转化为比率表、返回单分类变量每一个类别的比率、或者百分比、返回单分类变量每一个类别的百分比

data+scenario+science+insight 3701

R语言使用epiDisplay包的cc函数计算优势比(Odds Ratio,OR)的值及其置信区间并可视化(包含卡方检验和Fisher精确检验结果)、输入数据为生成的列联表基于make2x2函数

R语言使用epiDisplay包的cc函数计算优势比(Odds Ratio,OR)的值及其置信区间并可视化(包含卡方检验和Fisher精确检验结果)、输入数据为生成的列联表基于make2x2函数

statistics+insight+vista+power 987

R语言使用epiDisplay包的cs函数计算相对危险度(Relative Risk,RR)的值及其置信区间、输入数据为生成的列联表基于make2x2函数

R语言使用epiDisplay包的cs函数计算相对危险度(Relative Risk,RR)的值及其置信区间、输入数据为生成的列联表基于make2x2函数

statistics+insight+vista+power 704

R语言统计分析全流程:数据导入、统计检验与可视化实践

数据分析是科研与工程实践中的基础技能,R语言凭借丰富的统计函数和可视化能力成为首选工具。面对外部数据,正确读取CSV与Excel文件是分析的前提,read.csv与read_excel的参数设置直接影响数据质量。在数据清洗之后,t检验、卡方检验和线性回归等统计方法能够揭示变量间的关系,而ggplot2则可将结果直观呈现。合理封装统计函数有助于提升代码复用率和结果核验效率。本文以一份课程作业为线索,系统拆解R语言从数据导入、统计建模到图表输出的完整流程,帮助读者快速掌握可迁移到实际项目中的技术要点。

weixin_34199764的博客 142

epitools-icy:适用于生物成像平台的EpiTools插件

欢迎使用CellGraph(EpiTools的又名icy插件) CellGraph是用于生物成像框架的插件集合,可将骨架图像转换为交互式叠加层以浏览和分析您的数据(示例)。 CellGraph是EpiTools项目的一部分,EpiTools项目是一个用于量化上皮生长动力学的开源图像分析工具包。 要了解有关该项目的更多信息,请访问我们的项目网站或相关代码库: EpiTools主页: ://epitools.github.io 图像处理部分(MATLAB): : 如果您喜欢CellGraph并在工作中使用它,请引用我们在《发展细胞》(2016年1月)中的EpiTools论文,该论文可从免费获得。 插件细分 插件涵盖了分析的后续步骤: 从输入骨架文件开始生成时空图 使用户可以在剩余分割错误的情况下手动交互式地修改骨架图像 解释数据并以图形叠加层(即附加图像层)和表格文件的形式输出结

epitools:我对Ruby标准库的扩展

epitools 对基本Ruby对象的有用的杂项改进,以及一些额外的数据结构和方便的包装器。 您可以将其视为轻量级ActiveSupport。 所有Epitools模块(以及一堆Ruby的stdlib)都,因此速度非常快。 (在您的.irbrc或.pryrc文件中需要此文件,而您将不再需要另一个Ruby stdlib模块!) 增强的基类: , , , , , , 等。 附加功能: (文件系统的面向对象的接口–它是File,Dir,FileUtils和Pathname都合并为一个!) (伪造的浏览器,具有缓存,Cookie,下载进度栏,以及您熟悉和喜爱的其余机械化/ nokogiri API) (defunkt增强版本–向String添加ANSI着色方法,例如:#red,#green,#light_blue等) (与Struct类似,但setter始终将输入强

【RK3399】Android平台增加一款声卡设备(ES7210+ES8156),进行录音/播放测试。

文章目录前言一、开发环境二、概述三、硬件介绍1、ES72102、ES81563、数字麦克风阵列4、音频示意图四、下载SDK五、编译、烧写1、u-boot2、kernel3、Android SDK4、烧写分区5、烧写固件六、声卡驱动1、添加codec代码2、修改Kconfig3、修改Makefile4、修改rockchip_defconfig5、修改DTS七、声卡调试1、查看声卡注册信息2、使用tinycap/tinyplay录音和放音3、使用示波器观测八、修改HAL层1、修改默认capture/playba

rentong123的博客 2万+

跨时钟域传输数据——单bit和多bit信号(总结)

总结单bit和多bit信号的跨时钟域传输

qq_42135020的博客 1万+

从Podfile到分享成功:ShareSDK小红书模块集成全流程实战(附视频分享代码)

本文详细介绍了iOS应用如何通过ShareSDK集成小红书分享功能的全流程,包括环境配置、SDK初始化、图片和视频分享实现,以及常见问题排查和性能优化策略。特别针对视频分享这一高频需求场景,提供了完整的代码示例和实战技巧,帮助开发者快速实现社交分享功能。

weixin_42540248的博客 237

ANSYS Workbench实战:用网格自适应搞定超弹性橡胶大变形仿真(附避坑命令流)

本文深入探讨了ANSYS Workbench中超弹性橡胶大变形仿真的网格自适应技术,重点解析了混合U-P单元的应用、非线性自适应网格的实战技巧及材料模型选择的注意事项。通过具体案例和命令流示例,帮助工程师有效解决橡胶仿真中的收敛问题和网格畸变挑战,提升仿真精度和效率。

weixin_42666036的博客 306

⑩电子产品拆解分析-家用无线遥控开关433Mhz

①免布线随意贴,装上就能使用解决单线开关烦恼;②遥控配对简单,无线通讯距离长,信号可穿墙;

a6662580的博客 4757

超级全的PCB LAYOUT高速信号走线指南——简化应用版

在PCB Layout中,几乎涵盖了所有的高速信号走线指南。包括了TF/SD、HDMI、LVDS、DVP、eDP、MIPI、USB2.0、USB3.0、MAC、BT.1120、PCIE高速信号等等。此版本为简化版。

bhxc809751502的博客 8560

python:实现brutefore破解wifi(附完整源码)

python:实现brutefore破解wifi(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 5789

杰理外挂flash使用教程(四):制作fat32文件系统格式的资源文件

本文档提供了FAT文件系统镜像生成与资源打包的完整指南,包含两种实现方案:推荐的WSL/Ubuntu环境方案和Windows原生方案。详细说明了从创建空白镜像、格式化、资源文件复制到最终打包为设备可用的res.bin文件的完整流程,并对比了FAT32与FAT16的特性差异。文档还包含关键文件说明、使用注意事项和典型应用场景,适用于嵌入式系统开发、固件升级等场景。

qq_42014563的博客 1359

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

上一篇: R语言快速制作文献中线表-Table1表格
下一篇: 使用Shapiro-Wilk检验评估残差是否服从正态分布(R语言)
普通网友
博客等级 码龄3年 247粉丝 610原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址