lm中的错误(Sales~Discount,data = dtsample2):未使用的参数(data = dtsample2)

时间:2017-09-21 13:29:46

标签: r lm

执行以下线性回归时,会引发以下错误。变量在数据集中是数字。

dtsample2 <- read.csv("dtsample2.csv")
gt <- lm(Sales ~ Discount, data = dtsample2)
  

lm(Sales~Discount,data = dtsample2)出错:未使用的参数   (data = dtsample2)

请在下面找到会话信息。

sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
 [1] tcltk     stats4    grid      splines   stats     graphics  grDevices utils     datasets  methods  
[11] base     

other attached packages:
 [1] RcmdrPlugin.FuzzyClust_1.1 FactoMineR_1.36            RcmdrPlugin.EZR_1.35      
 [4] Hmisc_4.0-3                Formula_1.2-2              xtable_1.8-2              
 [7] forecast_8.1               xts_0.10-0                 zoo_1.8-0                 
[10] tseries_0.10-42            TeachingDemos_2.10         RcmdrPlugin.EcoVirtual_1.0
[13] EcoVirtual_1.0             RcmdrPlugin.EBM_1.0-10     epiR_0.9-87               
[16] RcmdrPlugin.EACSPIR_0.2-2  reshape_0.8.6              nortest_1.0-4             
[19] ez_4.4-0                   abind_1.4-5                R2HTML_2.3.2              
[22] RcmdrPlugin.doex_0.2.0     RcmdrPlugin.DoE_0.12-3     relimp_1.0-5              
[25] DoE.wrapper_0.8-10         rsm_2.8                    FrF2_1.7-2                
[28] DoE.base_0.30              conf.design_2.0.0          RcmdrPlugin.depthTools_1.3
[31] depthTools_0.4             RcmdrPlugin.coin_1.0-22    multcomp_1.4-6            
[34] TH.data_1.0-8              mvtnorm_1.0-6              coin_1.2-0                
[37] survival_2.41-3            biclust_1.2.0              colorspace_1.3-2          
[40] MASS_7.3-47                RcmdrPlugin.BCA_0.9-8      flexclust_1.3-4           
[43] modeltools_0.2-21          lattice_0.20-35            BCA_0.9-3                 
[46] Rcmdr_2.3-2                RcmdrMisc_1.0-5            sandwich_2.3-4            
[49] car_2.1-5                  ggthemes_3.4.0             ggplot2_2.2.1             
[52] e1071_1.6-8                dplyr_0.7.1                rJava_0.9-8               
[55] ModelMetrics_1.1.0         lme4_1.1-13                arules_1.5-2              
[58] Matrix_1.2-10              ROCR_1.0-7                 gplots_3.0.1              
[61] RSQLite_2.0               

loaded via a namespace (and not attached):
 [1] stringr_1.2.0                gdata_2.18.0                 gtools_3.5.0                
 [4] bindrcpp_0.2                 rlang_0.1.1                  htmlTable_1.9               
 [7] iterators_1.0.8              mgcv_1.8-17                  blob_1.1.0                  
[10] bitops_1.0-6                 base64enc_0.1-3              quantreg_5.33               
[13] reshape2_1.4.2               R6_2.2.2                     bit_1.1-12                  
[16] clue_0.3-53                  plyr_1.8.4                   tkrplot_0.0-23              
[19] stringi_1.1.5                tcltk2_1.2-11                BsMD_2013.0718              
[22] rpart.plot_2.1.2             munsell_0.4.3                vcd_1.4-3                   
[25] MatrixModels_0.4-1           ggthemr_1.1.0                htmlwidgets_0.9             
[28] leaps_3.0                    quadprog_1.5-5               quantmod_0.4-10             
[31] pbkrtest_0.4-7               DBI_0.7                      memoise_1.1.0               
[34] bindr_0.1                    foreign_0.8-69               pkgconfig_2.0.1             
[37] BiasedUrn_1.07               tools_3.4.1                  acepack_1.4.1               
[40] SparseM_1.77                 clv_0.3-2.1                  cluster_2.0.6               
[43] compiler_3.4.1               assertthat_0.2.0             caTools_1.17.1              
[46] igraph_1.0.1                 gtable_0.2.0                 RcmdrPlugin.epack_1.2.5     
[49] glue_1.1.1                   readxl_1.0.0                 digest_0.6.12               
[52] RColorBrewer_1.1-2           knitr_1.16                   doParallel_1.0.10           
[55] htmltools_0.3.6              KernSmooth_2.23-15           DiceDesign_1.7              
[58] data.table_1.10.4            lmtest_0.9-35                foreach_1.4.3               
[61] sfsmisc_1.1-1                flashClust_1.01-2            RcmdrPlugin.FactoMineR_1.6-0
[64] fracdiff_1.4-2               backports_1.1.0              lazyeval_0.2.0              
[67] magrittr_1.5                 AlgDesign_1.1-7.3            checkmate_1.8.3             
[70] estimability_1.2             minqa_1.2.4                  timeDate_3012.100           
[73] Rcpp_0.12.12                 coda_0.19-1                  bit64_0.9-7                 
[76] scales_0.4.1                 TTR_0.23-2                   lsmeans_2.26-3              
[79] nloptr_1.0.4                 combinat_0.0-8               tibble_1.3.3                
[82] latticeExtra_0.6-28          RcmdrPlugin.Export_0.3-1     cellranger_1.1.0            
[85] nnet_7.3-12                  codetools_0.2-15             curl_2.7                    
[88] gridExtra_2.2.1              nlme_3.1-131                 class_7.3-14                
[91] parallel_3.4.1               lhs_0.14                     rpart_4.1-11                
[94] scatterplot3d_0.3-40        

1 个答案:

答案 0 :(得分:0)

之所以可能发生,是因为您自己定义了较早的自定义lm函数,并且/或者某些具有特定lm定义的软件包已覆盖base::lm

  • 您可以呼叫rm(list = ls())并重新启动R会话以 避免这种行为。
  • 或者您可以调用gt <- base::lm(Sales ~ Discount, data = dtsample2)lm包中调用base,并具有所需的功能。

请查看示例如何发生:

lm <- function(x) {
  0
}

lm(x ~ y, data = df)
# Error in lm(x ~ y, data = df) : unused argument (data = df)