我是R和统计学的新手,并且无法弄清楚如何在运行多元线性回归后绘制预测值与实际值的关系.我遇到过类似的问题(只是无法理解代码).如果您解释一下代码,我将不胜感激.这是我到目前为止所做的:
# Attach file containing variables and responses
q <- read.csv("C:/Users/A/Documents/Design.csv")
attach(q)
# Run a linear regression
model <- lm(qo~P+P1+P4+I)
# Summary of linear regression results
summary(model)
Run Code Online (Sandbox Code Playgroud)
预测与实际的关系是如此,我可以用图形方式看出我的回归在我的实际数据中的适合程度.
我正在尝试创建一个带有多个选项卡的闪亮应用程序。每个选项卡都有自己的侧边栏。我还没能让它发挥作用。任何有关错误的帮助将不胜感激。下面是代码
ui <- fluidPage(
titlePanel("Hi"),
sidebarLayout(position = "left",
sidebarPanel(
conditionalPanel(condition = "input.tabs1==1",
selectizeInput('invar',"Reg in", choices = varnames, multiple = TRUE)),
conditionalPanel(condition = "input.tabs1==2",
selectizeInput('outvar',"Reg out", choices = predictors, multiple = FALSE)),
),
mainPanel(
tabsetPanel(id="tabs1",
tabPanel("input",value=1,plotOutput("Input"),
tabPanel("output",value=2,plotOutput("Output")
))))
))
Run Code Online (Sandbox Code Playgroud) 我在从 Shiny 中的反应式创建数据框时遇到问题。该应用程序允许用户上传一些数据,因此数据集是反应性的。然后,它允许用户选择输入和输出变量,这些变量将传递到回归中并生成图。我不断收到一条错误消息:
Error in as.data.frame.default: cannot coerce class "c("reactiveExpr", "reactive")" to a data.frame
Run Code Online (Sandbox Code Playgroud)
我相信它来自我的 df 变量,它应该是用户上传数据的数据框。在搜索互联网后,我无法确保解决方法。任何帮助,将不胜感激。到目前为止的代码如下。
library(shiny)
library(triangle)
library(readxl)
library(leaps)
library(coefplot)
library(relaimpo)
library(data.table)
library(XLConnect)
library(xlsx)
ui <- fluidPage(
titlePanel("Hi"),
sidebarLayout(position = "left",
sidebarPanel(
conditionalPanel(condition = "input.tabs1==1",
tags$style(type='text/css', ".well { max-width: 20em; }"),
# Tags:
tags$head(
tags$style(type="text/css", "select[multiple] { width: 100%; height:10em}"),
tags$style(type="text/css", "select { width: 100%}"),
tags$style(type="text/css", "input { width: 19em; max-width:100%}")
),
# Select filetype:
selectInput("readFunction", "Function to read data:", c(
# Base R:
"read.table",
"read.csv",
"read.csv2",
"read.delim", …Run Code Online (Sandbox Code Playgroud) 我有缺失值的数据框:
import pandas as pd
data = {'Brand':['residential','unclassified','tertiary','residential','unclassified','primary','residential'],
'Price': [22000,25000,27000,"NA","NA",10000,"NA"]
}
df = pd.DataFrame(data, columns = ['Brand', 'Price'])
print (df)
Run Code Online (Sandbox Code Playgroud)
导致此数据框:
Brand Price
0 residential 22000
1 unclassified 25000
2 tertiary 27000
3 residential NA
4 unclassified NA
5 primary 10000
6 residential NA
Run Code Online (Sandbox Code Playgroud)
我想用固定值(住宅=1000,未分类=2000)在价格列中填写住宅和未分类的缺失值,但是我不想丢失住宅或未分类价格列中已经存在的任何值,所以输出应该是这样的:
Brand Price
0 residential 22000
1 unclassified 25000
2 tertiary 27000
3 residential 1000
4 unclassified 2000
5 primary 10000
6 residential 1000
Run Code Online (Sandbox Code Playgroud)
完成这项工作的最简单方法是什么