R语言代做编程辅导M3S2 Spring – Assessed Coursework:linear model(附答案)

For this coursework you are required to download a dataset personal to you. 

dataset is available at:

由LE PHUONG撰写

http://wwwf.imperial.ac.uk/~fdl06/M3S2_cw_2015/.RData
where you must replace with your CID number. Any problems, email me. This
dataset contains a dataframe called mydat | it consists of a response y and 3 columns of

covariates x1, x2 and x3. Be aware!

×

现在提到了代写服务,肯定很多人都不会觉得陌生,就算是国内也是有着专业代写作业的服务行业的,能够为有需求的学生提供很多的帮助,不过其实代写机构在国外会更获得学生的支持,这是因为国外的学校对于平时的作业要求比较严格,为了获得更高的分数顺利毕业,不少留学生就会让代写机构帮忙完成作业,比较常见的作业代写类型,就是计算机专业了,因为对于留学生来说这个技术对于Machine Learning或者AI的代码编程要求更高,所以找代写机构完成作业会简单轻松很多,那么代写机构的水平,要怎么选择才会比较高?

1、代写机构正规专业

不论是在什么情况下,选择正规合法经营的机构肯定是首要的操作,这也是为了避免自己在找机构的时候,出现上当受骗的现象,造成自己的经济出现损失,带来的影响还是非常大的,所以需要注意很多细节才可以,所以在这样的情况下,代写机构的选择,也要选择在经营方面属于正规合法的类型,这样才可以保证服务进行的时候,不会出现各种问题,也可以减少损失的出现,而且正规合法也是代写机构的合格基础。

2、代写机构编程能力

作业的难度相信很多人都很熟悉,特别是对于AI深度学习或者是人工神经网络这种算法来说,因为要对SVM、Design Tree、线性回归以及编程有很高的要求,可以说作业的完成要求非常高,因此才会带动代写机构的发展,找专业的代写机构,一般都是会有专业的人员帮忙进行作业的完成,因为这类型的作业对专业要求比较高,因此代写机构也要具备专业能力才可以,否则很容易导致作业的完成出现问题,出现低分的评价。

3、代写机构收费情况

现在有非常多的留学生,都很在意作业的完成度,为了保证作业可以顺利的被完成,要进行的相关操作可是非常多的,代写机构也是因为如此才会延伸出来的,在现在发展也很迅速,现在选择代写机构的时候,一定要重视收费情况的合理性,因为代写作业还是比较费精力的,而且对于专业能力要求也高,所以价格方面一般会收取几千元至万元左右的价格,但是比较简单的也只需要几百元价格。

4、代写机构完成速度

大部分人都很在意代写机构的专业能力,也会很关心要具备什么能力,才可以展现出稳定的代写能力,其实专业的代写机构,对于作业完成度、作业完成时间、作业专业性等方面,都是要有一定的能力的,特别是在完成的时间上,一定要做到可以根据客户规定的时间内完成的操作,才可以作为合格专业的代写机构存在,大众在选择的时候,也可以重视完成时间这一点来。

现在找专业的CS代写机构帮忙完成作业的代写,完全不是奇怪的事情了,而且专业性越强的作业,需要代写机构帮忙的几率就会越高,代写就发展很好,需求量还是非常高的,这也可以很好的说明了,这个专业的难度以及专业性要求,才可以增加代写机构的存在。



Q1) (a) In R fit the normal linear model with:

image.png

Based upon the summary of the model, do you think that the model fits the data
well? Explain your reasoning using the values reported in the R summary | but
do not include the whole summary in your report.
(b) Perform a hypothesis test to ascertain whether or not to include the intercept
term | use a 5% significance level. Include your code.
(c) Conduct a hypothesis test comparing the models:
E(Y ) = β1 against E(Y ) = β1 + β2×2 + β3×3 + β4×4
as a 5% level. Include your code.
(d) By inspecting the leverages and residuals, identify any potential outliers. Name
these data points by their index number. Give your reasoning as to why you

hree plots if necessary

   mod=lm(y~x1+x2+x3,data=mydat)

summary(mod) 

believe these are potential outliers. You may present up to t

image.png
从残差值来看,拟合模型的预测值与实际数值差值较小,因此模型拟合较好。

image.png


常数项,x1,x2的p值均小于0.05,说明以上变量对y均有显著的影响。
image.png
从R-square值来看,该模型的拟合程度仍有提高的空间。

python岭回归、Lasso、随机森林、XGBoost、Keras神经网络、kmeans聚类链家租房数据地理可视化分析

阅读文章


B)#b.r

    mod2=lm(y~x1+x2+x3-1,data=mydat)#删除常数项

t.test(mod2$fitted.values,mod$fitted.values,conf.level=0.95)
image.png


随时关注您喜欢的主题


从检验结果来看,在5%的显著性水平上可以看到两个模型存在差异。


image.png

和模型1的拟合结果相比可以发现去除常数项后,模型2的R-squre要大于模型1,即拟合程度要好于模型1.


C)#c.r

    mod3=lm(y~1)

summary(mod3)
image.png
image.png
可以发现包含常数项和仅包含常数项的两个模型非常相似。P值大于0.05,因此可以接受原假设,即这两个模型是相似的。

D)#d.r

image.png
可以发现第6,57,38个样本的预测值与实际样本值的标准残差要大于其他值,因此可以认为6,57,38个样本为离群点。



image.png
可以看到底38,101个样本对cook距离的值产生了较大的影响,明显不同与其他样本。因此

可以认为第38和101个样本对模型产生了影响,因此可以认为是离群点。

image.png

Q2) We shall now consider a GLM with a Gamma response distribution.
(a) Show that a random variable Y where Y follows a Gamma distribution with
probability density function:

image.png
image.png
(c) Rewrite (by \hand") the IWLS algorithm (similar to Algorithm 3.1 in notes on  

page 38) specifically for the Gamma response and using the link:

image.png
This is called the inverse link function.  

Continue to use the inverse link function for the remainder of the
questions.
(d) Write the components of the total score U1; : : : ; Up and the Fisher information
matrix for this model.
(e) Given the observations y, what is a sensible initial guess to begin the IWLS
algorithm in general?
(f) Manually write an IWLS algorithm to fit a Gamma GLM using your data, mydat,
using the inverse link and same linear predictor in Q1a). Use the deviance as the
convergence criteria and initial guess of β as (0:5; 0:5; 0:5; 0:5). Present your code
and along with your final estimate of β and final deviance.
(g) Based on your IWLS results, compute φbD and φbp and the estimates of var(βb2)

In R fit the model again with a Gamma response i.e.  

glm(y~x1+x2+x3,family=Gamma,data=mydat)
Note the capital G in Gamma. Verify the results with your IWLS results.
(h) Give a prediction for the response given by the model for x1= 13, x2= 5 x3= 0:255
and give a 91% confidence interval for this prediction. Include your code.
(i) Perform a hypothesis test between this model and another model with the same
link and response distribution but with linear predictor η where
ηi = β1 + β2xi1 + β3xi2 for i = 1; : : : ; n:
Use a 5% significance level. You may use the deviance function here. Include
your code.
(j) Using your IWLS results, manually compute the leverages of the observations for this model | present your code (but not the values) and plot the leverages
against the observation index number.
(k) Proceed to investigate diagnostic plots for your Gamma GLM. Identify any potential outliers | give your reasoning. Remove the most suspicious data point | you must remove 1 and only 1 | and refit the same model. Compare and
comment on the change of the model with and without this data point | you
may wish to refer to the relative change in the estimated coefficients. You may present up to three plots if necessary.

        
    x3 <- mydat$x3

X=cbind(1,x1,x2,x3)

ilogit <- function(u)

  1/(1+exp(-u))

D <- function(mu){#deviance函数

  a <- (y-mu)/mu

  b <- -log(y/mu)
image.png
image.png
       G)#g.r

 

eta = cbind(1,x1,x2,x3)%*%beta

mu=1/(eta)

z = eta+((y-mu)/(-mu^2)) #form the adjusted variate

w = mu^2 #weights
image.png
image.png
       
       H)#h.r

mod= glm(y~x1+x2+x3,family=Gamma,data=mydat)

 

  x1= 13
   pp=predict(mod, newdata=data.frame(x1,x2,x3), level = 0.91, int = 'p')#用估计的参数对样本点进行预测
   
   
   
image.png
       I)#i.r

mod2=lm(y~x1+x2,data=mydat)
image.png
   由于p值大于0.05,无法拒绝原假设H0,因此从deviance的差异度来看,可以认为两个模型并没有显著的差别。
   
   
   
       J)#j.r

plot(mod)

image.png
       K)#k.r

y1=exp(beta[1]+beta[2]*x1+beta[3]*x2+beta[4]*x3)
image.png
   从残差拟合情况图来看,第44,28,81号样本点的残差值较大,可能为异常点,其中81号样本与拟合值的残差是最大的。
   
   
   
image.png
   从正态分布qq图来看,大部分样本点分布在正态分布直线周围,可以认为样本点的总体服从正态分布。其中44,28,81号样本点里正态分布直线较远,因此可以认为其不符合正态分布,可能是离群点。

从残差leverage图来看,第57,101,40号样本具有较大的cook距离,即都对我们的预测值产生了较大的影响。

image.png
image.png
   计算这3个样本的leverage统计量,可以发现第44号样本的值大于其他连个样本,因此认为第44号样本为异常点,可以删去。

对比删去44号样本的模型和原来的模型

       mod2=lm(y~x1+x2+x3, family = Gamma,data=mydat1)

summary(mod2)
image.png
image.png

可以看到修改后的模型deviance residuals值减少了,不同变量对因变量的影响也更加显著,因此模型的拟合度提高。


关于分析师

在此对LE PHUONG对本文所作的贡献表示诚挚感谢,她在山东大学完成了计算机科学与技术专业的硕士学位,专注数据分析、数据可视化、数据采集等。擅长Python、SQL、C/C++、HTML、CSS、VSCode、Linux、Jupyter Notebook。

 
QQ在线咨询
售前咨询热线
15121130882
售后咨询热线
0571-63341498

关注有关新文章的微信公众号


永远不要错过任何见解。当新文章发表时,我们会通过微信公众号向您推送。

技术干货

最新洞察

This will close in 0 seconds