
数据缺失必须被优先处理。如果是缺失的很少很少,无伤大雅,那么直接删了也没问题。除此之外,应该想办法补上它,i.e. 预测。
Little和Ruth(1987)把数据缺失的机制分为三类:
完全随机缺失(missing completely at random, MCAR)
所缺失的数据是完全随机的,缺失发生的概率既与已观察到的数据无关,也与未观察到的数据无关。这是一种比较理想的情况。
随机缺失(missing at random, MAR)
数据的缺失不是完全随机的。缺失数据发生的概率与所观察到的变量是有关的,而与未观察到的数据的特征是无关的。这是一个比较严重的问题,在这种情况下,我们需要进一步检查数据收集过程,并尝试了解数据为什么丢失。 例如,如果在一项问卷调查中,大多数人没有回答某个问题,他们为什么这么做,是问题不清楚吗?
不可忽略的缺失(non-ignorable missing ,NIM)
亦称为非随机缺失(not missing at random, NMAR),也有研究者将其称为MNAR(missing not at random)。 缺失数据不仅依赖于其它变量,又依赖于变量本身,这种缺失即为不可忽略的缺失。
一般MAR碰见多一些。在R语言中,非常容易搞定。只需要用mice库。更多应用请参考帮助文档。 http://www.stefvanbuuren.nl/publications/MICE%20V1.0%20Manual%20TNO00038%202000.pdf
mice是链式方程多元插值的简写(Multivariate Imputation by Chained Equations)。R中有个同名包提供了多种先进的缺失值处理方法。它使用一种颇不常见的方法来进行两步插值:先利用mice函数建模再用complete函数生成完整数据。效果非常的好,令人惊讶。 注意mice库假设数据缺失为MAR。
下面的程序使用mice库自带的数据nhanes
这篇文章 https://datascienceplus.com/imputing-missing-data-with-r-mice-package/ 讨论了更多mice库的应用,但是最基础的也就是这些了。
去掉TextField后的程序,这个程序是要用到repaint()的,具体请参考程序中的注释位置:import java.awt.*
import java.awt.event.*
class mCar extends Frame{
Color redColor
int xl=80,yl=80,speed=10,step=5/*********注意这里***********/
public mCar(){
addKeyListener(new KeyAdapter(){ /*********注意这里***********/
public void keyPressed(KeyEvent e){
if(e.getKeyCode()== KeyEvent.VK_UP){
System.out.println("\n Go Up")
yl-=speed/*********注意这里***********/
}
else if(e.getKeyCode()== KeyEvent.VK_DOWN){
System.out.println("\n Go Down")
yl+=speed/*********注意这里***********/
}
else if(e.getKeyCode()== KeyEvent.VK_LEFT){
System.out.println("\n Go Left")
xl-=speed/*********注意这里***********/
}
else if(e.getKeyCode()== KeyEvent.VK_RIGHT){
System.out.println("\n Go Right")
xl+=speed/*********注意这里***********/
}
else if(e.getKeyCode()== KeyEvent.VK_F1){
speed+=step/*********注意这里***********/
System.out.println("\n Speed Up")
}
else if(e.getKeyCode()== KeyEvent.VK_F2){
System.out.println("\n Speed Down")
speed-=step/*********注意这里***********/
}
else
System.out.println(e.getKeyChar())
repaint()/*********注意这里***********/
}
}
)
setSize(400,300)
setVisible(true)
setLocation(400,200)
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose()
System.exit(0)
}
}
)
}
public void paint(Graphics g){
g.setColor(Color.GREEN)
g.fillRect(xl, yl, 40, 40)/*********注意这里***********/
}
}
public class miniCar {
public static void main(String[] args){
new mCar()
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)