zoukankan      html  css  js  c++  java
  • longitudinal model

    1.读数据
        excel文件
            1.library(RODBC);z<-odbcConnectExcel("weather.xls");(w<-sqlFetch(z,"Sheet1"));odbcClose(z);
            选择文件:    data=odbcConnectExcel(file.choose());显示文件信息:sqlTables(data);
            2.文件另存为prn格式;w<-read.table("weather.prn",header=T)
            3.文件另存为csv格式:w<-read.csv("weather.prn",header=T)

        文本文件
            x=read.table("weather.txt");编辑文档edit(x);


    2.写文件
        write.table(w,file="e:\rtemp\weather.txt")

       
    3.longitudinal model
        建立模型
            mixed effects model:
                library(nlme)
                e.g:lme . fit1 <- lme ( distance ~age , data = Orthodont ,random = ~ age | Subject , method = "ML")

                lme.fit1<-lme(Pm~Temperature,data=w,random=~Temperature|Location,method="ML");summary(lme.fit1);
                lme.fit2<-update(lme.fit1,fixed=Pm~Temperature*Time);summary(lme.fit2);

                    lme.fit1=lme(logpm~Wind+Population+Green+Weather+Road+GDP+Temperature+Zone,data=w.dat,random=~GDP|Location,method="ML")


                模型比较
                    anova(lme.fit1,lme.fit2)
           
            Gee model:
                fit.gee1=gee(Pm~Zone,Location,data=w.dat);
                fit.gee2=gee(Pm~Zone,Location,data=w.dat,corstr="AR-M")
                fit.gee3=gee(Pm~Zone,Location,data=w.dat,corstr="exchangeable")
                fit.gee4=gee(Pm~Zone,Location,data=w.dat,corstr="unstructured")
               
                fit.gee1=gee(Pm~Wind+Population+Green+Weather+Road+GDP+Temperature+Zone,Location,data=w.dat)

    4.画图
        散点图
            attach(w);plot(Temperature,Pm);plot(z$Time,z$Pm,type="l")

            plot(z$Time,z$Pm,type="b");qqnorm(Pm)
            plot(w.dat$Time,w.dat$Pm,type="b")
    5.退出
        q()
        清屏:Ctrl+L

    6.分类数据
        Weather=1:3;Weather=factor(Weather);Location=1:20;Location=factor(Location); Time=1:7;Time=factor(Time);
    Zone=1:4;Zone=factor(Zone);


    lpm=log(Pm)
    w.dat=groupedData(Pm~GDP|Location,data=w);

    7.对残差进行分析:   
        plot(lme.fit3,resid(.,type="p")~fitted(.)|Zone,id=0.05,adj=-0.3)
        qqnorm(lme.fit3,~resid(.)|Zone)

  • 相关阅读:
    使用docker部署zabbix
    如何用好 IDEA ,Java 撸码效率至少提升 5 倍?
    getpass模块
    linux下利用nohup后台运行jar文件包程序
    Spring Cloud 与 Dubbo 区别
    git 打标签并推送tag到托管服务器
    git-stash用法小结
    git推送本地分支到远程分支
    Git dev分支合并到master分支完美实战
    IntelliJ远程调试教程
  • 原文地址:https://www.cnblogs.com/breece/p/3869826.html
Copyright © 2011-2022 走看看