YouTip LogoYouTip

R Func Lm

# Fit linear model model <- lm(sales ~ ad_spend) # View model summary print(summary(model)) # Predict new data new_spend <- data.frame(ad_spend = c(17, 23)) predictions <- predict(model, new_spend) print(paste("Predicted Sales:", predictions))

Executing the above code outputs:

Call:
lm(formula = sales ~ ad_spend)

Residuals:
    Min      1Q  Median      3Q     Max 
-4.3780 -1.5831 -0.4329  1.8202  4.9347 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  17.1622     3.4394   4.990  0.00106 ** 
ad_spend      3.0623     0.1933  15.839 2.42e-07 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2.829 on 8 degrees of freedom
Multiple R-squared:  0.9691,	Adjusted R-squared:  0.9652 
F-statistic: 250.9 on 1 and 8 DF,  p-value: 2.422e-07

 "Predicted Sales: 69.2218150385764 87.5953501640316"

R-squared is 0.9691, indicating that advertising spend can explain approximately 97% of the variation in sales.

Image 4: R Language Examples R Language Examples

← R Func MapplyR Func Library β†’