This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
demanda=read.csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vRvpWjqkQ08tzZzgzCwdnxeEVaZqcVe64M0611kxVzZ2VsRtYz3ggbkhm597o0MWmYZh_KaZ2XNZQHj/pub?output=csv")
colnames(demanda)=c("fecha","sexo","edad","si o no", "12","15","18","21","24","27","30","33","35")
names(demanda)
## [1] "fecha" "sexo" "edad" "si o no" "12" "15" "18"
## [8] "21" "24" "27" "30" "33" "35"
library(tidyr)
df.long=gather(demanda,key = "precio", value = "cantidades",5:13)
class(df.long$precio)
## [1] "character"
class(df.long$cantidades)
## [1] "integer"
df.long$precio=as.numeric(df.long$precio)
attach(df.long)
regl=lm(cantidades~precio,data = df.long)
summary(regl)
##
## Call:
## lm(formula = cantidades ~ precio, data = df.long)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.672 -4.508 -2.695 -0.893 93.119
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 10.83629 1.88054 5.762 1.55e-08 ***
## precio -0.26366 0.07504 -3.514 0.000487 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 12.06 on 448 degrees of freedom
## Multiple R-squared: 0.02682, Adjusted R-squared: 0.02465
## F-statistic: 12.35 on 1 and 448 DF, p-value: 0.0004867
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.