R语言 多元线性回归 研究年龄、身高、体重的关系
- 0-20岁数据分析
data <- read.table('e://kg.txt',header = TRUE,sep = '\t')
data <- data %>% as_tibble()
data %>% attach()
data %>% ggplot(aes(cm, kg))+ geom_line()
data %>% ggplot(aes(age,cm))+ geom_line()
data %>% ggplot(aes(age,kg))+ geom_line()# age 与 height 与weight 关系:
data[1:3] %>% cor() %>% corrplot::corrplot(method = "color",addCoef.col = "grey")
lm_data <- data %>% lm(kg~I(cm^3),.)
lm_data %>% summary()
lm_data
plot(cm^3,kg,xaxt='n');
axis(1,at=cm^3,labels=cm);
abline(lm_data)# ggplot拟合
data %>% ggplot(aes(cm^3,kg)) + geom_point() + geom_smooth()
- 分性别数据分析
# https://zhuanlan.zhihu.com/p/94372177
# https://www.jianshu.com/p/a081a791ae03
# https://cloud.tencent.com/developer/article/1674211
# https://www3.nd.edu/~steve/computing_with_data/2_Motivation/motivate_ht_wt.html?spm=a2c4e.11153940.blogcont603256.20.333b1d6fYOsiOK
# 载入数据,数据集在这里下载:https://github.com/johnmyleswhite/ML_for_Hackers/blob/master/02-Exploration/data/01_heights_weights_genders.csv
library(tidyverse)
ht_weight_df <- read.table("e://01_heights_weights_genders.txt",header = TRUE,sep = "\t") %>% as_tibble()
ht_weight_df %>% mice::md.pattern()# 绘图查看相关性
ht_weight_df %>% select(-1) %>% cor() %>% corrplot::corrplot(method = "color",addCoef.col = "grey")
ht_weight_df %>% select(-1) %>% sample_frac(0.1) %>% plot(cex = 0.1)# 拟合检验线性相关
lm_ht_weight <- lm(Weight ~ Height, data = ht_weight_df)
lm_ht_weight %>% summary()
lm_ht_weight %>% abline()# 分性别对照
ht_weight_df %>% group_by(Gender) %>% dplyr::summarise( round( mean( Height)* 2.54))# subset(Gender == )也可选取组# fivenum() 不能[2]、select(2)# sapply()不能$变量、select(2)# psych::describe() 不能[2]# pastecs::stat.desc()、Hmisc::describe()、summary() 都可以# plyr::ddply(.(Gender), function(df) summary(df$Height))从原数据分组求值# 查看分布
par(mfrow = c(1,1))
ht_weight_df %>% subset(Gender == "Male") %>% select(Height) %>% unlist() %>% as.numeric() %>% density() %>% plot(type = "h", col = 4, ann = FALSE) # main被屏蔽
ht_weight_df %>% subset(Gender == "Female") %>% select(Height) %>% unlist() %>% as.numeric() %>% density() %>% lines(col = 2)
title(main = "Height By Gender")
abline(col = c(1, 2),lty = 3,v = c(mean(ht_weight_df %>% subset(Gender == "Male") %>% select(Height) %>% unlist()),mean(ht_weight_df %>% subset(Gender == "Female") %>% select(Height) %>% unlist())))
ht_weight_df %>% ggplot(aes(x = Height, colour = Gender)) + geom_density()
ht_weight_df %>% ggplot(aes(sample = Height)) + geom_point(stat = "qq") + facet_wrap(~Gender) # stat_qq requires sample# 分类数据线性拟合
ht_weight_df %>% ggplot(aes(x = Height, y = Weight, colour = Gender)) +geom_point(alpha = 0.2) + geom_smooth(method = "lm", formula = y ~ x)
lm_ht_wt_by_gender <- lm(Weight ~ Height * Gender, data = ht_weight_df)
lm_ht_wt_by_gender %>% summary()
- 如果观察人的一生,身高、体重的变化曲线,会是什么样的呢?
R语言 多元线性回归 研究年龄、身高、体重的关系相关推荐
- R语言 —— 多元线性回归
一.模型简介 一元线性回归是一个主要影响因素作为自变量来解释因变量的变化,在现实问题研究中,因变量的变化往往受几个重要因素的影响,此时就需要用两个或两个以上的影响因素作为自变量来解释因变量的变化,这就 ...
- R语言——多元线性回归
1.多元线性回归模型 1.1多元回归模型与多元回归方程 设因变量为y,k个自变量分别为,描述因变量y如何依赖于自变量和误差项ε的方程称为多元回归模型.其一般形式可表示为: 式中,为模型的参数,ε为随机 ...
- R语言多元线性回归模型分析 习题
一. 要了解学校毕业生起始工资的变化是否能用学生的平均成绩点数(GPA)和毕业生的年年来解释.下表为某学校办公室提供的样本数据. 二.研究货运总量(万吨)与工业总产值x1(亿元),农业总产值x2(亿元 ...
- 机器学习与R语言 多元线性回归insurance.R:保险费
insurance <- read.csv("insurance.csv", stringsAsFactors = TRUE) str(insurance)#既然因变量是ch ...
- 多元线性回归分析c语言,多元线性回归公式推导及R语言实现
多元线性回归 多元线性回归模型 实际中有很多问题是一个因变量与多个自变量成线性相关,我们可以用一个多元线性回归方程来表示. 为了方便计算,我们将上式写成矩阵形式: Y = XW 假设自变量维度为N W ...
- R语言多元(多变量)GARCH :GO-GARCH、BEKK、DCC-GARCH和CCC-GARCH模型和可视化
全文链接:http://tecdat.cn/?p=30647 从Engle在1982发表自回归条件异方差(ARCH)模型的论文以来,金融时间序列数据的波动性就倍受关注.同时,近几年又出现了研究股票市场 ...
- R语言计算线性回归的最小二乘估计
R语言计算线性回归的最小二乘估计 全称:线性回归的最小二乘法(OLS回归),ordinary least square,字面翻译:普通最小平方: 内容:包括三个部分:简单线性回归.多项式回归.多元线性 ...
- R语言使用线性回归模型来预测(predict)单个样本的目标值(响应值、response)实战
R语言使用线性回归模型来预测(predict)单个样本的目标值(响应值.response)实战 目录
- R语言基于线性回归(Linear Regression)进行特征筛选(feature selection)
R语言基于线性回归(Linear Regression)进行特征筛选(feature selection) 对一个学习任务来说,给定属性集,有些属性很有用,另一些则可能没什么用.这里的属性即称为&qu ...
最新文章
- 笨方法学python3怎么样_抖音笨李白是什么歌 抖音笨李白歌曲歌词介绍
- xsi:schemaLocation有何作用
- 2021 年 Angular vs. React vs. Vue 前端框架对比
- Mysql报too many connections详解
- 方阵的迹(trace)及其微分(导数)
- 安装Ubuntu系统后的配置工作
- osx86 10.4.3 BF1118 的界面
- Java基础之集合篇(内容超详细,带你轻松搞懂List、Set和Map的使用)
- 苹果开发者账号注册、管理注意事项
- “欢迎来到智能城市,我是小武”
- hdfs误删文件恢复教程
- android 锁屏界面 sim卡,注意!手机的这个密码比锁屏密码更重要,赶紧设置!攻略→...
- 【面试题】将ip地址转换成整数
- 数据分析-深度学习Day5
- 【科学文献计量】中英文文献标题及摘要可读性指标分析与可视化
- 【环境搭建】手把手教你安装Ubuntu16.04系统
- inux常用命令-持续更新中(转载:小牛导航,super-nb)
- 人生算法第一天心得总结(A)九段进阶(3-6)
- 【高级数理统计R语言学习】5 协方差分析
- 小程序 项目文件夹命名导致的Bug
热门文章
- 艾永亮超级产品:企业做竞品分析的三大方向
- 开源项目学习方法ABC
- 涌html编写星空图,canvas实现十二星座星空图
- php聊天室系统实验报告,PHP聊天室技术
- 空气净化器的新思路:将植物养在机器里
- JAVA代码—算法基础:拨号键盘的字母组合问题
- SQL 之 HAVING
- html 绘制正方形,HTML5之Canvas画正方形
- JAVA数轴分界含义,1.程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。 用JAVA 谢谢 每部要有注释求大...
- 在 Oracle sql developer导入样例表数据上 运行脚本