【原创】r语言房价回归分析代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
data=read.table("data.txt",header=T)
head(data)
## case Taxes Beds Baths New Price Size
## 1 1 3104 4 2 0 279900 2048
## 2 2 1173 2 1 0 146500 912
## 3 3 3076 4 2 0 237700 1654
## 4 4 1608 3 2 0 200000 2068
## 5 5 1454 3 3 0 159900 1477
## 6 6 2997 3 2 1 499900 3153
# A. Please open the dataset, omit any missing values, and name it myda ta.
mydata=na.omit(data)
# B
plot(mydata[,-1])
# C. Using -ggplot- suite
colnames(mydata)
## [1] "case""Taxes""Beds""Baths""New""Price""Size"
library(ggplot2)
ggplot(mydata, aes(x = Size, y = Price)) + geom_point(aes( )) +
geom_smooth()
ggplot(mydata, aes(x = Taxes, y = Price)) +
geom_point(aes( )) +
geom_smooth()
# D. Do your visualizations show a positive, negative,
# or no relationship?
# E. Is there evidence that you may need to transform any of your varia bles? Why? Motivate
# your answer by showing any relevant statistics or graphs
ggplot(mydata, aes(x =(Size) , y =log(Price))) +
geom_point(aes( )) +
geom_smooth()
ggplot(mydata, aes(x = (Taxes), y =log(Price))) + geom_point(aes( )) +
geom_smooth()