Message Boards Message Boards

0
|
5715 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Fit a linear model in Mathematica ?

Posted 9 years ago

Hi everyone.I need someone to help me derive the wolfram mathematica from this.

salary=c(1000,12000,12500,14000,15000,17000,25000,30000,50000) experience=c(2,3,4,6,8,10,12,14,15) lm(salary~experience)

Call: lm(formula = salary ~ experience)

Coefficients: (Intercept) experience
-1693 2591

summary(lm(salary~experience))

Call: lm(formula = salary ~ experience)

Residuals: Min 1Q Median 3Q Max -7217 -4399 -2489 3829 12828

Coefficients: Estimate Std. Error t value Pr(>|t|)
(Intercept) -1692.8 4728.5 -0.358 0.73089

experience 2591.0 503.4 5.147 0.00133 **

Signif. codes: 0 ‘*’ 0.001 ‘’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 6858 on 7 degrees of freedom Multiple R-squared: 0.791, Adjusted R-squared: 0.7611 F-statistic: 26.49 on 1 and 7 DF, p-value: 0.001329

y=2591x-1693+u

confint(lm(salary~experience,level=95)) 2.5 % 97.5 % (Intercept) -12873.931 9488.302 experience 1400.609 3781.427 plot(lm(salary~experience)) Hit <Return> to see next plot: Hit <Return> to see next plot: Hit <Return> to see next plot: Hit <Return> to see next plot: plot(salary,experience)

POSTED BY: irene mwei
3 Replies
Posted 9 years ago

The following will likely give you most of what you show above. The inline documentation has additional options.

salary = {1000, 12000, 12500, 14000, 15000, 17000, 25000, 30000, 50000};
experience = {2, 3, 4, 6, 8, 10, 12, 14, 15};
data = Table[{experience[[i]], salary[[i]]}, {i, Length[salary]}]
lm = LinearModelFit[data, x, x]
lm[{"ParameterTable", "RSquared", "AdjustedRSquared", "ANOVATable"}]

with output

Regression output

POSTED BY: Jim Baldwin
Posted 9 years ago

I'm assuming that your question is "How do I translate R code that fits a linear model into Mathematica?" If so, the LinearModelFit function is what you need.

POSTED BY: Jim Baldwin
Posted 9 years ago

Thanks for your reply.my professor send a file in java and clearly I dont really understand how to go about.I have really tried but I have not managed.

POSTED BY: irene mwei
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract